Revision: 1237
Author:   peterdb
Date:     2006-07-26 02:17:26 -0700 (Wed, 26 Jul 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1237&view=rev

Log Message:
-----------
- added revert icon and revert message for DirtyIndicatorInterceptor
- made DirtyIndicatorInterceptor configurable through xml

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptor.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptorFactory.java
    
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/application/messages.properties
    
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/image/images.properties

Added Paths:
-----------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactory.java
    
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactoryTests.java
Added: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactory.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactory.java
                          (rev 0)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactory.java
  2006-07-26 09:17:26 UTC (rev 1237)
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.springframework.richclient.form.builder.support;
+
+import java.util.Arrays;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.binding.form.FormModel;
+import org.springframework.richclient.form.builder.FormComponentInterceptor;
+import 
org.springframework.richclient.form.builder.FormComponentInterceptorFactory;
+import org.springframework.util.Assert;
+
+/**
+ * <code>FormComponentInterceptorFactory</code> implementation that can 
include or
+ * exclude form models.
+ * 
+ * @author Peter De Bruycker
+ */
+public abstract class ConfigurableFormComponentInterceptorFactory implements 
FormComponentInterceptorFactory,
+        InitializingBean {
+    private String[] excludedFormModelIds;
+
+    private String[] includedFormModelIds;
+
+    /**
+     * Returns a <code>FormComponentInterceptor</code> for the given
+     * <code>FormModel</code>. Checks against the included and excluded
+     * <code>FormModel</code> ids.
+     * <p>
+     * If the excluded ids are specified and contain the given form model, 
returns
+     * <code>null</code>. <br>
+     * If the included ids are specified and don't contain the given form 
model, returns
+     * <code>null</code>. <br>
+     * 
+     * @param formModel the <code>FormModel</code>
+     * @return a <code>FormComponentInterceptor</code> for the given
+     *         <code>FormModel</code>
+     */
+    public final FormComponentInterceptor getInterceptor( FormModel formModel 
) {
+        // if excludedFormModelIds have been specified, use this to check if 
the
+        // form is excluded
+        if( excludedFormModelIds != null && Arrays.asList( 
excludedFormModelIds ).contains( formModel.getId() ) ) {
+            return null;
+        }
+
+        // if includedFormModelIds have been specified, use this to check if 
the
+        // form is included
+        if( includedFormModelIds != null && !Arrays.asList( 
includedFormModelIds ).contains( formModel.getId() ) ) {
+            return null;
+        }
+
+        // if we fall through, create an interceptor
+        return createInterceptor( formModel );
+    }
+
+    /**
+     * Returns a <code>FormComponentInterceptor</code> for the given
+     * <code>FormModel</code>.
+     * 
+     * @param formModel the <code>FormModel</code>
+     * @return the <code>FormComponentInterceptor</code>
+     */
+    protected abstract FormComponentInterceptor createInterceptor( FormModel 
formModel );
+
+    public void afterPropertiesSet() throws Exception {
+        Assert.state( excludedFormModelIds == null || includedFormModelIds == 
null,
+                "only one of excludedFormModelIds or includedFormModelIds can 
be given" );
+    }
+
+    /**
+     * Returns the excluded <code>FormModel</code> ids.
+     * 
+     * @return the excluded ids
+     */
+    public String[] getExcludedFormModelIds() {
+        return excludedFormModelIds;
+    }
+
+    /**
+     * Sets the excluded <code>FormModel</code> ids.
+     * <p>
+     * Either <code>excludedFormModelIds</code> or 
<code>includedFormModelIds</code>
+     * should be set.
+     * 
+     * @param excludedFormModelIds the excluded ids
+     */
+    public void setExcludedFormModelIds( String[] excludedFormModelIds ) {
+        this.excludedFormModelIds = excludedFormModelIds;
+    }
+
+    /**
+     * Returns the included <code>FormModel</code> ids.
+     * 
+     * @return the included ids
+     */
+    public String[] getIncludedFormModelIds() {
+        return includedFormModelIds;
+    }
+
+    /**
+     * Sets the included <code>FormModel</code> ids.
+     * <p>
+     * Either <code>excludedFormModelIds</code> or 
<code>includedFormModelIds</code>
+     * should be set.
+     * 
+     * @param includedFormModelIds the excluded ids
+     */
+    public void setIncludedFormModelIds( String[] includedFormModelIds ) {
+        this.includedFormModelIds = includedFormModelIds;
+    }
+}

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptor.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptor.java
    2006-07-26 06:34:27 UTC (rev 1236)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptor.java
    2006-07-26 09:17:26 UTC (rev 1237)
@@ -97,7 +97,7 @@
                     }
                 });
 
