Java Code Examples for org.openide.util.ContextAwareAction#createContextAwareInstance()

The following examples show how to use org.openide.util.ContextAwareAction#createContextAwareInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopComponentTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCanTCGarbageCollectWhenActionInMap() {
    TopComponent tc = new TopComponent();
    class CAA extends AbstractAction implements
            ContextAwareAction {
        public void actionPerformed(ActionEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Action createContextAwareInstance(Lookup actionContext) {
            return this;
        }

    }
    ContextAwareAction del = new CAA();
    ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
    Action a = context.createContextAwareInstance(tc.getLookup());
    tc.getActionMap().put("key", a);

    WeakReference<Object> ref = new WeakReference<Object>(tc);
    tc = null;
    a = null;
    del = null;
    context = null;
    assertGC("Can the component GC?", ref);
}
 
Example 2
Source File: TopComponentTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCanTCGarbageCollectWhenActionInMapAndAssignLookup() {
    TopComponent tc = new TopComponent();
    class CAA extends AbstractAction implements
            ContextAwareAction {
        public void actionPerformed(ActionEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Action createContextAwareInstance(Lookup actionContext) {
            return this;
        }

    }
    tc.associateLookup(Lookups.fixed(tc.getActionMap(), tc));
    ContextAwareAction del = new CAA();
    ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
    Action a = context.createContextAwareInstance(tc.getLookup());
    tc.getActionMap().put("key", a);

    WeakReference<Object> ref = new WeakReference<Object>(tc);
    tc = null;
    a = null;
    del = null;
    context = null;
    assertGC("Can the component GC?", ref);
}
 
Example 3
Source File: SaveAsActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testActionStatusUpdatedOnLookupChange() throws Exception {
    final InstanceContent content = new InstanceContent();
    Lookup lkp = new AbstractLookup( content );
    final SaveAsCapable saveAsImpl = new SaveAsCapable() {
        public void saveAs(FileObject folder, String name) throws IOException {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    };
    
    TopComponent tc = new TopComponent( lkp );
    editorMode.dockInto( tc );
    tc.open();
    tc.requestActive();
    assertTrue(Arrays.asList(WindowManager.getDefault().getOpenedTopComponents(editorMode)).contains(tc));
    
    ContextAwareAction action = SaveAsAction.create();
    assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", action.isEnabled() );
    
    Action a = action.createContextAwareInstance( tc.getLookup() );
    
    content.add( saveAsImpl );
    assertTrue( "action is enabled for editor windows with SaveAsCapable in their Lookup", a.isEnabled() );
    content.remove( saveAsImpl );
    assertFalse( "action is disabled for editor windows without SaveAsCapable in their Lookup", a.isEnabled() );
}
 
Example 4
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testMultiContextAction() throws Exception {
    ContextAwareAction a = (ContextAwareAction) Actions.forID("Tools", "on.numbers");

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    NumberLike ten = new NumberLike(10);
    NumberLike three = new NumberLike(3);
    ic.add(ten);
    ic.add(three);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 13, MultiContext.cnt);

    ic.remove(ten);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Adds 3", 16, MultiContext.cnt);

    ic.remove(three);
    assertFalse("It is disabled", clone.isEnabled());
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("No change", 16, MultiContext.cnt);
}
 
Example 5
Source File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testContextAction() throws Exception {
    Context.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContext.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 10, Context.cnt);

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Global Action stays same", 10, Context.cnt);
}
 
Example 6
Source File: ContextActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testBasicUsageWithEnablerFromLayer() throws Exception {
    FileObject folder;
    folder = FileUtil.getConfigFile("actions/support/test");
    assertNotNull("testing layer is loaded: ", folder);

    FileObject fo = folder.getFileObject("testContextEnabler.instance");
    
    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof ContextAwareAction)) {
        fail("Shall create an action: " + obj);
    }
    ContextAwareAction caa = (ContextAwareAction)obj;
    Action action = caa.createContextAwareInstance(lookupProxy);
    
    
    doBasicUsageWithEnabler(action);
}
 
