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