List of usage examples for org.eclipse.jface.action IContributionItem isEnabled
boolean isEnabled();
From source file:org.eclipse.epf.authoring.ui.editors.AbstractDiagramEditor.java
License:Open Source License
protected void contributeToContextMenu(IMenuManager menu) { boolean canModify = !isReadOnly(); IAction action = getActionRegistry().getAction(REFRESH_FROM_BASE_ACTIVITY); if (action.isEnabled() && canModify) { menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, action); }/*from w ww .j a v a 2 s . c om*/ // the align menu is a cascading menu IContributionItem ci = createAlignMenu(); if (ci.isEnabled() && canModify) { menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator()); menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, ci); menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator()); } action = getActionRegistry().getAction(DELETE_DIAGRAM); if (action.isEnabled() && canModify) { menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator()); menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, action); menu.appendToGroup(GEFActionConstants.MB_ADDITIONS, new Separator()); } }
From source file:org.eclipse.gmf.tests.runtime.diagram.ui.logic.LogicDiagramTests.java
License:Open Source License
/** * Tests the initial enablement of the zoom toolbar entry. See Bugzilla * 110815.//from w w w . java 2 s . c o m * * @throws Exception */ public void testZoomToolbarEnablement() throws Exception { getTestFixture().openDiagram(); IContributionItem[] items = ((IEditorSite) getDiagramWorkbenchPart().getSite()).getActionBars() .getToolBarManager().getItems(); boolean foundIt = false; for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; if (item instanceof ZoomContributionItem) { foundIt = true; assertTrue(item.isEnabled()); } } assertTrue(foundIt); }
From source file:org.eclipse.ui.internal.quickaccess.ActionProvider.java
License:Open Source License
private void collectContributions(MenuManager menu, Set result) { IContributionItem[] items = menu.getItems(); for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; if (item instanceof SubContributionItem) { item = ((SubContributionItem) item).getInnerItem(); }//from w w w .j a v a 2 s .com if (item instanceof MenuManager) { collectContributions((MenuManager) item, result); } else if (item instanceof ActionContributionItem && item.isEnabled()) { result.add(item); } } }
From source file:org.eclipse.wst.sse.sieditor.test.ui.v2.dt.DTTreeContextMenuListenerTest.java
License:Open Source License
/** * Test method for/*from w w w . j av a 2 s . c om*/ * {@link org.eclipse.wst.sse.sieditor.ui.v2.dt.DTTreeContextMenuListener#updateActionsState(org.eclipse.wst.sse.sieditor.ui.v2.dt.nodes.IDataTypesTreeNode)} * . */ @SuppressWarnings("boxing") @Test public final void testSetActionsEnablementInSiEditor() { controllerMock = new SIDTControllerMock(true); final ITreeNode nodeMock = createNiceMock(IStructureTypeNode.class); final IModelObject objectMock = createISchemaMockFromSameModel(); expect(nodeMock.getModelObject()).andReturn(objectMock).anyTimes(); replay(nodeMock); controllerMock.setModelObjectForCompare(objectMock); controllerMock.setEditDeleteAllowed(Boolean.valueOf(false)); final IModelObject model = EasyMock.createNiceMock(IModelObject.class); expect(model.getModelRoot()).andReturn(null).anyTimes(); replay(model); controllerMock.setModelObject(model); treeViewer.setSelection(new StructuredSelection(nodeMock)); IMenuManager menu = new MenuManager(); DTTreeContextMenuListener dtTreeContextMenuListener = new DTTreeContextMenuListener(controllerMock, treeViewer); dtTreeContextMenuListener.menuAboutToShow(menu); IContributionItem[] items = menu.getItems(); final IModelObject modelObjectMock = createISchemaMockFromSameModel(); final IDataTypesTreeNode treeNodeMock = createMock(INamespaceNode.class); expect(treeNodeMock.isReadOnly()).andReturn(Boolean.valueOf(false)).anyTimes(); expect(treeNodeMock.getModelObject()).andReturn(modelObjectMock).anyTimes(); expect(treeNodeMock.getParent()).andReturn(null).anyTimes(); expect(treeNodeMock.isImportedNode()).andReturn(false).anyTimes(); expect(treeNodeMock.getCategories()).andReturn(0).anyTimes(); replay(treeNodeMock); treeViewer.setSelection(new StructuredSelection(treeNodeMock)); final SIDTControllerMock controller = new SIDTControllerMock(false); controller.setModelObjectForCompare(modelObjectMock); dtTreeContextMenuListener = new DTTreeContextMenuListener(controller, treeViewer); menu = new MenuManager(); dtTreeContextMenuListener.menuAboutToShow(menu); verify(treeNodeMock); items = menu.getItems(); for (final IContributionItem iContributionItem : items) { if (iContributionItem instanceof ActionContributionItem) { final boolean shouldBeEnabled = !ContextMenuConstants.ADD_ATTRIBUTE_ACTION_ID .equals(iContributionItem.getId()) && !ContextMenuConstants.COPY_TYPE_ACTION_ID.equals(iContributionItem.getId()) && !ContextMenuConstants.PASTE_TYPE_ACTION_ID.equals(iContributionItem.getId()) && !ContextMenuConstants.ADD_ELEMENT_ACTION_ID.equals(iContributionItem.getId()) && !org.eclipse.wst.sse.sieditor.ui.v2.wsdltree.ContextMenuConstants.OPEN_IN_NEW_EDITOR_ACTION_ID .equals(iContributionItem.getId()); assertEquals(iContributionItem.toString(), shouldBeEnabled, iContributionItem.isEnabled()); } } }
From source file:org.eclipse.wst.sse.sieditor.test.ui.v2.dt.DTTreeContextMenuListenerTest.java
License:Open Source License
/** * Test method for/*from w ww .j a v a 2s. co m*/ * {@link org.eclipse.wst.sse.sieditor.ui.v2.dt.DTTreeContextMenuListener#updateActionsState(org.eclipse.wst.sse.sieditor.ui.v2.dt.nodes.IDataTypesTreeNode)} * . */ @SuppressWarnings("boxing") @Test public final void testSetActionsEnablementStandalone() { controllerMock = new SIDTControllerMock(true); final ITreeNode nodeMock = createNiceMock(IDataTypesTreeNode.class); final IModelObject objectMock = createISchemaMockFromSameModel(); expect(nodeMock.getModelObject()).andReturn(objectMock).anyTimes(); replay(nodeMock); controllerMock.setEditDeleteAllowed(Boolean.valueOf(false)); controllerMock.setModelObjectForCompare(objectMock); final IModelObject mock = EasyMock.createNiceMock(IModelObject.class); expect(mock.getModelRoot()).andReturn(null); replay(mock); controllerMock.setModelObject(mock); treeViewer.setSelection(new StructuredSelection(nodeMock)); IMenuManager menu = new MenuManager(); DTTreeContextMenuListener dtTreeContextMenuListener = new DTTreeContextMenuListener(controllerMock, treeViewer); dtTreeContextMenuListener.menuAboutToShow(menu); IContributionItem[] items = menu.getItems(); final IModelObject modelObjectMock = createISchemaMockFromSameModel(); final IDataTypesTreeNode treeNodeMock = createNiceMock(INamespaceNode.class); expect(treeNodeMock.isReadOnly()).andReturn(Boolean.valueOf(false)).anyTimes(); expect(treeNodeMock.getModelObject()).andReturn(modelObjectMock).anyTimes(); expect(treeNodeMock.isImportedNode()).andReturn(false).anyTimes(); replay(treeNodeMock); treeViewer.setSelection(new StructuredSelection(treeNodeMock)); final DTControllerMock controller = new DTControllerMock(false); controller.setModelObjectForCompare(modelObjectMock); dtTreeContextMenuListener = new DTTreeContextMenuListener(controller, treeViewer); menu = new MenuManager(); dtTreeContextMenuListener.menuAboutToShow(menu); verify(treeNodeMock); items = menu.getItems(); for (final IContributionItem iContributionItem : items) { if (iContributionItem instanceof ActionContributionItem) { final boolean shouldBeEnabled = !ContextMenuConstants.ADD_ATTRIBUTE_ACTION_ID .equals(iContributionItem.getId()) && !ContextMenuConstants.COPY_TYPE_ACTION_ID.equals(iContributionItem.getId()) && !ContextMenuConstants.PASTE_TYPE_ACTION_ID.equals(iContributionItem.getId()) && !ContextMenuConstants.ADD_ELEMENT_ACTION_ID.equals(iContributionItem.getId()) && !org.eclipse.wst.sse.sieditor.ui.v2.wsdltree.ContextMenuConstants.OPEN_IN_NEW_EDITOR_ACTION_ID .equals(iContributionItem.getId()); assertEquals(iContributionItem.toString(), shouldBeEnabled, iContributionItem.isEnabled()); } } }