Author: kmorin
Date: 2014-03-14 17:47:04 +0100 (Fri, 14 Mar 2014)
New Revision: 2625
Url: http://forge.nuiton.org/projects/nuiton-utils/repository/revisions/2625
Log:
fixes #3119 [BeanMonitor] Add a constructor to set only the properties which must not be listened
Modified:
trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
Modified: trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java
===================================================================
--- trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2014-02-04 09:39:39 UTC (rev 2624)
+++ trunk/src/main/java/org/nuiton/util/beans/BeanMonitor.java 2014-03-14 16:47:04 UTC (rev 2625)
@@ -65,9 +65,12 @@
/** Logger */
private static final Log log = LogFactory.getLog(BeanMonitor.class);
- /** Names of properties to watch on attached bean. */
+ /** Names of properties to watch or not on attached bean. */
protected final List<String> propertyNames;
+ /** If true, then listen to the properties which are not in the propertyNames */
+ protected boolean excludeMode;
+
/** Names of monitored and modified properties for the attached bean. */
protected final Map<String, PropertyDiff> propertyDiffs;
@@ -86,6 +89,11 @@
* @param propertyNames the names of properties to monitor
*/
public BeanMonitor(String... propertyNames) {
+ this(false, propertyNames);
+ }
+
+ public BeanMonitor(boolean exclude, String... propertyNames) {
+ this.excludeMode = exclude;
this.propertyNames = new ArrayList<String>(Arrays.asList(propertyNames));
propertyDiffs = new LinkedHashMap<String, PropertyDiff>();
@@ -93,7 +101,8 @@
@Override
public void propertyChange(PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
- if (!BeanMonitor.this.propertyNames.contains(propertyName)) {
+ if (excludeMode && BeanMonitor.this.propertyNames.contains(propertyName)
+ || !excludeMode && !BeanMonitor.this.propertyNames.contains(propertyName)) {
return;
}
@@ -262,4 +271,13 @@
propertyNames.addAll(Arrays.asList(properties));
clearModified();
}
+
+ public boolean isExcludeMode() {
+ return excludeMode;
+ }
+
+ public void setExcludeMode(boolean excludeMode) {
+ this.excludeMode = excludeMode;
+ clearModified();
+ }
}