Search in sources :

Example 1 with IMenuCreator

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

the class ActionsInputDialog method createActions.

/**
 * Creates the actions.
 */
private void createActions() {
    addAction = new Action("Add") {

        @Override
        public void run() {
        }
    };
    addAction.setMenuCreator(new IMenuCreator() {

        private Menu menu;

        @Override
        public void dispose() {
            if (menu != null) {
                menu.dispose();
                menu = null;
            }
        }

        @Override
        public Menu getMenu(final Control parent) {
            if (menu != null) {
                menu.dispose();
            }
            menu = createMenu(parent, false);
            return menu;
        }

        @Override
        public Menu getMenu(final Menu parent) {
            return null;
        }
    });
    addAction.setToolTipText("Add an action");
    addAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/add.gif"));
    copyAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction newAction = ((AbstractWidgetAction) selection.getFirstElement()).getCopy();
                actionsInput.addAction(newAction);
                actionsViewer.setSelection(new StructuredSelection(newAction));
                refreshActionsViewer(newAction);
            }
        }
    };
    copyAction.setText("Copy Action");
    copyAction.setToolTipText("Copy the selected action");
    copyAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/copy.gif"));
    copyAction.setEnabled(false);
    removeAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                actionsList.remove((AbstractWidgetAction) selection.getFirstElement());
                refreshActionsViewer(null);
                this.setEnabled(false);
            }
        }
    };
    removeAction.setText("Remove Action");
    removeAction.setToolTipText("Remove the selected action from the list");
    removeAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/delete.gif"));
    removeAction.setEnabled(false);
    moveUpAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
                int i = actionsList.indexOf(widgetAction);
                if (i > 0) {
                    actionsList.remove(widgetAction);
                    actionsList.add(i - 1, widgetAction);
                    refreshActionsViewer(widgetAction);
                }
            }
        }
    };
    moveUpAction.setText("Move Up Action");
    moveUpAction.setToolTipText("Move up the selected action");
    moveUpAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_prev.gif"));
    moveUpAction.setEnabled(false);
    moveDownAction = new Action() {

        @Override
        public void run() {
            IStructuredSelection selection = (IStructuredSelection) actionsViewer.getSelection();
            if (!selection.isEmpty() && selection.getFirstElement() instanceof AbstractWidgetAction) {
                AbstractWidgetAction widgetAction = (AbstractWidgetAction) selection.getFirstElement();
                int i = actionsList.indexOf(widgetAction);
                if (i < actionsList.size() - 1) {
                    actionsList.remove(widgetAction);
                    actionsList.add(i + 1, widgetAction);
                    refreshActionsViewer(widgetAction);
                }
            }
        }
    };
    moveDownAction.setText("Move Down Action");
    moveDownAction.setToolTipText("Move down the selected action");
    moveDownAction.setImageDescriptor(CustomMediaFactory.getInstance().getImageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/search_next.gif"));
    moveDownAction.setEnabled(false);
}
Also used : AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction) Action(org.eclipse.jface.action.Action) Control(org.eclipse.swt.widgets.Control) IMenuCreator(org.eclipse.jface.action.IMenuCreator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Menu(org.eclipse.swt.widgets.Menu) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Example 2 with IMenuCreator

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

the class OPIEditorActionBarContributor method buildActions.

@Override
protected void buildActions() {
    addRetargetAction(new UndoRetargetAction());
    addRetargetAction(new RedoRetargetAction());
    addRetargetAction(new DeleteRetargetAction());
    addRetargetAction(new ZoomInRetargetAction());
    addRetargetAction(new ZoomOutRetargetAction());
    addRetargetAction(new MatchWidthRetargetAction());
    addRetargetAction(new MatchHeightRetargetAction());
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.TOP));
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.MIDDLE));
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.BOTTOM));
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.LEFT));
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.CENTER));
    addRetargetAction(new AlignmentRetargetAction(PositionConstants.RIGHT));
    RetargetAction a = new RetargetAction(GEFActionConstants.TOGGLE_GRID_VISIBILITY, "Toggle Grid Visibility", IAction.AS_CHECK_BOX);
    a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, // $NON-NLS-1$
    "icons/grid.png"));
    addRetargetAction(a);
    a = new RetargetAction(GEFActionConstants.TOGGLE_SNAP_TO_GEOMETRY, "Toggle Snap To Geometry", IAction.AS_CHECK_BOX);
    a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/snap2geometry.png"));
    addRetargetAction(a);
    a = new RetargetAction(GEFActionConstants.TOGGLE_RULER_VISIBILITY, "Toggle Ruler Visibility", IAction.AS_CHECK_BOX);
    a.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(OPIBuilderPlugin.PLUGIN_ID, "icons/ruler.png"));
    addRetargetAction(a);
    for (DistributeType dt : DistributeType.values()) {
        if (dt != DistributeType.HORIZONTAL_GAP) {
            a = new RetargetAction(dt.getActionID(), dt.getLabel());
            a.setImageDescriptor(dt.getImageDescriptor());
            addRetargetAction(a);
        }
    }
    // This is only for action displaying in toolbar
    a = new RetargetAction(DistributeType.HORIZONTAL_GAP.getActionID(), DistributeType.HORIZONTAL_GAP.getLabel(), IAction.AS_DROP_DOWN_MENU);
    a.setImageDescriptor(DistributeType.HORIZONTAL_GAP.getImageDescriptor());
    a.setMenuCreator(new IMenuCreator() {

        Menu menu;

        @Override
        public Menu getMenu(Menu parent) {
            return null;
        }

        @Override
        public Menu getMenu(Control parent) {
            if (menu != null)
                return menu;
            MenuManager manager = new MenuManager();
            for (DistributeType dt : DistributeType.values()) {
                if (dt != DistributeType.HORIZONTAL_GAP)
                    manager.add(getAction(dt.getActionID()));
            }
            menu = manager.createContextMenu(parent);
            return menu;
        }

        @Override
        public void dispose() {
            if (menu != null) {
                menu.dispose();
                menu = null;
            }
        }
    });
    addRetargetAction(a);
}
Also used : RedoRetargetAction(org.eclipse.gef.ui.actions.RedoRetargetAction) UndoRetargetAction(org.eclipse.gef.ui.actions.UndoRetargetAction) ZoomOutRetargetAction(org.eclipse.gef.ui.actions.ZoomOutRetargetAction) AlignmentRetargetAction(org.eclipse.gef.ui.actions.AlignmentRetargetAction) MatchHeightRetargetAction(org.eclipse.gef.ui.actions.MatchHeightRetargetAction) ZoomInRetargetAction(org.eclipse.gef.ui.actions.ZoomInRetargetAction) MatchWidthRetargetAction(org.eclipse.gef.ui.actions.MatchWidthRetargetAction) RetargetAction(org.eclipse.ui.actions.RetargetAction) RedoRetargetAction(org.eclipse.gef.ui.actions.RedoRetargetAction) DeleteRetargetAction(org.eclipse.gef.ui.actions.DeleteRetargetAction) IMenuCreator(org.eclipse.jface.action.IMenuCreator) DeleteRetargetAction(org.eclipse.gef.ui.actions.DeleteRetargetAction) MatchWidthRetargetAction(org.eclipse.gef.ui.actions.MatchWidthRetargetAction) ZoomInRetargetAction(org.eclipse.gef.ui.actions.ZoomInRetargetAction) DistributeType(org.csstudio.opibuilder.actions.DistributeWidgetsAction.DistributeType) MatchHeightRetargetAction(org.eclipse.gef.ui.actions.MatchHeightRetargetAction) Control(org.eclipse.swt.widgets.Control) AlignmentRetargetAction(org.eclipse.gef.ui.actions.AlignmentRetargetAction) UndoRetargetAction(org.eclipse.gef.ui.actions.UndoRetargetAction) MenuManager(org.eclipse.jface.action.MenuManager) ZoomOutRetargetAction(org.eclipse.gef.ui.actions.ZoomOutRetargetAction) Menu(org.eclipse.swt.widgets.Menu)

