From ad05c29ae05fe75dea65dfec54812af7d3178c21 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 16 Nov 2012 17:05:48 +0400 Subject: [PATCH] [by: cdr] IDEA-95008 Code Style | Arrangement: item appears if two rules are simultaneously deleted by deleting their components --- .../ArrangementMatchNodeComponentFactory.java | 50 ++++++++++++------- .../ArrangementMatchingRulesControl.java | 16 +++--- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java index 5f7e8d962050..5fa073fbbb21 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java @@ -88,18 +88,21 @@ public class ArrangementMatchNodeComponentFactory { ArrangementAnimationManager.Callback { - @NotNull private final StdArrangementMatchRule myRule; + @NotNull private final StdArrangementMatchRule myRule; + + @NotNull private Object myModelValue; private int myRow; RemoveAtomConditionCallback(@NotNull StdArrangementMatchRule rule) { myRule = rule; + myModelValue = myRule; } @Override public void consume(@NotNull ArrangementAtomMatchConditionComponent component) { ArrangementAtomMatchCondition condition = component.getMatchCondition(); ArrangementMatchingRulesModel model = myList.getModel(); - int i = getRuleIndex(); + int i = getModelIndex(); if (i < 0) { return; } @@ -108,7 +111,7 @@ public class ArrangementMatchNodeComponentFactory { ArrangementMatchCondition existingCondition = myRule.getMatcher().getCondition(); if (existingCondition.equals(condition)) { // We can't just remove an element at this time because that breaks last row rendering. - model.set(i, new DummyElement()); + model.set(i, myModelValue = new DummyElement()); } else { assert existingCondition instanceof ArrangementCompositeMatchCondition; @@ -116,13 +119,15 @@ public class ArrangementMatchNodeComponentFactory { operands.remove(condition); if (operands.isEmpty()) { // We can't just remove an element at this time because that breaks last row rendering. - model.set(i, new DummyElement()); + model.set(i, myModelValue = new DummyElement()); } else if (operands.size() == 1) { - model.set(i, new StdArrangementMatchRule(new StdArrangementEntryMatcher(operands.iterator().next()), myRule.getOrderType())); + myModelValue = new StdArrangementMatchRule(new StdArrangementEntryMatcher(operands.iterator().next()), myRule.getOrderType()); + model.set(i, myModelValue); } else if (ArrangementConstants.LOG_RULE_MODIFICATION) { LOG.info(String.format("Removed '%s' condition. Current rule state: %s", condition, myRule)); + myModelValue = myRule; } } @@ -132,37 +137,46 @@ public class ArrangementMatchNodeComponentFactory { @Override public void onAnimationIteration(boolean finished) { + refreshRow(); + if (myRow < 0) { + return; + } myList.repaintRows(myRow, myRow, finished); if (!finished) { return; } ArrangementMatchingRulesModel model = myList.getModel(); - boolean repaintToBottom = getRuleIndex() < 0; - if (repaintToBottom) { - Object removeCandidate = model.getElementAt(myRow); - if (removeCandidate instanceof DummyElement) { - model.removeRow(myRow); - } - } - - if (repaintToBottom && myRow < model.getSize()) { - myList.repaintRows(myRow, model.getSize() - 1, true); + if (myModelValue instanceof DummyElement) { + model.removeRow(myRow); } } - private int getRuleIndex() { + private void refreshRow() { + ArrangementMatchingRulesModel model = myList.getModel(); + if (myRow < 0 || myRow >= model.getSize()) { + myRow = getModelIndex(); + } + else { + Object o = model.getElementAt(myRow); + if (o != myModelValue) { + myRow = getModelIndex(); + } + } + } + + private int getModelIndex() { // We can't just use model.indexOf(myRule) because there is a possible case that the model contain equal // rules (rule1.equals(rule2) == true). That's why we have a helper method for search by reference identity. ArrangementMatchingRulesModel model = myList.getModel(); for (int i = 0, max = model.getSize(); i < max; i++) { - if (model.getElementAt(i) == myRule) { + if (model.getElementAt(i) == myModelValue) { return i; } } return -1; } } - + private static class DummyElement { @Override public String toString() { diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java index 166d67d9ab2d..8e93abd2c212 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchingRulesControl.java @@ -421,17 +421,19 @@ public class ArrangementMatchingRulesControl extends JBTable { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + if (isEditing() && getEditingRow() == row) { + return EMPTY_RENDERER; + } if (value instanceof ArrangementRepresentationAware) { return ((ArrangementRepresentationAware)value).getComponent(); } - if (!(value instanceof StdArrangementMatchRule)) { - return EMPTY_RENDERER; - } - - StdArrangementMatchRule rule = (StdArrangementMatchRule)value; ArrangementListRowDecorator component = myComponents.get(row); if (component == null) { + if (!(value instanceof StdArrangementMatchRule)) { + return EMPTY_RENDERER; + } + StdArrangementMatchRule rule = (StdArrangementMatchRule)value; ArrangementMatchConditionComponent ruleComponent = myFactory.getComponent(rule.getMatcher().getCondition(), rule, true); component = new ArrangementListRowDecorator(ruleComponent, ArrangementMatchingRulesControl.this); myComponents.set(row, component); @@ -441,7 +443,9 @@ public class ArrangementMatchingRulesControl extends JBTable { component.setRowIndex((myEditorRow >= 0 && row > myEditorRow) ? row : row + 1); component.setSelected(getSelectionModel().isSelectedIndex(row) || (myEditorRow >= 0 && row == myEditorRow - 1)); component.setBeingEdited(myEditorRow >= 0 && myEditorRow == row + 1); - component.setShowSortIcon(rule.getOrderType() == ArrangementEntryOrderType.BY_NAME); + boolean showSortIcon = value instanceof StdArrangementMatchRule + && ((StdArrangementMatchRule)value).getOrderType() == ArrangementEntryOrderType.BY_NAME; + component.setShowSortIcon(showSortIcon); return component.getUiComponent(); } }