org.openide.awt.Actions Java Examples
The following examples show how to use
org.openide.awt.Actions.
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: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * Checks that custom action isEnable is called when no property is specified */ public void testCustomEnableActionNoPropety() { Action a = Actions.forID("Foo", "test.CustomEnableAction2"); assertFalse(a.isEnabled()); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); assertNotNull(instance); CustomEnableAction2 save = (CustomEnableAction2)instance; instance.setEnabled(true); assertTrue(a.isEnabled()); a.actionPerformed(new ActionEvent(this, 0, "cmd2")); assertSame(save, instance); }
Example #2
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 |
/** * Checks that the action enables on non-null property value */ public void testEnableOnNonNull() throws Exception { Action a = Actions.forID("Foo", "test.NonNull"); assertNotNull(a); assertFalse(a.isEnabled()); // now provide model with non-null set up already NonNullModel mdl = new NonNullModel(); mdl.setProp1(new ArrayList<>()); lookupContent.add(mdl); assertTrue("Must be enabled after model with property arrives", a.isEnabled()); mdl.setProp1(null); assertFalse("Must disable when property becomes null", a.isEnabled()); }
Example #4
Source File: TabsComponent.java From netbeans with Apache License 2.0 | 6 votes |
private JToggleButton createButton(MultiViewDescription description) { final JToggleButton button = new JToggleButton(); Mnemonics.setLocalizedText(button, Actions.cutAmpersand(description.getDisplayName())); button.setModel(new TabsButtonModel(description)); button.setRolloverEnabled(true); Border b = (getButtonBorder()); if (b != null) { button.setBorder(b); } if( AQUA ) { button.putClientProperty("JButton.buttonType", "square"); button.putClientProperty("JComponent.sizeVariant", "small"); } if (buttonMouseListener == null) { buttonMouseListener = new ButtonMouseListener(); } button.addMouseListener (buttonMouseListener); button.setToolTipText(NbBundle.getMessage(TabsComponent.class, "TabButton.tool_tip", button.getText())); button.setFocusable(true); button.setFocusPainted(true); return button; }
Example #5
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * Checks that toggle action is not instantiated prematurely */ public void testToggleActionInstantiate() throws Exception { Action a = Actions.forID("Foo", "test.ToggleAction"); assertFalse("Action must be unchecked", (Boolean)a.getValue(Action.SELECTED_KEY)); assertNull("Must not eagerly instantiate", instance2); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); assertNull("Must not instantiate just on data presence", instance2); mod.boolProp = true; mod.supp.firePropertyChange("boolProp", null, null); assertNull("Must not instantiate just when guard goes true", instance2); a.actionPerformed(new ActionEvent(this, 0, "cmd2")); // instantiated assertNotNull(instance2); }
Example #6
Source File: ProfilerToolbarDropdownAction.java From netbeans with Apache License 2.0 | 6 votes |
private static JMenuItem createDropdownItem(final Action action) { String name = (String)action.getValue("menuText"); // NOI18N if (name == null || name.trim().isEmpty()) name = (String)action.getValue(NAME); final JMenuItem item = new JMenuItem(Actions.cutAmpersand(name)) { public void fireActionPerformed(ActionEvent e) { action.actionPerformed(e); } }; item.setEnabled(action.isEnabled()); // #231371 action.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String propName = evt.getPropertyName(); if ("enabled".equals(propName)) { // NOI18N item.setEnabled((Boolean)evt.getNewValue()); } else if ("menuText".equals(propName)) { // NOI18N item.setText(Actions.cutAmpersand((String) evt.getNewValue())); } } }); return item; }
Example #7
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 testToggleActionModelFreed() { ActionModel3 mod = new ActionModel3(); mod.boolProp = true; lookupContent.add(mod); Action a = Actions.forID("Foo", "test.ToggleAction"); assertTrue("Must become checked after prop change", (Boolean)a.getValue(Action.SELECTED_KEY)); a.actionPerformed(new ActionEvent(this, 0, "cmd")); reinitActionLookup(); Reference<ActionModel3> r = new WeakReference<>(mod); mod = null; assertGC("Action model must be GCed", r); }
Example #8
Source File: ProfilerToolbarDropdownAction.java From netbeans with Apache License 2.0 | 6 votes |
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 #9
Source File: TopComponentTest.java From netbeans with Apache License 2.0 | 6 votes |
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 #10
Source File: TopComponentTest.java From netbeans with Apache License 2.0 | 6 votes |
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 #11
Source File: RefactoringContextAction.java From netbeans with Apache License 2.0 | 6 votes |
@Override public JComponent[] synchMenuPresenters(JComponent[] items) { JComponent[] comps = new JComponent[1]; for (JComponent item : items) { if (item instanceof Actions.MenuItem) { comps[0] = item; // update menu items to reflect Action.isEnabled ((Actions.MenuItem) item).synchMenuPresenters(comps); } else if(item instanceof JMenu) { JMenu jMenu = (JMenu) item; for (Component subItem : jMenu.getMenuComponents()) { if (subItem instanceof Actions.MenuItem) { comps[0] = (JComponent) subItem; // update menu items to reflect Action.isEnabled ((Actions.MenuItem) subItem).synchMenuPresenters(comps); } } } } // returns most up-to date items return createMenuItems(); }
Example #12
Source File: ActionProcessorTest.java From netbeans with Apache License 2.0 | 6 votes |
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 #13
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that the stateful action is instantiated only just before it is * invoked. Enablement should be evaluated by the framework without any * user code loaded. */ public void testEnableActionInstantiation() { assertEquals("Not pre-created", 0, created); Action a = Actions.forID("Foo", "test.InstAction"); assertNotNull(a); assertEquals("Not direcly created from layer", 0, created); assertFalse("No data in lookup", a.isEnabled()); assertEquals("Not created unless data present", 0, created); ActionModel3 mod = new ActionModel3(); lookupContent.add(mod); // still not enabled assertFalse("Property not sets", a.isEnabled()); assertEquals("Not created unless guard is set", 0, created); mod.boolProp = true; mod.supp.firePropertyChange("boolProp", null, null); assertTrue("Property not set", a.isEnabled()); assertEquals("Not created before invocation", 0, created); a.actionPerformed(new ActionEvent(this, 0, "cmd")); assertEquals("Not created before invocation", 1, created); assertNotNull(received); assertEquals("cmd", received.getActionCommand()); }
Example #14
Source File: TopComponentProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testMultipleUsageInEQ() throws Exception { FileObject pukMuk = FileUtil.getConfigFile("Puk/Muk/multi-use.shadow"); assertNotNull("One reference found", pukMuk); FileObject jukLuk = FileUtil.getConfigFile("Juk/Luk/multi-use.shadow"); assertNotNull("2nd reference found", jukLuk); Action a = Actions.forID("Windows", "multi.use"); assertNotNull("Action created", a); assertEquals("No call to withReferences factory yet", 0, TC.cnt2); a.actionPerformed(new ActionEvent(this, 0, null)); assertEquals("One call to factory", 1, TC.cnt2); }
Example #15
Source File: NodeAction.java From netbeans with Apache License 2.0 | 5 votes |
public JMenuItem getMenuPresenter() { if (isMethodOverridden(delegate, "getMenuPresenter")) { // NOI18N return delegate.getMenuPresenter(); } else { return new Actions.MenuItem(this, true); } }
Example #16
Source File: CoverageAction.java From netbeans with Apache License 2.0 | 5 votes |
public JMenuItem getPopupPresenter() { if (project != null) { return createMenu(project, configureAction, extraActions); } else { return new Actions.MenuItem(this, false); } }
Example #17
Source File: ConfEGTaskConfNode.java From BART with MIT License | 5 votes |
@Override public Action[] getActions(boolean context) { Action[] result = new Action[]{ Actions.forID("ConfRGTaskConfNode", "it.unibas.bartgui.controlegt.actions.node.ConfEGTNode.Edit"), null, SystemAction.get(PropertiesAction.class), }; return result; }
Example #18
Source File: RunGruntTaskAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public JMenuItem getPopupPresenter() { if (project == null) { return new Actions.MenuItem(this, false); } return BuildTools.getDefault().createTasksMenu(new TasksMenuSupportImpl(project, gruntfile)); }
Example #19
Source File: SimpleNode.java From BART with MIT License | 5 votes |
@Override public Action[] getActions(boolean context) { Action[] a = super.getActions(context); Action[] all = new Action[a.length+ 2]; System.arraycopy(a, 0, all, 2, a.length); all[0]=Actions.forID("SimpleNode", "it.unibas.bartgui.controlegt.actions.LoadSimpleNode"); all[1]=null; return all; }
Example #20
Source File: InstanceDataObjectCopyTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void setUp () throws java.lang.Exception { clearWorkDir (); Lookup.getDefault().lookup(ModuleInfo.class); openAction = Actions.forID("System", "org.openide.actions.OpenAction"); }
Example #21
Source File: PropertiesAction.java From netbeans with Apache License 2.0 | 5 votes |
public JMenuItem getPopupPresenter() { JMenuItem prop = new Actions.MenuItem(this, false); Action customizeAction = SystemAction.get(CustomizeAction.class); // Retrieve context sensitive action instance if possible. if (lookup != null) { customizeAction = ((ContextAwareAction) customizeAction).createContextAwareInstance(lookup); } if (customizeAction.isEnabled()) { JInlineMenu mi = new JInlineMenu(); mi.setMenuItems(new JMenuItem[] { new Actions.MenuItem(customizeAction, false), prop }); return mi; } else { for (Node n : nodes()) { for (Node.PropertySet ps : n.getPropertySets()) { if (ps.getProperties().length > 0) { // OK, we have something to show! return prop; } } } // else nothing to show, so show nothing return new JInlineMenu(); } }
Example #22
Source File: ProjectTestRestServicesAction.java From netbeans with Apache License 2.0 | 5 votes |
private ProjectTestRestServicesAction(Lookup lookup) { if (lookup == null) { lookup = Utilities.actionsGlobalContext(); } this.lookup = lookup; watch = new Class[]{Project.class, DataObject.class}; command = RestSupport.COMMAND_TEST_RESTBEANS; presenterName = NbBundle.getMessage(ProjectTestRestServicesAction.class, "LBL_TestRestBeansAction_Name"); setDisplayName(presenterName); putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); }
Example #23
Source File: DirtyStrategyTableNode.java From BART with MIT License | 5 votes |
@Override public Action[] getActions(boolean context) { Action[] a = { Actions.forID("DirtyStrategiesNode", "it.unibas.bartgui.controlegt.actions.node.DirtyStrategies.EditDirtyStrategyTableNode"), null, Actions.forID("DirtyStrategiesNode", "it.unibas.bartgui.controlegt.actions.node.DirtyStrategies.RemoveDirtyStrategyTableNode"), }; return a; }
Example #24
Source File: StatefulActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that the "enabled" property is used by default if property is not specified * @throws Exception */ public void testDefaulPropertyEnable() throws Exception { Action a = Actions.forID("Foo", "test.DefEnableAction"); assertFalse(a.isEnabled()); DefaultActionModel mod = new DefaultActionModel(); lookupContent.add(mod); assertFalse(a.isEnabled()); mod.setEnabled(true); assertTrue(a.isEnabled()); }
Example #25
Source File: DefaultAWTBridge.java From netbeans with Apache License 2.0 | 5 votes |
public JMenuItem createMenuPresenter (Action action) { if (action instanceof BooleanStateAction) { BooleanStateAction b = (BooleanStateAction)action; return new Actions.CheckboxMenuItem (b, true); } if (action.getValue(Actions.ACTION_VALUE_TOGGLE) != null) { return new Actions.CheckboxMenuItem(action, true); } if (action instanceof SystemAction) { SystemAction s = (SystemAction)action; return new Actions.MenuItem (s, true); } return new Actions.MenuItem (action, true); }
Example #26
Source File: StatisticNode.java From BART with MIT License | 5 votes |
@Override public Action[] getActions(boolean context) { Action[] a = { Actions.forID("StatisticNode", "it.unibas.bartgui.controlegt.actions.node.Statistics.Open"), Actions.forID("StatisticNode", "it.unibas.bartgui.controlegt.actions.node.Statistics.Export"), null, SystemAction.get(RenameAction.class), SystemAction.get(DeleteAction.class), null, SystemAction.get(PropertiesAction.class), }; return a; }
Example #27
Source File: ActionProcessorTest.java From netbeans with Apache License 2.0 | 5 votes |
@ActionReferences({ @ActionReference( path="Loaders/text/x-my/Actions", id=@ActionID(category="System", id="org.openide.actions.OpenAction"), position=100, separatorAfter=200 ) }) public void testAlwaysEnabledAction() throws Exception { assertEquals("Not created yet", 0, Always.created); Action a = Actions.forID("Tools", "my.test.Always"); assertNotNull("action found", a); assertEquals("Still not created", 0, Always.created); assertEquals("I am always on!", a.getValue(Action.NAME)); assertEquals("Not even now created", 0, Always.created); a.actionPerformed(new ActionEvent(this, 300, "")); assertEquals("Created now!", 1, Always.created); assertEquals("Action called", 300, Always.cnt); FileObject shad = FileUtil.getConfigFile( "My/Folder/D-F6.shadow" ); assertNotNull("Shadow created", shad); assertEquals("Right position", 333, shad.getAttribute("position")); assertEquals("Proper link", "Actions/Tools/my-test-Always.instance", shad.getAttribute("originalFile")); }
Example #28
Source File: DependenciesEditorTopComponent.java From BART with MIT License | 5 votes |
private void init() { scrPane = new JScrollPane(); editorButton = new EditorButtonPanel(); editorButton.getSaveRButton() .setAction( Actions.forID("DependenciesNode", "it.unibas.bartgui.controlegt.actions.node.DependenciesNode.ReloadDependencies")); /*editorButton.getResetButton() .setAction( Actions.forID("DependenciesNode", "it.unibas.bartgui.controlegt.actions.node.DependenciesNode.Reset"));*/ textPane = new JTextPane(new DependenciesStyleContext()); //textPane.getDocument().addUndoableEditListener(UndoRedomanager); textPane.getDocument().addDocumentListener(new DocListener()); JScrollPane scrPaneText = new JScrollPane(); scrPaneText.setViewportView(textPane); textLineNumber = new TextLineNumber(textPane); scrPaneText.setRowHeaderView(textLineNumber); //JPanel panel = new JPanel(new BorderLayout()); //panel.add(editorButton,BorderLayout.NORTH); //panel.add(scrPaneText,BorderLayout.CENTER); //scrPane.setViewportView(panel); add(editorButton,BorderLayout.NORTH); add(scrPaneText,BorderLayout.CENTER); }
Example #29
Source File: OutlierErrorTableNode.java From BART with MIT License | 5 votes |
@Override public Action[] getActions(boolean context) { Action[] result = new Action[]{ Actions.forID("RandomErrorsNode", "it.unibas.bartgui.controlegt.actions.node.randomError.EditToDO"), }; return result; }
Example #30
Source File: ProjectAction.java From netbeans with Apache License 2.0 | 5 votes |
@SuppressWarnings("LeakingThisInConstructor") private ProjectAction(String command, ProjectActionPerformer performer, String namePattern, String popupPattern, Icon icon, Lookup lookup) { super(icon, lookup, new Class<?>[] {Project.class, DataObject.class}); this.command = command; if ( command != null ) { ShortcutManager.INSTANCE.registerAction(command, this); } this.performer = performer; this.namePattern = namePattern; this.popupPattern = popupPattern; String presenterName = ActionsUtil.formatName( getNamePattern(), 0, "" ); setDisplayName( presenterName ); putValue(SHORT_DESCRIPTION, Actions.cutAmpersand(presenterName)); }