-        InterceptorOverlayHelper.attachOverlay(overlay.getControl(), 
component, OverlayHelper.NORTH_WEST, 3, 0);
+        InterceptorOverlayHelper.attachOverlay(overlay.getControl(), 
component, OverlayHelper.NORTH_WEST, 5, 0);
         overlay.setVisible(false);
     }
 
@@ -127,7 +127,7 @@
             JPanel control = new JPanel(new BorderLayout());
             control.setName("dirtyOverlay");
 
-            control.setOpaque(false);
+            control.setOpaque(true);
 
             IconSource iconSource = 
(IconSource)ApplicationServicesLocator.services().getService(IconSource.class);
             Icon icon = iconSource.getIcon(DIRTY_ICON_KEY);
@@ -161,6 +161,7 @@
             getControl().setVisible(visible);
             // manually set the size, otherwise sometimes the overlay is not 
shown (it has size 0,0)
             getControl().setSize(getControl().getPreferredSize());
+            
 
             if (visible) {
                 MessageSource messageSource =

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptorFactory.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptorFactory.java
     2006-07-26 06:34:27 UTC (rev 1236)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/builder/support/DirtyIndicatorInterceptorFactory.java
     2006-07-26 09:17:26 UTC (rev 1237)
@@ -17,15 +17,15 @@
 
 import org.springframework.binding.form.FormModel;
 import org.springframework.richclient.form.builder.FormComponentInterceptor;
-import 
org.springframework.richclient.form.builder.FormComponentInterceptorFactory;
 
 /**
  * Factory for <code>DirtyIndicatorInterceptor</code> instances.
- *
+ * 
  * @author Peter De Bruycker
  */
-public class DirtyIndicatorInterceptorFactory implements 
FormComponentInterceptorFactory {
-    public FormComponentInterceptor getInterceptor(FormModel formModel) {
-        return new DirtyIndicatorInterceptor(formModel);
+
+public class DirtyIndicatorInterceptorFactory extends 
ConfigurableFormComponentInterceptorFactory {
+    protected FormComponentInterceptor createInterceptor( FormModel formModel 
) {
+        return new DirtyIndicatorInterceptor( formModel );
     }
 }

Modified: 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/application/messages.properties
===================================================================
--- 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/application/messages.properties
   2006-07-26 06:34:27 UTC (rev 1236)
+++ 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/application/messages.properties
   2006-07-26 09:17:26 UTC (rev 1237)
@@ -148,4 +148,5 @@
 verb.default=must be
 verb.default.negated=must not be
 
-dirty.message={0} has changed, original value is {1}.
\ No newline at end of file
+dirty.message={0} has changed, original value is {1}.
+revert.message=Revert {0} to its original value.
\ No newline at end of file

Modified: 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/image/images.properties
===================================================================
--- 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/image/images.properties
   2006-07-26 06:34:27 UTC (rev 1236)
+++ 
trunk/spring-richclient/support/src/main/resources/org/springframework/richclient/image/images.properties
   2006-07-26 09:17:26 UTC (rev 1237)
@@ -30,4 +30,5 @@
 severity.warning.overlay=alert/warning_co.gif
 severity.error.overlay=alert/error_co.gif
 
-dirty.overlay=edit/dirty_co.gif
\ No newline at end of file
+dirty.overlay=edit/dirty_co.gif
+revert.overlay=edit/revert_co.gif
\ No newline at end of file

Added: 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactoryTests.java
===================================================================
--- 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactoryTests.java
                             (rev 0)
+++ 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/builder/support/ConfigurableFormComponentInterceptorFactoryTests.java
     2006-07-26 09:17:26 UTC (rev 1237)
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.springframework.richclient.form.builder.support;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.springframework.binding.form.FormModel;
+import org.springframework.binding.form.support.DefaultFormModel;
+import 
org.springframework.binding.value.swing.TestableFormComponentInterceptor;
+import org.springframework.richclient.form.builder.FormComponentInterceptor;
+
+/**
+ * Tests for <code>ConfigurableFormComponentInterceptorFactory</code>.
+ * 
+ * @author Peter De Bruycker
+ */
+public class ConfigurableFormComponentInterceptorFactoryTests extends TestCase 
{
+    public void testSettingBothIncludedAndExcludedFormModelIdsMustFail() 
throws Exception {
+        TestableConfigurableFormComponentInterceptorFactory factory = new 
TestableConfigurableFormComponentInterceptorFactory();
+
+        factory.setIncludedFormModelIds( new String[] { "included-0", 
"included-1" } );
+        factory.setExcludedFormModelIds( new String[] { "excluded-0", 
"excluded-1" } );
+
+        try {
+            factory.afterPropertiesSet();
+            fail( "Should throw IllegalStateException" );
+        } catch( IllegalStateException e ) {
+            // test passes;
+        }
+    }
+
+    public void testSetIncludedFormModelIds() throws Exception {
+        TestableConfigurableFormComponentInterceptorFactory factory = new 
TestableConfigurableFormComponentInterceptorFactory();
+        factory.setCreateThis( new TestableFormComponentInterceptor() );
+
+        factory.setIncludedFormModelIds( new String[] { "included-0", 
"included-1" } );
+        factory.afterPropertiesSet();
+
+        assertTrue( Arrays.equals( new String[] { "included-0", "included-1" 
}, factory.getIncludedFormModelIds() ) );
+
+        DefaultFormModel included = new DefaultFormModel();
+        included.setId( "included-0" );
+        DefaultFormModel excluded = new DefaultFormModel();
+        excluded.setId( "excluded-0" );
+
+        assertNotNull( "FormModel should be included", factory.getInterceptor( 
included ) );
+        assertNull( "FormModel is not included", factory.getInterceptor( 
excluded ) );
+    }
+
+    public void testSetExcludedFormModelIds() throws Exception {
+        TestableConfigurableFormComponentInterceptorFactory factory = new 
TestableConfigurableFormComponentInterceptorFactory();
+        factory.setCreateThis( new TestableFormComponentInterceptor() );
+
+        factory.setExcludedFormModelIds( new String[] { "excluded-0", 
"excluded-1" } );
+        factory.afterPropertiesSet();
+
+        assertTrue( Arrays.equals( new String[] { "excluded-0", "excluded-1" 
}, factory.getExcludedFormModelIds() ) );
+
+        DefaultFormModel included = new DefaultFormModel();
+        included.setId( "included-0" );
+        DefaultFormModel excluded = new DefaultFormModel();
+        excluded.setId( "excluded-0" );
+
+        assertNotNull( "FormModel should be included", factory.getInterceptor( 
included ) );
+        assertNull( "FormModel is not included", factory.getInterceptor( 
excluded ) );
+    }
+    
+    private class TestableConfigurableFormComponentInterceptorFactory extends 
ConfigurableFormComponentInterceptorFactory {
+        private FormComponentInterceptor createThis;
+        private FormModel lastFormModel;
+
+        protected FormComponentInterceptor createInterceptor( FormModel 
formModel ) {
+            lastFormModel = formModel;
+            return createThis;
+        }
+
+        public void reset() {
+            createThis = null;
+            lastFormModel = null;
+        }
+
+        public void setCreateThis( FormComponentInterceptor createThis ) {
+            this.createThis = createThis;
+        }
+
+        public void setLastFormModel( FormModel lastFormModel ) {
+            this.lastFormModel = lastFormModel;
+        }
+
+        public FormModel getLastFormModel() {
+            return lastFormModel;
+        }
+    }
+}


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


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to