Java Code Examples for javax.swing.Action#isEnabled()
The following examples show how to use
javax.swing.Action#isEnabled() .
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: MergeAction.java From netbeans with Apache License 2.0 | 6 votes |
Action getDelegateAction() { Action result = null; synchronized (this) { result = delegateAction; if (result == null || !result.isEnabled()) { if (attached()) { result = updateDelegateAction(); } else { result = findEnabledAction(); } } } if (result == null) { result = actions[0]; } return result; }
Example 2
Source File: IsOverriddenAnnotationAction.java From netbeans with Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent e) { if (!invokeDefaultAction((JTextComponent) e.getSource())) { Action actions[] = ImplementationProvider.getDefault().getGlyphGutterActions((JTextComponent) e.getSource()); if (actions == null) return ; int nextAction = 0; while (nextAction < actions.length && actions[nextAction] != this) nextAction++; nextAction++; if (actions.length > nextAction) { Action a = actions[nextAction]; if (a!=null && a.isEnabled()){ a.actionPerformed(e); } } } }
Example 3
Source File: ActionsSearchProvider.java From netbeans with Apache License 2.0 | 6 votes |
private Action checkNodeAction (Action action) { if (action == null) { return null; } try { if (action.isEnabled()) { return action; } } catch (Throwable thr) { if (thr instanceof ThreadDeath) { throw (ThreadDeath)thr; } // just log problems, it is common that some actions may complain Logger.getLogger(getClass().getName()).log(Level.FINE, "Problem asking isEnabled on action " + action, thr); } return null; }
Example 4
Source File: TreeView.java From netbeans with Apache License 2.0 | 6 votes |
static void performPreferredActionOnNodes(Node[] nodes) { if (nodes.length > 0) { Action a = nodes[0].getPreferredAction(); if (a == null) { return; } for (int i=1; i<nodes.length; i++) { Action ai = nodes[i].getPreferredAction(); if (ai == null || !ai.equals(a)) { return; } } // switch to replacement action if there is some a = takeAction(a, nodes); if (a != null && a.isEnabled()) { a.actionPerformed(new ActionEvent( nodes.length == 1 ? nodes[0] : nodes, ActionEvent.ACTION_PERFORMED, "")); // NOI18N } else { Utilities.disabledActionBeep(); } } }
Example 5
Source File: CategoryList.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void actionPerformed( ActionEvent e ) { Item item = getItemAt( getSelectedIndex() ); if( null == item ) return; Node itemNode = item.getLookup().lookup(org.openide.nodes.Node.class); if( null == itemNode ) return; Action performer; if( doCopy ) performer = new Utils.CopyItemAction( itemNode ); else performer = new Utils.CutItemAction( itemNode ); if( performer.isEnabled() ) performer.actionPerformed( e ); }
Example 6
Source File: VCSStatusTable.java From netbeans with Apache License 2.0 | 5 votes |
/** * Called when user dbl-clicks on a node. May be intercepted and handled in a different way. By default a node's preferred action is invoked. * @param node */ protected void mouseClicked (VCSStatusNode node) { Action action = node.getNodeAction(); if (action != null && action.isEnabled()) { action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, node.getFile().getAbsolutePath())); } }
Example 7
Source File: ActionConcentrator.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Returns, whether all actions are disabled. * If one action is enabled, then this method will return * true. * * @return true, if at least one action is enabled, false * otherwise. */ public boolean isEnabled() { for (int i = 0; i < this.actions.size(); i++) { final Action a = (Action) this.actions.get(i); if (a.isEnabled()) { return true; } } return false; }
Example 8
Source File: GeneralAction.java From netbeans with Apache License 2.0 | 5 votes |
void updateState(ActionMap prev, ActionMap now, boolean fire) { if (key == null) { return; } boolean prevEnabled = false; if (prev != null) { Action prevAction = prev.get(key); if (prevAction != null) { prevEnabled = fire && prevAction.isEnabled(); prevAction.removePropertyChangeListener(weakL); } } if (now != null) { Action nowAction = now.get(key); boolean nowEnabled; if (nowAction != null) { nowAction.addPropertyChangeListener(weakL); nowEnabled = nowAction.isEnabled(); } else { nowEnabled = fallback != null && fallback.isEnabled(); } PropertyChangeSupport sup = fire ? support : null; if (sup != null && nowEnabled != prevEnabled) { sup.firePropertyChange("enabled", prevEnabled, !prevEnabled); // NOI18N } } }
Example 9
Source File: PropertyMonitor.java From netbeans with Apache License 2.0 | 5 votes |
public boolean inspectAction(Action a) { if (a == null) { return false; } if ("enabled".equals(property)) { // NOI18N return a.isEnabled(); } return a.getValue(property) == Boolean.TRUE; }
Example 10
Source File: FileTreeView.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && MouseUtils.isDoubleClick(e)) { int row = view.getOutline().rowAtPoint(e.getPoint()); if (row == -1) return; T n = convertNode(getNodeAt(view.getOutline().convertRowIndexToModel(row))); if (n != null) { Action action = n.getNodeAction(); if (action != null && action.isEnabled()) { action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "")); // NOI18N e.consume(); } } } }
Example 11
Source File: TerminalContainerTopComponent.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void componentOpened() { TerminalPinSupport support = TerminalPinSupport.getDefault(); List<TerminalPinSupport.TerminalDetails> readStoredDetails = support.readStoredDetails(); // support.clear(); for (TerminalPinSupport.TerminalDetails details : readStoredDetails) { TerminalPinSupport.TerminalCreationDetails creationDetails = details.getCreationDetails(); TerminalPinSupport.TerminalPinningDetails pinningDetails = details.getPinningDetails(); ExecutionEnvironment env = ExecutionEnvironmentFactory.fromUniqueID(creationDetails.getExecEnv()); String cwd = pinningDetails.getCwd(); if (cwd.isEmpty()) { /* Will be opened in a default location */ cwd = null; } TerminalSupport.restoreTerminal(pinningDetails.getTitle(), env, cwd, creationDetails.isPwdFlag(), creationDetails.getId()); } JComponent selectedTerminal = getIOContainer().getSelected(); if (selectedTerminal == null && (this.getClientProperty(AUTO_OPEN_LOCAL_PROPERTY) != Boolean.FALSE)) { for (Action action : getToolbarActions()) { if (action.getValue(Action.NAME).toString().startsWith(LOCAL_TERMINAL_PREFIX) && action.isEnabled()) { action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, SILENT_MODE_COMMAND)); break; } } } }
Example 12
Source File: ProjectActionTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCommandEnablement() throws Exception { TestSupport.ChangeableLookup lookup = new TestSupport.ChangeableLookup(); Action action = new ProjectAction("COMMAND", "TestProjectAction", null, lookup); action.isEnabled(); // priming check assertEnablement(action, false); lookup.change(d1_1); assertEnablement(action, true); lookup.change(d1_1, d1_2); assertEnablement(action, false); lookup.change(d1_1, d2_1); assertEnablement(action, false); TestActionProvider tap2 = new TestActionProvider(); project2.setLookup(Lookups.singleton(tap2)); lookup.change(d2_1); assertEnablement(action, true); lookup.change(d1_1, d2_1); assertEnablement(action, true); action.actionPerformed(null); assertEquals("[COMMAND]", tap1.invocations.toString()); assertEquals("[COMMAND]", tap2.invocations.toString()); tap1.listenerSuccess = true; tap2.listenerSuccess = true; action.actionPerformed(null); assertEquals("[COMMAND, COMMAND]", tap1.invocations.toString()); assertEquals("[COMMAND, COMMAND]", tap2.invocations.toString()); tap1.listenerSuccess = false; action.actionPerformed(null); assertEquals("[COMMAND, COMMAND, COMMAND]", tap1.invocations.toString()); assertEquals("[COMMAND, COMMAND]", tap2.invocations.toString()); }
Example 13
Source File: TaskListTable.java From netbeans with Apache License 2.0 | 5 votes |
public void actionPerformed( ActionEvent e ) { if( 0 == getModel().getRowCount() ) return; int currentRow = getSelectedRow(); if( currentRow < 0 ) { currentRow = 0; } else if( !(isFoldingModel() && getFoldingModel().isGroupRow(currentRow)) ) { currentRow += (navigateToNextTask ? 1 : -1); } TaskListModel tlm = (TaskListModel)getModel(); while( true ) { if( currentRow < 0 ) currentRow = tlm.getRowCount()-1; else if( currentRow >= tlm.getRowCount() ) currentRow = 0; Task t = tlm.getTaskAtRow( currentRow ); if( null != t ) { getSelectionModel().setSelectionInterval( currentRow, currentRow ); scrollRectToVisible( getCellRect( currentRow, 0, true ) ); Action a = new OpenTaskAction( t ); if( a.isEnabled() ) { a.actionPerformed( e ); } else { TaskListTopComponent.findInstance().requestActive(); } break; } else if( isFoldingModel() ) { FoldingTaskListModel.FoldingGroup fg = getFoldingModel().getGroupAtRow( currentRow ); if( !fg.isExpanded() ) fg.setExpanded( true ); } currentRow += (navigateToNextTask ? 1 : -1); } }
Example 14
Source File: CategoryNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Action[] getActions(boolean context) { if (actions == null) { Node n = getParentNode(); if( null == n ) { return new Action[0]; } List<Action> actionList = new ArrayList<Action>(12); actionList.add( new Utils.PasteItemAction( this ) ); actionList.add( null ); Action a = new Utils.NewCategoryAction( n ); if( a.isEnabled() ) { actionList.add( a ); actionList.add( null ); } actionList.add( new Utils.DeleteCategoryAction(this) ); actionList.add( new Utils.RenameCategoryAction(this) ); actionList.add( null ); actionList.add( new Utils.SortItemsAction(this) ); actionList.add( null ); actionList.add( new Utils.SortCategoriesAction( n ) ); actionList.add( null ); actionList.add( new Utils.RefreshPaletteAction() ); actions = actionList.toArray( new Action[actionList.size()] ); } PaletteActions customActions = (PaletteActions)getParentNode().getLookup().lookup( PaletteActions.class ); if( null != customActions ) { return Utils.mergeActions( actions, customActions.getCustomCategoryActions( getLookup() ) ); } return actions; }
Example 15
Source File: IssueTable.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == '\n') { // NOI18N int row = table.getSelectedRow(); if (row != -1) { row = sorter.modelIndex(row); Action action = tableModel.getNodes()[row].getPreferredAction(); if (action.isEnabled()) { action.actionPerformed(new ActionEvent(this, 0, "")); // NOI18N } } } }
Example 16
Source File: IndirectAction.java From netbeans with Apache License 2.0 | 4 votes |
@Override protected boolean isEnabled(Collection<? extends T> targets) { Action delegateStub = delegate.createContextAwareInstance(delegateLookup(targets)); return delegateStub.isEnabled(); }
Example 17
Source File: DefaultItem.java From netbeans with Apache License 2.0 | 4 votes |
public void invokePreferredAction( ActionEvent e ) { Action action = itemNode.getPreferredAction(); if( null != action && action.isEnabled() ) { action.actionPerformed( e ); } }
Example 18
Source File: KeysTableView.java From pgptool with GNU General Public License v3.0 | 4 votes |
private void safePerformAction(Action action, ActionEvent event) { if (action != null && action.isEnabled()) { action.actionPerformed(event); } }
Example 19
Source File: LookupSensitiveActionTest.java From netbeans with Apache License 2.0 | 4 votes |
protected boolean isEnabled(Action action) { assertTrue("Is AWT thread", EventQueue.isDispatchThread()); return action.isEnabled(); }
Example 20
Source File: ExplorerContextMenuFactory.java From visualvm with GNU General Public License v2.0 | 4 votes |
private List<Action>[] getActions(FileObject actionsFO, boolean allowDefaultActions) { // Init caches for default and regular context menu actions List<Action> defaultActions = new ArrayList(); List<Action> actions = new ArrayList(); if (actionsFO != null) { DataFolder actionsDF = DataFolder.findFolder(actionsFO); DataObject[] menuItems = actionsDF.getChildren(); for (DataObject menuItemDO : menuItems) { FileObject fobj = menuItemDO.getPrimaryFile(); if (fobj.isFolder()) { LOGGER.log(Level.WARNING, "Nested menus not supported for Applications context menu: " + fobj, fobj); // NOI18N } else { InstanceCookie menuItemCookie = (InstanceCookie)menuItemDO.getCookie(InstanceCookie.class); try { Object menuItem = menuItemCookie.instanceCreate(); boolean isDefaultAction = false; Object isDefaultActionObj = fobj.getAttribute("default"); // NOI18N if (isDefaultActionObj != null) try { isDefaultAction = (Boolean)isDefaultActionObj; if (!allowDefaultActions && isDefaultAction) LOGGER.log(Level.WARNING, "Default actions not supported for " + actionsFO.getPath() + ": " + menuItem, menuItem); // NOI18N } catch (Exception e) { LOGGER.log(Level.WARNING, "Cannot determine whether context menu action is default: " + isDefaultActionObj, isDefaultActionObj); // NOI18N } List<Action> actionsList = isDefaultAction ? defaultActions : actions; if (menuItem instanceof Action) { Action action = (Action)menuItem; if (action.isEnabled()) actionsList.add(action); } else if (menuItem instanceof JSeparator) { if (isDefaultAction) { LOGGER.log(Level.WARNING, "Separator cannot be added to default actions " + menuItem, menuItem); // NOI18N } else { actionsList.add(null); } } else { LOGGER.log(Level.WARNING, "Unsupported context menu item: " + menuItem, menuItem); // NOI18N } } catch (Exception ex) { LOGGER.log(Level.SEVERE, "Unable to resolve context menu action: " + menuItemDO, menuItemDO); // NOI18N } } } } // Return actions return new List[] { cleanupActions(defaultActions), cleanupActions(actions) }; }