You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/04/22 00:42:54 UTC
svn commit: r936555 - in /pivot/trunk: core/src/org/apache/pivot/beans/
core/src/org/apache/pivot/collections/concurrent/
tools/src/org/apache/pivot/tools/wtk/ wtk/src/org/apache/pivot/wtk/content/
wtk/src/org/apache/pivot/wtkx/
Author: gbrown
Date: Wed Apr 21 22:42:53 2010
New Revision: 936555
URL: http://svn.apache.org/viewvc?rev=936555&view=rev
Log:
Add Map methods to BeanAdapter; update variable names that referenced BeanDictionary.
Modified:
pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java
pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java
pivot/trunk/tools/src/org/apache/pivot/tools/wtk/BeanMonitor.java
pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentPropertyInspectorSkin.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java
pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
Modified: pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java Wed Apr 21 22:42:53 2010
@@ -20,22 +20,25 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
-import org.apache.pivot.collections.Dictionary;
+import org.apache.pivot.collections.Map;
+import org.apache.pivot.collections.MapListener;
+import org.apache.pivot.util.ListenerList;
/**
- * Exposes Java bean properties of an object via the {@link Dictionary}
- * interface. A call to {@link Dictionary#get(Object)} invokes the getter for
+ * Exposes Java bean properties of an object via the {@link Map}
+ * interface. A call to {@link Map#get(Object)} invokes the getter for
* the corresponding property, and a call to
- * {@link Dictionary#put(Object, Object)} invokes the property's setter.
+ * {@link Map#put(Object, Object)} invokes the property's setter.
* <p>
* Properties may provide multiple setters; the appropriate setter to invoke
* is determined by the type of the value being set. If the value is
* <tt>null</tt>, the return type of the getter method is used.
*/
-public class BeanAdapter implements Dictionary<String, Object>, Iterable<String> {
+public class BeanAdapter implements Map<String, Object> {
/**
* Property iterator. Walks the list of methods defined by the bean and
* returns a value for each getter method.
@@ -133,6 +136,8 @@ public class BeanAdapter implements Dict
private Object bean;
private boolean ignoreReadOnlyProperties;
+ private MapListenerList<String, Object> mapListeners = new MapListenerList<String, Object>();
+
public static final String GET_PREFIX = "get";
public static final String IS_PREFIX = "is";
public static final String SET_PREFIX = "set";
@@ -312,7 +317,10 @@ public class BeanAdapter implements Dict
}
}
- return null;
+ Object previousValue = null;
+ mapListeners.valueUpdated(this, key, previousValue);
+
+ return previousValue;
}
/**
@@ -325,6 +333,15 @@ public class BeanAdapter implements Dict
}
/**
+ * @throws UnsupportedOperationException
+ * This method is not supported.
+ */
+ @Override
+ public synchronized void clear() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
* Verifies the existence of a property. The property must have a getter
* method; write-only properties are not supported.
*
@@ -356,6 +373,38 @@ public class BeanAdapter implements Dict
}
/**
+ * @throws UnsupportedOperationException
+ * This method is not supported.
+ */
+ @Override
+ public boolean isEmpty() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * This method is not supported.
+ */
+ @Override
+ public int getCount() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Comparator<String> getComparator() {
+ return null;
+ }
+
+ /**
+ * @throws UnsupportedOperationException
+ * This method is not supported.
+ */
+ @Override
+ public void setComparator(Comparator<String> comparator) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
* Tests the read-only state of a property.
*
* @param key
@@ -404,6 +453,11 @@ public class BeanAdapter implements Dict
return new PropertyIterator();
}
+ @Override
+ public ListenerList<MapListener<String, Object>> getMapListeners() {
+ return mapListeners;
+ }
+
/**
* Returns the getter method for a property.
*
@@ -418,6 +472,19 @@ public class BeanAdapter implements Dict
}
/**
+ * Returns the setter method for a property.
+ *
+ * @param key
+ * The property name.
+ *
+ * @return
+ * The getter method, or <tt>null</tt> if the method does not exist.
+ */
+ private Method getSetterMethod(String key, Class<?> valueType) {
+ return getSetterMethod(bean.getClass(), key, valueType);
+ }
+
+ /**
* Returns the public, non-static field for a property. Note that fields
* will only be consulted for bean properties after bean methods.
*
@@ -433,19 +500,6 @@ public class BeanAdapter implements Dict
}
/**
- * Returns the setter method for a property.
- *
- * @param key
- * The property name.
- *
- * @return
- * The getter method, or <tt>null</tt> if the method does not exist.
- */
- private Method getSetterMethod(String key, Class<?> valueType) {
- return getSetterMethod(bean.getClass(), key, valueType);
- }
-
- /**
* Tests the read-only state of a property. Note that is no such property
* exists, this method will return <tt>true</tt> (it will <u>not</u> throw
* an exception).
Modified: pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/concurrent/SynchronizedMap.java Wed Apr 21 22:42:53 2010
@@ -110,11 +110,6 @@ public class SynchronizedMap<K, V> imple
}
@Override
- public synchronized boolean isEmpty() {
- return map.isEmpty();
- }
-
- @Override
public synchronized void clear() {
if (!map.isEmpty()) {
map.clear();
@@ -128,6 +123,11 @@ public class SynchronizedMap<K, V> imple
}
@Override
+ public synchronized boolean isEmpty() {
+ return map.isEmpty();
+ }
+
+ @Override
public synchronized int getCount() {
return map.getCount();
}
Modified: pivot/trunk/tools/src/org/apache/pivot/tools/wtk/BeanMonitor.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/BeanMonitor.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/tools/src/org/apache/pivot/tools/wtk/BeanMonitor.java (original)
+++ pivot/trunk/tools/src/org/apache/pivot/tools/wtk/BeanMonitor.java Wed Apr 21 22:42:53 2010
@@ -145,7 +145,7 @@ public class BeanMonitor {
* events.
*/
private void registerBeanListeners() {
- BeanAdapter beanDictionary = new BeanAdapter(bean);
+ BeanAdapter beanAdapter = new BeanAdapter(bean);
Method[] methods = bean.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
@@ -173,7 +173,7 @@ public class BeanMonitor {
String propertyName = interfaceMethodName.substring(0,
interfaceMethodName.length() - PROPERTY_CHANGE_SUFFIX.length());
- if (beanDictionary.containsKey(propertyName)) {
+ if (beanAdapter.containsKey(propertyName)) {
notifyingProperties.add(propertyName);
}
}
Modified: pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentPropertyInspectorSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentPropertyInspectorSkin.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentPropertyInspectorSkin.java (original)
+++ pivot/trunk/tools/src/org/apache/pivot/tools/wtk/ComponentPropertyInspectorSkin.java Wed Apr 21 22:42:53 2010
@@ -60,9 +60,9 @@ class ComponentPropertyInspectorSkin ext
beanMonitor.getPropertyChangeListeners().add(new PropertyChangeListener() {
@Override
public void propertyChanged(Object bean, String propertyName) {
- BeanAdapter beanDictionary = new BeanAdapter(bean);
- Class<?> type = beanDictionary.getType(propertyName);
- updateControl(beanDictionary, propertyName, type);
+ BeanAdapter beanAdapter = new BeanAdapter(bean);
+ Class<?> type = beanAdapter.getType(propertyName);
+ updateControl(beanAdapter, propertyName, type);
}
});
@@ -85,10 +85,10 @@ class ComponentPropertyInspectorSkin ext
new HashMap<Class<?>, List<String>>(classComparator);
// Partition the properties by their declaring class
- BeanAdapter beanDictionary = new BeanAdapter(source);
- for (String propertyName : beanDictionary) {
+ BeanAdapter beanAdapter = new BeanAdapter(source);
+ for (String propertyName : beanAdapter) {
if (beanMonitor.isNotifying(propertyName)
- && !beanDictionary.isReadOnly(propertyName)) {
+ && !beanAdapter.isReadOnly(propertyName)) {
Method method = BeanAdapter.getGetterMethod(sourceType, propertyName);
Class<?> declaringClass = method.getDeclaringClass();
@@ -110,8 +110,8 @@ class ComponentPropertyInspectorSkin ext
List<String> propertyNames = declaringClassPartitions.get(declaringClass);
for (String propertyName : propertyNames) {
- Class<?> type = beanDictionary.getType(propertyName);
- addControl(beanDictionary, propertyName, type, section);
+ Class<?> type = beanAdapter.getType(propertyName);
+ addControl(beanAdapter, propertyName, type, section);
}
}
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewCellEditor.java Wed Apr 21 22:42:53 2010
@@ -214,9 +214,9 @@ public class TableViewCellEditor impleme
if (tableRow instanceof Dictionary<?, ?>) {
rowData = (Dictionary<String, Object>)tableRow;
} else {
- BeanAdapter beanDictionary = new BeanAdapter(tableRow);
- isReadOnly = beanDictionary.isReadOnly(columnName);
- rowData = beanDictionary;
+ BeanAdapter beanAdapter = new BeanAdapter(tableRow);
+ isReadOnly = beanAdapter.isReadOnly(columnName);
+ rowData = beanAdapter;
}
if (!isReadOnly) {
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java Wed Apr 21 22:42:53 2010
@@ -126,12 +126,12 @@ public class TableViewRowEditor implemen
// Get the row data, represented as a Dictionary
Object tableRow = tableView.getTableData().get(rowIndex);
Dictionary<String, Object> rowData;
- BeanAdapter beanDictionary = null;
+ BeanAdapter beanAdapter = null;
if (tableRow instanceof Dictionary<?, ?>) {
rowData = (Dictionary<String, Object>)tableRow;
} else {
- beanDictionary = new BeanAdapter(tableRow);
- rowData = beanDictionary;
+ beanAdapter = new BeanAdapter(tableRow);
+ rowData = beanAdapter;
}
// Set up the editor component hierarchy
@@ -178,8 +178,8 @@ public class TableViewRowEditor implemen
editorComponent = editorTextInput;
// Disable the text input for read-only properties
- if (beanDictionary != null
- && beanDictionary.isReadOnly(columnName)) {
+ if (beanAdapter != null
+ && beanAdapter.isReadOnly(columnName)) {
editorTextInput.setTextBindType(BindType.LOAD);
editorTextInput.setEnabled(false);
}
Modified: pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java?rev=936555&r1=936554&r2=936555&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtkx/WTKXSerializer.java Wed Apr 21 22:42:53 2010
@@ -630,11 +630,11 @@ public class WTKXSerializer implements S
throw new SerializationException("Property elements cannot have a namespace prefix.");
}
- BeanAdapter beanDictionary = new BeanAdapter(element.value);
+ BeanAdapter beanAdapter = new BeanAdapter(element.value);
- if (beanDictionary.isReadOnly(localName)) {
+ if (beanAdapter.isReadOnly(localName)) {
elementType = Element.Type.READ_ONLY_PROPERTY;
- value = beanDictionary.get(localName);
+ value = beanAdapter.get(localName);
assert (value != null) : "Read-only properties cannot be null.";
if (attributes.getLength() > 0
@@ -921,8 +921,8 @@ public class WTKXSerializer implements S
}
case WRITABLE_PROPERTY: {
- BeanAdapter beanDictionary = new BeanAdapter(element.parent.value);
- beanDictionary.put(localName, element.value);
+ BeanAdapter beanAdapter = new BeanAdapter(element.parent.value);
+ beanAdapter.put(localName, element.value);
break;
}