Index: openide/test/unit/src/org/openide/actions/AbstractCallbackActionTestHidden.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/actions/AbstractCallbackActionTestHidden.java,v --- openide/test/unit/src/org/openide/actions/AbstractCallbackActionTestHidden.java 9 Jan 2003 17:08:58 -0000 1.2 +++ openide/test/unit/src/org/openide/actions/AbstractCallbackActionTestHidden.java 10 Jan 2003 07:43:36 -0000 @@ -67,7 +67,7 @@ map.put (actionKey (), action); lookup = org.openide.util.lookup.Lookups.singleton(map); // Retrieve context sensitive action instance if possible. - clone = global.clone(lookup); + clone = global.createContextAwareInstance(lookup); listener = new CntListener (); clone.addPropertyChangeListener(listener); Index: openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java,v --- openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java 9 Jan 2003 17:09:00 -0000 1.2 +++ openide/test/unit/src/org/openide/explorer/ExplorerPanelTest.java 10 Jan 2003 07:43:36 -0000 @@ -22,13 +22,13 @@ import javax.swing.Action; -import org.openide.actions.ActionCloneable; import org.openide.actions.CopyAction; import org.openide.actions.CutAction; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.nodes.AbstractNode; import org.openide.util.actions.SystemAction; +import org.openide.util.ContextAwareAction; import org.openide.util.Lookup; import org.openide.util.Utilities; @@ -84,8 +84,8 @@ panel.getExplorerManager().setRootContext(new TestRoot( new Node[] {enabledNode, disabledNode})); - Action copy = ((ActionCloneable)SystemAction.get(CopyAction.class)).clone(context); - Action cut = ((ActionCloneable)SystemAction.get(CutAction.class)).clone(context); + Action copy = ((ContextAwareAction)SystemAction.get(CopyAction.class)).createContextAwareInstance(context); + Action cut = ((ContextAwareAction)SystemAction.get(CutAction.class)).createContextAwareInstance(context); assertTrue("Copy action has to be disabled", !copy.isEnabled()); assertTrue("Cut action has to be disabled", !cut.isEnabled()); Index: openide/test/unit/src/org/openide/util/UtilitiesActionsTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/util/UtilitiesActionsTest.java,v --- openide/test/unit/src/org/openide/util/UtilitiesActionsTest.java 9 Jan 2003 17:09:02 -0000 1.2 +++ openide/test/unit/src/org/openide/util/UtilitiesActionsTest.java 10 Jan 2003 07:43:36 -0000 @@ -36,7 +36,7 @@ public void testActionClone () throws Exception { CloneAction original = new CloneAction (); - javax.swing.Action clone = org.openide.util.Utilities.actionClone (original, Lookup.EMPTY); + javax.swing.Action clone = original.createContextAwareInstance(Lookup.EMPTY); assertTrue ("Clone is instance of desired class", clone instanceof CloneAction); assertNull ("Original has empty lookup", original.lookup); @@ -50,7 +50,7 @@ public JMenuItem item = new JMenuItem ("Ahoj"); public int called; - protected Action cloneAction () { + protected CloneAction cloneAction () { return new MyAction (); } @@ -83,11 +83,12 @@ } public void testActionsToPopupFromComponent () throws Exception { - final org.openide.util.Lookup lookup = org.openide.util.lookup.Lookups.singleton (this); + Lookup lookup = org.openide.util.lookup.Lookups.singleton (this); + final Lookup[] returnedLookup = {lookup}; class Provider extends javax.swing.JComponent implements Lookup.Provider { public Lookup getLookup () { - return lookup; + return returnedLookup[0]; } } @@ -117,11 +118,20 @@ javax.swing.JPopupMenu menu = org.openide.util.Utilities.actionsToPopup (arr, menuOwner); - Lookup actionLookup = ((CloneAction)arr[0].clone).lookup; + Lookup actionLookup = arr[0].clone.lookup; + assertNotNull("Clone lookup is not null", actionLookup); assertEquals ("The lookup returned by 'provider' is assigned to the clonned actions", this, actionLookup.lookup (this.getClass ()) ); + // Now try it without a (valid) Lookup.Provider in the component hierarchy. + returnedLookup[0] = null; + arr[0].clone = null; + menu = org.openide.util.Utilities.actionsToPopup (arr, menuOwner); + + actionLookup = arr[0].clone.lookup; + assertNotNull("Clone lookup is not null", actionLookup); + javax.swing.ActionMap map = (javax.swing.ActionMap)actionLookup.lookup (javax.swing.ActionMap.class); assertNotNull ("Action map is in the lookup", map); assertNull ("ActionMap of parent of Lookup.Provider is not included", map.get ("1")); @@ -131,34 +141,24 @@ assertNull ("But of course the sibling's one is not", map.get ("5")); } - class CloneAction extends javax.swing.AbstractAction { + class CloneAction extends javax.swing.AbstractAction implements ContextAwareAction { public Lookup lookup; - public Action clone; + public CloneAction clone; public void actionPerformed (java.awt.event.ActionEvent ev) { } - protected Action cloneAction () { + protected CloneAction cloneAction () { return new CloneAction (); } - public void putValue (String name, Object value) { - if (name.equals ("lookup")) { - assertNull ("Not yet assigned", lookup); - lookup = (Lookup)value; - return; - } - super.putValue (name, value); - } - - public Object getValue (String name) { - if (name.equals ("actionClone")) { - assertNull ("We support just one clone right now", clone); - clone = cloneAction (); - return clone; - } - return super.getValue (name); + public Action createContextAwareInstance(Lookup actionContext) { + assertNull ("We support just one clone right now", clone); + clone = cloneAction (); + clone.lookup = actionContext; + return clone; } + } // end of CloneAction } Index: openide/test/unit/src/org/openide/util/actions/CallbackSystemActionTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/util/actions/CallbackSystemActionTest.java,v --- openide/test/unit/src/org/openide/util/actions/CallbackSystemActionTest.java 9 Jan 2003 17:09:02 -0000 1.2 +++ openide/test/unit/src/org/openide/util/actions/CallbackSystemActionTest.java 10 Jan 2003 07:43:36 -0000 @@ -180,7 +180,7 @@ ActionMap map = new ActionMap (); CallbackSystemAction system = (CallbackSystemAction)SystemAction.get(SurviveFocusChgCallbackAction.class); system.setActionPerformer (null); - map.put (system.getValue("key"), action); + map.put (system.getActionMapKey(), action); @@ -191,7 +191,7 @@ // Without action map // - clone = system.clone(org.openide.util.Lookup.EMPTY); + clone = system.createContextAwareInstance(org.openide.util.Lookup.EMPTY); assertTrue ("Action should not be enabled if no callback provided", !clone.isEnabled()); @@ -206,7 +206,7 @@ action.setEnabled (false); org.openide.util.Lookup context = org.openide.util.lookup.Lookups.singleton(map); - clone = system.clone(context); + clone = system.createContextAwareInstance(context); CntListener listener = new CntListener (); clone.addPropertyChangeListener (listener); Index: openide/test/unit/src/org/openide/util/actions/NodeActionTest.java =================================================================== RCS file: /cvs/openide/test/unit/src/org/openide/util/actions/NodeActionTest.java,v --- openide/test/unit/src/org/openide/util/actions/NodeActionTest.java 9 Jan 2003 17:09:02 -0000 1.5 +++ openide/test/unit/src/org/openide/util/actions/NodeActionTest.java 10 Jan 2003 07:43:36 -0000 @@ -363,7 +363,7 @@ InstanceContent ic = new InstanceContent (); org.openide.util.lookup.AbstractLookup lookup = new org.openide.util.lookup.AbstractLookup (ic); - javax.swing.Action clone = org.openide.util.Utilities.actionClone (s, lookup); + javax.swing.Action clone = s.createContextAwareInstance(lookup); clone.addPropertyChangeListener(counter); assertTrue ("Not enabled", !clone.isEnabled());