Revision: 1315
Author:   mathiasbr
Date:     2006-08-19 15:35:44 -0700 (Sat, 19 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1315&view=rev

Log Message:
-----------
minor improvements

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/AbstractListBinding.java
Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/AbstractListBinding.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/AbstractListBinding.java
    2006-08-19 14:32:47 UTC (rev 1314)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/AbstractListBinding.java
    2006-08-19 22:35:44 UTC (rev 1315)
@@ -43,28 +43,20 @@
 
     private JComponent component;
 
-    final ReflectiveVisitorHelper visitor = new ReflectiveVisitorHelper();
+    final ReflectiveVisitorHelper visitorHelper = new 
ReflectiveVisitorHelper();
 
     private final SelectableItemsVisitor selectableItemsVisitor = new 
SelectableItemsVisitor();
 
     private Object selectableItems;
 
-    private Comparator comparator;
-
-    private Constraint filter;
-
     private final FilterConstraint filterConstraint = new FilterConstraint();
 
-    private final Observer filterObserver = new FilterObserver();
-
     private final BindingComparator bindingComparator = new 
BindingComparator();
 
     private ListModel bindingModel;
 
     private AbstractFilteredListModel filteredModel;
 
-    private final Observer comparatorObserver = new ComparatorObserver();
-
     public AbstractListBinding(JComponent component, FormModel formModel, 
String formPropertyPath,
             Class requiredSourceClass) {
         super(formModel, formPropertyPath, requiredSourceClass);
@@ -96,29 +88,15 @@
     }
 
     public final void setComparator(Comparator comparator) {
-        if (comparator != this.comparator || (comparator != null && 
!comparator.equals(this.comparator))) {
-            if (this.comparator instanceof Observable) {
-                ((Observable) 
this.comparator).deleteObserver(comparatorObserver);
-            }
-            this.comparator = comparator;
-            if (comparator instanceof Observable) {
-                ((Observable) this.comparator).addObserver(comparatorObserver);
-            }
-            comparatorChanged();
-        }
+        bindingComparator.setComparator(comparator);
     }
 
+    public Comparator getComparator() {
+        return bindingComparator.getComparator();
+    }
+
     public final void setFilter(Constraint filter) {
-        if (filter != this.filter || (filter != null && 
!filter.equals(this.filter))) {
-            if (this.filter instanceof Observable) {
-                ((Observable) this.filter).deleteObserver(filterObserver);
-            }
-            this.filter = filter;
-            if (filter instanceof Observable) {
-                ((Observable) this.filter).addObserver(filterObserver);
-            }
-            filterChanged();
-        }
+        filterConstraint.setFilter(filter);
     }
 
     protected final JComponent doBindControl() {
@@ -128,14 +106,6 @@
 
     protected abstract void doBindControl(ListModel bindingModel);
 
-    protected void filterChanged() {
-        filterConstraint.filterChanged();
-    }
-
-    protected void comparatorChanged() {
-        bindingComparator.comparatorChanged();
-    }
-
     protected void selectableItemsChanged() {
         if (filteredModel != null) {
             filteredModel.setFilteredModel(createModel());
@@ -143,7 +113,7 @@
     }
 
     protected ListModel createModel() {
-        return (ListModel) visitor.invokeVisit(selectableItemsVisitor, 
selectableItems);
+        return (ListModel) visitorHelper.invokeVisit(selectableItemsVisitor, 
selectableItems);
     }
 
     protected AbstractFilteredListModel getFilteredModel() {
@@ -168,12 +138,36 @@
         return new FilteredListModel(model, constraint);
     }
 
-    protected class SelectableItemsVisitor {
+    /**
+     * Converts the given object value into the given targetClass
+     * 
+     * @param value
+     *            the value to convert
+     * @param targetClass
+     *            the target class to convert the value to
+     * @return the converted value
+     * 
+     * @throws ConversionException
+     *             if the value can not be converted
+     */
+    protected Object convertValue(Object value, Class targetClass) throws 
ConversionException {
+        Assert.notNull(value);
+        Assert.notNull(targetClass);
+        return getConversionService().getConversionExecutor(value.getClass(), 
targetClass).execute(value);
+    }
 
+    protected abstract ListModel getDefaultModel();
+
+    public Constraint getFilter() {
+        return filterConstraint.getFilter();
+    }
+
+    class SelectableItemsVisitor {
+
         ListModel visit(ValueModel valueModel) {
             Assert.notNull(valueModel.getValue(),
                     "value of ValueModel must not be null. Use an empty 
Collection or Array");
-            ListModel model = (ListModel) visitor.invokeVisit(this, 
valueModel.getValue());
+            ListModel model = (ListModel) visitorHelper.invokeVisit(this, 
valueModel.getValue());
             return new ValueModelFilteredListModel(model, valueModel);
         }
 
@@ -186,7 +180,7 @@
         }
     }
 
-    protected class ValueModelFilteredListModel extends 
AbstractFilteredListModel implements PropertyChangeListener {
+    class ValueModelFilteredListModel extends AbstractFilteredListModel 
implements PropertyChangeListener {
 
         private final ValueModel valueModel;
 
@@ -197,41 +191,15 @@
         }
 
         public void propertyChange(PropertyChangeEvent evt) {
-            setFilteredModel((ListModel) 
visitor.invokeVisit(selectableItemsVisitor, valueModel.getValue()));
+            setFilteredModel((ListModel) 
visitorHelper.invokeVisit(selectableItemsVisitor, valueModel.getValue()));
         }
 
     }
 
-    public Comparator getComparator() {
-        return comparator;
-    }
+    class FilterConstraint extends Observable implements Constraint, Observer {
 
-    /**
-     * Converts the given object value into the given targetClass
-     * 
-     * @param value
-     *            the value to convert
-     * @param targetClass
-     *            the target class to convert the value to
-     * @return the converted value
-     * 
-     * @throws ConversionException
-     *             if the value can not be converted
-     */
-    protected Object convertValue(Object value, Class targetClass) throws 
ConversionException {
-        Assert.notNull(value);
-        Assert.notNull(targetClass);
-        return getConversionService().getConversionExecutor(value.getClass(), 
targetClass).execute(value);
-    }
+        private Constraint filter;
 
-    protected abstract ListModel getDefaultModel();
-
-    public Constraint getFilter() {
-        return filter;
-    }
-
-    private class FilterConstraint extends Observable implements Constraint {
-
         public boolean test(Object argument) {
             if (filter != null) {
                 return filter.test(argument);
@@ -239,20 +207,37 @@
             return true;
         }
 
-        public void filterChanged() {
+        public Constraint getFilter() {
+            return filter;
+        }
+
+        public void setFilter(Constraint filter) {
+            if (filter != this.filter || (filter != null && 
!filter.equals(this.filter))) {
+                if (this.filter instanceof Observable) {
+                    ((Observable) this.filter).deleteObserver(this);
+                }
+                this.filter = filter;
+                if (filter instanceof Observable) {
+                    ((Observable) this.filter).addObserver(this);
+                }
+                update();
+            }
+        }
+
+        public void update() {
             setChanged();
             notifyObservers();
         }
-    }
 
-    private class FilterObserver implements Observer {
-
         public void update(Observable o, Object arg) {
-            filterChanged();
+            update();
         }
     }
 
-    private class BindingComparator extends Observable implements Comparator {
+    class BindingComparator extends Observable implements Comparator, Observer 
{
+
+        private Comparator comparator;
+
         public int compare(Object o1, Object o2) {
             if (comparator != null) {
                 return comparator.compare(o1, o2);
@@ -260,17 +245,30 @@
             return 0;
         }
 
-        public void comparatorChanged() {
+        public void setComparator(Comparator comparator) {
+            if (comparator != this.comparator || (comparator != null && 
!comparator.equals(this.comparator))) {
+                if (this.comparator instanceof Observable) {
+                    ((Observable) this.comparator).deleteObserver(this);
+                }
+                this.comparator = comparator;
+                if (comparator instanceof Observable) {
+                    ((Observable) this.comparator).addObserver(this);
+                }
+                update();
+            }
+        }
+
+        public Comparator getComparator() {
+            return comparator;
+        }
+
+        void update() {
             setChanged();
             notifyObservers();
         }
 
-    }
-
-    private class ComparatorObserver implements Observer {
-
         public void update(Observable o, Object arg) {
-            comparatorChanged();
+            update();
         }
 
     }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to