Java Code Examples for org.eclipse.jface.action.ActionContributionItem#getAction()

The following examples show how to use org.eclipse.jface.action.ActionContributionItem#getAction() . 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: SelectAllProjectExplorer_PluginUITest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Asserts that the context menu for the current navigator selection does not contain any duplicates.
 *
 * That is, two menu items that represent an action of the same class.
 */
private void assertContextMenuNoActionDuplicates() {
	MenuManager menu = new MenuManager();
	projectExplorer.getNavigatorActionService().fillContextMenu(menu);
	List<ActionContributionItem> actionContributions = Arrays.asList(menu.getItems()).stream()
			.filter(i -> i instanceof ActionContributionItem)
			.map(i -> ((ActionContributionItem) i))
			.collect(Collectors.toList());

	Map<String, ActionContributionItem> contributionNameMap = new HashMap<>();

	for (ActionContributionItem item : actionContributions) {
		ActionContributionItem mapItem = contributionNameMap.putIfAbsent(item.getAction().getText(), item);
		if (mapItem != null) {
			IAction mapAction = mapItem.getAction();
			IAction otherAction = item.getAction();

			// Double check if action is of the same type
			if (mapAction.getClass().equals(otherAction.getClass())) {
				fail("Action '" + mapAction.getClass().getSimpleName()
						+ "' is contributed twice to the context menu: "
						+ mapAction.toString() + " " + otherAction.toString());
			}
		}
	}
}
 
Example 2
Source File: HdViewPart.java    From http4e with Apache License 2.0 6 votes vote down vote up
public void fireAuthEnable( boolean enabled){
   IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager();
   IContributionItem[] items = toolbar.getItems();

   for (IContributionItem it : items) {
      if (it instanceof ActionContributionItem) {
         ActionContributionItem aci = (ActionContributionItem) it;
         if (aci.getAction() instanceof AuthenticationAction) {
            AuthenticationAction aa = (AuthenticationAction) aci.getAction();
            String img = null;
            if (enabled) {
               img = CoreImages.AUTH_ENABLED;
            } else {
               img = CoreImages.AUTH;
            }
            aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img)));
         }
      }
   }
}
 
Example 3
Source File: HdViewPart.java    From http4e with Apache License 2.0 6 votes vote down vote up
public void fireProxyEnable( boolean enabled){
   IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager();
   IContributionItem[] items = toolbar.getItems();
   for (IContributionItem it : items) {
      if (it instanceof ActionContributionItem) {
         ActionContributionItem aci = (ActionContributionItem) it;
         if (aci.getAction() instanceof ProxyAction) {
            ProxyAction aa = (ProxyAction) aci.getAction();
            String img = null;
            if (enabled) {
               img = CoreImages.PROXY_ENABLED;
            } else {
               img = CoreImages.PROXY;
            }
            aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img)));
         }
      }
   }
}
 
Example 4
Source File: AttributeViewPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void clearOldRestoreLibraryPropertiesAction( )
{
	IContributionItem[] items = getSite( ).getActionBars( )
			.getToolBarManager( )
			.getItems( );
	for ( IContributionItem item : items )
	{

		if ( item instanceof ActionContributionItem )
		{
			ActionContributionItem aItem = (ActionContributionItem) item;
			if ( aItem.getAction( ) instanceof RestoreLibraryPropertiesAction )
			{
				getSite( ).getActionBars( )
						.getToolBarManager( )
						.remove( item );
			}
		}
	}
}
 
Example 5
Source File: AbstractWorkbenchTestCase.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
protected IAction getPyUnitViewAction(ViewPart view, Class<?> class1) {
    IAction action = null;
    IContributionItem[] items = view.getViewSite().getActionBars().getToolBarManager().getItems();
    for (IContributionItem iContributionItem : items) {
        if (iContributionItem instanceof ActionContributionItem) {
            ActionContributionItem item = (ActionContributionItem) iContributionItem;
            IAction lAction = item.getAction();
            if (class1.isInstance(lAction)) {
                action = lAction;
            }
        }
    }
    if (action == null) {
        fail("Could not find action of class: " + class1);
    }
    return action;
}
 