Example 7
Source File: GlobalManagerTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testActionsUpdatedWhenActionMapChanges() throws Exception {
    ContextAwareAction a = Actions.callback("ahoj", null, true, "Ahoj!", "no/icon.png", true);
    final InstanceContent ic = new InstanceContent();
    Lookup lkp = new AbstractLookup(ic);

    ActionMap a1 = new ActionMap();
    ActionMap a2 = new ActionMap();
    a2.put("ahoj", new Enabled());

    ic.add(a1);
    Action clone = a.createContextAwareInstance(lkp);
    class L implements PropertyChangeListener {
        int cnt;
        public void propertyChange(PropertyChangeEvent evt) {
            cnt++;
        }
    }
    L listener = new L();
    clone.addPropertyChangeListener(listener);
    assertFalse("Not enabled", isEnabled(clone));

    ic.set(Collections.singleton(a2), null);

    assertTrue("Enabled now", isEnabled(clone));
    assertEquals("one change", 1, listener.cnt);
}
 
Example 8
Source File: HgProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void renameProject(Project p, Object caller) {
    if( p == null) return;
    
    ContextAwareAction action = (ContextAwareAction) CommonProjectActions.renameProjectAction();
    Lookup ctx = Lookups.singleton(p);
    Action ctxAction = action.createContextAwareInstance(ctx);
    ctxAction.actionPerformed(new ActionEvent(caller, 0, "")); // NOI18N
}
 
Example 9
Source File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMultiContextActionLookup() throws Exception {
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContextLookup.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);
    ic.add(3L);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 13, LookupContext.cnt);

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Adds 3", 16, LookupContext.cnt);

    ic.remove(3L);
    assertFalse("It is disabled", clone.isEnabled());
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("No change", 16, LookupContext.cnt);
}
 
Example 10
Source File: ContextActionInjectTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testMultiContextAction() throws Exception {
    MultiContext.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "actions/support/test/testInjectContextMulti.instance"
    );
    assertNotNull("File found", fo);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(10);
    ic.add(3L);

    assertEquals("Number lover!", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Global Action not called", 13, MultiContext.cnt);

    ic.remove(10);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Adds 3", 16, MultiContext.cnt);

    ic.remove(3L);
    assertFalse("It is disabled", clone.isEnabled());
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("No change", 16, MultiContext.cnt);
}
 
Example 11
Source File: CallbackActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testWithFallback() throws Exception {
    MyAction myAction = new MyAction();
    MyAction fallAction = new MyAction();
    
    ActionMap other = new ActionMap();
    ActionMap tc = new ActionMap();
    tc.put("somekey", myAction);
    
    InstanceContent ic = new InstanceContent();
    AbstractLookup al = new AbstractLookup(ic);
    ic.add(tc);
    
    ContextAwareAction a = callback("somekey", fallAction, al, false);
    CntListener l = new CntListener();
    a.addPropertyChangeListener(l);

    assertTrue("My action is on", myAction.isEnabled());
    assertTrue("Callback is on", a.isEnabled());
    
    l.assertCnt("No change yet", 0);
    
    ic.remove(tc);
    assertTrue("fall is on", fallAction.isEnabled());
    assertTrue("My is on as well", a.isEnabled());

    l.assertCnt("Still enabled, so no change", 0);
    
    fallAction.setEnabled(false);
    
    l.assertCnt("Now there was one change", 1);
    
    assertFalse("fall is off", fallAction.isEnabled());
    assertFalse("My is off as well", a.isEnabled());
    
    
    Action a2 = a.createContextAwareInstance(Lookup.EMPTY);
    assertEquals("Both actions are equal", a, a2);
    assertEquals("and have the same hash", a.hashCode(), a2.hashCode());
}
 
