List of usage examples for org.eclipse.jface.action Action setMenuCreator
@Override public void setMenuCreator(IMenuCreator creator)
From source file:com.aptana.browser.WebBrowserViewer.java
License:Open Source License
private void createCommandBar(Composite parent) { final MenuManager menuManager = new MenuManager("#CommandMenu"); //$NON-NLS-1$ MenuManager sizeMenuManager = new MenuManager(Messages.WebBrowserViewer_LBL_SetSize); sizeMenuManager.add(new Action(Messages.WebBrowserViewer_LBL_FullEditor) { @Override/* w w w . j av a 2 s. co m*/ public void run() { currentSize = null; layout(); } }); menuManager.add(sizeMenuManager); BrowserSizeCategory[] categories = BrowserPlugin.getDefault().getBrowserConfigurationManager() .getSizeCategories(); Arrays.sort(categories); MenuManager categoryMenuManager; BrowserSize[] sizes; for (BrowserSizeCategory category : categories) { // first level has the categories categoryMenuManager = new MenuManager(category.getName()); sizeMenuManager.add(categoryMenuManager); sizes = category.getSizes(); for (final BrowserSize size : sizes) { // then shows size configurations for each category categoryMenuManager.add(new Action(size.getName()) { @Override public void run() { disposeImage(); currentSize = size; boolean blackBackground = false; BrowserBackgroundImage image = currentSize.getImage(); if (image != null) { currentImage = image.getImageDescriptor().createImage(); blackBackground = image.isBlackBackground(); } Color background = blackBackground ? getDisplay().getSystemColor(SWT.COLOR_BLACK) : getDisplay().getSystemColor(SWT.COLOR_WHITE); setBackground(background); backgroundArea.setBackground(background); resizeBackground(); } }); } } sizeMenuManager.add(new Action(Messages.WebBrowserViewer_LBL_Custom) { @Override public void run() { setCustomSize(); } }); ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); Action action = new Action("Command", IAction.AS_DROP_DOWN_MENU) //$NON-NLS-1$ { @Override public void run() { // not doing anything } }; action.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_COMMAND)); action.setMenuCreator(new IMenuCreator() { public void dispose() { } public Menu getMenu(Control parent) { return menuManager.createContextMenu(parent); } public Menu getMenu(Menu parent) { return null; } }); toolBarManager.add(action); ToolBar sizeToolBar = toolBarManager.createControl(parent); sizeToolBar.setLayoutData(GridDataFactory.fillDefaults().create()); }
From source file:com.aptana.browser.WebBrowserViewer4Mac.java
License:Open Source License
protected void createCommandBar(Composite parent) { final MenuManager menuManager = new MenuManager("#CommandMenu"); //$NON-NLS-1$ menuManager.add(new Action(Messages.WebBrowserViewer_LBL_FullEditor) { @Override//w ww . j a v a2 s. c o m public void run() { currentSize = null; layout(); } }); BrowserSizeCategory[] categories = BrowserPlugin.getDefault().getBrowserConfigurationManager() .getSizeCategories(); Arrays.sort(categories); BrowserSize[] sizes; for (BrowserSizeCategory category : categories) { sizes = category.getSizes(); for (final BrowserSize size : sizes) { // then shows size configurations for each category menuManager.add(new Action(size.getName()) { @Override public void run() { disposeImage(); currentSize = size; boolean blackBackground = false; BrowserBackgroundImage image = currentSize.getImage(); if (image != null) { currentImage = image.getImageDescriptor().createImage(); blackBackground = image.isBlackBackground(); } Color background = blackBackground ? getDisplay().getSystemColor(SWT.COLOR_BLACK) : getDisplay().getSystemColor(SWT.COLOR_WHITE); setBackground(background); backgroundArea.setBackground(background); resizeBackground(); } }); } } menuManager.add(new Action(Messages.WebBrowserViewer_LBL_Custom) { @Override public void run() { setCustomSize(); } }); ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT); Action action = new Action(Messages.WebBrowserViewer_LBL_Set, IAction.AS_DROP_DOWN_MENU) //$NON-NLS-1$ { @Override public void run() { // not doing anything } }; action.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_COMMAND)); action.setMenuCreator(new IMenuCreator() { public void dispose() { } public Menu getMenu(Control parent) { return menuManager.createContextMenu(parent); } public Menu getMenu(Menu parent) { return null; } }); toolBarManager.add(action); ToolBar sizeToolBar = toolBarManager.createControl(parent); sizeToolBar.setLayoutData(GridDataFactory.fillDefaults().create()); }
From source file:eu.geclipse.traceview.internal.AbstractGraphVisualization.java
License:Open Source License
@Override public IContributionItem[] getToolBarItems() { Vector<IContributionItem> items = new Vector<IContributionItem>(); Action reset = new Action(Messages.getString("AbstractGraphVisualization.Reset"), //$NON-NLS-1$ Activator.getImageDescriptor("icons/reset.gif")) { //$NON-NLS-1$ @Override/*from w w w.jav a 2 s . c o m*/ public void run() { resetOrdering(); redraw(); } }; items.add(new ActionContributionItem(reset)); Action markerSelectionAction = new Action(Messages.getString("AbstractGraphVisualization.toggleMarkers"), //$NON-NLS-1$ Activator.getImageDescriptor("icons/marker.gif")) { //$NON-NLS-1$ @Override public void run() { MarkerOrderDialog dialog = new MarkerOrderDialog(getShell()); dialog.setEventMarkerEntries(eventMarkers.getEventMarkerEntries()); if (dialog.open() == Window.OK) { eventMarkers.eventMarkerEntries = dialog.getEventMarkerEntries(); eventMarkers.buildEventMarkersList(); redraw(); } } }; IMenuCreator menuCreator = new MarkerSelectionMenuCreator(this); markerSelectionAction.setMenuCreator(menuCreator); items.add(new ActionContributionItem(markerSelectionAction)); return items.toArray(new IContributionItem[items.size()]); }
From source file:org.cs3.pdt.graphicalviews.focusview.LogtalkView.java
License:Open Source License
@Override protected void initViewButtons(IToolBarManager toolBarManager) { super.initViewButtons(toolBarManager); inputSelector = new Action("Select input type", IAction.AS_DROP_DOWN_MENU) { @Override/*from w w w. ja va 2 s . co m*/ public void run() { if (getInputType() != InputType.PROJECT) { String result = askForLibrary(getInputType()); if (result != null) { setCurrentLibrary(result); logtalkViewCoordinator.diagramSettingsChanged(); } } } }; inputSelector.setImageDescriptor(ImageRepository.getImageDescriptor(ImageRepository.INPUT_TYPE_PROJECT)); inputSelector.setMenuCreator(new IMenuCreator() { private Menu menu; @Override public Menu getMenu(Menu parent) { return null; } @Override public Menu getMenu(Control parent) { Menu menu = new Menu(parent); createMenuItem(menu, InputType.PROJECT); createMenuItem(menu, InputType.LIBRARY); createMenuItem(menu, InputType.RECURSIVE_LIBRARY); this.menu = menu; return menu; } private void createMenuItem(final Menu menu, final InputType inputType) { final MenuItem item = new MenuItem(menu, SWT.RADIO); item.setText(inputType.getMenuItemLabel()); item.setImage(inputType.getImage()); item.setSelection(getInputType() == inputType); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!item.getSelection()) { return; } if (inputType != InputType.PROJECT) { String result = askForLibrary(inputType); if (result != null) { setInputType(inputType); setCurrentLibrary(result); } } else { setInputType(inputType); } } }); } @Override public void dispose() { if (menu != null) { menu.dispose(); menu = null; } } }); toolBarManager.add(inputSelector); Action typeSelector = new Action("Select diagram type", IAction.AS_DROP_DOWN_MENU) { }; typeSelector .setImageDescriptor(ImageRepository.getImageDescriptor(ImageRepository.CONFIGURE_LOGTALK_GRAPH)); typeSelector.setMenuCreator(new IMenuCreator() { private Menu menu; @Override public Menu getMenu(Menu parent) { return null; } @Override public Menu getMenu(Control parent) { Menu menu = new Menu(parent); createMenuItem(menu, DiagramType.ENTITY); createMenuItem(menu, DiagramType.CALL); createMenuItem(menu, DiagramType.INHERITANCE); createMenuItem(menu, DiagramType.USES); createMenuItem(menu, DiagramType.FILE_LOAD); createMenuItem(menu, DiagramType.FILE_DEPENDS); this.menu = menu; return menu; } private void createMenuItem(final Menu menu, final DiagramType diagramType) { final MenuItem item = new MenuItem(menu, SWT.RADIO); item.setText(diagramType.getLabel()); item.setSelection(getDiagramType() == diagramType); item.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { if (!item.getSelection()) { return; } setDiagramType(diagramType); } }); } @Override public void dispose() { if (menu != null) { menu.dispose(); menu = null; } } }); toolBarManager.add(typeSelector); }
From source file:org.eclipse.mdht.uml.ui.properties.internal.sections.InstanceSampleSection.java
License:Open Source License
/** * Generates the UI for the given class//from w w w. j a v a 2s .c o m * * @param class1 * @param path * the property path * @param basePath * the base property path * @param menu * if <code>null</code>, generates input fields for the given class, other generates UI actions into the menu to add/remove sample data * @param context * the list of UML classes accordingly to the property path (not including class1) */ private void addClass(final Class class1, final String path, final String basePath, IMenuManager menu, final List<Class> context) { List<IAction> actions = new ArrayList<IAction>(); final List<IAction> addclassactions = new ArrayList<IAction>(); final List<IAction> actionsRemove = new ArrayList<IAction>(); for (final Property property : editableAttributes(class1)) { Property baseProperty = getBaseProperty(property); final String propPath = abbreviate( path + "/" + (property.getType() instanceof DataType ? "@" : "") + property.getName()); final String propBasePath = abbreviate( basePath + "/" + (property.getType() instanceof DataType ? "@" : "") + baseProperty.getName()); if (property.getType() instanceof DataType && (getDefaultValue(property) == null || property.getLower() == 0)) { final String lastStep = lastStep(indexed(propPath, 1), indexed(propBasePath, 1)); if (menu != null) { if (countModelOccurences(propPath) < upper(property) && !isAlwaysVisible(property, path)) { Action action = new Action() { @Override public void run() { modifyFields(indexed(propPath, 1), "", false); refresh(); } }; action.setText(fixMenuText(ADD + lastStep)); actions.add(action); } else if (!isAlwaysVisible(property, path)) { Action action = new Action() { @Override public void run() { modifyFields(indexed(propPath, 1), null, false); refresh(); } }; action.setText(fixMenuText(REMOVE + lastStep)); actionsRemove.add(action); } } if (menu != null) { continue; } if (countModelOccurences(propPath) == 0 && !isAlwaysVisible(property, path)) { continue; } Label label = getWidgetFactory().createLabel(body, propPath.substring(1) + " :", 0); label.setLayoutData(new TableWrapData(TableWrapData.LEFT, TableWrapData.TOP)); label.setToolTipText(propBasePath.substring(1)); MenuManager propmenu = new MenuManager(); propmenu.setRemoveAllWhenShown(true); label.setMenu(propmenu.createContextMenu(label)); propmenu.addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(IMenuManager manager) { if (!isAlwaysVisible(property, path)) { Action action = new Action() { @Override public void run() { modifyFields(indexed(propPath, 1), null, false); refresh(); } }; action.setText(fixMenuText(REMOVE + lastStep)); manager.add(action); } if (!"".equals(path)) { Action action = new Action() { @Override public void run() { modifyFields(path, null, false); refresh(); } }; action.setText(fixMenuText(REMOVE + lastStep(path, basePath))); manager.add(action); } manager.add(new Separator()); addClass(class1, path, basePath, manager, context); manager.add(new Separator()); String pathParent = path; String basePathParent = basePath; for (int parentIndex = context.size() - 1; parentIndex >= 1; parentIndex--) { final int fparentIndex = parentIndex; final String fpathParent = pathParent = pathParent.substring(0, pathParent.lastIndexOf("/")); final String fbasePathParent = basePathParent = basePathParent.substring(0, basePathParent.lastIndexOf("/")); Action action = new Action() { @Override public void run() { } }; action.setText(".. " + lastStep(pathParent, basePathParent)); manager.add(action); action.setMenuCreator(new MenuCreator() { @Override protected void fillMenu(MenuManager dropDownMenuMgr) { System.out.println(context.get(fparentIndex).getName() + " " + fpathParent); addClass(context.get(fparentIndex), fpathParent, fbasePathParent, dropDownMenuMgr, context.subList(0, fparentIndex)); } }); } } }); if (property.getType() instanceof Enumeration || "EBooleanObject".equals(property.getType().getName())) { List<String> lits = new ArrayList<String>(); if (getDefaultValue(property) != null) { lits.add(getDefaultValue(property)); } else if (property.getType() instanceof Enumeration) { Enumeration enumeratedType = (Enumeration) property.getType(); for (EnumerationLiteral lit : enumeratedType.getOwnedLiterals()) { lits.add(lit.getName()); } } else { lits.add("true"); lits.add("false"); } lits.add(""); final Combo combo = new Combo(body, SWT.DROP_DOWN | SWT.READ_ONLY); combo.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP)); combo.setItems(lits.toArray(new String[] {})); if (lines.get(propPath) != null) { combo.select(lits.indexOf(lines.get(propPath))); // combo.setText(lines.get(propPath)); } combo.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { bodyModified = false; } public void focusLost(FocusEvent event) { if (bodyModified) { bodyModified = false; modifyFields(propPath, combo.getText(), false); } } }); combo.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { bodyModified = true; modifyFields(propPath, combo.getText(), false); } public void widgetSelected(SelectionEvent e) { bodyModified = true; modifyFields(propPath, combo.getText(), false); } }); combo.addModifyListener(modifyListener); if (indexed(propPath, 1).equals(focusPath)) { focusControl = combo; } } else { final Text text = getWidgetFactory().createText(body, "", "any".equals(property.getName()) ? SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL : 0); text.setLayoutData(new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.TOP)); if (lines.get(propPath) != null) { text.setText(lines.get(propPath)); } text.addFocusListener(new FocusListener() { public void focusGained(FocusEvent e) { bodyModified = false; } public void focusLost(FocusEvent event) { if (bodyModified) { bodyModified = false; modifyFields(propPath, text.getText(), false); } } }); text.addModifyListener(modifyListener); if (indexed(propPath, 1).equals(focusPath)) { focusControl = text; } } } } for (Property property : editableAttributes(class1)) { Property baseProperty = getBaseProperty(property); final String propPath = path + "/" + property.getName(); final String propBasePath = basePath + "/" + baseProperty.getName(); // if (property.getType() instanceof DataType || property.getType().conformsTo((Type) hl7_datatypes.getPackagedElement("ST"))) { // continue; // } if (!(property.getType() instanceof Class)) { continue; } final Class class2 = (Class) property.getType(); int addedInstances = countModelOccurences(propPath); if (menu == null) { // editors for nested content for (int index = 1; index <= 9; index++) { if (containsPath(indexed(propPath, index))) { List<Class> childContext = new ArrayList<Class>(context); childContext.add(class1); addClass(class2, indexed(propPath, index), indexed(propBasePath, index), menu, childContext); } } continue; } // allow removal of optional content if (addedInstances > property.getLower() || true) { for (int index = 1; index <= 9; index++) { if (containsPath(indexed(propPath, index))) { final int findex = index; Action action = new Action() { @Override public void run() { modifyFields(indexed(propPath, findex), null, false); refresh(); } }; String menuItemText = REMOVE + lastStep(indexed(propPath, index), indexed(propBasePath, index)); action.setText(fixMenuText(menuItemText)); actionsRemove.add(action); } } } boolean addedNewItem = false; // allow addition of optional content for (int index = 1; index <= 9; index++) { if (containsPath(indexed(propPath, index)) || addedInstances < upper(property) && !addedNewItem) { final int findex = index; Action action = new Action() { @Override public void run() { modifyFields(indexed(propPath, findex), "", false); refresh(); } }; action.setText(ADD + lastStep(indexed(propPath, findex), indexed(propBasePath, findex))); addclassactions.add(action); action.setMenuCreator(new MenuCreator() { @Override protected void fillMenu(MenuManager dropDownMenuMgr) { List<Class> childContext = new ArrayList<Class>(context); childContext.add(class1); addClass(class2, indexed(propPath, findex), indexed(propBasePath, findex), dropDownMenuMgr, childContext); } }); if (!containsPath(indexed(propPath, index))) { addedNewItem = true; } } } } sortActionsByCaption(actions); for (IAction action : actions) { menu.add(action); } if (menu != null) { menu.add(new Separator()); } if (!addclassactions.isEmpty() && addclassactions.size() <= 20) { sortActionsByCaption(addclassactions); for (IAction action : addclassactions) { menu.add(action); } menu.add(new Separator()); } else if (!addclassactions.isEmpty()) { Action action = new Action() { @Override public void run() { } }; action.setText("Add"); menu.add(action); action.setMenuCreator(new MenuCreator() { @Override protected void fillMenu(MenuManager dropDownMenuMgr) { sortActionsByCaption(addclassactions); for (IAction action : addclassactions) { dropDownMenuMgr.add(action); } } }); } if (!actionsRemove.isEmpty()) { Action action = new Action() { @Override public void run() { } }; action.setText("Remove"); menu.add(action); action.setMenuCreator(new MenuCreator() { @Override protected void fillMenu(MenuManager dropDownMenuMgr) { sortActionsByCaption(actionsRemove); for (IAction action : actionsRemove) { dropDownMenuMgr.add(action); } } }); } }
From source file:org.gluster.storage.management.console.utils.GUIHelper.java
License:Open Source License
public Action createPullDownMenu(String menuName, String iconPath, final MenuManager menuManager) { Action action = new Action(menuName, IAction.AS_DROP_DOWN_MENU) { public void run() { }//from w ww . ja va 2 s .com }; action.setMenuCreator(new IMenuCreator() { @Override public Menu getMenu(Menu menu) { return null; } @Override public Menu getMenu(Control control) { return menuManager.createContextMenu(control); } @Override public void dispose() { } }); action.setImageDescriptor(getImageDescriptor(iconPath)); return action; }
From source file:org.mxupdate.eclipse.shell.ShellView.java
License:Apache License
/** * Creates the shell view with an output text field {@link #textOutput} and * an input text field {@link #textInput}. * * @param _parent parent composite element where the new GUI elements * must be added/* ww w.j a va 2 s. c o m*/ * @see #textInput * @see #textOutput */ @Override() public void createPartControl(final Composite _parent) { _parent.setLayout(new GridLayout(1, false)); this.textOutput = new StyledText(_parent, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); this.textOutput.setEditable(false); this.textOutput.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1)); this.textOutput.setEnabled(false); this.textInput = new Text(_parent, SWT.SINGLE | SWT.BORDER); this.textInput.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false, 1, 1)); this.textInput.setEnabled(false); // key listener for the input text field // (execute, previous history entry, next history entry) this.textInput.addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent _event) { switch (_event.keyCode) { case SWT.CR: ShellView.this.execute(); break; case SWT.ARROW_UP: ShellView.this.prevHistoryEntry(); break; case SWT.ARROW_DOWN: ShellView.this.nextHistoryEntry(); break; default: } } }); // clear button this.getViewSite().getActionBars().getMenuManager() .add(new Action(Messages.getString("ShellView.ClearOutputButton")) { //$NON-NLS-1$ @Override() public void run() { ShellView.this.textOutput.setText(""); //$NON-NLS-1$ } }); this.getViewSite().getActionBars().getToolBarManager().add(new Action( Messages.getString("ShellView.ButtonPrevious"), PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_BACK)) { @Override() public void run() { ShellView.this.prevHistoryEntry(); } }); this.getViewSite().getActionBars().getToolBarManager().add(new Action( Messages.getString("ShellView.ButtonNext"), PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_FORWARD)) { @Override() public void run() { ShellView.this.nextHistoryEntry(); } }); final Action action = new Action("Select Project", Action.AS_DROP_DOWN_MENU) { }; action.setMenuCreator(new IMenuCreator() { @Override() public void dispose() { } @Override() public Menu getMenu(final Control _parent) { final MenuManager mg = new MenuManager(); for (final String project : Activator.getDefault().getProjectNames()) { mg.add(new Action(project) { @Override() public void run() { action.setText(Messages.getString("ShellView.ProjectSelect", project)); //$NON-NLS-1$ ShellView.this.curProjectName = project; ShellView.this.textInput.setEnabled(true); ShellView.this.textOutput.setEnabled(true); ShellView.this.getViewSite().getActionBars().getToolBarManager().update(true); } }); } return mg.createContextMenu(_parent); } @Override() public Menu getMenu(final Menu _menu) { return null; } }); this.getViewSite().getActionBars().getToolBarManager().add(action); // set colors this.updateStyle(); this.textInput.setFocus(); ShellPreference.addListener(this); }
From source file:org.openmaji.implementation.tool.eclipse.editor.kinetic.KINeticContextMenuProvider.java
License:Open Source License
protected void buildLifeCycleItems(IMenuManager menu) { IAction actionLifeCycleState = getRegistry().getAction(LifeCycleAction.ID_LIFE_CYCLE_STATE); Action action = new Action("Life Cycle State") { };//from w ww . j a va 2s.c om action.setMenuCreator(actionLifeCycleState.getMenuCreator()); menu.appendToGroup(ActionConstants.GROUP_LIFECYCLESTATE, new ActionContributionItem(action)); }
From source file:org.phpsrc.eclipse.pti.tools.phpdepend.ui.views.PHPDependSummaryView.java
License:Open Source License
private void createToolbar() { IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); Action history = new Action("History", Action.AS_DROP_DOWN_MENU) { public void runWithEvent(Event e) { IMenuCreator mc = getMenuCreator(); if (mc != null) { ToolItem ti = (ToolItem) e.widget; Menu m = mc.getMenu(ti.getParent()); if (m != null) { Point point = ti.getParent().toDisplay(new Point(e.x, e.y + ti.getBounds().height)); m.setLocation(point.x, point.y); m.setVisible(true);//from w w w . j a va 2 s . c o m } } } }; history.setImageDescriptor( PHPDependPlugin.getDefault().getImageRegistry().getDescriptor(PHPDependPlugin.IMG_PHP_DEPEND)); history.setMenuCreator(new IMenuCreator() { private Menu listMenu; public Menu getMenu(Menu parent) { return null; } public Menu getMenu(Control parent) { if (listMenu != null) listMenu.dispose(); listMenu = new Menu(parent); int length = summaries.size(); if (length == 0) { MenuItem m = new MenuItem(listMenu, SWT.CHECK); m.setText("Empty"); m.setEnabled(false); } else { for (int i = length - 1; i >= 0; i--) { MetricRunSession s = summaries.get(i); MenuItem m = new MenuItem(listMenu, SWT.CHECK); m.setText(s.getGenerated().toString()); m.setSelection(i == showIndex); m.setEnabled(i != showIndex); m.setData("index", new Integer(i)); m.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { MenuItem item = (MenuItem) e.getSource(); Integer index = (Integer) item.getData("index"); showIndex = index.intValue(); tree.removeAll(); tree.setItemCount(1); } public void widgetDefaultSelected(SelectionEvent e) { } }); } new MenuItem(listMenu, SWT.SEPARATOR); MenuItem m = new MenuItem(listMenu, SWT.PUSH); m.setText("Clear History"); m.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { tree.removeAll(); table.removeAll(); showIndex = -1; int size = summaries.size(); for (int i = size - 1; i >= 0; i--) { summaries.remove(i); } } public void widgetDefaultSelected(SelectionEvent e) { } }); } return listMenu; } public void dispose() { if (listMenu != null) listMenu.dispose(); } }); mgr.add(new ActionContributionItem(history)); }
From source file:org.rssowl.ui.internal.CoolBarAdvisor.java
License:Open Source License
private Action getAction(final CoolBarItem item, final CoolBarMode mode, final ToolBarManager manager) { Action action = new Action(item.getName(), item.getStyle()) { @Override/*from ww w . j a v a2 s . c o m*/ public String getId() { return item.getId(); } @Override public String getActionDefinitionId() { return item.hasCommand() ? item.getId() : null; } @Override public ImageDescriptor getImageDescriptor() { return mode == CoolBarMode.TEXT ? null : item.getImg(); } @Override public ImageDescriptor getDisabledImageDescriptor() { return mode == CoolBarMode.TEXT ? null : item.getDisabledImg(); } @Override public void run() { CoolBarAdvisor.this.run(this, item, manager); } }; action.setToolTipText(item.getTooltip()); action.setMenuCreator(getMenu(item)); return action; }