Example 3 with IMenuCreator

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

the class SelectCRSAction method getMenuCreator.

@Override
public IMenuCreator getMenuCreator() {
    return new MenuCreator(control -> {
        MenuManager menuManager = new MenuManager();
        menuManager.setRemoveAllWhenShown(true);
        menuManager.addMenuListener(manager -> {
            menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_4326));
            menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_3857));
            menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_3395));
            menuManager.add(new SetCRSAction(valueEditor, GisConstants.SRID_SIMPLE));
            menuManager.add(new Separator());
            List<Integer> recentSRIDs = GISEditorUtils.getRecentSRIDs();
            if (!recentSRIDs.isEmpty()) {
                for (Integer recentSRID : recentSRIDs) {
                    menuManager.add(new SetCRSAction(valueEditor, recentSRID));
                }
                menuManager.add(new Separator());
            }
            menuManager.add(new Action(GISMessages.panel_select_crs_action_menu_manager_other) {

                @Override
                public void run() {
                    SelectCRSAction.this.run();
                }
            });
            menuManager.add(new Action(GISMessages.panel_select_crs_action_menu_manager_config) {

                @Override
                public void run() {
                    new GISViewerConfigurationDialog(valueEditor.getEditorControl().getShell()).open();
                }
            });
        });
        return menuManager;
    });
}
Also used : Action(org.eclipse.jface.action.Action) MenuCreator(org.jkiss.dbeaver.ui.MenuCreator) IMenuCreator(org.eclipse.jface.action.IMenuCreator) MenuManager(org.eclipse.jface.action.MenuManager) Separator(org.eclipse.jface.action.Separator)

