Search in sources :

Example 36 with IMenuManager

use of org.eclipse.jface.action.IMenuManager in project cubrid-manager by CUBRID.

the class PerspectiveChangedListener method hidePerspectiveHide.

public void hidePerspectiveHide(PerspectiveChangeEvent event) {
    WorkbenchWindow window = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        ICoolBarManager coolBarManager = window.getCoolBarManager2();
        IMenuManager menuManager = window.getMenuBarManager();
        ActionAdvisor.getInstance().hideToolbar(coolBarManager);
        ActionAdvisor.getInstance().hideMenu(menuManager);
    }
}
Also used : WorkbenchWindow(org.eclipse.ui.internal.WorkbenchWindow) IMenuManager(org.eclipse.jface.action.IMenuManager) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Example 37 with IMenuManager

use of org.eclipse.jface.action.IMenuManager in project sling by apache.

the class JcrPropertiesView method hookContextMenu.

private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            JcrPropertiesView.this.fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    IWorkbenchPartSite site = getSite();
    if (site != null) {
        site.registerContextMenu(menuMgr, viewer);
    }
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener)

Example 38 with IMenuManager

use of org.eclipse.jface.action.IMenuManager in project bndtools by bndtools.

the class RepositoriesView method createContextMenu.

void createContextMenu() {
    MenuManager mgr = new MenuManager();
    Menu menu = mgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    mgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    getSite().registerContextMenu(mgr, viewer);
    mgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            try {
                manager.removeAll();
                IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
                if (!selection.isEmpty()) {
                    final Object firstElement = selection.getFirstElement();
                    if (firstElement instanceof Actionable) {
                        final RepositoryPlugin rp = getRepositoryPlugin(firstElement);
                        //
                        // Use the Actionable interface to fill the menu
                        // Should extend this to allow other menu entries
                        // from the view, but currently there are none
                        //
                        final Actionable act = (Actionable) firstElement;
                        Map<String, Runnable> actions = act.actions();
                        if (actions != null) {
                            for (final Entry<String, Runnable> e : actions.entrySet()) {
                                String label = e.getKey();
                                boolean enabled = true;
                                boolean checked = false;
                                String description = null;
                                Matcher m = LABEL_PATTERN.matcher(label);
                                if (m.matches()) {
                                    if (m.group(1) != null)
                                        enabled = false;
                                    if (m.group(2) != null)
                                        checked = true;
                                    label = m.group(3);
                                    description = m.group(4);
                                }
                                Action a = new Action(label.replace("&", "&&")) {

                                    @Override
                                    public void run() {
                                        Job backgroundJob = new Job("Repository Action '" + getText() + "'") {

                                            @Override
                                            protected IStatus run(IProgressMonitor monitor) {
                                                try {
                                                    e.getValue().run();
                                                    if (rp != null && rp instanceof Refreshable)
                                                        Central.refreshPlugin((Refreshable) rp);
                                                } catch (final Exception e) {
                                                    IStatus status = new Status(IStatus.ERROR, Plugin.PLUGIN_ID, "Error executing: " + getName(), e);
                                                    Plugin.getDefault().getLog().log(status);
                                                }
                                                monitor.done();
                                                return Status.OK_STATUS;
                                            }
                                        };
                                        backgroundJob.addJobChangeListener(new JobChangeAdapter() {

                                            @Override
                                            public void done(IJobChangeEvent event) {
                                                if (event.getResult().isOK()) {
                                                    viewer.getTree().getDisplay().asyncExec(new Runnable() {

                                                        @Override
                                                        public void run() {
                                                            viewer.refresh();
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                        backgroundJob.setUser(true);
                                        backgroundJob.setPriority(Job.SHORT);
                                        backgroundJob.schedule();
                                    }
                                };
                                a.setEnabled(enabled);
                                if (description != null)
                                    a.setDescription(description);
                                a.setChecked(checked);
                                manager.add(a);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : Action(org.eclipse.jface.action.Action) IStatus(org.eclipse.core.runtime.IStatus) Matcher(java.util.regex.Matcher) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) Actionable(aQute.bnd.service.Actionable) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) Entry(java.util.Map.Entry) GroupMarker(org.eclipse.jface.action.GroupMarker) Menu(org.eclipse.swt.widgets.Menu) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Refreshable(aQute.bnd.service.Refreshable) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Map(java.util.Map)

Example 39 with IMenuManager

use of org.eclipse.jface.action.IMenuManager in project meclipse by flaper87.

the class MeclipseView method hookContextMenu.

private void hookContextMenu() {
    MenuManager menuMgr = new MenuManager("#PopupMenu");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            if (selection.isEmpty()) {
                MeclipseView.this.fillContextMenu(manager);
                return;
            }
            TreeObject obj = (TreeObject) selection.getFirstElement();
            manager.add(new Separator());
            obj.fillContextMenu(manager);
        }
    });
    Menu menu = menuMgr.createContextMenu(viewer.getControl());
    viewer.getControl().setMenu(menu);
    getSite().registerContextMenu(menuMgr, viewer);
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) TreeObject(org.mongodb.meclipse.views.objects.TreeObject) IMenuManager(org.eclipse.jface.action.IMenuManager) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IMenuListener(org.eclipse.jface.action.IMenuListener) Separator(org.eclipse.jface.action.Separator)

Example 40 with IMenuManager

use of org.eclipse.jface.action.IMenuManager in project translationstudio8 by heartsome.

the class WorkingSetRootModeActionGroup method fillActionBars.

/*
	 * (non-Javadoc)
	 * 
	 * @see ActionGroup#fillActionBars(IActionBars)
	 */
public void fillActionBars(IActionBars actionBars) {
    if (hasContributedToViewMenu)
        return;
    IMenuManager topLevelSubMenu = new MenuManager(WorkbenchNavigatorMessages.actions_WorkingSetRootModeActionGroup_Top_Level_Element_);
    addActions(topLevelSubMenu);
    actionBars.getMenuManager().insertBefore(IWorkbenchActionConstants.MB_ADDITIONS, topLevelSubMenu);
    hasContributedToViewMenu = true;
}
Also used : MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

IMenuManager (org.eclipse.jface.action.IMenuManager)88 MenuManager (org.eclipse.jface.action.MenuManager)72 IMenuListener (org.eclipse.jface.action.IMenuListener)48 Menu (org.eclipse.swt.widgets.Menu)43 Separator (org.eclipse.jface.action.Separator)31 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 IAction (org.eclipse.jface.action.IAction)9 TreeViewer (org.eclipse.jface.viewers.TreeViewer)9 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 GridData (org.eclipse.swt.layout.GridData)8 Action (org.eclipse.jface.action.Action)7 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)7 Composite (org.eclipse.swt.widgets.Composite)7 GridLayout (org.eclipse.swt.layout.GridLayout)6 List (java.util.List)5 ICoolBarManager (org.eclipse.jface.action.ICoolBarManager)5 FocusEvent (org.eclipse.swt.events.FocusEvent)5 ActionManager (com.cubrid.common.ui.spi.action.ActionManager)4 IContributionItem (org.eclipse.jface.action.IContributionItem)4 Point (org.eclipse.swt.graphics.Point)4