You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/08/17 09:31:57 UTC
[GitHub] sdedic closed pull request #701: Fixed enable evaluation for cloned PropertyMonitors. Defined default …
sdedic closed pull request #701: Fixed enable evaluation for cloned PropertyMonitors. Defined default …
URL: https://github.com/apache/incubator-netbeans/pull/701
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/openide.awt/src/org/openide/awt/ActionState.java b/openide.awt/src/org/openide/awt/ActionState.java
index fda05bace2..814ebf0b3d 100644
--- a/openide.awt/src/org/openide/awt/ActionState.java
+++ b/openide.awt/src/org/openide/awt/ActionState.java
@@ -59,6 +59,9 @@
* <li>if {@link #checkValue} is {@link #NON_NULL_VALUE}, the action is checked if and only if
* the value is not {@code null}.
* <li>if the value type is an enum, its {@link Enum#name} is compared to {@link #checkValue}
+ * <li>if the value is a {@link Collection} or {@link Map}, state evaluates to the {@link Collection#isEmpty} or
+ * {@link Map#isEmpty}, respectively.
+ * <li>if the value is a {@link Number}, state will be true if value evaluates to <b>a positive integer</b>.
* <li>the state will be {@code false} (unchecked) otherwise.
* <p/>
* If {@link #type} is set to {@link Action}.class, the annotated element <b>must
diff --git a/openide.awt/src/org/openide/awt/PropertyMonitor.java b/openide.awt/src/org/openide/awt/PropertyMonitor.java
index 7b36d4d6de..9ed2cae15e 100644
--- a/openide.awt/src/org/openide/awt/PropertyMonitor.java
+++ b/openide.awt/src/org/openide/awt/PropertyMonitor.java
@@ -26,6 +26,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
import java.util.List;
@@ -520,6 +521,14 @@ private boolean interpretAsBoolean(Object v) {
}
}
if (checkedValue == null) {
+ // v is not null;
+ if (v instanceof Collection) {
+ return !((Collection) v).isEmpty();
+ } else if (v instanceof Map) {
+ return !((Map) v).isEmpty();
+ } else if (Number.class.isInstance(v)) {
+ return ((Number)v).intValue() > 0;
+ }
return false;
}
if (checkedValue == ActionState.NON_NULL_VALUE) {
@@ -551,6 +560,7 @@ public PropertyMonitor(PropertyMonitor other) {
this.listenerType = other.listenerType;
this.refGetter = other.refGetter;
this.valueFactory = other.valueFactory;
+ this.valType = other.valType;
this.refAddListener = other.refAddListener;
this.refRemoveListener = other.refRemoveListener;
this.listenerInterface = other.listenerInterface;
diff --git a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/StatefulActionProcessorTest.java b/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/StatefulActionProcessorTest.java
index 2c594544ae..5de71623e8 100644
--- a/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/StatefulActionProcessorTest.java
+++ b/openide.awt/test/unit/src/org/netbeans/modules/openide/awt/StatefulActionProcessorTest.java
@@ -31,6 +31,8 @@
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
+import javax.swing.DefaultListModel;
+import javax.swing.DefaultListSelectionModel;
import javax.swing.ListSelectionModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -1377,4 +1379,44 @@ public void actionPerformed(ActionEvent e) {
received = e;
}
}
+
+ public void testCustomContextAwareInstance() {
+ Action a = Actions.forID("Foo", "test.ListAction");
+ DefaultListSelectionModel model = new DefaultListSelectionModel();
+
+ InstanceContent localContent1 = new InstanceContent();
+ AbstractLookup localLookup1 = new AbstractLookup(localContent1);
+
+ Action la = ((ContextAwareAction)a).createContextAwareInstance(localLookup1);
+
+ assertFalse(a.isEnabled());
+ assertFalse(la.isEnabled());
+
+ localContent1.add(model);
+
+ assertFalse(a.isEnabled());
+ assertTrue(la.isEnabled());
+ assertFalse((Boolean)la.getValue(Action.SELECTED_KEY));
+
+ // checks that the context-bound instance changes its selected state
+ // if the model changes (relevant property change event is fired)
+ model.setSelectionInterval(1, 2);
+ assertTrue((Boolean)la.getValue(Action.SELECTED_KEY));
+ }
+
+ public void testCustomListenerAction() {
+ Action a = Actions.forID("Foo", "test.ListAction");
+ DefaultListSelectionModel model = new DefaultListSelectionModel();
+
+ assertFalse(a.isEnabled());
+ assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
+
+ lookupContent.add(model);
+ assertTrue(a.isEnabled());
+ assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
+
+ model.addSelectionInterval(1, 1);
+ assertTrue(a.isEnabled());
+ assertTrue((Boolean)a.getValue(Action.SELECTED_KEY));
+ }
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists