Java Code Examples for org.eclipse.swt.widgets.Control#setMenu()
The following examples show how to use
org.eclipse.swt.widgets.Control#setMenu() .
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: ViewMenus.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Creates a menu for the given Control that will be populated by the provided populator This * can be used to construct dynamic menus that change contents depending of state. */ public void createControlContextMenu(Control control, final IMenuPopulator populator){ contextMenu = new MenuManager(); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager){ for (IAction ac : populator.fillMenu()) { if (ac == null) { contextMenu.add(new Separator()); } else { if (ac instanceof RestrictedAction) { ((RestrictedAction) ac).reflectRight(); } contextMenu.add(ac); } } } }); Menu menu = contextMenu.createContextMenu(control); control.setMenu(menu); }
Example 2
Source File: ViewMenus.java From elexis-3-core with Eclipse Public License 1.0 | 6 votes |
/** * Creates a menu for the given control containing the given actions * * @param control * the Control to add the menu to * @param actions * the actions to be shown in the menu */ public void createControlContextMenu(Control control, final IAction... actions){ List<IContributionItem> contributionItems = convertActionsToContributionItems(actions); contextMenu = new MenuManager(); contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager){ for (IAction iAction : actions) { if (iAction instanceof RestrictedAction) { ((RestrictedAction) iAction).reflectRight(); } } fillContextMenu(manager, contributionItems); } }); Menu menu = contextMenu.createContextMenu(control); control.setMenu(menu); }
Example 3
Source File: InternalCompositeTable.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Utility method: Creates a new row object or recycles one that had been * previously created but was no longer needed. * * @return The new row object. */ private TableRow getNewRow() { if (spareRows.size() > 0) { TableRow recycledRow = (TableRow) spareRows.removeFirst(); recycledRow.setVisible(true); return recycledRow; } Control newControl = createInternalControl(controlHolder, rowConstructor); if (menu != null) { newControl.setMenu(menu); } fireRowConstructionEvent(newControl); TableRow newRow = new TableRow(this, newControl); if (newRow.getRowControl() instanceof Composite) { Composite rowComp = (Composite) newRow.getRowControl(); if (rowComp.getLayout() instanceof GridRowLayout) { rowComp.setBackground(getBackground()); rowComp.addPaintListener(rowPaintListener); } } return newRow; }
Example 4
Source File: StatechartDefinitionSection.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void initContextMenu(Control control) { MenuManager menuManager = new FilteringMenuManager(); Menu contextMenu = menuManager.createContextMenu(control); control.setMenu(contextMenu); IWorkbenchPartSite site = editorPart.getSite(); if (site != null) site.registerContextMenu("org.yakindu.base.xtext.utils.jface.viewers.StyledTextXtextAdapterContextMenu", menuManager, site.getSelectionProvider()); }
Example 5
Source File: BuildSupplyChainMenuAction.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public Menu getMenu(Control control) { Menu menu = new Menu(control); createMenu(menu); control.setMenu(menu); return menu; }
Example 6
Source File: LayoutMenuAction.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public Menu getMenu(Control control) { Menu menu = new Menu(control); createMenu(menu); control.setMenu(menu); return menu; }
Example 7
Source File: TreeCompositeViewer.java From ice with Eclipse Public License 1.0 | 5 votes |
/** * Create the tree viewer that shows the TreeComposite for the current Form */ @Override public void createPartControl(Composite parent) { // Local Declarations IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolbarManager = actionBars.getToolBarManager(); // Create the default Actions. createActions(); toolbarManager.add(addAction); toolbarManager.add(deleteAction); // Set the parent reference viewerParent = parent; // Draw the viewer and set the initial tree. treeViewer = createViewer(viewerParent); treeViewer.setInput(inputTree); // Register the TreeViewer as a selection provider so that other widgets // and parts can get its current selection. getSite().setSelectionProvider(treeViewer); // Create a MenuManager that will enable a context menu in the // TreeViewer. MenuManager menuManager = new MenuManager(); menuManager.setRemoveAllWhenShown(true); menuManager.addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(IMenuManager manager) { TreeCompositeViewer.this.fillContextMenu(manager); } }); Control control = treeViewer.getControl(); Menu menu = menuManager.createContextMenu(control); control.setMenu(menu); return; }
Example 8
Source File: LibraryExplorerTreeViewPage.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Creates the context menu */ private void createContextMenus( ) { menuManager = new LibraryExplorerContextMenuProvider( this ); Control control = getTreeViewer( ).getControl( ); Menu menu = menuManager.createContextMenu( control ); control.setMenu( menu ); getSite( ).registerContextMenu( "org.eclipse.birt.report.designer.ui.lib.explorer.view", menuManager, //$NON-NLS-1$ getSite( ).getSelectionProvider( ) ); }
Example 9
Source File: JUnitStatusContributionItem.java From eclipse-extras with Eclipse Public License 1.0 | 5 votes |
private void attachContextMenu( Control control ) { MenuManager menuManager = new MenuManager(); menuManager.add( new ActivateJUnitViewOnFailureAction() ); menuManager.add( new Separator() ); menuManager.add( new CloseJUnitStatusAction( getWorkbenchWindow().getWorkbench() ) ); Menu contextMenu = menuManager.createContextMenu( control ); control.setMenu( contextMenu ); }
Example 10
Source File: AbstractEditorPropertySection.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void initContextMenu(Control control) { MenuManager menuManager = new FilteringMenuManager(); Menu contextMenu = menuManager.createContextMenu(control); control.setMenu(contextMenu); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite(); site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider()); }
Example 11
Source File: XtextStyledTextCellEditor.java From statecharts with Eclipse Public License 1.0 | 5 votes |
protected void initContextMenu(Control control) { MenuManager menuManager = createMenuManager(); Menu contextMenu = menuManager.createContextMenu(control); control.setMenu(contextMenu); IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite(); site.registerContextMenu(CONTEXTMENUID, menuManager, site.getSelectionProvider()); }
Example 12
Source File: MechanicStatusControlContribution.java From workspacemechanic with Eclipse Public License 1.0 | 5 votes |
/** * Creates and registers a new popup menu on the supplied control. * * <p> * When the menu is about to be shown the * {@link #fillContextMenu(IMenuManager)} method will be called. */ private void createContextMenu(Control control) { MenuManager mgr = new MenuManager("#PopupMenu"); mgr.setRemoveAllWhenShown(true); mgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { fillContextMenu(manager); } }); Menu menu = mgr.createContextMenu(control); control.setMenu(menu); }
Example 13
Source File: EventViewTable.java From neoscada with Eclipse Public License 1.0 | 5 votes |
protected void hookContextMenu ( final Control control, final ISelectionProvider selectionProvider, final IViewSite viewSite ) { final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown ( true ); menuMgr.addMenuListener ( new IMenuListener () { @Override public void menuAboutToShow ( final IMenuManager manager ) { fillContextMenu ( manager ); } } ); final Menu menu = menuMgr.createContextMenu ( control ); control.setMenu ( menu ); viewSite.registerContextMenu ( menuMgr, selectionProvider ); }
Example 14
Source File: MonitorsViewTable.java From neoscada with Eclipse Public License 1.0 | 5 votes |
protected void hookContextMenu ( final Control control, final ISelectionProvider selectionProvider, final IViewSite viewSite ) { final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$ menuMgr.setRemoveAllWhenShown ( true ); menuMgr.addMenuListener ( new IMenuListener () { @Override public void menuAboutToShow ( final IMenuManager manager ) { fillContextMenu ( manager ); } } ); final Menu menu = menuMgr.createContextMenu ( control ); control.setMenu ( menu ); viewSite.registerContextMenu ( menuMgr, selectionProvider ); }
Example 15
Source File: ErrorTraceTreeViewer.java From tlaplus with MIT License | 4 votes |
private void createContextMenu() { final MenuManager contextMenu = new MenuManager("#ViewerMenu"); //$NON-NLS-1$ contextMenu.setRemoveAllWhenShown(true); contextMenu.addMenuListener(new IMenuListener() { @Override public void menuAboutToShow(final IMenuManager menuManager) { final Object selection = ((IStructuredSelection)treeViewer.getSelection()).getFirstElement(); if (selection instanceof TLCState) { menuManager.add(new Action("Run model from this point") { @Override public void run() { if (modelEditor != null) { final Model m = modelEditor.getModel(); if (m != null) { try { final int specType = m.getAttribute( IModelConfigurationConstants.MODEL_BEHAVIOR_SPEC_TYPE, IModelConfigurationDefaults.MODEL_BEHAVIOR_TYPE_DEFAULT); if (specType == IModelConfigurationDefaults.MODEL_BEHAVIOR_TYPE_NO_SPEC) { return; } final MainModelPage page = (MainModelPage)modelEditor.findPage(MainModelPage.ID); final String init = ((TLCState) selection).getConjunctiveDescription(false); if (specType == IModelConfigurationDefaults.MODEL_BEHAVIOR_TYPE_SPEC_CLOSED) { page.setInitNextBehavior(init, ""); modelEditor.setActivePage(MainModelPage.ID); Display.getDefault().asyncExec(() -> { MessageDialog.openInformation(null, "Model Reconfigured", "The model has been set up to begin checking from the selected " + "state; please enter the next-state relation (usually Next), review the model parameters and run the checker."); }); } else { page.setInitNextBehavior(init, null); modelEditor.setActivePage(MainModelPage.ID); Display.getDefault().asyncExec(() -> { MessageDialog.openInformation(null, "Model Reconfigured", "The model has been set up to begin checking from the selected " + "state; please review the model parameters and run the checker."); }); } // We previously handled the config alteration and model check launch behind the // scenes but have since stopped doing that. I'm leaving a portion of this here, // commented out, in case we decide to return to that workflow. // final StringBuilder constraint = new StringBuilder(); // if (specType == IModelConfigurationDefaults.MODEL_BEHAVIOR_TYPE_SPEC_CLOSED) { // final String temporalSpecification = m.getAttribute(IModelConfigurationConstants.MODEL_BEHAVIOR_CLOSED_SPECIFICATION, ""); // } // // constraint.append(((TLCState) selection).getConjunctiveDescription(false)); // // m.setAttribute(IModelConfigurationConstants.MODEL_BEHAVIOR_SEPARATE_SPECIFICATION_INIT, constraint.toString()); // m.save(null); // // modelEditor.launchModel(TLCModelLaunchDelegate.MODE_MODELCHECK, true); } catch (final CoreException e) { TLCActivator.logError("Problem encountered attempting to launch checker.", e); } } } else { TLCActivator.logInfo( "Were not able to launch ammended model because we have no model editor."); } } }); } /* In earlier versions of the Toolbox, we also provided: Collapse All (treeViewer.collapseAll()) Expand to default level (treeViewer.collapseAll(); treeViewer.expandToLevel(2);) Expand All (treeViewer.expandAll()) But we now provide expand and collapse through the parent section's toolbar */ } }); final Control c = treeViewer.getControl(); final Menu menu = contextMenu.createContextMenu(c); c.setMenu(menu); }
Example 16
Source File: ClipboardCopy.java From BiglyBT with GNU General Public License v2.0 | 4 votes |
public static void addCopyToClipMenu( final Control control, final copyToClipProvider provider ) { MouseAdapter ml = (MouseAdapter)control.getData( MOUSE_LISTENER_KEY ); if ( ml != null ){ control.removeMouseListener( ml ); } ml = new MouseAdapter() { @Override public void mouseDown( MouseEvent e ) { if ( control.isDisposed()){ return; } final String text = provider.getText(); if ( control.getMenu() != null || text == null || text.length() == 0 ){ return; } if (!(e.button == 3 || (e.button == 1 && e.stateMask == SWT.CONTROL))){ return; } final Menu menu = new Menu(control.getShell(),SWT.POP_UP); MenuItem item = new MenuItem( menu,SWT.NONE ); item.setData( MENU_ITEM_KEY, "" ); String msg_text_id; if ( provider instanceof copyToClipProvider2 ){ msg_text_id = ((copyToClipProvider2)provider).getMenuResource(); }else{ msg_text_id = "label.copy.to.clipboard"; } item.setText( MessageText.getString( msg_text_id )); item.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected( SelectionEvent arg0) { new Clipboard(control.getDisplay()).setContents(new Object[] {text}, new Transfer[] {TextTransfer.getInstance()}); } }); control.setMenu( menu ); menu.addMenuListener( new MenuAdapter() { @Override public void menuHidden( MenuEvent arg0 ) { if ( control.getMenu() == menu ){ control.setMenu( null ); } } }); menu.setVisible( true ); } }; control.setData( MOUSE_LISTENER_KEY, ml ); control.addMouseListener( ml ); }
Example 17
Source File: N4IDEXpectView.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public void createPartControl(Composite parent) { FillLayout fillLayout = new FillLayout(SWT.VERTICAL); fillLayout.marginHeight = 5; fillLayout.marginWidth = 5; parent.setLayout(fillLayout); // main container container = new Composite(parent, SWT.BORDER); container.setLayout(new FillLayout()); // create container for stack trace data Composite stacktraceDataContainer = new Composite(parent, SWT.BORDER); FormLayout formLayout = new FormLayout(); formLayout.marginHeight = 5; formLayout.marginWidth = 5; formLayout.spacing = 5; stacktraceDataContainer.setLayout(formLayout); Composite stackLabelContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE); stackLabelContainer.setLayout(new GridLayout()); FormData stackLabelFormData = new FormData(); stackLabelFormData.top = new FormAttachment(0); stackLabelFormData.left = new FormAttachment(0); stackLabelFormData.right = new FormAttachment(100); stackLabelFormData.bottom = new FormAttachment(20); stackLabelContainer.setLayoutData(stackLabelFormData); Composite stackTraceContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE); stackTraceContainer.setLayout(new FillLayout()); FormData stackTraceFormData = new FormData(); stackTraceFormData.top = new FormAttachment(stackLabelContainer); stackTraceFormData.left = new FormAttachment(0); stackTraceFormData.right = new FormAttachment(100); stackTraceFormData.bottom = new FormAttachment(100); stackTraceContainer.setLayoutData(stackTraceFormData); // Create viewer for test tree in main container testTreeViewer = new TreeViewer(container); testTreeViewer.setContentProvider(new XpectContentProvider()); testTreeViewer.setLabelProvider(new XpectLabelProvider(this.testsExecutionStatus)); testTreeViewer.setInput(null); // create stack trace label stacktraceLabel = new Label(stackLabelContainer, SWT.SHADOW_OUT); FontData fontData = stacktraceLabel.getFont().getFontData()[0]; Display display = Display.getCurrent(); // may be null if outside the UI thread if (display == null) display = Display.getDefault(); Font font = new Font(display, new FontData(fontData.getName(), fontData .getHeight(), SWT.BOLD)); // Make stack trace label bold stacktraceLabel.setFont(font); stacktraceLabel.setText(NO_TRACE_MSG); // create stack trace console MessageConsole messageConsole = new MessageConsole("trace", null); stacktraceConsole = new TraceConsole(messageConsole); stacktraceConsoleViewer = new TextConsoleViewer(stackTraceContainer, messageConsole); // context menu getSite().setSelectionProvider(testTreeViewer); MenuManager contextMenu = new MenuManager(); contextMenu.setRemoveAllWhenShown(true); getSite().registerContextMenu(contextMenu, testTreeViewer); Control control = testTreeViewer.getControl(); Menu menu = contextMenu.createContextMenu(control); control.setMenu(menu); activateContext(); createSelectionActions(); }