Example 12
Source File: GlobalManagerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testActionsCanHoldOnLookup() {
    class TopComponent extends JPanel implements Lookup.Provider {
        Lookup l;

        void associateLookup(Lookup f) {
            l = f;
        }

        public Lookup getLookup() {
            return l;
        }
    }
    TopComponent tc = new TopComponent();
    class CAA extends AbstractAction implements
            ContextAwareAction {
        public void actionPerformed(ActionEvent arg0) {
            throw new UnsupportedOperationException("Not supported yet.");
        }

        public Action createContextAwareInstance(Lookup actionContext) {
            return this;
        }

    }
    tc.associateLookup(Lookups.fixed(tc.getActionMap(), tc));
    ContextAwareAction del = new CAA();
    ContextAwareAction context = Actions.context(Integer.class, true, true, del, null, "DisplayName", null, true);
    Action a = context.createContextAwareInstance(tc.getLookup());
    tc.getActionMap().put("key", a);

    WeakReference<Object> ref = new WeakReference<Object>(tc);
    tc = null;
    a = null;
    del = null;
    context = null;
    assertGC("Can the component GC?", ref);

}
 
Example 13
Source File: CallbackSystemActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testPropertyChangeListenersDetachedAtFinalizeIssue58100() throws Exception {
    
    class MyAction extends AbstractAction {
        public void actionPerformed(ActionEvent ev) {
        }
    }
    MyAction action = new MyAction();
    ActionMap map = new ActionMap();
    
    map.put("key", action);
    Lookup context = Lookups.singleton(map);
    ContextAwareAction systemaction = CallbackActionTest.callback("key", null, Utilities.actionsGlobalContext(), false);
    Action delegateaction = systemaction.createContextAwareInstance(context);
    
    assertEquals("Action is expected to have no listener", 0, action.getPropertyChangeListeners().length);
    
    Reference<Object> actionref = new WeakReference<Object>(systemaction);
    systemaction = null;
    delegateaction = null;
    assertGC("CallbackSystemAction is supposed to be GCed", actionref);
    
    assertEquals(
        "Action is expected to have no PropertyChangeListener attached:\n" + 
            Arrays.asList(action.getPropertyChangeListeners())
        , 0, 
        action.getPropertyChangeListeners().length
    );
}
 
Example 14
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testSurviveFocusChangeBehavior() throws Exception {
    class MyAction extends AbstractAction {
        public int cntEnabled;
        public int cntPerformed;
        
        @Override
        public boolean isEnabled() {
            cntEnabled++;
            return true;
        }
        
        @Override
        public void actionPerformed(ActionEvent ev) {
            cntPerformed++;
        }
    }
    MyAction myAction = new MyAction();
    
    ActionMap disable = new ActionMap();
    ActionMap enable = new ActionMap();
    
    InstanceContent ic = new InstanceContent();
    AbstractLookup al = new AbstractLookup(ic);
    
    ContextAwareAction temp = (ContextAwareAction) Actions.forID("Windows", "my.survival.action");
    Action a = temp.createContextAwareInstance(al);
    
    enable.put(SURVIVE_KEY, myAction);
    
    ic.add(enable);
    assertTrue("MyAction is enabled", a.isEnabled());
    ic.set(Collections.singletonList(disable), null);
    assertTrue("Remains enabled on other component", a.isEnabled());
    ic.remove(disable);
}
 
