当前位置: 首页>>代码示例>>Java>>正文


Java ContextAwareAction.createContextAwareInstance方法代码示例

本文整理汇总了Java中org.openide.util.ContextAwareAction.createContextAwareInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ContextAwareAction.createContextAwareInstance方法的具体用法?Java ContextAwareAction.createContextAwareInstance怎么用?Java ContextAwareAction.createContextAwareInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.util.ContextAwareAction的用法示例。


在下文中一共展示了ContextAwareAction.createContextAwareInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testActionStatusUpdatedOnLookupChange

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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() );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:SaveAsActionTest.java

示例2: testCanTCGarbageCollectWhenActionInMap

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:TopComponentTest.java

示例3: testCanTCGarbageCollectWhenActionInMapAndAssignLookup

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TopComponentTest.java

示例4: testMultiContextAction

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ActionProcessorTest.java

示例5: testActionsUpdatedWhenActionMapChanges

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:GlobalManagerTest.java

示例6: testBasicUsageWithEnablerFromLayer

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:ContextActionTest.java

示例7: testContextAction

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ContextActionInjectTest.java

示例8: testCallbackAction

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ActionProcessorTest.java

示例9: testCallbackOnFieldAction

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:ActionProcessorTest.java

示例10: testSurviveFocusChangeBehavior

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:36,代码来源:ActionProcessorTest.java

示例11: testPropertyChangeListenersDetachedAtFinalizeIssue58100

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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
    );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:CallbackSystemActionTest.java

示例12: testActionsCanHoldOnLookup

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:GlobalManagerTest.java

示例13: testWithFallback

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:CallbackActionTest.java

示例14: testMultiContextAction

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:ContextActionInjectTest.java

示例15: testMultiContextActionLookup

import org.openide.util.ContextAwareAction; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ContextActionInjectTest.java


注:本文中的org.openide.util.ContextAwareAction.createContextAwareInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。