Example 4 with IMenuCreator

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

the class SelectTilesAction method getMenuCreator.

@Override
public IMenuCreator getMenuCreator() {
    return new MenuCreator(control -> {
        MenuManager menuManager = new MenuManager();
        menuManager.setRemoveAllWhenShown(true);
        menuManager.addMenuListener(manager -> {
            if (valueEditor.getValueSRID() != 0) {
                for (LeafletTilesDescriptor ld : GeometryViewerRegistry.getInstance().getLeafletTiles()) {
                    menuManager.add(new SetTilesAction(valueEditor, ld));
                }
            }
        });
        return menuManager;
    });
}
Also used : MenuCreator(org.jkiss.dbeaver.ui.MenuCreator) IMenuCreator(org.eclipse.jface.action.IMenuCreator) LeafletTilesDescriptor(org.jkiss.dbeaver.ui.gis.registry.LeafletTilesDescriptor) MenuManager(org.eclipse.jface.action.MenuManager)

Aggregations

IMenuCreator (org.eclipse.jface.action.IMenuCreator)4 MenuManager (org.eclipse.jface.action.MenuManager)3 Action (org.eclipse.jface.action.Action)2 Control (org.eclipse.swt.widgets.Control)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuCreator (org.jkiss.dbeaver.ui.MenuCreator)2 DistributeType (org.csstudio.opibuilder.actions.DistributeWidgetsAction.DistributeType)1 AbstractWidgetAction (org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)1 AlignmentRetargetAction (org.eclipse.gef.ui.actions.AlignmentRetargetAction)1 DeleteRetargetAction (org.eclipse.gef.ui.actions.DeleteRetargetAction)1 MatchHeightRetargetAction (org.eclipse.gef.ui.actions.MatchHeightRetargetAction)1 MatchWidthRetargetAction (org.eclipse.gef.ui.actions.MatchWidthRetargetAction)1 RedoRetargetAction (org.eclipse.gef.ui.actions.RedoRetargetAction)1 UndoRetargetAction (org.eclipse.gef.ui.actions.UndoRetargetAction)1 ZoomInRetargetAction (org.eclipse.gef.ui.actions.ZoomInRetargetAction)1 ZoomOutRetargetAction (org.eclipse.gef.ui.actions.ZoomOutRetargetAction)1 Separator (org.eclipse.jface.action.Separator)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 RetargetAction (org.eclipse.ui.actions.RetargetAction)1