]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.workbench/src/org/simantics/workbench/internal/SimanticsWorkbenchActionBarAdvisor.java
Improve startup time for fresh or rollback'd session in index writing
[simantics/platform.git] / bundles / org.simantics.workbench / src / org / simantics / workbench / internal / SimanticsWorkbenchActionBarAdvisor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.workbench.internal;
13
14 import java.util.HashSet;
15 import java.util.Set;
16
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.eclipse.core.runtime.IExtension;
19 import org.eclipse.jface.action.ActionContributionItem;
20 import org.eclipse.jface.action.GroupMarker;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.action.IContributionItem;
23 import org.eclipse.jface.action.IMenuManager;
24 import org.eclipse.jface.action.IStatusLineManager;
25 import org.eclipse.jface.action.MenuManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.jface.util.Util;
28 import org.eclipse.ui.IWorkbenchActionConstants;
29 import org.eclipse.ui.IWorkbenchWindow;
30 import org.eclipse.ui.actions.ActionFactory;
31 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
32 import org.eclipse.ui.actions.ContributionItemFactory;
33 import org.eclipse.ui.actions.OpenInNewWindowAction;
34 import org.eclipse.ui.application.ActionBarAdvisor;
35 import org.eclipse.ui.application.IActionBarConfigurer;
36 import org.eclipse.ui.ide.IDEActionFactory;
37 import org.eclipse.ui.internal.Workbench;
38 import org.eclipse.ui.internal.WorkbenchPlugin;
39 import org.eclipse.ui.internal.cheatsheets.actions.CheatSheetCategoryBasedSelectionAction;
40 import org.eclipse.ui.internal.registry.ActionSetRegistry;
41 import org.eclipse.ui.internal.registry.IActionSetDescriptor;
42
43 /**
44  * An action bar advisor is responsible for creating, adding, and disposing of
45  * the actions added to a workbench window. Each window will be populated with
46  * new actions.
47  */
48 public class SimanticsWorkbenchActionBarAdvisor extends ActionBarAdvisor {
49
50     //private final WorkbenchActionBuilder ideAdvisor;
51
52     private final IWorkbenchWindow window;
53
54     /**
55      * Indicates if the action builder has been disposed
56      */
57     private boolean                isDisposed = false;
58
59     // Actions - important to allocate these only in makeActions, and then use
60     // them
61     // in the fill methods. This ensures that the actions aren't recreated
62     // when fillActionBars is called with FILL_PROXY.
63
64     // File
65     private IWorkbenchAction       closeAction;
66
67     private IWorkbenchAction       closeAllAction;
68
69     private IWorkbenchAction       closeOthersAction;
70
71     private IWorkbenchAction       closeAllSavedAction;
72
73 //    private IWorkbenchAction       saveAction;
74
75 //    protected IWorkbenchAction       printAction;
76
77     protected IWorkbenchAction       openWorkspaceAction;
78
79     private IWorkbenchAction       importResourcesAction;
80
81     private IWorkbenchAction       exportResourcesAction;
82
83     protected IWorkbenchAction       quitAction;
84
85     // Edit
86     protected IWorkbenchAction       undoAction;
87
88     protected IWorkbenchAction       redoAction;
89
90     protected IWorkbenchAction       cutAction;
91
92     protected IWorkbenchAction       copyAction;
93
94     protected IWorkbenchAction       pasteAction;
95
96     protected IWorkbenchAction       deleteAction;
97
98     protected IWorkbenchAction       selectAllAction;
99
100     // Navigate
101     private IWorkbenchAction       backwardHistoryAction;
102
103     private IWorkbenchAction       forwardHistoryAction;
104
105     private IWorkbenchAction       goIntoAction;
106
107     private IWorkbenchAction       backAction;
108
109     private IWorkbenchAction       forwardAction;
110
111     private IWorkbenchAction       upAction;
112
113     private IWorkbenchAction       nextAction;
114
115     private IWorkbenchAction       previousAction;
116
117     // Window
118     private IWorkbenchAction       newWindowAction;
119
120     private IWorkbenchAction       newEditorAction;
121
122     private IWorkbenchAction       savePerspectiveAction;
123
124     private IWorkbenchAction       resetPerspectiveAction;
125
126     private IWorkbenchAction       editActionSetAction;
127
128     private IWorkbenchAction       closePerspAction;
129
130     private IWorkbenchAction       closeAllPerspsAction;
131
132     private IWorkbenchAction       openPreferencesAction;
133
134     // Window/Navigation
135     private IWorkbenchAction       showViewMenuAction;
136
137     private IWorkbenchAction       showPartPaneMenuAction;
138
139     private IWorkbenchAction       maximizePartAction;
140
141     private IWorkbenchAction       minimizePartAction;
142
143     private IWorkbenchAction       nextEditorAction;
144
145     private IWorkbenchAction       prevEditorAction;
146
147     private IWorkbenchAction       activateEditorAction;
148
149     private IWorkbenchAction       switchToEditorAction;
150
151     private IWorkbenchAction       openEditorDropDownAction;
152
153     private IWorkbenchAction       nextPartAction;
154
155     private IWorkbenchAction       prevPartAction;
156
157     private IWorkbenchAction       nextPerspectiveAction;
158
159     private IWorkbenchAction       prevPerspectiveAction;
160
161     // Help
162     private IWorkbenchAction       introAction;
163
164     private IWorkbenchAction       tocAction;
165
166     private IWorkbenchAction       searchAction;
167
168     private IWorkbenchAction       dynamicHelpAction;
169
170     private IAction                cheatSheetsAction;
171
172     private IWorkbenchAction       aboutAction;
173
174
175     /**
176      * Constructs a new action builder which contributes actions
177      * to the given window.
178      * 
179      * @param configurer the action bar configurer for the window
180      */
181     public SimanticsWorkbenchActionBarAdvisor(IActionBarConfigurer configurer) {
182         super(configurer);
183         //ideAdvisor = new WorkbenchActionBuilder(configurer);
184         window = configurer.getWindowConfigurer().getWindow();
185     }
186
187     /**
188      * Returns the window to which this action builder is contributing.
189      */
190     private IWorkbenchWindow getWindow() {
191         return window;
192     }
193
194     /**
195      * Disposes any resources and unhooks any listeners that are no longer needed.
196      * Called when the window is closed.
197      */
198     @Override
199     public void dispose() {
200         if (isDisposed) {
201             return;
202         }
203
204         isDisposed = true;
205
206         // null out actions to make leak debugging easier
207         // File
208         closeAction = null;
209         closeAllAction = null;
210         closeAllSavedAction = null;
211         closeOthersAction = null;
212 //        saveAction = null;
213 //        printAction = null;
214         openWorkspaceAction = null;
215         importResourcesAction = null;
216         exportResourcesAction = null;
217         quitAction = null;
218
219         // Edit
220         undoAction = null;
221         redoAction = null;
222         cutAction = null;
223         copyAction = null;
224         pasteAction = null;
225         deleteAction = null;
226         selectAllAction = null;
227
228         // Navigate
229         backwardHistoryAction = null;
230         forwardHistoryAction = null;
231         goIntoAction = null;
232         backAction = null;
233         forwardAction = null;
234         upAction = null;
235         nextAction = null;
236         previousAction = null;
237
238         // Window
239         newWindowAction = null;
240         newEditorAction = null;
241         openPreferencesAction = null;
242         savePerspectiveAction = null;
243         resetPerspectiveAction = null;
244         editActionSetAction = null;
245         closePerspAction = null;
246         closeAllPerspsAction = null;
247         openPreferencesAction = null;
248
249         // Window/Navigation
250         showViewMenuAction = null;
251         showPartPaneMenuAction = null;
252         maximizePartAction = null;
253         minimizePartAction = null;
254         nextPartAction = null;
255         prevPartAction = null;
256         nextPerspectiveAction = null;
257         prevPerspectiveAction = null;
258
259         nextEditorAction = null;
260         prevEditorAction = null;
261         activateEditorAction = null;
262         switchToEditorAction = null;
263         openEditorDropDownAction = null;
264
265         // Help
266         introAction = null;
267         tocAction = null;
268         searchAction = null;
269         dynamicHelpAction = null;
270         cheatSheetsAction = null;
271         aboutAction = null;
272
273         super.dispose();
274     }
275
276     @Override
277     protected void makeActions(final IWorkbenchWindow window) {
278         // Creates the actions and registers them.
279         // Registering is needed to ensure that key bindings work.
280         // The corresponding commands keybindings are defined in the plugin.xml
281         // file.
282         // Registering also provides automatic disposal of the actions when
283         // the window is closed.
284
285         // File
286         closeAction = ActionFactory.CLOSE.create(window);
287         register(closeAction);
288         closeAllAction = ActionFactory.CLOSE_ALL.create(window);
289         register(closeAllAction);
290         closeOthersAction = ActionFactory.CLOSE_OTHERS.create(window);
291         register(closeOthersAction);
292         closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED.create(window);
293         register(closeAllSavedAction);
294 //        saveAction = ActionFactory.SAVE.create(window);
295 //        register(saveAction);
296 //        printAction = ActionFactory.PRINT.create(window);
297 //        register(printAction);
298         openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE.create(window);
299         register(openWorkspaceAction);
300         importResourcesAction = ActionFactory.IMPORT.create(window);
301         register(importResourcesAction);
302         exportResourcesAction = ActionFactory.EXPORT.create(window);
303         register(exportResourcesAction);
304         quitAction = ActionFactory.QUIT.create(window);
305         register(quitAction);
306
307         // Edit
308 //        undoAction = ActionFactory.UNDO.create(window);
309 //        register(undoAction);
310 //        redoAction = ActionFactory.REDO.create(window);
311 //        register(redoAction);
312 //        cutAction = ActionFactory.CUT.create(window);
313 //        register(cutAction);
314 //        copyAction = ActionFactory.COPY.create(window);
315 //        register(copyAction);
316 //        pasteAction = ActionFactory.PASTE.create(window);
317 //        register(pasteAction);
318 //        deleteAction = ActionFactory.DELETE.create(window);
319 //        register(deleteAction);
320 //        selectAllAction = ActionFactory.SELECT_ALL.create(window);
321 //        register(selectAllAction);
322
323         // Navigate
324         forwardHistoryAction = ActionFactory.FORWARD_HISTORY.create(window);
325         register(forwardHistoryAction);
326         backwardHistoryAction = ActionFactory.BACKWARD_HISTORY.create(window);
327         register(backwardHistoryAction);
328         goIntoAction = ActionFactory.GO_INTO.create(window);
329         register(goIntoAction);
330         backAction = ActionFactory.BACK.create(window);
331         register(backAction);
332         forwardAction = ActionFactory.FORWARD.create(window);
333         register(forwardAction);
334         upAction = ActionFactory.UP.create(window);
335         register(upAction);
336         nextAction = ActionFactory.NEXT.create(window);
337         //nextAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV));
338         register(nextAction);
339         previousAction = ActionFactory.PREVIOUS.create(window);
340         //previousAction.setImageDescriptor(IDEInternalWorkbenchImages.getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV));
341         register(previousAction);
342
343
344         // Window
345         newWindowAction = OPEN_NEW_WINDOW.create(getWindow());
346         newWindowAction.setText("&New Window");
347         register(newWindowAction);
348         newEditorAction = ActionFactory.NEW_EDITOR.create(window);
349         register(newEditorAction);
350         editActionSetAction = ActionFactory.EDIT_ACTION_SETS.create(window);
351         register(editActionSetAction);
352         savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE.create(window);
353         register(savePerspectiveAction);
354         resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
355         register(resetPerspectiveAction);
356         closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create(window);
357         register(closePerspAction);
358         closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES.create(window);
359         register(closeAllPerspsAction);
360         openPreferencesAction = ActionFactory.PREFERENCES.create(window);
361 //        preferencesAction = new OpenPreferencesAction(window);
362 //        preferencesAction.setId("preferences");
363         register(openPreferencesAction);
364
365         // Window/Navigation: Actions for invisible accelerators
366         showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
367         register(showViewMenuAction);
368         showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU.create(window);
369         register(showPartPaneMenuAction);
370         maximizePartAction = ActionFactory.MAXIMIZE.create(window);
371         register(maximizePartAction);
372         minimizePartAction = ActionFactory.MINIMIZE.create(window);
373         register(minimizePartAction);
374
375         nextEditorAction = ActionFactory.NEXT_EDITOR.create(window);
376         register(nextEditorAction);
377         prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create(window);
378         register(prevEditorAction);
379         ActionFactory.linkCycleActionPair(nextEditorAction, prevEditorAction);
380         activateEditorAction = ActionFactory.ACTIVATE_EDITOR.create(window);
381         register(activateEditorAction);
382         switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS.create(window);
383         register(switchToEditorAction);
384         openEditorDropDownAction = ActionFactory.SHOW_WORKBOOK_EDITORS.create(window);
385         register(openEditorDropDownAction);
386
387         nextPartAction = ActionFactory.NEXT_PART.create(window);
388         register(nextPartAction);
389         prevPartAction = ActionFactory.PREVIOUS_PART.create(window);
390         register(prevPartAction);
391         ActionFactory.linkCycleActionPair(nextPartAction, prevPartAction);
392         nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE.create(window);
393         register(nextPerspectiveAction);
394         prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE.create(window);
395         register(prevPerspectiveAction);
396         ActionFactory.linkCycleActionPair(nextPerspectiveAction, prevPerspectiveAction);
397
398         // Help
399         if (window.getWorkbench().getIntroManager().hasIntro()) {
400             introAction = ActionFactory.INTRO.create(window);
401             register(introAction);
402         }
403         tocAction = ActionFactory.HELP_CONTENTS.create(window);
404         register(tocAction);
405         searchAction = ActionFactory.HELP_SEARCH.create(window);
406         register(searchAction);
407         dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);
408         register(dynamicHelpAction);
409         cheatSheetsAction = new CheatSheetCategoryBasedSelectionAction("&Cheat Sheets...");
410         cheatSheetsAction.setId("org.eclipse.ui.help.cheatSheetsAction");
411         register(cheatSheetsAction);
412         aboutAction = ActionFactory.ABOUT.create(window);
413         register(aboutAction);
414     }
415
416     /*
417      * TODO: HACK for removing Eclipse's own forced and totally unwanted actionSet extensions.
418      * Remove if a better way to achieve the same effect is found.
419      */
420     protected void hackRemoveUnwantedNavigationActions() {
421         ActionSetRegistry reg = WorkbenchPlugin.getDefault().getActionSetRegistry();
422         IActionSetDescriptor[] actionSets = reg.getActionSets();
423         String actionSetId[] = {
424                 "org.eclipse.ui.edit.text.actionSet.navigation",
425                 "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
426                 "org.eclipse.ui.NavigateActionSet"
427         };
428         Set<String> actionSetIds = new HashSet<String>();
429         for (String s : actionSetId)
430             actionSetIds.add(s);
431
432         for (int i = 0; i < actionSets.length; i++) {
433             if ((!actionSetIds.contains(actionSets[i].getId())))
434                 continue;
435             IExtension ext = actionSets[i].getConfigurationElement().getDeclaringExtension();
436             reg.removeExtension(ext, new Object[] { actionSets[i] });
437         }
438     }
439
440     @Override
441     protected void fillMenuBar(IMenuManager menuBar) {
442         hackRemoveUnwantedNavigationActions();
443
444         menuBar.add(createFileMenu());
445         menuBar.add(createEditMenu());
446         menuBar.add(createNavigateMenu());
447         menuBar.add(createProjectMenu());
448         menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
449         menuBar.add(createWindowMenu());
450         menuBar.add(createHelpMenu());
451     }
452
453     @Override
454     protected void fillStatusLine(IStatusLineManager statusLine) {
455         //System.out.println("fillStatusLine: " + statusLine);
456         //statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, GlobalStatusLineContributionItem.getInstance());
457 //        statusLine.add(new GraphRequestStatusContribution(window));
458 //        statusLine.add(new DumpHeapContribution(window));
459 //        statusLine.add(new DumpStackTracesContribution(window));
460 //        statusLine.add(new FlushRequestsContribution(window));
461 //        statusLine.add(new SearchContribution(window));
462     }
463
464     protected IContributionItem createFileMenu() {
465         //MenuManager menu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
466         MenuManager menu = new MenuManager("&File", ISimanticsWorkbenchConstants.M_FILE);
467
468         menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
469 //        {
470 //            // create the New submenu, using the same id for it as the New action
471 //            String newText = IDEWorkbenchMessages.Workbench_new;
472 //            String newId = ActionFactory.NEW.getId();
473 //            MenuManager newMenu = new MenuManager(newText, newId) {
474 //                public String getMenuText() {
475 //                    String result = super.getMenuText();
476 //                    if (newQuickMenu == null) {
477 //                        return result;
478 //                    }
479 //                    String shortCut = newQuickMenu.getShortCutString();
480 //                    if (shortCut == null) {
481 //                        return result;
482 //                    }
483 //                    return result + "\t" + shortCut; //$NON-NLS-1$
484 //                }
485 //            };
486 //            newMenu.add(new Separator(newId));
487 //            this.newWizardMenu = new NewWizardMenu(getWindow());
488 //            newMenu.add(this.newWizardMenu);
489 //            newMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
490 //            menu.add(newMenu);
491 //        }
492
493         menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
494         menu.add(new Separator());
495
496         menu.add(closeAction);
497         menu.add(closeAllAction);
498         //menu.add(closeAllSavedAction);
499         menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
500         menu.add(new Separator());
501 //        menu.add(saveAction);
502
503         menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
504         menu.add(new Separator());
505 //        menu.add(printAction);
506         menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
507         menu.add(new Separator());
508         menu.add(openWorkspaceAction);
509         menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
510         menu.add(new Separator());
511 //        menu.add(importResourcesAction);
512 //        menu.add(exportResourcesAction);
513         menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
514         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
515
516         menu.add(new Separator());
517
518         // If we're on OS X we shouldn't show this command in the File menu. It
519         // should be invisible to the user. However, we should not remove it -
520         // the carbon UI code will do a search through our menu structure
521         // looking for it when Cmd-Q is invoked (or Quit is chosen from the
522         // application menu.
523         ActionContributionItem quitItem = new ActionContributionItem(quitAction);
524         quitItem.setVisible(!Util.isMac());
525         menu.add(quitItem);
526         menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
527
528         return menu;
529     }
530
531     protected IContributionItem createEditMenu() {
532         MenuManager menu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
533
534 //        menu.add(undoAction);
535 //        menu.add(redoAction);
536 //        menu.add(new Separator());
537 //        menu.add(cutAction);
538 //        menu.add(copyAction);
539 //        menu.add(pasteAction);
540 //        menu.add(new Separator());
541 //        menu.add(deleteAction);
542 //        menu.add(selectAllAction);
543         menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
544 //        menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
545 //        menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
546         menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));
547         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
548         menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
549
550         return menu;
551     }
552
553     /**
554      * Creates and returns the Navigate menu.
555      */
556     protected MenuManager createNavigateMenu() {
557         MenuManager menu = new MenuManager("&Navigate", IWorkbenchActionConstants.M_NAVIGATE);
558         menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_START));
559 //        menu.add(goIntoAction);
560
561 //        MenuManager goToSubMenu = new MenuManager("&Go To", IWorkbenchActionConstants.GO_TO);
562 //        menu.add(goToSubMenu);
563 //        goToSubMenu.add(backAction);
564 //        goToSubMenu.add(forwardAction);
565 //        goToSubMenu.add(upAction);
566 //        goToSubMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
567
568         menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT));
569         for (int i = 2; i < 5; ++i) {
570             menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT + i));
571         }
572         menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT));
573         {
574
575 //            MenuManager showInSubMenu = new MenuManager("Sho&w In", "showIn") {
576 //                public String getMenuText() {
577 //                    String result = super.getMenuText();
578 //                    if (showInQuickMenu == null) {
579 //                        return null;
580 //                    }
581 //                    String shortCut = showInQuickMenu.getShortCutString();
582 //                    if (shortCut == null) {
583 //                        return result;
584 //                    }
585 //                    return result + "\t" + shortCut; //$NON-NLS-1$
586 //                }
587 //            };
588 //            showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
589 //                    .create(getWindow()));
590 //            menu.add(showInSubMenu);
591         }
592         for (int i = 2; i < 5; ++i) {
593             menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT + i));
594         }
595         menu.add(new Separator());
596 //        menu.add(nextAction);
597 //        menu.add(previousAction);
598         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
599         menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_END));
600
601         //TBD: Location of this actions
602         menu.add(new Separator());
603 //        menu.add(backwardHistoryAction);
604 //        menu.add(forwardHistoryAction);
605         return menu;
606     }
607
608     /**
609      * Creates and returns the Project menu.
610      */
611     protected MenuManager createProjectMenu() {
612         MenuManager menu = new MenuManager("&Project", ISimanticsWorkbenchConstants.M_PROJECT);
613         menu.add(new Separator(IWorkbenchActionConstants.PROJ_START));
614
615 //        menu.add(openProjectAction);
616 //        menu.add(closeProjectAction);
617 //        menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
618 //        menu.add(new Separator());
619 //        menu.add(buildAllAction);
620 //        menu.add(buildProjectAction);
621 //        addWorkingSetBuildActions(menu);
622 //        menu.add(cleanAction);
623 //        menu.add(toggleAutoBuildAction);
624 //        menu.add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));
625 //        menu.add(new Separator());
626
627         menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
628         menu.add(new GroupMarker(IWorkbenchActionConstants.PROJ_END));
629         menu.add(new Separator());
630 //        menu.add(projectPropertyDialogAction);
631         return menu;
632     }
633
634
635     protected IContributionItem createWindowMenu() {
636         MenuManager menu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);
637
638         menu.add(newWindowAction);
639 //        menu.add(newEditorAction);
640
641         menu.add(new Separator());
642         addPerspectiveActions(menu);
643         menu.add(new Separator());
644         addKeyboardShortcuts(menu);
645         Separator sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS);
646         sep.setVisible(!Util.isMac());
647         menu.add(sep);
648         sep = new Separator(IWorkbenchActionConstants.MB_ADDITIONS + ".end"); //$NON-NLS-1$
649         sep.setVisible(!Util.isMac());
650         menu.add(sep);
651
652         // See the comment for quit in createFileMenu
653         ActionContributionItem openPreferencesItem = new ActionContributionItem(openPreferencesAction);
654         openPreferencesItem.setVisible(!Util.isMac());
655         menu.add(openPreferencesItem);
656
657         menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
658         return menu;
659     }
660
661     protected IContributionItem createHelpMenu() {
662         // Help
663         MenuManager menu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
664
665         menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
666         if (introAction != null)
667             menu.add(introAction);
668         menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
669         menu.add(new Separator("group.main"));
670         //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
671         menu.add(tocAction);
672         menu.add(searchAction);
673         menu.add(dynamicHelpAction);
674         menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
675         menu.add(new Separator("group.main")); //$NON-NLS-1$
676         //addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
677         addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
678         menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
679         menu.add(cheatSheetsAction);
680         addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
681         addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
682         addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
683         menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
684         //addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
685         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
686         //menu.add(new Separator());
687         menu.add(new Separator("group.about")); //$NON-NLS-1$
688
689         ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
690         aboutItem.setVisible(!Util.isMac());
691         menu.add(aboutItem);
692         menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
693         return menu;
694     }
695
696     /**
697      * Adds the perspective actions to the specified menu.
698      */
699     private void addPerspectiveActions(MenuManager menu) {
700         {
701             MenuManager changePerspMenuMgr = new MenuManager("&Open Perspective", "openPerspective");
702             IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(getWindow());
703             changePerspMenuMgr.add(changePerspMenuItem);
704             menu.add(changePerspMenuMgr);
705         }
706         {
707             MenuManager showViewMenuMgr = new MenuManager("Show &View", "showView");
708             IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST.create(getWindow());
709             showViewMenuMgr.add(showViewMenu);
710             menu.add(showViewMenuMgr);
711         }
712         menu.add(new Separator());
713         menu.add(editActionSetAction);
714         menu.add(savePerspectiveAction);
715         menu.add(resetPerspectiveAction);
716         menu.add(closePerspAction);
717         menu.add(closeAllPerspsAction);
718     }
719
720     /**
721      * Adds the keyboard navigation submenu to the specified menu.
722      */
723     private void addKeyboardShortcuts(MenuManager menu) {
724         MenuManager subMenu = new MenuManager("Navi&gation", "shortcuts");
725         menu.add(subMenu);
726
727         subMenu.add(showPartPaneMenuAction);
728         subMenu.add(showViewMenuAction);
729         subMenu.add(new Separator());
730         subMenu.add(maximizePartAction);
731         subMenu.add(minimizePartAction);
732         subMenu.add(new Separator());
733         subMenu.add(activateEditorAction);
734         subMenu.add(nextEditorAction);
735         subMenu.add(prevEditorAction);
736         subMenu.add(switchToEditorAction);
737         subMenu.add(openEditorDropDownAction);
738         subMenu.add(new Separator());
739         subMenu.add(nextPartAction);
740         subMenu.add(prevPartAction);
741         subMenu.add(new Separator());
742         subMenu.add(nextPerspectiveAction);
743         subMenu.add(prevPerspectiveAction);
744     }
745
746     /*
747     private static String[] getPreferencePageIDs() {
748         PreferenceManager mgr = PlatformUI.getWorkbench().getPreferenceManager();
749         List nodes = mgr.getElements(PreferenceManager.POST_ORDER);
750         String result[] = new String[nodes.size()];
751         int i=0;
752         for (Object o : nodes) {
753             IPreferenceNode node = (IPreferenceNode) o;
754             result[i++] = node.getId();
755         }
756         return result;
757     }
758      */
759
760     /*
761     class OpenPreferencesAction extends Action implements ActionFactory.IWorkbenchAction {
762         IWorkbenchWindow workbenchWindow;
763         public OpenPreferencesAction(IWorkbenchWindow window) {
764             super(WorkbenchMessages.OpenPreferences_text);
765             workbenchWindow = window;
766             setActionDefinitionId("org.eclipse.ui.window.preferences");
767             setToolTipText(WorkbenchMessages.OpenPreferences_toolTip);
768             window.getWorkbench().getHelpSystem().setHelp(this,
769                     IWorkbenchHelpContextIds.OPEN_PREFERENCES_ACTION);
770         }
771         public String[] getIDsToBeDisplayed() {
772             String nodes[] = ApplicationActionBarAdvisor.getPreferencePageIDs();
773             List<String> ids = new ArrayList<String>();
774             for (String node: nodes) {
775                 if (node.startsWith("fi"))
776                     ids.add(node);
777             }
778             return ids.toArray(new String[0]);
779         }
780         public void run() {
781             if (workbenchWindow == null)
782                 return;
783
784             String toBeDisplayed[] = getIDsToBeDisplayed();
785             PreferenceDialog dialog =
786                 PreferencesUtil.createPreferenceDialogOn(null, null, toBeDisplayed, null);
787             dialog.open();
788         }
789         public void dispose() {
790             workbenchWindow = null;
791         }
792     }
793      */
794
795     /**
796      * Our own version of the "New Window" in
797      * <code>IWorkbenchAction.OPEN_NEW_WINDOW</code> action which allows
798      * setting the page input IAdaptable.
799      */
800     public static final ActionFactory OPEN_NEW_WINDOW = new ActionFactory("openNewWindow") {//$NON-NLS-1$
801         @Override
802         public IWorkbenchAction create(IWorkbenchWindow window) {
803             if (window == null) {
804                 throw new IllegalArgumentException();
805             }
806             IWorkbenchAction action = new NewWindowAction(window);
807             action.setId(getId());
808             return action;
809         }
810     };
811
812     /**
813      * This version of {@link OpenInNewWindowAction} will simply add a new
814      * unique IAdaptable page input object for each window created through it.
815      */
816     static class NewWindowAction extends OpenInNewWindowAction {
817         private IWorkbenchWindow workbenchWindow;
818         public NewWindowAction(IWorkbenchWindow window) {
819             super(window);
820             this.workbenchWindow = window;
821         }
822         @Override
823         public void dispose() {
824             workbenchWindow = null;
825             super.dispose();
826         }
827         @Override
828         public void run() {
829             IAdaptable defaultInput = ((Workbench) workbenchWindow.getWorkbench()).getDefaultPageInput();
830             setPageInput(new DelegateAdaptable(defaultInput));
831             super.run();
832         }
833     }
834
835     static class DelegateAdaptable implements IAdaptable {
836         IAdaptable target;
837         public DelegateAdaptable(IAdaptable target) {
838             this.target = target;
839         }
840         @SuppressWarnings({ "rawtypes" })
841         @Override
842         public Object getAdapter(Class adapter) {
843             return (target != null) ? target.getAdapter(adapter) : null;
844         }
845     }
846
847     /**
848      * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu.
849      * The test for whether a separator should be added is done by checking for
850      * the existence of a preference matching the string
851      * useSeparator.MENUID.GROUPID that is set to <code>true</code>.
852      * 
853      * @param menu
854      *            the menu to add to
855      * @param groupId
856      *            the group id for the added separator or group marker
857      */
858     private void addSeparatorOrGroupMarker(MenuManager menu, String groupId) {
859         String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
860         boolean addExtraSeparators = Activator.getDefault().getPreferenceStore().getBoolean(prefId);
861         if (addExtraSeparators) {
862             menu.add(new Separator(groupId));
863         } else {
864             menu.add(new GroupMarker(groupId));
865         }
866     }
867
868 }