Skip to content
Browse files

PIVOT-887: Make changes to Spinner and BXMLSerializer such that using…

… the DefaultProperty of Spinner (which is "spinnerData") in a BXML file will work correctly.

Normally if the original value is a Sequence (as it always will be for the spinner data) the child is added to the sequence.  But using an ImmutableList enables BXMLSerializer to catch the UnsupportedOperationException and do a beanAdapter.put instead (which results in a call to "setSpinnerData"), which is the correct thing to do.

git-svn-id: https://svn.apache.org/repos/asf/pivot/trunk@1428650 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 9711dc7 commit e528b4c011855c33806ca4be1e41abc463d0031e Roger Lee Whitcomb committed
Showing with 12 additions and 2 deletions.
  1. +5 −1 core/src/org/apache/pivot/beans/BXMLSerializer.java
  2. +7 −1 wtk/src/org/apache/pivot/wtk/Spinner.java
View
6 core/src/org/apache/pivot/beans/BXMLSerializer.java
@@ -1210,7 +1210,11 @@ private void processEndElement() throws SerializationException {
if (defaultPropertyValue instanceof Sequence<?>) {
Sequence<Object> sequence = (Sequence<Object>)defaultPropertyValue;
- sequence.add(element.value);
+ try {
+ sequence.add(element.value);
+ } catch (UnsupportedOperationException uoe) {
+ beanAdapter.put(defaultPropertyName, element.value);
+ }
} else {
beanAdapter.put(defaultPropertyName, element.value);
}
View
8 wtk/src/org/apache/pivot/wtk/Spinner.java
@@ -20,6 +20,7 @@
import org.apache.pivot.beans.DefaultProperty;
import org.apache.pivot.collections.ArrayList;
+import org.apache.pivot.collections.immutable.ImmutableList;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.ListListener;
import org.apache.pivot.collections.Sequence;
@@ -354,9 +355,14 @@ public void comparatorChanged(List<Object> list, Comparator<Object> previousComp
/**
* Creates a spinner populated with an empty array list.
+ * <p> The default contents is an {@link ImmutableList} so that
+ * if the default property (which is "spinnerData") is invoked in a BXML
+ * file, <code>BXMLSerializer</code> trying to add to this immutable sequence
+ * will catch an exception and will do a {@link #setSpinnerData setSpinnerData(List<?>)}
+ * instead.
*/
public Spinner() {
- this(new ArrayList<Object>());
+ this(new ImmutableList<Object>(new ArrayList<Object>()));
}
/**

0 comments on commit e528b4c

Please sign in to comment.
Something went wrong with that request. Please try again.