org.eclipse.gmf.examples.mindmap.rcp.application.DiagramEditorActionBarAdvisor.java Source code

Java tutorial

Introduction

Here is the source code for org.eclipse.gmf.examples.mindmap.rcp.application.DiagramEditorActionBarAdvisor.java

Source

/*
 * Copyright (c) 2006, 2007 Borland Software Corporation.
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  which accompanies this distribution, and is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *  
 *   Contributors:
 *      Richard Gronback (Borland) - initial API and implementation
 */
package org.eclipse.gmf.examples.mindmap.rcp.application;

import java.util.Iterator;

import org.eclipse.emf.common.ui.action.WorkbenchWindowActionDelegate;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.ui.action.LoadResourceAction;
import org.eclipse.gmf.examples.mindmap.rcp.part.Messages;
import org.eclipse.gmf.examples.mindmap.rcp.part.MindmapCreationWizard;
import org.eclipse.gmf.examples.mindmap.rcp.part.MindmapDiagramEditorPlugin;
import org.eclipse.gmf.examples.mindmap.rcp.part.MindmapDiagramEditorUtil;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarContributionItem;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

/**
 * @generated
 */
public class DiagramEditorActionBarAdvisor extends ActionBarAdvisor {

    /**
     * @generated
     */
    private ActionFactory.IWorkbenchAction lockToolBarAction;

    /**
     * @generated
     */
    private ActionFactory.IWorkbenchAction toggleCoolbarAction;

    /**
     * @generated
     */
    public DiagramEditorActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    /**
     * @generated
     */
    private IWorkbenchWindow getWindow() {
        return getActionBarConfigurer().getWindowConfigurer().getWindow();
    }

    /**
     * @generated
     */
    protected void makeActions(IWorkbenchWindow window) {
        toggleCoolbarAction = ActionFactory.TOGGLE_COOLBAR.create(window);
        register(toggleCoolbarAction);
        lockToolBarAction = ActionFactory.LOCK_TOOL_BAR.create(window);
        register(lockToolBarAction);

        register(ActionFactory.CLOSE.create(window));

        register(ActionFactory.CLOSE_ALL.create(window));

        register(ActionFactory.SAVE.create(window));

        register(ActionFactory.SAVE_AS.create(window));

        register(ActionFactory.SAVE_ALL.create(window));

        register(ActionFactory.QUIT.create(window));

        register(ActionFactory.UNDO.create(window));

        register(ActionFactory.REDO.create(window));

        register(ActionFactory.CUT.create(window));

        register(ActionFactory.COPY.create(window));

        register(ActionFactory.PASTE.create(window));

        register(ActionFactory.DELETE.create(window));

        register(ActionFactory.SELECT_ALL.create(window));

        register(ActionFactory.OPEN_NEW_WINDOW.create(window));

        register(ActionFactory.PRINT.create(window));
    }

    /**
     * @generated
     */
    protected void fillMenuBar(IMenuManager menu) {

        {
            IMenuManager menuX = new MenuManager(Messages.ApplicationMenuName_File,
                    IWorkbenchActionConstants.M_FILE);

            menuX.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));

            {
                IMenuManager menuXX = new MenuManager(Messages.ApplicationMenuName_New, "new");

                menuXX.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
                menuX.add(menuXX);
            }

            menuX.add(new Separator());

            menuX.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

            menuX.add(new Separator());

            menuX.add(getAction(ActionFactory.CLOSE.getId()));

            menuX.add(getAction(ActionFactory.CLOSE_ALL.getId()));

            menuX.add(new Separator());

            menuX.add(getAction(ActionFactory.SAVE.getId()));

            menuX.add(getAction(ActionFactory.SAVE_AS.getId()));

            menuX.add(getAction(ActionFactory.SAVE_ALL.getId()));

            menuX.add(new Separator());

