Search in sources :

Example 51 with IMenuManager

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

the class CubridNavigatorView method createPartControl.

/**
	 * Create the part control
	 *
	 * @param parent Composite
	 */
public void createPartControl(Composite parent) {
    ViewForm viewForm = new ViewForm(parent, SWT.NONE);
    viewForm.setLayout(new GridLayout());
    tv = new TreeViewer(viewForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    tv.setFilters(NodeFilterManager.getInstance().getViewerFilter());
    //create the navigator
    createNavigator();
    //get the isShowGroup configuration
    isShowGroup = savedIsShowGroup();
    //set the tree view's input.
    setTreeInput();
    toolTip = new ToolTip(tv.getTree().getShell(), SWT.BALLOON);
    toolTip.setAutoHide(true);
    //Create the context menu
    MenuManager contextMenuManager = new MenuManager("#PopupMenu", "navigatorContextMenu");
    contextMenuManager.setRemoveAllWhenShown(true);
    contextMenuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            buildPopupMenu(manager);
        }
    });
    Menu contextMenu = contextMenuManager.createContextMenu(tv.getControl());
    tv.getControl().setMenu(contextMenu);
    // register the context menu for providing extension by extension point
    IWorkbenchPartSite site = getSite();
    site.registerContextMenu(contextMenuManager, tv);
    site.setSelectionProvider(tv);
    //add the select the object text composite to top left of toolbar
    ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
    ToolBarManager toolBarManager = new ToolBarManager(toolBar);
    SelectTreeObjContrItem textContrItem = new SelectTreeObjContrItem(tv);
    toolBarManager.add(textContrItem);
    toolBarManager.update(true);
    viewForm.setContent(tv.getControl());
    viewForm.setTopLeft(toolBar);
    //add the other actions to the top right of toolbar
    toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.CENTER);
    toolBarManager = new ToolBarManager(toolBar);
    buildToolBar(toolBarManager);
    toolBarManager.update(true);
    viewForm.setTopRight(toolBar);
    //Add the actions to view menu bar, you can add them by extension point or code define
    IActionBars actionBar = getViewSite().getActionBars();
    final IMenuManager menuManager = actionBar.getMenuManager();
    menuManager.addMenuListener(new IMenuListener2() {

        //reserve these actions by code define,these codes rebuild every time.
        //hence when hide, remove them not including these actions by extension point
        private IMenuManager lastMenuManager = new MenuManager();

        public void menuAboutToShow(IMenuManager manager) {
            lastMenuManager.removeAll();
            //build the code defined actions
            buildViewMenu(lastMenuManager);
            for (IContributionItem item : lastMenuManager.getItems()) {
                manager.add(item);
            }
        }

        public void menuAboutToHide(IMenuManager manager) {
            for (IContributionItem item : lastMenuManager.getItems()) {
                manager.remove(item);
            }
        }
    });
    menuManager.add(new Separator());
    activeContext();
    addListener();
    setFocus();
}
Also used : ToolTip(org.eclipse.swt.widgets.ToolTip) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IContributionItem(org.eclipse.jface.action.IContributionItem) IMenuListener(org.eclipse.jface.action.IMenuListener) IToolBarManager(org.eclipse.jface.action.IToolBarManager) ToolBarManager(org.eclipse.jface.action.ToolBarManager) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ViewForm(org.eclipse.swt.custom.ViewForm) GridLayout(org.eclipse.swt.layout.GridLayout) IMenuListener2(org.eclipse.jface.action.IMenuListener2) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) ToolBar(org.eclipse.swt.widgets.ToolBar) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IActionBars(org.eclipse.ui.IActionBars) Separator(org.eclipse.jface.action.Separator)

Example 52 with IMenuManager

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

the class CommonUITool method registerCopyPasteContextMenu.

/**
	 *
	 * Register context menu for styled text
	 *
	 * @param text StyledText
	 * @param isEditable boolean
	 */
public static void registerCopyPasteContextMenu(final StyledText text, final boolean isEditable, final boolean isCopiable) {
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            if (isCopiable) {
                IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
                if (copyAction instanceof CopyAction) {
                    manager.add(copyAction);
                    if (!copyAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAction, text);
                    }
                }
                IAction copyAllAction = ActionManager.getInstance().getAction(CopyAllAction.ID);
                if (copyAllAction instanceof CopyAllAction) {
                    manager.add(copyAllAction);
                    if (!copyAllAction.isEnabled()) {
                        FocusAction.changeActionStatus(copyAllAction, text);
                    }
                }
            }
            if (!isEditable) {
                return;
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction instanceof PasteAction) {
                manager.add(pasteAction);
                if (!pasteAction.isEnabled()) {
                    FocusAction.changeActionStatus(pasteAction, text);
                }
            }
        }
    });
    Menu contextMenu = menuManager.createContextMenu(text);
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (!copyAction.isEnabled()) {
                FocusAction.changeActionStatus(copyAction, text);
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction != null && !pasteAction.isEnabled()) {
                FocusAction.changeActionStatus(pasteAction, text);
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) IAction(org.eclipse.jface.action.IAction) CopyAction(com.cubrid.common.ui.query.action.CopyAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CopyAllAction(com.cubrid.common.ui.query.action.CopyAllAction) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) PasteAction(com.cubrid.common.ui.query.action.PasteAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

Example 53 with IMenuManager

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

the class ApplicationActionBarAdvisor method fillMenuBar.

/**
	 * Fills the menu bar with the main menus for the window.
	 *
	 * @param menuBar the menu bar manager
	 */
protected void fillMenuBar(IMenuManager menuManager) {
    ActionManager manager = ActionManager.getInstance();
    MenuManager helpMenu = new MenuManager(Messages.mnu_helpMneuName, IWorkbenchActionConstants.M_HELP);
    helpMenu.add(manager.getAction(HelpDocumentAction.ID));
    // fill in help menu
    if ("ko".equals(Messages.language)) {
        helpMenu.add(newFeatureAction);
    }
    helpMenu.add(new Separator());
    helpMenu.add(reportBugAction);
    helpMenu.add(new Separator());
    helpMenu.add(cubridOnlineForumAction);
    helpMenu.add(cubridProjectSiteAction);
    helpMenu.add(new Separator());
    helpMenu.add(new GroupMarker("updates"));
    helpMenu.add(new Separator());
    helpMenu.add(manager.getAction(ViewServerVersionAction.ID));
    helpMenu.add(new Separator());
    ActionContributionItem aboutActionItem = new ActionContributionItem(aboutAction);
    helpMenu.add(aboutActionItem);
    if (Util.isMac()) {
        aboutActionItem.setVisible(false);
    }
    menuManager.add(helpMenu);
}
Also used : ActionManager(com.cubrid.common.ui.spi.action.ActionManager) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) GroupMarker(org.eclipse.jface.action.GroupMarker) Separator(org.eclipse.jface.action.Separator)

