tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andy...@apache.org
Subject svn commit: r642429 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/form/LabeledPropertySelectionModel.java test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
Date Fri, 28 Mar 2008 23:28:07 GMT
Author: andyhot
Date: Fri Mar 28 16:28:05 2008
New Revision: 642429

URL: http://svn.apache.org/viewvc?rev=642429&view=rev
Log:
TAPESTRY-2310: allow label to be enabled

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java?rev=642429&r1=642428&r2=642429&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
Fri Mar 28 16:28:05 2008
@@ -16,8 +16,11 @@
 
 /**
  * Decorates an underlying {@link IPropertySelectionModel}adding an initial property. The
label,
- * option, and value of the initial property are configurable.
- * 
+ * option, and value of the initial property are configurable.<p/>
+ *
+ * By default, the label will be rendered as disabled if its option is null. This behavior
can be
+ * changed by {@link #setLabelAlwaysEnabled(boolean)}.
+ *  
  * @author Paul Ferraro
  * @since 4.0
  */
@@ -81,6 +84,8 @@
     private Object _option = null;
 
     private String _value = "";
+
+    private boolean _labelAlwaysEnabled;
     
     /**
      * Constructs a new LabeledPropertySelectionModel using an empty model and default label,
@@ -159,6 +164,29 @@
     }
 
     /**
+     * Constructs a new LabeledPropertySelectionModel using the specified model, label, option,
and
+     * value.
+     *
+     * @param model
+     *            the underlying model to decorate
+     * @param label
+     *            the label of the initial property
+     * @param option
+     *            the option value of the initial property
+     * @param value
+     *            the value of the initial property
+     * @param labelAlwaysEnabled
+     *            if the label should always be enabled
+     */
+    public LabeledPropertySelectionModel(IPropertySelectionModel model, String label, Object
option, String value,
+                                         boolean labelAlwaysEnabled)
+    {
+        this(model, label, option, value);
+
+        _labelAlwaysEnabled = labelAlwaysEnabled;
+    }
+
+    /**
      * Returns the underlying IPropertySelectionModel.
      * 
      * @return the underlying IPropertySelectionModel
@@ -213,7 +241,7 @@
 
     public boolean isDisabled(int index)
     {
-        return index == 0 ? _option == null : _model.isDisabled(index - 1);
+        return index == 0 ? (!_labelAlwaysEnabled && _option == null) : _model.isDisabled(index
- 1);
     }
     
     /**
@@ -288,5 +316,21 @@
     public void setOption(Object option)
     {
         _option = option;
+    }
+
+    /**
+     * Returns if label should always be enabled.
+     */
+    public boolean isLabelAlwaysEnabled()
+    {
+        return _labelAlwaysEnabled;
+    }
+
+    /**
+     * Sets the state of the label.
+     */
+    public void setLabelAlwaysEnabled(boolean labelAlwaysEnabled)
+    {
+        _labelAlwaysEnabled = labelAlwaysEnabled;
     }
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java?rev=642429&r1=642428&r2=642429&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LabeledPropertySelectionModelTest.java
Fri Mar 28 16:28:05 2008
@@ -81,6 +81,20 @@
         assert model.isDisabled(2);
     }
 
+    public void test_Label_Never_Disabled()
+    {
+        String label = "Choose...";
+
+        LabeledPropertySelectionModel model =
+                new LabeledPropertySelectionModel(createInnerModel(), label, null, "", true);
+
+        assertEquals(model.getLabel(0), label);
+        assertEquals(model.getLabel(1), String.valueOf(Boolean.TRUE));
+        assert !model.isDisabled(0);
+        assert !model.isDisabled(1);
+        assert model.isDisabled(2);
+    }
+
     public void test_Label_Option_Disabled()
     {
         String label = "Choose...";



Mime
View raw message