[by: cdr] IDEA-95008 Code Style | Arrangement: <empty rule> item appears if two rules are simultaneously deleted by deleting their components

This commit is contained in:
Denis.Zhdanov
2012-11-16 17:25:45 +04:00
parent 1da7f0de95
commit ad05c29ae0
2 changed files with 42 additions and 24 deletions
@@ -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() {
@@ -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();
}
}