Example 54 with IMenuManager

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

the class ApplicationWorkbenchWindowAdvisor method removePlatformDependencyActions.

private void removePlatformDependencyActions() {
    // remove some menu items
    IMenuManager mm = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
    for (IContributionItem item : mm.getItems()) {
        if (item == null) {
            continue;
        }
        if (item instanceof MenuManager) {
            MenuManager sm = (MenuManager) item;
            for (IContributionItem sitem : sm.getItems()) {
                if (sitem == null || sitem.getId() == null) {
                    continue;
                }
                if (sitem.getId().equals("org.eclipse.ui.actions.showKeyAssistHandler") || sitem.getId().equals("com.cubrid.common.update.p2.menu.install") || sitem.getId().equals("converstLineDelimitersTo") || sitem.getId().equals("save.ext") || sitem.getId().equals("org.eclipse.ui.openLocalFile") || sitem.getId().equals("new.ext")) {
                    sm.remove(sitem.getId());
                    sm.update(true);
                    mm.update(true);
                }
            }
        }
    }
    // remove some tool bar items
    ICoolBarManager cm = getWindowConfigurer().getActionBarConfigurer().getCoolBarManager();
    for (IContributionItem item : cm.getItems()) {
        if (item == null || item.getId() == null) {
            continue;
        }
        if (item.getId().equals("org.eclipse.ui.edit.text.actionSet.annotationNavigation") || item.getId().equals("org.eclipse.ui.edit.text.actionSet.navigation")) {
            cm.remove(item.getId());
            cm.update(true);
        }
    }
    // remove some preference items
    PreferenceManager pm = getWindowConfigurer().getWindow().getWorkbench().getPreferenceManager();
    for (IPreferenceNode item : pm.getRootSubNodes()) {
        if (item.getId().equals("org.eclipse.help.ui.browsersPreferencePage") || item.getId().equals("org.eclipse.ui.preferencePages.Workbench")) {
            pm.remove(item.getId());
        }
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Example 55 with IMenuManager

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

the class QueryExecuter method registerInputMethodContextMenu.

/**
	 *
	 * Register input method context menu for styled text
	 *
	 * @param text StyledText
	 * @param isEditable boolean
	 */
public void registerInputMethodContextMenu(final StyledText text, final boolean isEditable, final String type, final TableItem item, final int column) {
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent event) {
            ActionManager.getInstance().changeFocusProvider(text);
        }
    });
    MenuManager menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    menuManager.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (copyAction instanceof CopyAction) {
                manager.add(copyAction);
                if (!copyAction.isEnabled()) {
                    FocusAction.changeActionStatus(copyAction, text);
                }
            }
            if (!isEditable) {
                return;
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction instanceof PasteAction) {
                manager.add(pasteAction);
                if (!pasteAction.isEnabled()) {
                    FocusAction.changeActionStatus(pasteAction, text);
                }
            }
            IAction inputAction = ActionManager.getInstance().getAction(InputMethodAction.ID);
            if (inputAction instanceof InputMethodAction) {
                manager.add(inputAction);
                if (!inputAction.isEnabled()) {
                    FocusAction.changeActionStatus(inputAction, text);
                } else {
                    ((InputMethodAction) inputAction).setType(type);
                    ((InputMethodAction) inputAction).setTableItem(item);
                    ((InputMethodAction) inputAction).setColumn(column);
                    ((InputMethodAction) inputAction).setQueryExecuter(executer);
                }
                if (isEditMode()) {
                    inputAction.setEnabled(true);
                } else {
                    inputAction.setEnabled(false);
                }
            }
        }
    });
    Menu contextMenu = menuManager.createContextMenu(text);
    text.setMenu(contextMenu);
    text.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
            if (!copyAction.isEnabled()) {
                FocusAction.changeActionStatus(copyAction, text);
            }
            IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
            if (pasteAction != null && !pasteAction.isEnabled()) {
                FocusAction.changeActionStatus(pasteAction, text);
            }
            IAction inputAction = ActionManager.getInstance().getAction(InputMethodAction.ID);
            if (inputAction != null) {
                FocusAction.changeActionStatus(inputAction, text);
            }
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) IAction(org.eclipse.jface.action.IAction) CopyAction(com.cubrid.common.ui.query.action.CopyAction) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FocusEvent(org.eclipse.swt.events.FocusEvent) IMenuListener(org.eclipse.jface.action.IMenuListener) PasteAction(com.cubrid.common.ui.query.action.PasteAction) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) SelectionEvent(org.eclipse.swt.events.SelectionEvent) InputMethodAction(com.cubrid.common.ui.query.action.InputMethodAction) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu)

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