use of org.eclipse.jface.action.ActionContributionItem in project eclipse.platform.text by eclipse.
the class OpenSearchDialogPageAction method addToMenu.
private void addToMenu(Menu localMenu, IAction action, int accelerator) {
StringBuilder label = new StringBuilder();
if (accelerator >= 0 && accelerator < 10) {
// add the numerical accelerator
label.append('&');
label.append(accelerator);
label.append(' ');
}
label.append(action.getText());
action.setText(label.toString());
ActionContributionItem item = new ActionContributionItem(action);
item.fill(localMenu, -1);
}
use of org.eclipse.jface.action.ActionContributionItem in project linuxtools by eclipse.
the class AbstractMassifTest method getToolbarAction.
protected IAction getToolbarAction(String actionId) {
IAction result = null;
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
for (IContributionItem item : manager.getItems()) {
if (item instanceof ActionContributionItem) {
ActionContributionItem actionItem = (ActionContributionItem) item;
if (actionItem.getAction().getId().equals(actionId)) {
result = actionItem.getAction();
}
}
}
return result;
}
use of org.eclipse.jface.action.ActionContributionItem in project linuxtools by eclipse.
the class MultiProcessTest method testExecPidMenu.
@Test
public void testExecPidMenu() throws CoreException, URISyntaxException, IOException {
ILaunchConfigurationWorkingCopy config = createConfiguration(proj.getProject()).getWorkingCopy();
config.setAttribute(LaunchConfigurationConstants.ATTR_GENERAL_TRACECHILD, true);
config.doSave();
// $NON-NLS-1$
doLaunch(config, "testExec");
ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
MassifViewPart dynamicView = (MassifViewPart) view.getDynamicView();
MassifOutput output = dynamicView.getOutput();
MassifPidMenuAction menuAction = null;
IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
for (IContributionItem item : manager.getItems()) {
if (item instanceof ActionContributionItem && ((ActionContributionItem) item).getAction() instanceof MassifPidMenuAction) {
menuAction = (MassifPidMenuAction) ((ActionContributionItem) item).getAction();
}
}
assertNotNull(menuAction);
Integer[] pids = dynamicView.getOutput().getPids();
Shell shell = new Shell(Display.getCurrent());
Menu pidMenu = menuAction.getMenu(shell);
assertEquals(2, pidMenu.getItemCount());
ActionContributionItem firstPid = (ActionContributionItem) pidMenu.getItem(0).getData();
ActionContributionItem secondPid = (ActionContributionItem) pidMenu.getItem(1).getData();
// check initial state
assertTrue(firstPid.getAction().isChecked());
assertFalse(secondPid.getAction().isChecked());
assertArrayEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());
// select second pid
selectItem(pidMenu, 1);
assertFalse(firstPid.getAction().isChecked());
assertTrue(secondPid.getAction().isChecked());
assertArrayEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());
// select second pid again
selectItem(pidMenu, 1);
assertFalse(firstPid.getAction().isChecked());
assertTrue(secondPid.getAction().isChecked());
assertArrayEquals(output.getSnapshots(pids[1]), dynamicView.getSnapshots());
// select first pid
selectItem(pidMenu, 0);
assertTrue(firstPid.getAction().isChecked());
assertFalse(secondPid.getAction().isChecked());
assertArrayEquals(output.getSnapshots(pids[0]), dynamicView.getSnapshots());
}
use of org.eclipse.jface.action.ActionContributionItem in project linuxtools by eclipse.
the class MassifPidMenuAction method getMenu.
@Override
public Menu getMenu(Control parent) {
if (menu == null) {
if (pids != null) {
menu = new Menu(parent);
for (int i = 0; i < pids.length; i++) {
final Integer pid = pids[i];
ActionContributionItem item = new ActionContributionItem(new // $NON-NLS-1$
Action(// $NON-NLS-1$
"PID " + pids[i], // $NON-NLS-1$
IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
MenuItem[] items = menu.getItems();
for (int j = 0; j < items.length; j++) {
IAction action = ((ActionContributionItem) items[j].getData()).getAction();
action.setChecked(false);
}
setChecked(true);
view.setPid(pid);
Display.getDefault().syncExec(() -> view.refreshView());
}
});
item.fill(menu, -1);
}
}
// Check first item
ActionContributionItem item = (ActionContributionItem) menu.getItem(0).getData();
item.getAction().setChecked(true);
}
return menu;
}
use of org.eclipse.jface.action.ActionContributionItem in project knime-core by knime.
the class KnimeResourceNavigator method fillContextMenu.
/**
* Fills the context menu with the actions contained in this group and its
* subgroups. Additionally the close project item is removed as not intended
* for the knime projects. Note: Projects which are closed in the default
* navigator are not shown in the knime navigator any more.
*
* @param menu the context menu
*/
@Override
public void fillContextMenu(final IMenuManager menu) {
// fill the menu
super.fillContextMenu(menu);
// remove the close project item
menu.remove(CloseResourceAction.ID);
// items do not have an id
for (IContributionItem item : menu.getItems()) {
if (item instanceof ActionContributionItem) {
ActionContributionItem aItem = (ActionContributionItem) item;
// remove the gointo item
if (aItem.getAction() instanceof GoIntoAction) {
menu.remove(aItem);
} else if (aItem.getAction() instanceof OpenInNewWindowAction) {
menu.remove(aItem);
} else if (aItem.getAction() instanceof CloseUnrelatedProjectsAction) {
menu.remove(aItem);
}
}
}
// move must be our own action (due to workflow locks)
if (menu.find(MoveResourceAction.ID) != null) {
menu.insertBefore(MoveResourceAction.ID, new MoveWorkflowAction(getTreeViewer()));
menu.remove(MoveResourceAction.ID);
}
// remove the default import export actions to store the own one
// that invokes the knime export wizard directly
menu.remove("import");
menu.insertBefore("export", new ImportKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
menu.remove("export");
menu.insertAfter(ImportKnimeWorkflowAction.ID, new ExportKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
String id = ImportKnimeWorkflowAction.ID;
// add an open action which is not listed as the project is normally
// not openable.
menu.insertBefore(id, new Separator());
menu.insertBefore(id, new OpenKnimeProjectAction(this));
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new EditMetaInfoAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
if (NodeExecutionJobManagerPool.getNumberOfJobManagersFactories() > 1) {
menu.insertAfter(ExportKnimeWorkflowAction.ID, new WFShowJobMgrViewAction());
}
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ResetWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new CancelWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ExecuteWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new ConfigureWorkflowAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new OpenCredentialVariablesDialogAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new OpenWorkflowVariablesDialogAction());
menu.insertAfter(ExportKnimeWorkflowAction.ID, new Separator());
menu.insertBefore(RefreshAction.ID, new GroupMarker(KNIME_ADDITIONS));
menu.insertBefore(RefreshAction.ID, new Separator());
menu.insertBefore(id, new Separator());
// another bad workaround to replace the first "New" menu manager
// with the "Create New Workflow" action
// store all items, remove all, add the action and then
// add all but the first one
IContributionItem[] items = menu.getItems();
for (IContributionItem item : items) {
menu.remove(item);
}
menu.add(new NewKnimeWorkflowAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow()));
menu.add(new CreateWorkflowGroupAction());
for (int i = 1; i < items.length; i++) {
menu.add(items[i]);
}
}
Aggregations