Example 6
Source File: ViewMenus.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private void fillContextMenu(IMenuManager manager, List<IContributionItem> contributionItems){
	manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
	for (IContributionItem contributionItem : contributionItems) {
		if (contributionItem == null) {
			manager.add(new Separator());
			continue;
		} else if (contributionItem instanceof ActionContributionItem) {
			ActionContributionItem ac = (ActionContributionItem) contributionItem;
			if (ac.getAction() instanceof RestrictedAction) {
				((RestrictedAction) ac.getAction()).reflectRight();
			}
		}
		contributionItem.update();
		manager.add(contributionItem);
	}
}
 
Example 7
Source File: SDView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Enables or disables the Pages... menu item, depending on the number of pages
 *
 * @param bar the bar containing the action
 */
protected void updatePagesMenuItem(IActionBars bar) {
    if (fSdPagingProvider instanceof ISDAdvancedPagingProvider) {
        IMenuManager menuManager = bar.getMenuManager();
        ActionContributionItem contributionItem = (ActionContributionItem) menuManager.find(OpenSDPagesDialog.ID);
        IAction openSDPagesDialog = null;
        if (contributionItem != null) {
            openSDPagesDialog = contributionItem.getAction();
        }

        if (openSDPagesDialog instanceof OpenSDPagesDialog) {
            openSDPagesDialog.setEnabled(((ISDAdvancedPagingProvider) fSdPagingProvider).pagesCount() > 1);
        }
    }
}
 
Example 8
Source File: GamaNavigator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void createPartControl(final Composite compo) {
	this.parent = GamaToolbarFactory.createToolbars(this, compo);

	super.createPartControl(parent);
	restoreState();
	final IToolBarManager tb = getViewSite().getActionBars().getToolBarManager();
	for (final IContributionItem item : tb.getItems()) {
		if (item instanceof ActionContributionItem) {
			final ActionContributionItem aci = (ActionContributionItem) item;
			final IAction action = aci.getAction();
			if (action instanceof LinkEditorAction) {
				link = action;
				tb.remove(aci);
			} else if (action instanceof org.eclipse.ui.internal.navigator.actions.CollapseAllAction) {
				tb.remove(aci);
			}

		}
	}
	linkItem.setSelection(link.isChecked());
	tb.update(true);
	tb.insertBefore("toolbar.toggle", byDate.toCheckAction());
	tb.insertBefore("toolbar.toggle", expandAll.toAction());
	tb.insertBefore(expandAll.getId(), collapseAll.toAction());

	try {
		final IDecoratorManager mgr = PlatformUI.getWorkbench().getDecoratorManager();
		mgr.setEnabled("msi.gama.application.date.decorator", false);
	} catch (final CoreException e) {
		e.printStackTrace();
	}
	properties =
			new PropertyDialogAction(new SameShellProvider(getSite().getShell()), getSite().getSelectionProvider());
	findControl.initialize();

}
 
Example 9
Source File: GraphicalView.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
private void updateAutoSyncToggleButtonState() {
    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    ActionContributionItem autoSyncToggleContribution = (ActionContributionItem) toolBarManager
            .find("com.abstratt.imageviewer.autoUpdate");
    if (autoSyncToggleContribution != null) {
        IAction action = autoSyncToggleContribution.getAction();
        action.setChecked(isAutoSync());
    }
}
 
Example 10
Source File: ApplicationActionBarAdvisor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void menuAboutToShow(IMenuManager manager){
	IContributionItem[] items = manager.getItems();
	for (IContributionItem iContributionItem : items) {
		if(iContributionItem instanceof ActionContributionItem) {
			ActionContributionItem aci = (ActionContributionItem) iContributionItem;		
			IAction action = aci.getAction();
			if(action instanceof RestrictedAction) {
				RestrictedAction ra = (RestrictedAction) aci.getAction();
				ra.reflectRight();
				continue;
			}
			String id = action.getActionDefinitionId();
			if(id==null) {
				continue;
			}
			switch (id) {
			case IWorkbenchCommandConstants.FILE_EXIT:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_EXIT));
				break;
			case IWorkbenchCommandConstants.WINDOW_NEW_WINDOW:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_NEWWINDOW));
				break;
			case IWorkbenchCommandConstants.HELP_ABOUT:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_ABOUT));
				break;
			case IWorkbenchCommandConstants.WINDOW_PREFERENCES:
				action.setEnabled(CoreHub.acl.request(AccessControlDefaults.AC_PREFS));
				break;
			default:
				break;
			}
		}
	}
}