r1253 - in jaxx/trunk/jaxx-runtime-api: . src/main/java/jaxx/runtime
Author: tchemit Date: 2009-03-03 07:50:33 +0000 (Tue, 03 Mar 2009) New Revision: 1253 Modified: jaxx/trunk/jaxx-runtime-api/changelog.txt jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/DefaultApplicationContext.java jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/Util.java Log: add pcs in ApplicationContext add method in Util to filter JAXX property changed listeners Modified: jaxx/trunk/jaxx-runtime-api/changelog.txt =================================================================== --- jaxx/trunk/jaxx-runtime-api/changelog.txt 2009-03-01 20:36:23 UTC (rev 1252) +++ jaxx/trunk/jaxx-runtime-api/changelog.txt 2009-03-03 07:50:33 UTC (rev 1253) @@ -1,4 +1,8 @@ -1.2 ??? 2009???? +1.3 ??? 200903?? + * 20090302 [chemit] - add pcs in ApplicationContext + - add method in Util to filter JAXX property changed listeners + +1.2 letellier 2009022? * 2009021 [chemit] - introduce DefaultApplicationContext iwth annotation system. 1.1 chemit 20090220 Modified: jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/DefaultApplicationContext.java =================================================================== --- jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/DefaultApplicationContext.java 2009-03-01 20:36:23 UTC (rev 1252) +++ jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/DefaultApplicationContext.java 2009-03-03 07:50:33 UTC (rev 1253) @@ -1,5 +1,7 @@ package jaxx.runtime; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.lang.annotation.*; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; @@ -81,6 +83,7 @@ public DefaultApplicationContext() { super(); forwards = new HashMap<Class, Class>(); + pcs = new PropertyChangeSupport(this); } public DefaultApplicationContext(JAXXObject ui) { @@ -89,6 +92,9 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private final Log log = LogFactory.getLog(DefaultApplicationContext.class); + /** to manage properties modifications */ + protected PropertyChangeSupport pcs; + @SuppressWarnings({"unchecked"}) @Override public <T> T getContextValue(Class<T> clazz, String name) { @@ -178,6 +184,34 @@ super.removeContextValue(klazz, name); } + public void addPropertyChangeListener(PropertyChangeListener listener) { + pcs.addPropertyChangeListener(listener); + } + + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.addPropertyChangeListener(propertyName, listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + pcs.removePropertyChangeListener(listener); + } + + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + pcs.removePropertyChangeListener(propertyName, listener); + } + + public synchronized boolean hasListeners(String propertyName) { + return pcs.hasListeners(propertyName); + } + + public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { + return pcs.getPropertyChangeListeners(propertyName); + } + + public synchronized PropertyChangeListener[] getPropertyChangeListeners() { + return pcs.getPropertyChangeListeners(); + } + protected Object newInstance(Class<?> clazz) throws IllegalArgumentException { Object value = null; @@ -240,4 +274,8 @@ throw new IllegalArgumentException(ex); } } + + protected void firePropertyChange(String name, Object oldValue, Object newValue) { + pcs.firePropertyChange(name, oldValue, newValue); + } } Modified: jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/Util.java =================================================================== --- jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/Util.java 2009-03-01 20:36:23 UTC (rev 1252) +++ jaxx/trunk/jaxx-runtime-api/src/main/java/jaxx/runtime/Util.java 2009-03-03 07:50:33 UTC (rev 1253) @@ -12,6 +12,8 @@ import javax.swing.UIManager; import java.awt.Component; import java.awt.Dimension; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeListenerProxy; import java.io.IOException; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationHandler; @@ -409,6 +411,45 @@ return createIcon(iconPath + "i18n/" + name + ".png"); } + /** + * detects all PropertychangedListener added by Jaxx uis + * (should be a {@link DataBindingListener} + * + * @param propertyNames the array of property names to find + * @param listeners the array of listeners to filter + * @return the filtered listeners + */ + public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) { + if (listeners == null || listeners.length == 0) { + return new PropertyChangeListener[0]; + } + List<String> pNames = Arrays.asList(propertyNames); + + List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>(); + + for (PropertyChangeListener listener : listeners) { + String pName = null; + PropertyChangeListenerProxy plistener = null; + if (listener instanceof PropertyChangeListenerProxy) { + plistener = (PropertyChangeListenerProxy) listener; + if (!pNames.contains(plistener.getPropertyName())) { + // not on the good property + continue; + } + listener = (PropertyChangeListener) plistener.getListener(); + pName = plistener.getPropertyName(); + } + if (plistener != null && pName != null && listener instanceof DataBindingListener) { + if (log.isDebugEnabled()) { + log.debug("find config listener to remove [" + pName + "] : " + listener); + } + toRemove.add(plistener); + //toRemove.add(listener); + } + } + return toRemove.toArray(new PropertyChangeListener[toRemove.size()]); + } + private static String getIconPath() { String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY); if (iconPath == null) {
participants (1)
-
tchemit@users.labs.libre-entreprise.org