Java Code Examples for org.openide.awt.Actions#forID()

The following examples show how to use org.openide.awt.Actions#forID() . 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: ProfilerToolbarDropdownAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getToolbarPresenter() {
    if (toolbarPresenter == null) {
        // gets the real action registered in the menu from layer
        Action a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachMainProject"); // NOI18N
        final Action attachProjectAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();
        
        // gets the real action registered in the menu from layer
        a = Actions.forID("Profile", "org.netbeans.modules.profiler.actions.AttachAction"); // NOI18N
        final Action attachProcessAction = a != null ? a : /* XXX should be impossible */AttachAction.getInstance();

        JPopupMenu dropdownPopup = new JPopupMenu();
        dropdownPopup.add(createDropdownItem(defaultAction));
        dropdownPopup.add(createDropdownItem(attachProjectAction));
        dropdownPopup.addSeparator();
        dropdownPopup.add(createDropdownItem(attachProcessAction));

        JButton button = DropDownButtonFactory.createDropDownButton(new ImageIcon(
                new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)), dropdownPopup);
        Actions.connect(button, defaultAction);

        toolbarPresenter = button;
    }

    return toolbarPresenter;
}
 
Example 2
Source File: StatefulActionProcessorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks that the action framework reacts uses {@code addChangeListener}
 * @throws Exception 
 */
public void testToggleActionEabledStateChange() throws Exception {
    Action a = Actions.forID("Foo", "test.ToggleAction3");
    assertFalse("Action must be unchecked", (Boolean)a.getValue(Action.SELECTED_KEY));
    assertFalse("Action must be disabled without data", a.isEnabled());
    assertNull("Must not eagerly instantiate", instance2);
    
    ActionModel4 mod = new ActionModel4();
    lookupContent.add(mod);

    assertNull("Must not be created on data presence", instance2);
    assertTrue("Must be enabled when data is ready", a.isEnabled());
    assertFalse("Must not be checked unless guard is true", (Boolean)a.getValue(Action.SELECTED_KEY));

    mod.boolProp = true;
    mod.fire();
    assertTrue("Must become checked after prop change", (Boolean)a.getValue(Action.SELECTED_KEY));
    
    
    a.actionPerformed(new ActionEvent(this, 0, "cmd2"));
    
    assertNotNull(received);
    assertEquals("cmd2", received.getActionCommand());
}
 
Example 3
Source File: StatefulActionProcessorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Checks that the action enables on null property value
 */
public void testEnableOnNull() throws Exception {
    Action a = Actions.forID("Foo", "test.Null");
    assertNotNull(a);
    assertFalse(a.isEnabled());
    
    // now provide model with non-null set up already
    NonNullModel mdl = new NonNullModel();
    
    lookupContent.add(mdl);
    
    assertTrue("Must be enabled after model with property arrives", a.isEnabled());
    
    mdl.setProp1(new ArrayList<>());
    assertFalse("Must disable when property becomes null", a.isEnabled());
}
 
Example 4
Source File: SaveIsAsynchronousTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
    saveAction = (ContextAwareAction) Actions.forID("System", "org.openide.actions.SaveAction");
    saveAllAction = Actions.forID("System", "org.openide.actions.SaveAllAction");
    assertNotNull("Save action found", saveAction);
    assertNotNull("Save All action found", saveAllAction);
    
    assertEquals("Nothing in the registry", null, MySavable.REGISTRY.lookup(MySavable.class));
}
 
Example 5
Source File: RandomErrorNode.java    From BART with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    Action[] result = new Action[]{
        Actions.forID("RandomErrorsNode", "it.unibas.bartgui.controlegt.actions.node.randomError.EditToDO"),
        null,
        SystemAction.get(OpenLocalExplorerAction.class)
    };
    return result;
}
 
Example 6
Source File: DirtyStrategiesNode.java    From BART with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    Action[] result = new Action[]{
        Actions.forID("DirtyStrategyNode","it.unibas.bartgui.controlegt.actions.node.DirtyStrategies.EditDirtyStrategy"),
        null,
        Actions.forID("DirtyStrategiesNode", "it.unibas.bartgui.controlegt.actions.node.DirtyStrategies.EditDefaultStrategy"),
        Actions.forID("DirtyStrategiesNode","it.unibas.bartgui.controlegt.actions.node.DirtyStrategies.RemoveDefaultDStrategy"),
        null,
        SystemAction.get(OpenLocalExplorerAction.class),
    };
    return result;
}
 
Example 7
Source File: VioGenQueryNode.java    From BART with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    Action[] result = new Action[]{
        Actions.forID("DependencyNode", 
                "it.unibas.bartgui.controlegt.actions.node.DependenciesNode.Open"),
        null,
        Actions.forID("DependenciesNode", "it.unibas.bartgui.controlegt.actions.node.DependenciesNode.Edit"),
        null,
        SystemAction.get(PropertiesAction.class),
        };
    return result;
}
 
Example 8
Source File: StatefulActionProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCustomListenerAction() {
    Action a = Actions.forID("Foo", "test.ListAction");
    DefaultListSelectionModel model = new DefaultListSelectionModel();
    
    assertFalse(a.isEnabled());
    assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
    
    lookupContent.add(model);
    assertTrue(a.isEnabled());
    assertFalse((Boolean)a.getValue(Action.SELECTED_KEY));
    
    model.addSelectionInterval(1, 1);
    assertTrue(a.isEnabled());
    assertTrue((Boolean)a.getValue(Action.SELECTED_KEY));
}
 
Example 9
Source File: InstanceDataObjectCopyTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp () throws java.lang.Exception {
    clearWorkDir ();
    Lookup.getDefault().lookup(ModuleInfo.class);
    
    openAction = Actions.forID("System", "org.openide.actions.OpenAction");
}
 