Example 15
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCallbackOnFieldAction() throws Exception {
    Callback.cnt = 0;
    
    FileObject fo = FileUtil.getConfigFile(
        "Actions/Edit/my-field-action.instance"
    );
    assertNotNull("File found", fo);
    Object icon = fo.getAttribute("iconBase");
    assertEquals("Icon found", "org/openide/awt/TestIcon.png", icon);
    Object obj = fo.getAttribute("instanceCreate");
    assertNotNull("Attribute present", obj);
    assertTrue("It is context aware action", obj instanceof ContextAwareAction);
    ContextAwareAction a = (ContextAwareAction)obj;

    class MyAction extends AbstractAction {
        int cnt;
        @Override
        public void actionPerformed(ActionEvent e) {
            cnt += e.getID();
        }
    }
    MyAction my = new MyAction();
    ActionMap m = new ActionMap();
    m.put(ACTION_MAP_KEY, my);

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(m);

    assertEquals("I am context", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Local Action called", 300, my.cnt);
    assertEquals("Global Action not called", 0, Callback.cnt);

    ic.remove(m);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Local Action stays", 300, my.cnt);
    assertEquals("Global Action not called, there is no fallback", 0, Callback.cnt);
}
 
Example 16
Source File: ActionProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCallbackAction() throws Exception {
    Callback.cnt = 0;
    ContextAwareAction a = (ContextAwareAction) Actions.forID("Tools", "my.action");

    class MyAction extends AbstractAction {
        int cnt;
        @Override
        public void actionPerformed(ActionEvent e) {
            cnt += e.getID();
        }
    }
    MyAction my = new MyAction();
    ActionMap m = new ActionMap();
    m.put("klic", my);

    InstanceContent ic = new InstanceContent();
    AbstractLookup lkp = new AbstractLookup(ic);
    Action clone = a.createContextAwareInstance(lkp);
    ic.add(m);

    assertEquals("I am context", clone.getValue(Action.NAME));
    clone.actionPerformed(new ActionEvent(this, 300, ""));
    assertEquals("Local Action called", 300, my.cnt);
    assertEquals("Global Action not called", 0, Callback.cnt);

    ic.remove(m);
    clone.actionPerformed(new ActionEvent(this, 200, ""));
    assertEquals("Local Action stays", 300, my.cnt);
    assertEquals("Global Action ncalled", 200, Callback.cnt);
}
 
Example 17
Source File: ContextActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testContextXMLDefinition() throws Exception {
    FileObject folder;
    folder = FileUtil.getConfigFile("actions/support/test");
    assertNotNull("testing layer is loaded: ", folder);

    FileObject fo = folder.getFileObject("testContext.instance");
    
    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof ContextAwareAction)) {
        fail("Shall create an action: " + obj);
    }
    ContextAwareAction caa = (ContextAwareAction)obj;
    Action action = caa.createContextAwareInstance(lookupProxy);

    assertEquals("Both actions are equal", action, caa);
    assertEquals("and have the same hash", action.hashCode(), caa.hashCode());
    
    
    class SimpleAction extends AbstractAction {
        public int cnt;
        
        public void actionPerformed(ActionEvent e) {
            cnt++;
        }
    }
    SimpleAction simpleAction = new SimpleAction();
    
    ActionMap map = new ActionMap();
    
    
    LookupWithOpenable openLookup = new LookupWithOpenable();
    
    activate(openLookup);
    assertTrue("Our action is enabled", this.getIsEnabled(action));
    openLookup.setHasCookie(false);
    assertFalse("Our action is not enabled", this.getIsEnabled(action));

    activate(openLookup, Lookups.singleton(map));
    assertFalse("Still disabled", this.getIsEnabled(action));
    map.put("contextKey", simpleAction);
    assertTrue("Now enabled", this.getIsEnabled(action));
    
    doActionPerformed(action, new ActionEvent(this, 0, ""));
    assertEquals("simple action invoked", 1, simpleAction.cnt);
    
    openLookup.setHasCookie(true);
    assertTrue("Still enabled", this.getIsEnabled(action));

    doActionPerformed(action, new ActionEvent(this, 0, ""));
    assertEquals("simple action invoked again", 2, simpleAction.cnt);
    
    activate(openLookup, Lookups.singleton(new ActionMap()));
    assertTrue("Yet enabled", this.getIsEnabled(action));
    doActionPerformed(action, new ActionEvent(this, 0, ""));

    assertEquals("Our SimpleCookieAction invoked", 1, SimpleCookieAction.runOn.size());
    List<? extends Openable> open = SimpleCookieAction.runOn.get(0);
    assertEquals("Our SimpleCookieAction invoked", 1, open.size());
    assertSame("the right instance", openLookup.lookup(Openable.class), open.get(0));
    
    String n = (String)action.getValue(Action.NAME);
    assertEquals("Open", n);
}
 
