cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ksen...@apache.org
Subject svn commit: r1332169 - in /cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/undo/JComboBoxUndoListener.java swing/ComboSelectionBinding.java
Date Mon, 30 Apr 2012 12:01:13 GMT
Author: kseniak
Date: Mon Apr 30 12:01:12 2012
New Revision: 1332169

URL: http://svn.apache.org/viewvc?rev=1332169&view=rev
Log:
Cayenne Internal(CAY-3) fixed excessive events added to undo list

Modified:
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java
    cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/ComboSelectionBinding.java

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java?rev=1332169&r1=1332168&r2=1332169&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java
(original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/JComboBoxUndoListener.java
Mon Apr 30 12:01:12 2012
@@ -29,6 +29,7 @@ import org.apache.cayenne.modeler.Applic
 public class JComboBoxUndoListener implements ItemListener {
 
     private Object deselectedItem;
+    private boolean isUserAction = true;
 
     public void itemStateChanged(ItemEvent e) {
         int stateChange = e.getStateChange();
@@ -38,16 +39,22 @@ public class JComboBoxUndoListener imple
                 deselectedItem = e.getItem();
                 break;
             case ItemEvent.SELECTED:
-
-                UndoManager undoManager = Application.getInstance().getUndoManager();
-                undoManager.addEdit(new JComboBoxUndoableEdit(
-                        (JComboBox) e.getSource(),
-                        deselectedItem,
-                        e.getItem(),
-                        this));
-
+                // don't add event to undo list, if it was just the default setting
+                if (isUserAction) {
+                    UndoManager undoManager = Application.getInstance().getUndoManager();
+                    undoManager.addEdit(new JComboBoxUndoableEdit((JComboBox) e
+                            .getSource(), deselectedItem, e.getItem(), this));
+                    
+                }
+                //set back to default value after the selecting new option
+                isUserAction = true;
                 break;
+
         }
 
     }
+
+    public void setIsUserAction(boolean isUserAction) {
+        this.isUserAction = isUserAction;
+    }
 }

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/ComboSelectionBinding.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/ComboSelectionBinding.java?rev=1332169&r1=1332168&r2=1332169&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/ComboSelectionBinding.java
(original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/swing/ComboSelectionBinding.java
Mon Apr 30 12:01:12 2012
@@ -23,11 +23,13 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.ItemListener;
 
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
 
 import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
+import org.apache.cayenne.modeler.undo.JComboBoxUndoListener;
 import org.apache.cayenne.validation.ValidationException;
 
 /**
@@ -90,6 +92,13 @@ public class ComboSelectionBinding exten
         modelUpdateDisabled = true;
         try {
             clear();
+            ItemListener[] listeners = comboBox.getItemListeners();
+            for (ItemListener itemListener : listeners) {
+                if (itemListener instanceof JComboBoxUndoListener) {
+                    //in order not to add event to undo list
+                    ((JComboBoxUndoListener) itemListener).setIsUserAction(false);
+                }
+            }
             if (value != null) {
                 this.comboBox.setSelectedItem(value.toString());
             }



Mime
View raw message