Java Code Examples for org.openide.util.actions.Presenter#Menu
The following examples show how to use
org.openide.util.actions.Presenter#Menu .
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: FileSystemActionTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testManualRefreshPreference() throws IOException { Preferences pref = NbPreferences.root().node("org/openide/actions/FileSystemRefreshAction"); assertFalse("Not set", pref.getBoolean("manual", false)); FileObject fo = FileUtil.toFileObject(getWorkDir()); Lookup lkp = Lookups.singleton(DataFolder.findFolder(fo).getNodeDelegate()); FileSystemAction fsa = FileSystemAction.get(FileSystemAction.class); Action a = fsa.createContextAwareInstance(lkp); assertEquals("Menu presenter ", true, a instanceof Presenter.Menu); Presenter.Menu pm = (Presenter.Menu)a; DynamicMenuContent submenu = (DynamicMenuContent)pm.getMenuPresenter(); assertEquals("No submenu", 0, submenu.getMenuPresenters().length); pref.putBoolean("manual", true); DynamicMenuContent submenu2 = (DynamicMenuContent)pm.getMenuPresenter(); assertEquals("One action", 1, submenu2.getMenuPresenters().length); }
Example 2
Source File: EditorOnlyDisplayer.java From netbeans with Apache License 2.0 | 6 votes |
private static boolean setShowEditorToolbar( boolean show ) { boolean res = true; Action toggleEditorToolbar = FileUtil.getConfigObject( "Editors/Actions/toggle-toolbar.instance", Action.class ); //NOI18N if( null != toggleEditorToolbar ) { if( toggleEditorToolbar instanceof Presenter.Menu ) { JMenuItem menuItem = ((Presenter.Menu)toggleEditorToolbar).getMenuPresenter(); if( menuItem instanceof JCheckBoxMenuItem ) { JCheckBoxMenuItem checkBoxMenu = ( JCheckBoxMenuItem ) menuItem; res = checkBoxMenu.isSelected(); if( checkBoxMenu.isSelected() != show ) { try { toggleEditorToolbar.actionPerformed( new ActionEvent( menuItem, 0, "")); //NOII18N } catch( Exception ex ) { //don't worry too much if it isn't working, we're just trying to be helpful here Logger.getLogger( EditorOnlyDisplayer.class.getName()).log( Level.FINE, null, ex ); } } } } } return res; }
Example 3
Source File: ToolsActionSlowTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testInlineIsNotBlocked() throws Exception { ToolsAction ta = ToolsAction.get(ToolsAction.class); Lookup lkp = Lookups.singleton(this); FileObject fo = FileUtil.createFolder(FileUtil.getConfigRoot(), "UI/ToolActions"); assertNotNull("ToolActions folder found", fo); fo.createFolder("Cat3").createData(BlockingAction.class.getName().replace('.', '-') + ".instance").setAttribute("position", 100); Action a = ta.createContextAwareInstance(lkp); assertTrue("It is menu presenter", a instanceof Presenter.Menu); Presenter.Menu mp = (Presenter.Menu)a; JMenuItem item = mp.getMenuPresenter(); assertTrue("Item is enabled", item.isEnabled()); DynamicMenuContent dmc = (DynamicMenuContent)item; final JComponent[] arr = dmc.getMenuPresenters(); assertEquals("One presenter to delegte to", 1, arr.length); assertFalse("Disabled", arr[0].isEnabled()); }
Example 4
Source File: LookupSensitiveActionBase.java From netbeans with Apache License 2.0 | 5 votes |
private JMenuItem item(Action a, boolean menu) { if (menu) { if (a instanceof Presenter.Menu) { return ((Presenter.Menu) a).getMenuPresenter(); } else { return new JMenuItem(a); } } else { if (a instanceof Presenter.Popup) { return ((Presenter.Popup)a).getPopupPresenter(); } else { return new JMenuItem(a); } } }
Example 5
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a menu item from an action. * * @param action an action * @return JMenuItem */ public static JMenuItem toMenuItem(Action action) { JMenuItem item; if (action instanceof Presenter.Menu) { item = ((Presenter.Menu) action).getMenuPresenter(); } else { item = new JMenuItem(); Actions.connect(item, action, false); } return item; }
Example 6
Source File: ProjectMenuItem.java From netbeans with Apache License 2.0 | 5 votes |
private JMenuItem createmenuItem(Action action) { JMenuItem item; if (action instanceof Presenter.Menu) { item = ((Presenter.Menu) action).getMenuPresenter(); } else if (action instanceof Presenter.Popup) { item = ((Presenter.Popup) action).getPopupPresenter(); } else { item = new JMenuItem(); Actions.connect(item, action, true); } return item; }
Example 7
Source File: Utils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a menu item from an action. * * @param action an action * @return JMenuItem */ public static JMenuItem toMenuItem(Action action) { JMenuItem item; if (action instanceof Presenter.Menu) { item = ((Presenter.Menu) action).getMenuPresenter(); } else if (action instanceof Presenter.Popup) { item = ((Presenter.Popup) action).getPopupPresenter(); } else { item = new JMenuItem(); Actions.connect(item, action, false); } return item; }
Example 8
Source File: DynaMenuModel.java From netbeans with Apache License 2.0 | 4 votes |
public void loadSubmenu(List<Object> cInstances, JMenu m, boolean remove, Map<Object,FileObject> cookiesToFiles) { // clear first - refresh the menu's content boolean addSeparator = false; Icon curIcon = null; Iterator it = cInstances.iterator(); menuItems = new ArrayList<JComponent>(cInstances.size()); actionToMenuMap.clear(); while (it.hasNext()) { Object obj = it.next(); if (obj instanceof Action) { FileObject file = cookiesToFiles.get(obj); if (file != null) { AcceleratorBinding.setAccelerator((Action) obj, file); } } if (obj instanceof Presenter.Menu) { // does this still apply?? obj = ((Presenter.Menu)obj).getMenuPresenter(); } if (obj instanceof DynamicMenuContent) { if(addSeparator) { menuItems.add(null); addSeparator = false; } DynamicMenuContent mn = (DynamicMenuContent)obj; JComponent[] itms = convertArray(mn.getMenuPresenters()); actionToMenuMap.put(mn, itms); Iterator itx = Arrays.asList(itms).iterator(); while (itx.hasNext()) { JComponent comp = (JComponent)itx.next(); menuItems.add(comp); // check icon isWithIcons = checkIcon(comp, isWithIcons); } continue; } if (obj instanceof JMenuItem) { if(addSeparator) { menuItems.add(null); addSeparator = false; } // check icon isWithIcons = checkIcon(obj, isWithIcons); menuItems.add((JMenuItem)obj); } else if (obj instanceof JSeparator) { addSeparator = menuItems.size() > 0; } else if (obj instanceof Action) { if(addSeparator) { menuItems.add(null); addSeparator = false; } Action a = (Action)obj; Actions.MenuItem item = new Actions.MenuItem(a, true); // check icon isWithIcons = checkIcon(item, isWithIcons); actionToMenuMap.put(item, new JComponent[] {item}); menuItems.add(item); } } if (isWithIcons) { menuItems = alignVertically(menuItems); } if (remove) { m.removeAll(); } // fill menu with built items JComponent curItem = null; boolean wasSeparator = false; for (Iterator<JComponent> iter = menuItems.iterator(); iter.hasNext(); ) { curItem = iter.next(); if (curItem == null) { // null means separator curItem = createSeparator(); } m.add(curItem); boolean isSeparator = curItem instanceof JSeparator; if (isSeparator && wasSeparator) { curItem.setVisible(false); } if (!(curItem instanceof InvisibleMenuItem)) { wasSeparator = isSeparator; } } }
Example 9
Source File: ActiveConfigActionTest.java From netbeans with Apache License 2.0 | 4 votes |
/** * Test of createContextAwareInstance method, of class ActiveConfigAction. */ @RandomlyFails public void testCreateContextAwareInstance() throws Exception { P p = PF.toCreate; OpenProjects.getDefault().open(new Project[] { p }, false); OpenProjects.getDefault().setMainProject(p); ActiveConfigAction instance = new ActiveConfigAction(); Action result = instance;//.createContextAwareInstance(actionContext); assertTrue("menu: " + result, result instanceof Presenter.Menu); Presenter.Menu menu = (Presenter.Menu)result; JMenuItem item = menu.getMenuPresenter(); assertNotNull(item); assertTrue("Enabled", item.isEnabled()); final DynamicMenuContent m = (DynamicMenuContent)item; assertEquals("One", 1, m.getMenuPresenters().length); holder = item; OpenProjects.getDefault().close(new Project[] { p }); assertNull("NO project selected", OpenProjects.getDefault().getMainProject()); WeakReference<Object> ref = new WeakReference<Object>(p); p = null; PF.toCreate = null; //Await refresh final Logger log = Logger.getLogger(ActiveConfigAction.class.getName()); final Level origLogLevel = log.getLevel(); final FH handler = new FH(); log.setLevel(Level.FINEST); log.addHandler(handler); try { handler.get(30, TimeUnit.SECONDS); } finally { log.setLevel(origLogLevel); log.removeHandler(handler); } //Rebuild the current pop up menu SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { m.getMenuPresenters(); } }); assertGC("Reference can go away", ref); }