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 29929
Collapse All | Expand All

(-)openide/test/unit/src/org/openide/actions/AbstractCallbackActionTestHidden.java (-1 / +1 lines)
Lines 67-73 Link Here
67
        map.put (actionKey (), action);
67
        map.put (actionKey (), action);
68
        lookup = org.openide.util.lookup.Lookups.singleton(map);
68
        lookup = org.openide.util.lookup.Lookups.singleton(map);
69
        // Retrieve context sensitive action instance if possible.
69
        // Retrieve context sensitive action instance if possible.
70
        clone = global.clone(lookup);
70
        clone = global.createContextAwareInstance(lookup);
71
        
71
        
72
        listener = new CntListener ();
72
        listener = new CntListener ();
73
        clone.addPropertyChangeListener(listener);
73
        clone.addPropertyChangeListener(listener);
(-)openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java (-3 / +3 lines)
Lines 22-34 Link Here
22
22
23
import javax.swing.Action;
23
import javax.swing.Action;
24
24
25
import org.openide.actions.ActionCloneable;
26
import org.openide.actions.CopyAction;
25
import org.openide.actions.CopyAction;
27
import org.openide.actions.CutAction;
26
import org.openide.actions.CutAction;
28
import org.openide.nodes.Children;
27
import org.openide.nodes.Children;
29
import org.openide.nodes.Node;
28
import org.openide.nodes.Node;
30
import org.openide.nodes.AbstractNode;
29
import org.openide.nodes.AbstractNode;
31
import org.openide.util.actions.SystemAction;
30
import org.openide.util.actions.SystemAction;
31
import org.openide.util.ContextAwareAction;
32
import org.openide.util.Lookup;
32
import org.openide.util.Lookup;
33
import org.openide.util.Utilities;
33
import org.openide.util.Utilities;
34
34
Lines 84-91 Link Here
84
            panel.getExplorerManager().setRootContext(new TestRoot(
84
            panel.getExplorerManager().setRootContext(new TestRoot(
85
                new Node[] {enabledNode, disabledNode}));
85
                new Node[] {enabledNode, disabledNode}));
86
86
87
            Action copy = ((ActionCloneable)SystemAction.get(CopyAction.class)).clone(context);
87
            Action copy = ((ContextAwareAction)SystemAction.get(CopyAction.class)).createContextAwareInstance(context);
88
            Action cut = ((ActionCloneable)SystemAction.get(CutAction.class)).clone(context);
88
            Action cut = ((ContextAwareAction)SystemAction.get(CutAction.class)).createContextAwareInstance(context);
89
89
90
            assertTrue("Copy action has to be disabled", !copy.isEnabled());
90
            assertTrue("Copy action has to be disabled", !copy.isEnabled());
91
            assertTrue("Cut action has to be disabled", !cut.isEnabled());
91
            assertTrue("Cut action has to be disabled", !cut.isEnabled());
(-)openide/test/unit/src/org/openide/util/UtilitiesActionsTest.java (-24 / +24 lines)
Lines 36-42 Link Here
36
    public void testActionClone () throws Exception {
36
    public void testActionClone () throws Exception {
37
        CloneAction original = new CloneAction ();
37
        CloneAction original = new CloneAction ();
38
        
38
        
39
        javax.swing.Action clone = org.openide.util.Utilities.actionClone (original, Lookup.EMPTY);
39
        javax.swing.Action clone = original.createContextAwareInstance(Lookup.EMPTY);
40
40
41
        assertTrue ("Clone is instance of desired class", clone instanceof CloneAction);
41
        assertTrue ("Clone is instance of desired class", clone instanceof CloneAction);
42
        assertNull ("Original has empty lookup", original.lookup);
42
        assertNull ("Original has empty lookup", original.lookup);
Lines 50-56 Link Here
50
            public JMenuItem item = new JMenuItem ("Ahoj");
50
            public JMenuItem item = new JMenuItem ("Ahoj");
51
            public int called;
51
            public int called;
52
            
52
            
53
            protected Action cloneAction () {
53
            protected CloneAction cloneAction () {
54
                return new MyAction ();
54
                return new MyAction ();
55
            }
55
            }
56
56
Lines 83-93 Link Here
83
    }
83
    }
84
    
84
    
85
    public void testActionsToPopupFromComponent () throws Exception {
85
    public void testActionsToPopupFromComponent () throws Exception {
86
        final org.openide.util.Lookup lookup = org.openide.util.lookup.Lookups.singleton (this);
86
        Lookup lookup = org.openide.util.lookup.Lookups.singleton (this);
87
        final Lookup[] returnedLookup = {lookup};
87
        
88
        
88
        class Provider extends javax.swing.JComponent implements Lookup.Provider {
89
        class Provider extends javax.swing.JComponent implements Lookup.Provider {
89
            public Lookup getLookup () {
90
            public Lookup getLookup () {
90
                return lookup;
91
                return returnedLookup[0];
91
            }
92
            }
92
        }
93
        }
93
        
94
        
Lines 117-127 Link Here
117
        
118
        
118
        javax.swing.JPopupMenu menu = org.openide.util.Utilities.actionsToPopup (arr, menuOwner);
119
        javax.swing.JPopupMenu menu = org.openide.util.Utilities.actionsToPopup (arr, menuOwner);
119
        
120
        
120
        Lookup actionLookup = ((CloneAction)arr[0].clone).lookup;
121
        Lookup actionLookup = arr[0].clone.lookup;
122
        assertNotNull("Clone lookup is not null", actionLookup);
121
        assertEquals ("The lookup returned by 'provider' is assigned to the clonned actions", 
123
        assertEquals ("The lookup returned by 'provider' is assigned to the clonned actions", 
122
            this, actionLookup.lookup (this.getClass ())
124
            this, actionLookup.lookup (this.getClass ())
123
        );
125
        );
124
        
126
        
127
        // Now try it without a (valid) Lookup.Provider in the component hierarchy.
128
        returnedLookup[0] = null;
129
        arr[0].clone = null;
130
        menu = org.openide.util.Utilities.actionsToPopup (arr, menuOwner);
131
        
132
        actionLookup = arr[0].clone.lookup;
133
        assertNotNull("Clone lookup is not null", actionLookup);
134
        
125
        javax.swing.ActionMap map = (javax.swing.ActionMap)actionLookup.lookup (javax.swing.ActionMap.class);
135
        javax.swing.ActionMap map = (javax.swing.ActionMap)actionLookup.lookup (javax.swing.ActionMap.class);
126
        assertNotNull ("Action map is in the lookup", map);
136
        assertNotNull ("Action map is in the lookup", map);
127
        assertNull ("ActionMap of parent of Lookup.Provider is not included", map.get ("1"));
137
        assertNull ("ActionMap of parent of Lookup.Provider is not included", map.get ("1"));
Lines 131-164 Link Here
131
        assertNull ("But of course the sibling's one is not", map.get ("5"));
141
        assertNull ("But of course the sibling's one is not", map.get ("5"));
132
    }
142
    }