Example 18
Source File: ContextActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testContextXMLDefinitionNoKey() throws Exception {
    FileObject folder;
    folder = FileUtil.getConfigFile("actions/support/test");
    assertNotNull("testing layer is loaded: ", folder);

    FileObject fo = folder.getFileObject("testContextNoKey.instance");

    Object obj = fo.getAttribute("instanceCreate");
    if (!(obj instanceof ContextAwareAction)) {
        fail("Shall create an action: " + obj);
    }
    ContextAwareAction caa = (ContextAwareAction)obj;
    Action action = caa.createContextAwareInstance(lookupProxy);

    assertEquals("Both actions are equal", action, caa);
    assertEquals("and have the same hash", action.hashCode(), caa.hashCode());


    class SimpleAction extends AbstractAction {
        public int cnt;

        public void actionPerformed(ActionEvent e) {
            cnt++;
        }
    }
    SimpleAction simpleAction = new SimpleAction();

    ActionMap map = new ActionMap();


    LookupWithOpenable openLookup = new LookupWithOpenable();

    activate(openLookup);
    assertTrue("Our action is enabled", this.getIsEnabled(action));
    openLookup.setHasCookie(false);
    assertFalse("Our action is not enabled", this.getIsEnabled(action));

    activate(openLookup, Lookups.singleton(map));
    assertFalse("Still disabled", this.getIsEnabled(action));
    map.put("contextKey", simpleAction);
    assertFalse("Action does not react to any key", this.getIsEnabled(action));

    openLookup.setHasCookie(true);
    assertTrue("Still enabled", this.getIsEnabled(action));

    doActionPerformed(action, new ActionEvent(this, 0, ""));
    assertEquals("no meaning in simple action", 0, simpleAction.cnt);
    assertEquals("Our SimpleCookieAction invoked", 1, SimpleCookieAction.runOn.size());
    List<? extends Openable> open = SimpleCookieAction.runOn.get(0);
    assertEquals("Our SimpleCookieAction invoked", 1, open.size());
    assertSame("the right instance", openLookup.lookup(Openable.class), open.get(0));

    String n = (String)action.getValue(Action.NAME);
    assertEquals("Open", n);
}
 
Example 19
Source File: CallbackSystemActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testLookupOfStateInActionMap() throws Exception {
    class MyAction extends AbstractAction {
        int actionPerformed;
        
        public void actionPerformed(ActionEvent ev) {
            actionPerformed++;
        }
        
    }
    MyAction action = new MyAction();
    
    ActionMap map = new ActionMap();
    InstanceContent ic = new InstanceContent();
    AbstractLookup al = new AbstractLookup(ic);
    ContextAwareAction system = CallbackActionTest.callback("systemKey", null, al, false);
    map.put("systemKey", action);
    
    
    
    Action clone;
    
    
    //
    // Without action map
    //
    
    clone = system.createContextAwareInstance(Lookup.EMPTY);
    
    assertTrue("Action should not be enabled if no callback provided", !clone.isEnabled());
    
    //
    // test with actionmap
    //
    action.setEnabled(false);
    
    Lookup context = Lookups.singleton(map);
    clone = system.createContextAwareInstance(context);
    Action clone2 = system.createContextAwareInstance(context);
    
    CntListener listener = new CntListener();
    clone.addPropertyChangeListener(listener);
    CntListener listener2 = new CntListener();
    clone2.addPropertyChangeListener(listener2);
    
    assertTrue("Not enabled now", !clone.isEnabled());
    action.setEnabled(true);
    assertTrue("Clone is enabled because the action in ActionMap is", clone.isEnabled());
    listener.assertCnt("One change expected", 1);
    listener2.assertCnt("One change expected", 1);
    
    clone.actionPerformed(new ActionEvent(this, 0, ""));
    assertEquals("MyAction.actionPerformed invoked", 1, action.actionPerformed);
    
    
    action.setEnabled(false);
    assertTrue("Clone is disabled because the action in ActionMap is", !clone.isEnabled());
    listener.assertCnt("Another change expected", 1);
    listener2.assertCnt("One change expected", 1);
    
    clone.actionPerformed(new ActionEvent(this, 0, ""));
    assertEquals("MyAction.actionPerformed invoked again", 2, action.actionPerformed);
}