You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2007/11/07 17:06:25 UTC
svn commit: r592802 - in /tapestry/tapestry4/trunk/tapestry-framework/src:
java/org/apache/tapestry/form/ test/org/apache/tapestry/form/
Author: jkuhnert
Date: Wed Nov 7 08:06:23 2007
New Revision: 592802
URL: http://svn.apache.org/viewvc?rev=592802&view=rev
Log:
-) Removed labaledpropertyselectionmodel functionality from BeanPropertySelectionModel.
-) Updated and refined isDisabled logic for labeledpropertyselectionmodel.
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LabeledPropertySelectionModel.java
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.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/BeanPropertySelectionModel.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java?rev=592802&r1=592801&r2=592802&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/BeanPropertySelectionModel.java Wed Nov 7 08:06:23 2007
@@ -22,13 +22,17 @@
import java.util.List;
/**
- * This class is a property selection model for an object list. This is used in PropertySelection,
+ * This class is a property selection model for an object list. This is used in {@link PropertySelection},
* MultiplePropertySelection or Palette tapestry components. For example, to use for a Hospital
- * class, and have the labels be the hospital names. <code>
+ * class, and have the labels be the hospital names.
+ *
+ * <p>
+ * <code>
* List<Hospital> list = ...;
* return new BeanPropertySelectionModel(hospitals, "name");
* </code>
- * This will use getName() on the Hospital object, as its display.
+ * </p>
+ * <p>This will use getName() on the Hospital object, as its display.</p>
*
* @author Gabriel Handford
*/
@@ -39,7 +43,6 @@
private static final long serialVersionUID = 3763091973006766644L;
protected List _list;
protected String _labelField;
- protected String _nullLabel;
/**
* Build an empty property selection model.
@@ -78,35 +81,13 @@
}
/**
- * Same as {@link #BeanPropertySelectionModel(java.util.List, String)} - with the added
- * functionality of using the specified <code>nullLabel</code> field as a pseudo item in
- * the list of options that stores a null value. This is useful for situations where you
- * want to present a "Choose.." option or similar invalid option to prompt users for input.
- *
- * @param list
- * The list of options.
- * @param labelField
- * The string expression to be used on each object to get the label value
- * for the option - such as "user.name".
- * @param nullLabel
- * Will be treated as a pseudo option that always resolves to a null value but
- * is properly displayed in the options list as the first element.
- */
- public BeanPropertySelectionModel(List list, String labelField, String nullLabel)
- {
- this(list, labelField);
-
- _nullLabel = nullLabel;
- }
-
- /**
* Get the number of options.
*
* @return option count
*/
public int getOptionCount()
{
- return _nullLabel != null ? _list.size() + 1 : _list.size();
+ return _list.size();
}
/**
@@ -118,14 +99,6 @@
*/
public Object getOption(int index)
{
- if (_nullLabel != null && index == 0)
- {
- return null;
- }
-
- if (_nullLabel != null)
- index--;
-
if (index > (_list.size() - 1))
{
return null;
@@ -143,14 +116,6 @@
*/
public String getLabel(int index)
{
- if (index == 0 && _nullLabel != null)
- {
- return _nullLabel;
- }
-
- if (_nullLabel != null)
- index--;
-
Object obj = _list.get(index);
try
@@ -176,7 +141,7 @@
public boolean isDisabled(int index)
{
- return index == 0 && _nullLabel != null;
+ return false;
}
/**
@@ -193,12 +158,37 @@
return null;
}
- int index = Integer.parseInt(value);
- if (index == 0 && _nullLabel != null)
- {
- return null;
- }
+ return getOption( Integer.parseInt(value));
+ }
+
+ public String toString()
+ {
+ return "BeanPropertySelectionModel[" +
+ "_list=" + _list +
+ '\n' +
+ ", _labelField='" + _labelField + '\'' +
+ '\n' +
+ ']';
+ }
+
+ public boolean equals(Object o)
+ {
+ if (this == o) return true;
+ if (!(o instanceof BeanPropertySelectionModel)) return false;
+
+ BeanPropertySelectionModel that = (BeanPropertySelectionModel) o;
- return getOption(index);
+ if (_labelField != null ? !_labelField.equals(that._labelField) : that._labelField != null) return false;
+ if (_list != null ? !_list.equals(that._list) : that._list != null) return false;
+
+ return true;
+ }
+
+ public int hashCode()
+ {
+ int result;
+ result = (_list != null ? _list.hashCode() : 0);
+ result = 31 * result + (_labelField != null ? _labelField.hashCode() : 0);
+ return result;
}
}
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=592802&r1=592801&r2=592802&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 Wed Nov 7 08:06:23 2007
@@ -151,8 +151,7 @@
* @param value
* the value of the initial property
*/
- public LabeledPropertySelectionModel(IPropertySelectionModel model, String label,
- Object option, String value)
+ public LabeledPropertySelectionModel(IPropertySelectionModel model, String label, Object option, String value)
{
this(model, label, option);
@@ -214,7 +213,7 @@
public boolean isDisabled(int index)
{
- return false;
+ return index == 0 && _option == null;
}
/**
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java?rev=592802&r1=592801&r2=592802&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/BeanPropertySelectionModelTest.java Wed Nov 7 08:06:23 2007
@@ -60,21 +60,4 @@
assertEquals(model.getOptionCount(), 0);
assertEquals(model.getOption(3), null);
}
-
- public void test_Null_Label()
- {
- List<SimpleBean> list = new ArrayList();
- list.add(new SimpleBean(1, "Name 1", "Description 1"));
- list.add(new SimpleBean(2, "Name 2", "Description 2"));
- list.add(new SimpleBean(3, "Name 3", "Description 3"));
-
- BeanPropertySelectionModel model = new BeanPropertySelectionModel(list, "name", "test");
-
- assertEquals(model.getOptionCount(), 4);
- assert model.getOption(3) != null;
-
- assertEquals(model.getOption(0), null);
- assertEquals(model.getLabel(0), "test");
- assertEquals(model.getLabel(1), "Name 1");
- }
}
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=592802&r1=592801&r2=592802&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 Wed Nov 7 08:06:23 2007
@@ -57,8 +57,7 @@
Object option = null;
String value = "-1";
- LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(),
- label, option, value);
+ LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(), label, option, value);
assertEquals(label, model.getLabel());
assertEquals(option, model.getOption());
@@ -69,6 +68,47 @@
validateModel(model);
}
+ public void test_Disabled()
+ {
+ String label = "Choose...";
+
+ LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(), label);
+
+ assertEquals(model.getLabel(0), label);
+ assertEquals(model.getLabel(1), String.valueOf(Boolean.TRUE));
+ assert model.isDisabled(0);
+ assert !model.isDisabled(1);
+ }
+
+ public void test_Label_Option_Disabled()
+ {
+ String label = "Choose...";
+ String option = "-1";
+
+ LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(), label, option);
+
+ assertEquals(model.getLabel(0), label);
+ assert !model.isDisabled(0);
+ assert !model.isDisabled(1);
+ }
+
+ public void test_Label_Value_With_Option_Disabled()
+ {
+ String label = "Choose...";
+ String value = "-1";
+ Object option = Boolean.FALSE;
+
+ LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(), label, option, value);
+
+ assertEquals(model.getLabel(0), label);
+ assertEquals(model.getOption(0), option);
+ assertEquals(model.getOptionCount(), 3);
+ assertEquals(model.getValue(0), value);
+
+ assert !model.isDisabled(0);
+ assert !model.isDisabled(1);
+ }
+
private void validateLabel(IPropertySelectionModel model, String label, Object option,
String value)
{
@@ -99,8 +139,7 @@
{
return new IPropertySelectionModel()
{
- private boolean[] values = new boolean[]
- { true, false };
+ private boolean[] values = new boolean[] { true, false };
public int getOptionCount()
{