Search in sources :

Example 56 with GroupMarker

use of org.eclipse.jface.action.GroupMarker 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 : IAction(org.eclipse.jface.action.IAction) 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) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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) IdentityHashMap(java.util.IdentityHashMap)

Example 57 with GroupMarker

use of org.eclipse.jface.action.GroupMarker in project dbeaver by serge-rider.

the class BaseTextEditor method editorContextMenuAboutToShow.

@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
    // super.editorContextMenuAboutToShow(menu);
    menu.add(new GroupMarker(GROUP_SQL_ADDITIONS));
    menu.add(new GroupMarker(GROUP_SQL_EXTRAS));
    menu.add(new Separator());
    menu.add(new Separator(ITextEditorActionConstants.GROUP_COPY));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_PRINT));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_EDIT));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_FIND));
    menu.add(new Separator(IWorkbenchActionConstants.GROUP_ADD));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_UNDO));
    menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_SAVE));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_REST));
    menu.add(new Separator());
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menu.add(new Separator());
    menu.add(new GroupMarker(GROUP_SQL_PREFERENCES));
    if (isEditable()) {
        addAction(menu, ITextEditorActionConstants.GROUP_UNDO, ITextEditorActionConstants.UNDO);
        addAction(menu, ITextEditorActionConstants.GROUP_SAVE, ITextEditorActionConstants.SAVE);
        addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.CUT);
        addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.COPY);
        addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.PASTE);
        IAction action = getAction(ITextEditorActionConstants.QUICK_ASSIST);
        if (action != null && action.isEnabled()) {
            addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ITextEditorActionConstants.QUICK_ASSIST);
        }
    } else {
        addAction(menu, ITextEditorActionConstants.GROUP_COPY, ITextEditorActionConstants.COPY);
    }
    IAction preferencesAction = getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES);
    if (preferencesAction != null) {
        menu.appendToGroup(GROUP_SQL_PREFERENCES, preferencesAction);
    }
    for (IActionContributor ac : actionContributors) {
        ac.contributeActions(menu);
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) GroupMarker(org.eclipse.jface.action.GroupMarker) Separator(org.eclipse.jface.action.Separator)

Example 58 with GroupMarker

use of org.eclipse.jface.action.GroupMarker in project dbeaver by serge-rider.

the class ERDEditorContextMenuProvider method buildContextMenu.

/**
 * @see ContextMenuProvider#buildContextMenu(org.eclipse.jface.action.IMenuManager)
 */
@Override
public void buildContextMenu(IMenuManager menu) {
    if (editor.isLoaded()) {
        ISelection selection = editor.getGraphicalViewer().getSelection();
        if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
            editor.fillPartContextMenu(menu, (IStructuredSelection) selection);
        }
        menu.add(new Separator());
        editor.fillAttributeVisibilityMenu(menu);
        menu.add(new DiagramLayoutAction(editor));
        menu.add(new Separator());
        menu.add(new Separator(GEFActionConstants.GROUP_UNDO));
        menu.add(new Separator(GEFActionConstants.GROUP_COPY));
        // menu.add(ActionUtils.makeCommandContribution(editor.getSite(), IWorkbenchCommandConstants.EDIT_COPY));
        menu.add(new Separator(GEFActionConstants.GROUP_PRINT));
        menu.add(new Separator(GEFActionConstants.GROUP_EDIT));
        menu.add(new Separator(GEFActionConstants.GROUP_VIEW));
        menu.add(new Separator(GEFActionConstants.GROUP_FIND));
        menu.add(new Separator(GEFActionConstants.GROUP_REST));
        menu.add(new Separator(GEFActionConstants.GROUP_SAVE));
        menu.add(new Separator());
        menu.add(new GroupMarker(NavigatorCommands.GROUP_TOOLS));
        menu.add(new GroupMarker(NavigatorCommands.GROUP_NAVIGATOR_ADDITIONS));
        menu.add(new GroupMarker(NavigatorCommands.GROUP_NAVIGATOR_ADDITIONS_END));
        menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
        menu.add(new GroupMarker(IActionConstants.MB_ADDITIONS_END));
    }
}
Also used : DiagramLayoutAction(org.jkiss.dbeaver.erd.ui.action.DiagramLayoutAction) ISelection(org.eclipse.jface.viewers.ISelection) GroupMarker(org.eclipse.jface.action.GroupMarker) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Separator(org.eclipse.jface.action.Separator)

