]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchActionBarAdvisor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / SimanticsWorkbenchActionBarAdvisor.java
diff --git a/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchActionBarAdvisor.java b/bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchActionBarAdvisor.java
new file mode 100644 (file)
index 0000000..d4cd0e0
--- /dev/null
@@ -0,0 +1,868 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.workbench.internal;\r
+\r
+import java.util.HashSet;\r
+import java.util.Set;\r
+\r
+import org.eclipse.core.runtime.IAdaptable;\r
+import org.eclipse.core.runtime.IExtension;\r
+import org.eclipse.jface.action.ActionContributionItem;\r
+import org.eclipse.jface.action.GroupMarker;\r
+import org.eclipse.jface.action.IAction;\r
+import org.eclipse.jface.action.IContributionItem;\r
+import org.eclipse.jface.action.IMenuManager;\r
+import org.eclipse.jface.action.IStatusLineManager;\r
+import org.eclipse.jface.action.MenuManager;\r
+import org.eclipse.jface.action.Separator;\r
+import org.eclipse.jface.util.Util;\r
+import org.eclipse.ui.IWorkbenchActionConstants;\r
+import org.eclipse.ui.IWorkbenchWindow;\r
+import org.eclipse.ui.actions.ActionFactory;\r
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;\r
+import org.eclipse.ui.actions.ContributionItemFactory;\r
+import org.eclipse.ui.actions.OpenInNewWindowAction;\r
+import org.eclipse.ui.application.ActionBarAdvisor;\r
+import org.eclipse.ui.application.IActionBarConfigurer;\r
+import org.eclipse.ui.ide.IDEActionFactory;\r
+import org.eclipse.ui.internal.Workbench;\r
+import org.eclipse.ui.internal.WorkbenchPlugin;\r
+import org.eclipse.ui.internal.cheatsheets.actions.CheatSheetCategoryBasedSelectionAction;\r
+import org.eclipse.ui.internal.registry.ActionSetRegistry;\r
+import org.eclipse.ui.internal.registry.IActionSetDescriptor;\r
+\r
+/**\r
+ * An action bar advisor is responsible for creating, adding, and disposing of\r
+ * the actions added to a workbench window. Each window will be populated with\r
+ * new actions.\r
+ */\r
+public class SimanticsWorkbenchActionBarAdvisor extends ActionBarAdvisor {\r
+\r
+    //private final WorkbenchActionBuilder ideAdvisor;\r
+\r
+    private final IWorkbenchWindow window;\r
+\r
+    /**\r
+     * Indicates if the action builder has been disposed\r
+     */\r
+    private boolean                isDisposed = false;\r
+\r
+    // Actions - important to allocate these only in makeActions, and then use\r
+    // them\r
+    // in the fill methods. This ensures that the actions aren't recreated\r
+    // when fillActionBars is called with FILL_PROXY.\r
+\r
+    // File\r
+    private IWorkbenchAction       closeAction;\r
+\r
+    private IWorkbenchAction       closeAllAction;\r
+\r
+    private IWorkbenchAction       closeOthersAction;\r
+\r
+    private IWorkbenchAction       closeAllSavedAction;\r
+\r
+//    private IWorkbenchAction       saveAction;\r
+\r
+//    protected IWorkbenchAction       printAction;\r
+\r
+    protected IWorkbenchAction       openWorkspaceAction;\r
+\r
+    private IWorkbenchAction       importResourcesAction;\r
+\r
+    private IWorkbenchAction       exportResourcesAction;\r
+\r
+    protected IWorkbenchAction       quitAction;\r
+\r
+    // Edit\r
+    protected IWorkbenchAction       undoAction;\r
+\r
+    protected IWorkbenchAction       redoAction;\r
+\r
+    protected IWorkbenchAction       cutAction;\r
+\r
+    protected IWorkbenchAction       copyAction;\r
+\r
+    protected IWorkbenchAction       pasteAction;\r
+\r
+    protected IWorkbenchAction       deleteAction;\r
+\r
+    protected IWorkbenchAction       selectAllAction;\r
+\r
+    // Navigate\r
+    private IWorkbenchAction       backwardHistoryAction;\r
+\r
+    private IWorkbenchAction       forwardHistoryAction;\r
+\r
+    private IWorkbenchAction       goIntoAction;\r
+\r
+    private IWorkbenchAction       backAction;\r
+\r
+    private IWorkbenchAction       forwardAction;\r
+\r
+    private IWorkbenchAction       upAction;\r
+\r
+    private IWorkbenchAction       nextAction;\r
+\r
+    private IWorkbenchAction       previousAction;\r
+\r
+    // Window\r
+    private IWorkbenchAction       newWindowAction;\r
+\r
+    private IWorkbenchAction       newEditorAction;\r
+\r
+    private IWorkbenchAction       savePerspectiveAction;\r
+\r
+    private IWorkbenchAction       resetPerspectiveAction;\r
+\r
+    private IWorkbenchAction       editActionSetAction;\r
+\r
+    private IWorkbenchAction       closePerspAction;\r
+\r
+    private IWorkbenchAction       closeAllPerspsAction;\r
+\r
+    private IWorkbenchAction       openPreferencesAction;\r
+\r
+    // Window/Navigation\r
+    private IWorkbenchAction       showViewMenuAction;\r
+\r
+    private IWorkbenchAction       showPartPaneMenuAction;\r
+\r
+    private IWorkbenchAction       maximizePartAction;\r
+\r
+    private IWorkbenchAction       minimizePartAction;\r
+\r
+    private IWorkbenchAction       nextEditorAction;\r
+\r
+    private IWorkbenchAction       prevEditorAction;\r
+\r
+    private IWorkbenchAction       activateEditorAction;\r
+\r
+    private IWorkbenchAction       switchToEditorAction;\r
+\r
+    private IWorkbenchAction       openEditorDropDownAction;\r
+\r
+    private IWorkbenchAction       nextPartAction;\r
+\r
+    private IWorkbenchAction       prevPartAction;\r
+\r
+    private IWorkbenchAction       nextPerspectiveAction;\r
+\r
+    private IWorkbenchAction       prevPerspectiveAction;\r
+\r
+    // Help\r
+    private IWorkbenchAction       introAction;\r
+\r
+    private IWorkbenchAction       tocAction;\r
+\r
+    private IWorkbenchAction       searchAction;\r
+\r
+    private IWorkbenchAction       dynamicHelpAction;\r
+\r
+    private IAction                cheatSheetsAction;\r
+\r
+    private IWorkbenchAction       aboutAction;\r
+\r
+\r
+    /**\r
+     * Constructs a new action builder which contributes actions\r
+     * to the given window.\r
+     * \r
+     * @param configurer the action bar configurer for the window\r
+     */\r
+    public SimanticsWorkbenchActionBarAdvisor(IActionBarConfigurer configurer) {\r
+        super(configurer);\r
+        //ideAdvisor = new WorkbenchActionBuilder(configurer);\r
+        window = configurer.getWindowConfigurer().getWindow();\r
+    }\r
+\r
+    /**\r
+     * Returns the window to which this action builder is contributing.\r
+     */\r
+    private IWorkbenchWindow getWindow() {\r
+        return window;\r
+    }\r
+\r
+    /**\r
+     * Disposes any resources and unhooks any listeners that are no longer needed.\r
+     * Called when the window is closed.\r
+     */\r
+    @Override\r
+    public void dispose() {\r
+        if (isDisposed) {\r
+            return;\r
+        }\r
+\r
+        isDisposed = true;\r
+\r
+        // null out actions to make leak debugging easier\r
+        // File\r
+        closeAction = null;\r
+        closeAllAction = null;\r
+        closeAllSavedAction = null;\r
+        closeOthersAction = null;\r
+//        saveAction = null;\r
+//        printAction = null;\r
+        openWorkspaceAction = null;\r
+        importResourcesAction = null;\r
+        exportResourcesAction = null;\r
+        quitAction = null;\r
+\r
+        // Edit\r
+        undoAction = null;\r
+        redoAction = null;\r
+        cutAction = null;\r
+        copyAction = null;\r
+        pasteAction = null;\r
+        deleteAction = null;\r
+        selectAllAction = null;\r
+\r
+        // Navigate\r
+        backwardHistoryAction = null;\r
+        forwardHistoryAction = null;\r
+        goIntoAction = null;\r
+        backAction = null;\r
+        forwardAction = null;\r
+        upAction = null;\r
+        nextAction = null;\r
+        previousAction = null;\r
+\r
+        // Window\r
+        newWindowAction = null;\r
+        newEditorAction = null;\r
+        openPreferencesAction = null;\r
+        savePerspectiveAction = null;\r
+        resetPerspectiveAction = null;\r
+        editActionSetAction = null;\r
+        closePerspAction = null;\r
+        closeAllPerspsAction = null;\r
+        openPreferencesAction = null;\r
+\r
+        // Window/Navigation\r
+        showViewMenuAction = null;\r
+        showPartPaneMenuAction = null;\r
+        maximizePartAction = null;\r
+        minimizePartAction = null;\r
+        nextPartAction = null;\r
+        prevPartAction = null;\r
+        nextPerspectiveAction = null;\r
+        prevPerspectiveAction = null;\r
+\r
+        nextEditorAction = null;\r
+        prevEditorAction = null;\r
+        activateEditorAction = null;\r
+        switchToEditorAction = null;\r
+        openEditorDropDownAction = null;\r
+\r
+        // Help\r
+        introAction = null;\r
+        tocAction = null;\r
+        searchAction = null;\r
+        dynamicHelpAction = null;\r
+        cheatSheetsAction = null;\r
+        aboutAction = null;\r
+\r
+        super.dispose();\r
+    }\r
+\r
+    @Override\r
+    protected void makeActions(final IWorkbenchWindow window) {\r
+        // Creates the actions and registers them.\r
+        // Registering is needed to ensure that key bindings work.\r
+        // The corresponding commands keybindings are defined in the plugin.xml\r
+        // file.\r
+        // Registering also provides automatic disposal of the actions when\r
+        // the window is closed.\r
+\r
+        // File\r
+        closeAction = ActionFactory.CLOSE.create(window);\r
+        register(closeAction);\r
+        closeAllAction = ActionFactory.CLOSE_ALL.create(window);\r
+        register(closeAllAction);\r
+        closeOthersAction = ActionFactory.CLOSE_OTHERS.create(window);\r
+        register(closeOthersAction);\r
+        closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED.create(window);\r
+        register(closeAllSavedAction);\r
+//        saveAction = ActionFactory.SAVE.create(window);\r
+//        register(saveAction);\r
+//        printAction = ActionFactory.PRINT.create(window);\r
+//        register(printAction);\r
+        openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE.create(window);\r
+        register(openWorkspaceAction);\r
+        importResourcesAction = ActionFactory.IMPORT.create(window);\r
+        register(importResourcesAction);\r
+        exportResourcesAction = ActionFactory.EXPORT.create(window);\r
+        register(exportResourcesAction);\r
+        quitAction = ActionFactory.QUIT.create(window);\r
+        register(quitAction);\r
+\r
+        // Edit\r
+//        undoAction = ActionFactory.UNDO.create(window);\r
+//        register(undoAction);\r
+//        redoAction = ActionFactory.REDO.create(window);\r
+//        register(redoAction);\r
+//        cutAction = ActionFactory.CUT.create(window);\r
+//        register(cutAction);\r
+//        copyAction = ActionFactory.COPY.create(window);\r
+//        register(copyAction);\r
+//        pasteAction = ActionFactory.PASTE.create(window);\r
+//        register(pasteAction);\r
+//        deleteAction = ActionFactory.DELETE.create(window);\r
+//        register(deleteAction);\r
+//        selectAllAction = ActionFactory.SELECT_ALL.create(window);\r
+//        register(selectAllAction);\r
+\r
+        // Navigate\r
+        forwardHistoryAction = ActionFactory.FORWARD_HISTORY.create(window);\r
+        register(forwardHistoryAction);\r
+        backwardHistoryAction = ActionFactory.BACKWARD_HISTORY.create(window);\r
+        register(backwardHistoryAction);\r
+        goIntoAction = ActionFactory.GO_INTO.create(window);\r
+        register(goIntoAction);\r
+        backAction = ActionFactory.BACK.create(window);\r
+        register(backAction);\r
+        forwardAction = ActionFactory.FORWARD.create(window);\r
+        register(forwardAction);\r
+        upAction = ActionFactory.UP.create(window);\r
+        register(upAction);\r
+        nextAction = ActionFactory.NEXT.create(window);\r
+        //nextAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV));\r
+        register(nextAction);\r
+        previousAction = ActionFactory.PREVIOUS.create(window);\r
+        //previousAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV));\r
+        register(previousAction);\r
+\r
+\r
+        // Window\r
+        newWindowAction = OPEN_NEW_WINDOW.create(getWindow());\r
+        newWindowAction.setText("&New Window");\r
+        register(newWindowAction);\r
+        newEditorAction = ActionFactory.NEW_EDITOR.create(window);\r
+        register(newEditorAction);\r
+        editActionSetAction = ActionFactory.EDIT_ACTION_SETS.create(window);\r
+        register(editActionSetAction);\r
+        savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create(window);\r
+        register(savePerspectiveAction);\r
+        resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);\r
+        register(resetPerspectiveAction);\r
+        closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create(window);\r
+        register(closePerspAction);\r
+        closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES.create(window);\r
+        register(closeAllPerspsAction);\r
+        openPreferencesAction = ActionFactory.PREFERENCES.create(window);\r
+//        preferencesAction = new OpenPreferencesAction(window);\r
+//        preferencesAction.setId("preferences");\r
+        register(openPreferencesAction);\r
+\r
+        // Window/Navigation: Actions for invisible accelerators\r
+        showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);\r
+        register(showViewMenuAction);\r
+        showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU.create(window);\r
+        register(showPartPaneMenuAction);\r
+        maximizePartAction = ActionFactory.MAXIMIZE.create(window);\r
+        register(maximizePartAction);\r
+        minimizePartAction = ActionFactory.MINIMIZE.create(window);\r
+        register(minimizePartAction);\r
+\r
+        nextEditorAction = ActionFactory.NEXT_EDITOR.create(window);\r
+        register(nextEditorAction);\r
+        prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create(window);\r
+        register(prevEditorAction);\r
+        ActionFactory.linkCycleActionPair(nextEditorAction, prevEditorAction);\r
+        activateEditorAction = ActionFactory.ACTIVATE_EDITOR.create(window);\r
+        register(activateEditorAction);\r
+        switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS.create(window);\r
+        register(switchToEditorAction);\r
+        openEditorDropDownAction = ActionFactory.SHOW_WORKBOOK_EDITORS.create(window);\r
+        register(openEditorDropDownAction);\r
+\r
+        nextPartAction = ActionFactory.NEXT_PART.create(window);\r
+        register(nextPartAction);\r
+        prevPartAction = ActionFactory.PREVIOUS_PART.create(window);\r
+        register(prevPartAction);\r
+        ActionFactory.linkCycleActionPair(nextPartAction, prevPartAction);\r
+        nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE.create(window);\r
+        register(nextPerspectiveAction);\r
+        prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE.create(window);\r
+        register(prevPerspectiveAction);\r
+        ActionFactory.linkCycleActionPair(nextPerspectiveAction, prevPerspectiveAction);\r
+\r
+        // Help\r
+        if (window.getWorkbench().getIntroManager().hasIntro()) {\r
+            introAction = ActionFactory.INTRO.create(window);\r
+            register(introAction);\r
+        }\r
+        tocAction = ActionFactory.HELP_CONTENTS.create(window);\r
+        register(tocAction);\r
+        searchAction = ActionFactory.HELP_SEARCH.create(window);\r
+        register(searchAction);\r
+        dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);\r
+        register(dynamicHelpAction);\r
+        cheatSheetsAction = new CheatSheetCategoryBasedSelectionAction("&Cheat Sheets...");\r
+        cheatSheetsAction.setId("org.eclipse.ui.help.cheatSheetsAction");\r
+        register(cheatSheetsAction);\r
+        aboutAction = ActionFactory.ABOUT.create(window);\r
+        register(aboutAction);\r
+    }\r
+\r
+    /*\r
+     * TODO: HACK for removing Eclipse's own forced and totally unwanted actionSet extensions.\r
+     * Remove if a better way to achieve the same effect is found.\r
+     */\r
+    protected void hackRemoveUnwantedNavigationActions() {\r
+        ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();\r
+        IActionSetDescriptor[] actionSets = reg.getActionSets();\r
+        String actionSetId[] = {\r
+                "org.eclipse.ui.edit.text.actionSet.navigation",\r
+                "org.eclipse.ui.edit.text.actionSet.annotationNavigation",\r
+                "org.eclipse.ui.NavigateActionSet"\r
+        };\r
+        Set<String> actionSetIds = new HashSet<String>();\r
+        for (String s : actionSetId)\r
+            actionSetIds.add(s);\r
+\r
+        for (int i = 0; i < actionSets.length; i++) {\r
+            if ((!actionSetIds.contains(actionSets[i].getId())))\r
+                continue;\r
+            IExtension ext = actionSets[i].getConfigurationElement().getDeclaringExtension();\r
+            reg.removeExtension(ext, new Object[] { actionSets[i] });\r
+        }\r
+    }\r
+\r
+    @Override\r
+    protected void fillMenuBar(IMenuManager menuBar) {\r
+        hackRemoveUnwantedNavigationActions();\r
+\r
+        menuBar.add(createFileMenu());\r
+        menuBar.add(createEditMenu());\r
+        menuBar.add(createNavigateMenu());\r
+        menuBar.add(createProjectMenu());\r
+        menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));\r
+        menuBar.add(createWindowMenu());\r
+        menuBar.add(createHelpMenu());\r
+    }\r
+\r
+    @Override\r
+    protected void fillStatusLine(IStatusLineManager statusLine) {\r
+        //System.out.println("fillStatusLine: " + statusLine);\r
+        //statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, GlobalStatusLineContributionItem.getInstance());\r
+//        statusLine.add(new GraphRequestStatusContribution(window));\r
+//        statusLine.add(new DumpHeapContribution(window));\r
+//        statusLine.add(new DumpStackTracesContribution(window));\r
+//        statusLine.add(new FlushRequestsContribution(window));\r
+//        statusLine.add(new SearchContribution(window));\r
+    }\r
+\r
+    protected IContributionItem createFileMenu() {\r
+        //MenuManager menu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);\r
+        MenuManager menu = new MenuManager("&File", ISimanticsWorkbenchConstants.M_FILE);\r
+\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));\r
+//        {\r
+//            // create the New submenu, using the same id for it as the New action\r
+//            String newText = IDEWorkbenchMessages.Workbench_new;\r
+//            String newId = ActionFactory.NEW.getId();\r
+//            MenuManager newMenu = new MenuManager(newText, newId) {\r
+//                public String getMenuText() {\r
+//                    String result = super.getMenuText();\r
+//                    if (newQuickMenu == null) {\r
+//                        return result;\r
+//                    }\r
+//                    String shortCut = newQuickMenu.getShortCutString();\r
+//                    if (shortCut == null) {\r
+//                        return result;\r
+//                    }\r
+//                    return result + "\t" + shortCut; //$NON-NLS-1$\r
+//                }\r
+//            };\r
+//            newMenu.add(new Separator(newId));\r
+//            this.newWizardMenu = new NewWizardMenu(getWindow());\r
+//            newMenu.add(this.newWizardMenu);\r
+//            newMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+//            menu.add(newMenu);\r
+//        }\r
+\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));\r
+        menu.add(new Separator());\r
+\r
+        menu.add(closeAction);\r
+        menu.add(closeAllAction);\r
+        //menu.add(closeAllSavedAction);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));\r
+        menu.add(new Separator());\r
+//        menu.add(saveAction);\r
+\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));\r
+        menu.add(new Separator());\r
+//        menu.add(printAction);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));\r
+        menu.add(new Separator());\r
+        menu.add(openWorkspaceAction);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));\r
+        menu.add(new Separator());\r
+//        menu.add(importResourcesAction);\r
+//        menu.add(exportResourcesAction);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));\r
+        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+\r
+        menu.add(new Separator());\r
+\r
+        // If we're on OS X we shouldn't show this command in the File menu. It\r
+        // should be invisible to the user. However, we should not remove it -\r
+        // the carbon UI code will do a search through our menu structure\r
+        // looking for it when Cmd-Q is invoked (or Quit is chosen from the\r
+        // application menu.\r
+        ActionContributionItem quitItem = new ActionContributionItem(quitAction);\r
+        quitItem.setVisible(!Util.isMac());\r
+        menu.add(quitItem);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));\r
+\r
+        return menu;\r
+    }\r
+\r
+    protected IContributionItem createEditMenu() {\r
+        MenuManager menu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);\r
+\r
+//        menu.add(undoAction);\r
+//        menu.add(redoAction);\r
+//        menu.add(new Separator());\r
+//        menu.add(cutAction);\r
+//        menu.add(copyAction);\r
+//        menu.add(pasteAction);\r
+//        menu.add(new Separator());\r
+//        menu.add(deleteAction);\r
+//        menu.add(selectAllAction);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));\r
+//        menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));\r
+//        menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));\r
+        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));\r
+\r
+        return menu;\r
+    }\r
+\r
+    /**\r
+     * Creates and returns the Navigate menu.\r
+     */\r
+    protected MenuManager createNavigateMenu() {\r
+        MenuManager menu = new MenuManager("&Navigate", IWorkbenchActionConstants.M_NAVIGATE);\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_START));\r
+//        menu.add(goIntoAction);\r
+\r
+//        MenuManager goToSubMenu = new MenuManager("&Go To", IWorkbenchActionConstants.GO_TO);\r
+//        menu.add(goToSubMenu);\r
+//        goToSubMenu.add(backAction);\r
+//        goToSubMenu.add(forwardAction);\r
+//        goToSubMenu.add(upAction);\r
+//        goToSubMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+\r
+        menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT));\r
+        for (int i = 2; i < 5; ++i) {\r
+            menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT + i));\r
+        }\r
+        menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT));\r
+        {\r
+\r
+//            MenuManager showInSubMenu = new MenuManager("Sho&w In", "showIn") {\r
+//                public String getMenuText() {\r
+//                    String result = super.getMenuText();\r
+//                    if (showInQuickMenu == null) {\r
+//                        return null;\r
+//                    }\r
+//                    String shortCut = showInQuickMenu.getShortCutString();\r
+//                    if (shortCut == null) {\r
+//                        return result;\r
+//                    }\r
+//                    return result + "\t" + shortCut; //$NON-NLS-1$\r
+//                }\r
+//            };\r
+//            showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN\r
+//                    .create(getWindow()));\r
+//            menu.add(showInSubMenu);\r
+        }\r
+        for (int i = 2; i < 5; ++i) {\r
+            menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT + i));\r
+        }\r
+        menu.add(new Separator());\r
+//        menu.add(nextAction);\r
+//        menu.add(previousAction);\r
+        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_END));\r
+\r
+        //TBD: Location of this actions\r
+        menu.add(new Separator());\r
+//        menu.add(backwardHistoryAction);\r
+//        menu.add(forwardHistoryAction);\r
+        return menu;\r
+    }\r
+\r
+    /**\r
+     * Creates and returns the Project menu.\r
+     */\r
+    protected MenuManager createProjectMenu() {\r
+        MenuManager menu = new MenuManager("&Project", ISimanticsWorkbenchConstants.M_PROJECT);\r
+        menu.add(new Separator(IWorkbenchActionConstants.PROJ_START));\r
+\r
+//        menu.add(openProjectAction);\r
+//        menu.add(closeProjectAction);\r
+//        menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));\r
+//        menu.add(new Separator());\r
+//        menu.add(buildAllAction);\r
+//        menu.add(buildProjectAction);\r
+//        addWorkingSetBuildActions(menu);\r
+//        menu.add(cleanAction);\r
+//        menu.add(toggleAutoBuildAction);\r
+//        menu.add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));\r
+//        menu.add(new Separator());\r
+\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.PROJ_END));\r
+        menu.add(new Separator());\r
+//        menu.add(projectPropertyDialogAction);\r
+        return menu;\r
+    }\r
+\r
+\r
+    protected IContributionItem createWindowMenu() {\r
+        MenuManager menu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);\r
+\r
+        menu.add(newWindowAction);\r
+//        menu.add(newEditorAction);\r
+\r
+        menu.add(new Separator());\r
+        addPerspectiveActions(menu);\r
+        menu.add(new Separator());\r
+        addKeyboardShortcuts(menu);\r
+        Separator sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS);\r
+        sep.setVisible(!Util.isMac());\r
+        menu.add(sep);\r
+        sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS + ".end"); //$NON-NLS-1$\r
+        sep.setVisible(!Util.isMac());\r
+        menu.add(sep);\r
+\r
+        // See the comment for quit in createFileMenu\r
+        ActionContributionItem openPreferencesItem = new ActionContributionItem(openPreferencesAction);\r
+        openPreferencesItem.setVisible(!Util.isMac());\r
+        menu.add(openPreferencesItem);\r
+\r
+        menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));\r
+        return menu;\r
+    }\r
+\r
+    protected IContributionItem createHelpMenu() {\r
+        // Help\r
+        MenuManager menu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);\r
+\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));\r
+        if (introAction != null)\r
+            menu.add(introAction);\r
+        menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$\r
+        menu.add(new Separator("group.main"));\r
+        //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$\r
+        menu.add(tocAction);\r
+        menu.add(searchAction);\r
+        menu.add(dynamicHelpAction);\r
+        menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$\r
+        menu.add(new Separator("group.main")); //$NON-NLS-1$\r
+        //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$\r
+        addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$\r
+        menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$\r
+        menu.add(cheatSheetsAction);\r
+        addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$\r
+        addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$\r
+        addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$\r
+        menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));\r
+        //addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);\r
+        menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));\r
+        //menu.add(new Separator());\r
+        menu.add(new Separator("group.about")); //$NON-NLS-1$\r
+\r
+        ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);\r
+        aboutItem.setVisible(!Util.isMac());\r
+        menu.add(aboutItem);\r
+        menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$\r
+        return menu;\r
+    }\r
+\r
+    /**\r
+     * Adds the perspective actions to the specified menu.\r
+     */\r
+    private void addPerspectiveActions(MenuManager menu) {\r
+        {\r
+            MenuManager changePerspMenuMgr = new MenuManager("&Open Perspective", "openPerspective");\r
+            IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(getWindow());\r
+            changePerspMenuMgr.add(changePerspMenuItem);\r
+            menu.add(changePerspMenuMgr);\r
+        }\r
+        {\r
+            MenuManager showViewMenuMgr = new MenuManager("Show &View", "showView");\r
+            IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST.create(getWindow());\r
+            showViewMenuMgr.add(showViewMenu);\r
+            menu.add(showViewMenuMgr);\r
+        }\r
+        menu.add(new Separator());\r
+        menu.add(editActionSetAction);\r
+        menu.add(savePerspectiveAction);\r
+        menu.add(resetPerspectiveAction);\r
+        menu.add(closePerspAction);\r
+        menu.add(closeAllPerspsAction);\r
+    }\r
+\r
+    /**\r
+     * Adds the keyboard navigation submenu to the specified menu.\r
+     */\r
+    private void addKeyboardShortcuts(MenuManager menu) {\r
+        MenuManager subMenu = new MenuManager("Navi&gation", "shortcuts");\r
+        menu.add(subMenu);\r
+\r
+        subMenu.add(showPartPaneMenuAction);\r
+        subMenu.add(showViewMenuAction);\r
+        subMenu.add(new Separator());\r
+        subMenu.add(maximizePartAction);\r
+        subMenu.add(minimizePartAction);\r
+        subMenu.add(new Separator());\r
+        subMenu.add(activateEditorAction);\r
+        subMenu.add(nextEditorAction);\r
+        subMenu.add(prevEditorAction);\r
+        subMenu.add(switchToEditorAction);\r
+        subMenu.add(openEditorDropDownAction);\r
+        subMenu.add(new Separator());\r
+        subMenu.add(nextPartAction);\r
+        subMenu.add(prevPartAction);\r
+        subMenu.add(new Separator());\r
+        subMenu.add(nextPerspectiveAction);\r
+        subMenu.add(prevPerspectiveAction);\r
+    }\r
+\r
+    /*\r
+    private static String[] getPreferencePageIDs() {\r
+        PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();\r
+        List nodes = mgr.getElements(PreferenceManager.POST_ORDER);\r
+        String result[] = new String[nodes.size()];\r
+        int i=0;\r
+        for (Object o : nodes) {\r
+            IPreferenceNode node = (IPreferenceNode) o;\r
+            result[i++] = node.getId();\r
+        }\r
+        return result;\r
+    }\r
+     */\r
+\r
+    /*\r
+    class OpenPreferencesAction extends Action implements ActionFactory.IWorkbenchAction {\r
+        IWorkbenchWindow workbenchWindow;\r
+        public OpenPreferencesAction(IWorkbenchWindow window) {\r
+            super(WorkbenchMessages.OpenPreferences_text);\r
+            workbenchWindow = window;\r
+            setActionDefinitionId("org.eclipse.ui.window.preferences");\r
+            setToolTipText(WorkbenchMessages.OpenPreferences_toolTip);\r
+            window.getWorkbench().getHelpSystem().setHelp(this,\r
+                    IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);\r
+        }\r
+        public String[] getIDsToBeDisplayed() {\r
+            String nodes[] = ApplicationActionBarAdvisor.getPreferencePageIDs();\r
+            List<String> ids = new ArrayList<String>();\r
+            for (String node: nodes) {\r
+                if (node.startsWith("fi"))\r
+                    ids.add(node);\r
+            }\r
+            return ids.toArray(new String[0]);\r
+        }\r
+        public void run() {\r
+            if (workbenchWindow == null)\r
+                return;\r
+\r
+            String toBeDisplayed[] = getIDsToBeDisplayed();\r
+            PreferenceDialog dialog =\r
+                PreferencesUtil.createPreferenceDialogOn(null, null, toBeDisplayed, null);\r
+            dialog.open();\r
+        }\r
+        public void dispose() {\r
+            workbenchWindow = null;\r
+        }\r
+    }\r
+     */\r
+\r
+    /**\r
+     * Our own version of the "New Window" in\r
+     * <code>IWorkbenchAction.OPEN_NEW_WINDOW</code> action which allows\r
+     * setting the page input IAdaptable.\r
+     */\r
+    public static final ActionFactory OPEN_NEW_WINDOW = new ActionFactory("openNewWindow") {//$NON-NLS-1$\r
+        @Override\r
+        public IWorkbenchAction create(IWorkbenchWindow window) {\r
+            if (window == null) {\r
+                throw new IllegalArgumentException();\r
+            }\r
+            IWorkbenchAction action = new NewWindowAction(window);\r
+            action.setId(getId());\r
+            return action;\r
+        }\r
+    };\r
+\r
+    /**\r
+     * This version of {@link OpenInNewWindowAction} will simply add a new\r
+     * unique IAdaptable page input object for each window created through it.\r
+     */\r
+    static class NewWindowAction extends OpenInNewWindowAction {\r
+        private IWorkbenchWindow workbenchWindow;\r
+        public NewWindowAction(IWorkbenchWindow window) {\r
+            super(window);\r
+            this.workbenchWindow = window;\r
+        }\r
+        @Override\r
+        public void dispose() {\r
+            workbenchWindow = null;\r
+            super.dispose();\r
+        }\r
+        @Override\r
+        public void run() {\r
+            IAdaptable defaultInput = ((Workbench) workbenchWindow.getWorkbench()).getDefaultPageInput();\r
+            setPageInput(new DelegateAdaptable(defaultInput));\r
+            super.run();\r
+        }\r
+    }\r
+\r
+    static class DelegateAdaptable implements IAdaptable {\r
+        IAdaptable target;\r
+        public DelegateAdaptable(IAdaptable target) {\r
+            this.target = target;\r
+        }\r
+        @SuppressWarnings({ "rawtypes" })\r
+        @Override\r
+        public Object getAdapter(Class adapter) {\r
+            return (target != null) ? target.getAdapter(adapter) : null;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu.\r
+     * The test for whether a separator should be added is done by checking for\r
+     * the existence of a preference matching the string\r
+     * useSeparator.MENUID.GROUPID that is set to <code>true</code>.\r
+     * \r
+     * @param menu\r
+     *            the menu to add to\r
+     * @param groupId\r
+     *            the group id for the added separator or group marker\r
+     */\r
+    private void addSeparatorOrGroupMarker(MenuManager menu, String groupId) {\r
+        String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$\r
+        boolean addExtraSeparators = Activator.getDefault().getPreferenceStore().getBoolean(prefId);\r
+        if (addExtraSeparators) {\r
+            menu.add(new Separator(groupId));\r
+        } else {\r
+            menu.add(new GroupMarker(groupId));\r
+        }\r
+    }\r
+\r
+}\r