Example 10
Source File: DBTableNode.java    From BART with MIT License 5 votes vote down vote up
@Override
public Action[] getActions(boolean context) {
    Action[] a = {
       Actions.forID("DBNode", "it.unibas.bartgui.controlegt.actions.node.dbNode.Open"), 
    };
    return a;
}
 
Example 11
Source File: StatefulActionProcessorTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that an action model is freed, after the actionPerformed is called,
 * and then the focus shifts so the model is not in Lookup.
 */
public void testActionModelFreed() {
    Action a = Actions.forID("Foo", "test.InstAction");
    ActionModel3 mod = new ActionModel3();
    lookupContent.add(mod);
    
    a.actionPerformed(new ActionEvent(this, 0, "cmd"));
    
    reinitActionLookup();
    
    Reference<ActionModel3> r = new WeakReference<>(mod);
    mod = null;
    assertGC("Action model must be GCed", r);
}
 
Example 12
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 13
Source File: TablePopupFactory.java    From Llunatic with GNU General Public License v3.0 4 votes vote down vote up
public TablePopupFactory() {
    super();
    separator.setEnabled(false);
    Action a = Actions.forID("Window", R.ActionId.SHOW_CELL_GROUP_EDITOR);
    cellGroup = new JMenuItem(a);
}
 
Example 14
Source File: NewTabAction.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
protected void performAction() {
    Action forID = Actions.forID("Window", "LocalTerminalAction"); //NOI18N
    forID.actionPerformed(new ActionEvent(getTerminal(), ActionEvent.ACTION_PERFORMED, null));
}
 
Example 15
Source File: DBTableNode.java    From BART with MIT License 4 votes vote down vote up
@Override
public Action getPreferredAction() {
    return Actions.forID("DBNode", "it.unibas.bartgui.controlegt.actions.node.dbNode.Open"); 
}
 
Example 16
Source File: StatefulActionProcessorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Checks how Action.isEnabled() tracks changes in the context and
 * property changes of the context objects
 */
public void testContextActionEnableChanges() throws Exception {
    InstanceContent localContent1 = new InstanceContent();
    AbstractLookup localLookup1 = new AbstractLookup(localContent1);
    InstanceContent localContent2 = new InstanceContent();
    AbstractLookup localLookup2 = new AbstractLookup(localContent2);
    
    ActionModel3 mdlGlobal = new ActionModel3();
    ActionModel3 mdlGlobal2 = new ActionModel3();
    lookupContent.add(mdlGlobal);
    
    Action a = Actions.forID("Foo", "test.InstAction");
    assertFalse("Must be disabled before guard is set", a.isEnabled());
    
    mdlGlobal.boolProp = true;
    mdlGlobal.supp.firePropertyChange("boolProp", null, null);
    assertTrue("Must turn enabled after guard change", a.isEnabled());
    
    // adopt into local context
    localContent1.add(mdlGlobal);
    Action localA = ((ContextAwareAction)a).createContextAwareInstance(localLookup1);
    assertTrue("Context action enable must initialize", localA.isEnabled());
    
    // turn to false
    mdlGlobal.boolProp = false;
    mdlGlobal.supp.firePropertyChange("boolProp", null, null);
    assertFalse("Global action must follow guard", a.isEnabled());
    assertFalse("Context action must follow guard", localA.isEnabled());
    
    mdlGlobal.boolProp = true;
    mdlGlobal.supp.firePropertyChange("boolProp", null, null);
    assertTrue(a.isEnabled());
    assertTrue(localA.isEnabled());

    // remove/replace the model in global Lookup
    lookupContent.remove(mdlGlobal);
    assertFalse("Global action must follow its Lookup", a.isEnabled());
    assertTrue("Context action must listen on its Lookup", localA.isEnabled());
    
    lookupContent.add(mdlGlobal2);
    assertFalse(a.isEnabled());
    assertTrue(localA.isEnabled());
    
    mdlGlobal2.boolProp = true;
    mdlGlobal2.supp.firePropertyChange("boolProp", null, null);
    
    assertTrue("Global action must enbale on new global guard", a.isEnabled());
    assertTrue(localA.isEnabled());
    
    mdlGlobal.boolProp = false;
    mdlGlobal.supp.firePropertyChange("boolProp", null, null);
    assertFalse("Context action must follow remembered guard", localA.isEnabled());
    
    ActionModel3 mdl3 = new ActionModel3();
    localContent2.add(mdl3);
    
    Action localB = ((ContextAwareAction)a).createContextAwareInstance(localLookup2);
    assertFalse(localB.isEnabled());
    
    mdl3.boolProp = true;
    mdl3.supp.firePropertyChange("boolProp", null, null);
    assertTrue(localB.isEnabled());
    assertFalse(localA.isEnabled());
}
 
Example 17
Source File: PatchesMenu.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Action getPatchAction () {
    return Actions.forID("Tools", "org.netbeans.modules.diff.PatchAction"); //NOI18N
}
 
Example 18
Source File: ActionFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static Action forID(String id) {
return Actions.forID(CATEGORY, id);
   }
 
Example 19
Source File: StatisticNode.java    From BART with MIT License 4 votes vote down vote up
@Override
public Action getPreferredAction() {
    return Actions.forID("StatisticNode", "it.unibas.bartgui.controlegt.actions.node.Statistics.Open");
}
 
Example 20
Source File: VioGenQueryNode.java    From BART with MIT License 4 votes vote down vote up
@Override
public Action getPreferredAction() {
    return Actions.forID("DependencyNode", 
                "it.unibas.bartgui.controlegt.actions.node.DependenciesNode.Open");
}