Example 59 with GroupMarker

use of org.eclipse.jface.action.GroupMarker in project dbeaver by serge-rider.

the class ValueViewerPanel method fillToolBar.

private void fillToolBar(final IContributionManager contributionManager) {
    contributionManager.add(new Separator());
    if (valueManager != null) {
        try {
            valueManager.contributeActions(contributionManager, previewController, valueEditor);
        } catch (Exception e) {
            log.error("Can't contribute value manager actions", e);
        }
    }
    contributionManager.add(new GroupMarker(IValueManager.GROUP_ACTIONS_ADDITIONAL));
    if (valueEditor != null && !valueEditor.isReadOnly()) {
        contributionManager.add(ActionUtils.makeCommandContribution(presentation.getController().getSite(), ValueViewCommandHandler.CMD_SAVE_VALUE));
        contributionManager.add(new Action("Auto-apply value", Action.AS_CHECK_BOX) {

            {
                setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.AUTO_SAVE));
            }

            @Override
            public boolean isChecked() {
                return DBWorkbench.getPlatform().getPreferenceStore().getBoolean(ResultSetPreferences.RS_EDIT_AUTO_UPDATE_VALUE);
            }

            @Override
            public void run() {
                boolean newValue = !isChecked();
                DBWorkbench.getPlatform().getPreferenceStore().setValue(ResultSetPreferences.RS_EDIT_AUTO_UPDATE_VALUE, newValue);
                presentation.getController().updatePanelActions();
            }
        });
    }
}
Also used : Action(org.eclipse.jface.action.Action) GroupMarker(org.eclipse.jface.action.GroupMarker) Separator(org.eclipse.jface.action.Separator) DBException(org.jkiss.dbeaver.DBException)

Example 60 with GroupMarker

use of org.eclipse.jface.action.GroupMarker in project yamcs-studio by yamcs.

the class YamcsStudioActionBarAdvisor method fillAppToolBar.

protected void fillAppToolBar(IToolBarManager appToolBar) {
    appToolBar.add(new Separator(IWorkbenchActionConstants.NEW_GROUP));
    appToolBar.add(new NewWizardDropDownAction(window));
    appToolBar.add(save);
    appToolBar.add(saveAll);
    appToolBar.add(new GroupMarker(COOL_GROUP_PROCESSOR_INFO));
    appToolBar.add(new GroupMarker(COOL_GROUP_BOOKMARK_SHORTCUTS));
    appToolBar.add(new GroupMarker(COOL_GROUP_PROCESSOR_CONTROLS));
    appToolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
}
Also used : NewWizardDropDownAction(org.eclipse.ui.actions.NewWizardDropDownAction) GroupMarker(org.eclipse.jface.action.GroupMarker) Separator(org.eclipse.jface.action.Separator)

Aggregations

GroupMarker (org.eclipse.jface.action.GroupMarker)117 Separator (org.eclipse.jface.action.Separator)93 IMenuManager (org.eclipse.jface.action.IMenuManager)44 MenuManager (org.eclipse.jface.action.MenuManager)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)17 IToolBarManager (org.eclipse.jface.action.IToolBarManager)12 IAction (org.eclipse.jface.action.IAction)10 IMenuListener (org.eclipse.jface.action.IMenuListener)10 Menu (org.eclipse.swt.widgets.Menu)8 Action (org.eclipse.jface.action.Action)7 ISelection (org.eclipse.jface.viewers.ISelection)5 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)4 ToolBarContributionItem (org.eclipse.jface.action.ToolBarContributionItem)4 ToolBarManager (org.eclipse.jface.action.ToolBarManager)4 Iterator (java.util.Iterator)2 AddPVAction (org.csstudio.trends.databrowser3.ui.AddPVAction)2 IFindReplaceTarget (org.eclipse.jface.text.IFindReplaceTarget)2 Point (org.eclipse.swt.graphics.Point)2 Shell (org.eclipse.swt.widgets.Shell)2