This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 68299
Collapse All | Expand All

(-)openide/actions/src/org/openide/actions/PropertiesAction.java (-14 / +2 lines)
Lines 7-13 Link Here
7
 * http://www.sun.com/
7
 * http://www.sun.com/
8
 *
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
12
 */
13
package org.openide.actions;
13
package org.openide.actions;
Lines 54-72 Link Here
54
    }
54
    }
55
55
56
    protected boolean enable(Node[] activatedNodes) {
56
    protected boolean enable(Node[] activatedNodes) {
57
        if (activatedNodes == null) {
57
        return activatedNodes != null;
58
            return false;
59
        }
60
61
        // This is not quite as exact as checking if the *intersection* of their
62
        // properties is also nonempty, but it is pretty close.
63
        for (int i = 0; i < activatedNodes.length; i++) {
64
            if (activatedNodes[i].getPropertySets().length > 0) {
65
                return true;
66
            }
67
        }
68
69
        return false;
70
    }
58
    }
71
59
72
    public JMenuItem getPopupPresenter() {
60
    public JMenuItem getPopupPresenter() {
(-)openide/actions/test/unit/src/org/openide/actions/PropertiesActionTest.java (+89 lines)
Added Link Here
1
/*
2
 *                 Sun Public License Notice
3
 *
4
 * The contents of this file are subject to the Sun Public License
5
 * Version 1.0 (the "License"). You may not use this file except in
6
 * compliance with the License. A copy of the License is available at
7
 * http://www.sun.com/
8
 *
9
 * The Original Code is NetBeans. The Initial Developer of the Original
10
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun
11
 * Microsystems, Inc. All Rights Reserved.
12
 */
13
14
package org.openide.actions;
15
16
import java.lang.reflect.InvocationTargetException;
17
import org.netbeans.junit.NbTestCase;
18
import org.openide.nodes.AbstractNode;
19
import org.openide.nodes.Children;
20
import org.openide.nodes.Node;
21
import javax.swing.Action;
22
import org.openide.nodes.Node.Property;
23
import org.openide.nodes.Node.PropertySet;
24
25
/** Issue 68299.
26
 *
27
 * @author Jiri Rechtacek
28
 */
29
public class PropertiesActionTest extends NbTestCase {
30
    public PropertiesActionTest (String testName) {
31
        super (testName);
32
    }
33
34
    protected void setUp () throws Exception {
35
    }
36
37
    protected void tearDown () throws Exception {
38
    }
39
40
    public void testEnableOnEmptyProperties () throws Exception {
41
        testEnable (new PropertySet [0]);
42
    }
43
44
    public void testEnableOnNullProperties () throws Exception {
45
        testEnable (null);
46
    }
47
    
48
    public void testEnableOnNotNullProperties () throws Exception {
49
        PropertySet [] s = new PropertySet [] { new PropertySet () {
50
                        public Property[] getProperties () {
51
                            Property p = new Property (String.class) {
52
                                public boolean canRead () {
53
                                    return true;
54
                                }
55
                                public boolean canWrite () {
56
                                    return true;
57
                                }
58
                                public Object getValue () throws IllegalAccessException,InvocationTargetException {
59
                                    return null;
60
                                }
61
                                public void setValue (Object val) throws IllegalAccessException,IllegalArgumentException,InvocationTargetException {
62
                                }
63
                            };
64
                            return new Property [] { p };
65
                        }
66
                    } };
67
68
        testEnable (s);
69
    }
70
    
71
    private void testEnable (final PropertySet [] pros) throws Exception {
72
        Node n = new AbstractNode (Children.LEAF) {
73
            public PropertySet [] getPropertySets () {
74
                return pros;
75
            }
76
        };
77
        
78
        
79
        assertEquals ("Node has the given properties.", pros, n.getPropertySets ());
80
        
81
        Node[] activatedNodes = new Node [] { n };
82
        
83
        PropertiesAction pa = (PropertiesAction) PropertiesAction.get (PropertiesAction.class);
84
        Action a = pa.createContextAwareInstance (n.getLookup ());
85
        
86
        assertTrue ("PropertiesAction is enabled.", a.isEnabled ());
87
    }
88
    
89
}

Return to bug 68299