133
    
143
    
134
    class CloneAction extends javax.swing.AbstractAction {
144
    class CloneAction extends javax.swing.AbstractAction implements ContextAwareAction {
135
        public Lookup lookup;
145
        public Lookup lookup;
136
        public Action clone;
146
        public CloneAction clone;
137
147
138
        public void actionPerformed (java.awt.event.ActionEvent ev) {
148
        public void actionPerformed (java.awt.event.ActionEvent ev) {
139
        }
149
        }
140
        
150
        
141
        protected Action cloneAction () {
151
        protected CloneAction cloneAction () {
142
            return new CloneAction ();
152
            return new CloneAction ();
143
        }
153
        }
144
154
145
        public void putValue (String name, Object value) {
155
        public Action createContextAwareInstance(Lookup actionContext) {
146
            if (name.equals ("lookup")) {
156
            assertNull ("We support just one clone right now", clone);
147
                assertNull ("Not yet assigned", lookup);
157
            clone = cloneAction ();
148
                lookup = (Lookup)value;
158
            clone.lookup = actionContext;
149
                return;
159
            return clone;
150
            }
151
            super.putValue (name, value);
152
        }
153
154
        public Object getValue (String name) {
155
            if (name.equals ("actionClone")) {
156
                assertNull ("We support just one clone right now", clone);
157
                clone = cloneAction ();
158
                return clone;
159
            }
160
            return super.getValue (name);
161
        }
160
        }
161
        
162
    } // end of CloneAction
162
    } // end of CloneAction
163
    
163
    
164
}
164
}
(-)openide/test/unit/src/org/openide/util/actions/CallbackSystemActionTest.java (-3 / +3 lines)
Lines 180-186 Link Here
180
        ActionMap map = new ActionMap ();
180
        ActionMap map = new ActionMap ();
181
        CallbackSystemAction system = (CallbackSystemAction)SystemAction.get(SurviveFocusChgCallbackAction.class);
181
        CallbackSystemAction system = (CallbackSystemAction)SystemAction.get(SurviveFocusChgCallbackAction.class);
182
        system.setActionPerformer (null);
182
        system.setActionPerformer (null);
183
        map.put (system.getValue("key"), action);
183
        map.put (system.getActionMapKey(), action);
184
184
185
        
185
        
186
        
186
        
Lines 191-197 Link Here
191
        // Without action map
191
        // Without action map
192
        //
192
        //
193
        
193
        
194
        clone = system.clone(org.openide.util.Lookup.EMPTY);
194
        clone = system.createContextAwareInstance(org.openide.util.Lookup.EMPTY);
195
        
195
        
196
        assertTrue ("Action should not be enabled if no callback provided", !clone.isEnabled());
196
        assertTrue ("Action should not be enabled if no callback provided", !clone.isEnabled());
197
        
197
        
Lines 206-212 Link Here
206
        action.setEnabled (false);
206
        action.setEnabled (false);
207
        
207
        
208
        org.openide.util.Lookup context = org.openide.util.lookup.Lookups.singleton(map);
208
        org.openide.util.Lookup context = org.openide.util.lookup.Lookups.singleton(map);
209
        clone = system.clone(context);
209
        clone = system.createContextAwareInstance(context);
210
        
210
        
211
        CntListener listener = new CntListener ();
211
        CntListener listener = new CntListener ();
212
        clone.addPropertyChangeListener (listener);
212
        clone.addPropertyChangeListener (listener);
(-)openide/test/unit/src/org/openide/util/actions/NodeActionTest.java (-1 / +1 lines)
Lines 363-369 Link Here
363
        InstanceContent ic = new InstanceContent ();
363
        InstanceContent ic = new InstanceContent ();
364
        org.openide.util.lookup.AbstractLookup lookup = new org.openide.util.lookup.AbstractLookup (ic);
364
        org.openide.util.lookup.AbstractLookup lookup = new org.openide.util.lookup.AbstractLookup (ic);
365
        
365
        
366
        javax.swing.Action clone = org.openide.util.Utilities.actionClone (s, lookup);
366
        javax.swing.Action clone = s.createContextAwareInstance(lookup);
367
        clone.addPropertyChangeListener(counter);
367
        clone.addPropertyChangeListener(counter);
368
        
368
        
369
        assertTrue ("Not enabled", !clone.isEnabled());
369
        assertTrue ("Not enabled", !clone.isEnabled());

Return to bug 29929