            menuX.add(getAction(ActionFactory.QUIT.getId()));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
            menu.add(menuX);
        }

        {
            IMenuManager menuX = new MenuManager(Messages.ApplicationMenuName_Edit,
                    IWorkbenchActionConstants.M_EDIT);

            menuX.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));

            menuX.add(getAction(ActionFactory.UNDO.getId()));

            menuX.add(getAction(ActionFactory.REDO.getId()));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));

            menuX.add(new Separator());

            menuX.add(getAction(ActionFactory.CUT.getId()));

            menuX.add(getAction(ActionFactory.COPY.getId()));

            menuX.add(getAction(ActionFactory.PASTE.getId()));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));

            menuX.add(new Separator());

            menuX.add(getAction(ActionFactory.DELETE.getId()));

            menuX.add(getAction(ActionFactory.SELECT_ALL.getId()));

            menuX.add(new Separator());

            menuX.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));

            menuX.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            menu.add(menuX);
        }

        menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

        {
            IMenuManager menuX = new MenuManager(Messages.ApplicationMenuName_Window,
                    IWorkbenchActionConstants.M_WINDOW);

            menuX.add(getAction(ActionFactory.OPEN_NEW_WINDOW.getId()));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
            menu.add(menuX);
        }

        {
            IMenuManager menuX = new MenuManager(Messages.ApplicationMenuName_Help,
                    IWorkbenchActionConstants.M_HELP);

            menuX.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));

            menuX.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
            menu.add(menuX);
        }
    }

    /**
     * @generated
     */
    protected void fillCoolBar(ICoolBarManager toolBar) {
        IMenuManager popUpMenu = new MenuManager();
        popUpMenu.add(new ActionContributionItem(lockToolBarAction));
        popUpMenu.add(new ActionContributionItem(toggleCoolbarAction));
        toolBar.setContextMenuManager(popUpMenu);

        toolBar.add(new GroupMarker("group.file"));

        {
            IToolBarManager toolBarX = new ToolBarManager();

            toolBarX.add(new Separator(IWorkbenchActionConstants.NEW_GROUP));

            toolBarX.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));

            toolBarX.add(new GroupMarker(IWorkbenchActionConstants.SAVE_GROUP));

            toolBarX.add(getAction(ActionFactory.SAVE.getId()));

            toolBarX.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));

            toolBarX.add(getAction(ActionFactory.PRINT.getId()));

            toolBarX.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));

            toolBarX.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
            toolBar.add(new ToolBarContributionItem(toolBarX, IWorkbenchActionConstants.TOOLBAR_FILE));
        }

        toolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));

        toolBar.add(new GroupMarker("group.nav"));

        toolBar.add(new GroupMarker(IWorkbenchActionConstants.GROUP_EDITOR));

        toolBar.add(new GroupMarker(IWorkbenchActionConstants.GROUP_HELP));

        {
            IToolBarManager toolBarX = new ToolBarManager();

            toolBarX.add(new Separator(IWorkbenchActionConstants.GROUP_HELP));

            toolBarX.add(new GroupMarker(IWorkbenchActionConstants.GROUP_APP));
            toolBar.add(new ToolBarContributionItem(toolBarX, IWorkbenchActionConstants.TOOLBAR_HELP));
        }
    }

    /**
     * @generated
     */
    public static class NewDiagramAction extends WorkbenchWindowActionDelegate {

        /**
         * @generated
         */
        public void run(IAction action) {
            MindmapCreationWizard wizard = new MindmapCreationWizard();
            wizard.init(getWindow().getWorkbench(), StructuredSelection.EMPTY);
            WizardDialog wizardDialog = new WizardDialog(getWindow().getShell(), wizard);
            wizardDialog.open();
        }
    }

    /**
     * Open URI action for the Mindmap diagram.
     * @generated
     */
    public static class OpenURIAction extends WorkbenchWindowActionDelegate {
        /**
         * Opens the editors for the files selected using the LoadResourceDialog.
         * @generated
         */
        public void run(IAction action) {
            LoadResourceAction.LoadResourceDialog loadResourceDialog = new LoadResourceAction.LoadResourceDialog(
                    getWindow().getShell());
            if (Dialog.OK == loadResourceDialog.open()) {
                for (Iterator it = loadResourceDialog.getURIs().iterator(); it.hasNext();) {

                    MindmapDiagramEditorUtil.openEditor((URI) it.next());

                }
            }
        }
    }

    /**
     * Open action for the Mindmap diagram.
     * @generated
     */
    public static class OpenAction extends WorkbenchWindowActionDelegate {
        /**
         * Opens the editors for the files selected using the file dialog.
         * @generated
         */
        public void run(IAction action) {
            String filePath = MindmapDiagramEditorUtil.openFilePathDialog(getWindow().getShell(), "*.mmd", //$NON-NLS-1$
                    SWT.OPEN);
            if (filePath != null) {
                MindmapDiagramEditorUtil.openEditor(URI.createFileURI(filePath));
            }
        }
    }

    /**
     * About action for the RCP application.
     * @generated
     */
    public static class AboutAction extends WorkbenchWindowActionDelegate {
        /**
         * @see IActionDelegate#run(IAction)
         * @generated
         */
        public void run(IAction action) {
            MessageDialog.openInformation(getWindow().getShell(), getString("_UI_About_title"), //$NON-NLS-1$
                    getString("_UI_About_text")); //$NON-NLS-1$
        }
    }

    /**
     * Looks up a string in the plugin.properties file for the plugin.
     * @generated
     */
    private static String getString(String key) {
        return MindmapDiagramEditorPlugin.getInstance().getBundleString(key);
    }
}