KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > WorkbenchActionBuilder


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.ide;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResourceChangeEvent;
15 import org.eclipse.core.resources.IResourceChangeListener;
16 import org.eclipse.core.resources.IResourceDelta;
17 import org.eclipse.core.resources.IWorkspace;
18 import org.eclipse.core.resources.IncrementalProjectBuilder;
19 import org.eclipse.core.resources.ResourcesPlugin;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.core.runtime.Preferences;
22 import org.eclipse.jface.action.ActionContributionItem;
23 import org.eclipse.jface.action.GroupMarker;
24 import org.eclipse.jface.action.IAction;
25 import org.eclipse.jface.action.IContributionItem;
26 import org.eclipse.jface.action.ICoolBarManager;
27 import org.eclipse.jface.action.IMenuManager;
28 import org.eclipse.jface.action.IStatusLineManager;
29 import org.eclipse.jface.action.IToolBarManager;
30 import org.eclipse.jface.action.MenuManager;
31 import org.eclipse.jface.action.Separator;
32 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
33 import org.eclipse.jface.preference.IPreferenceStore;
34 import org.eclipse.jface.util.IPropertyChangeListener;
35 import org.eclipse.jface.util.PropertyChangeEvent;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.widgets.Shell;
38 import org.eclipse.ui.IPageListener;
39 import org.eclipse.ui.IWorkbenchActionConstants;
40 import org.eclipse.ui.IWorkbenchPage;
41 import org.eclipse.ui.IWorkbenchWindow;
42 import org.eclipse.ui.actions.ActionFactory;
43 import org.eclipse.ui.actions.BuildAction;
44 import org.eclipse.ui.actions.ContributionItemFactory;
45 import org.eclipse.ui.actions.NewWizardMenu;
46 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
47 import org.eclipse.ui.application.ActionBarAdvisor;
48 import org.eclipse.ui.application.IActionBarConfigurer;
49 import org.eclipse.ui.ide.IDEActionFactory;
50 import org.eclipse.ui.ide.IIDEActionConstants;
51 import org.eclipse.ui.internal.IPreferenceConstants;
52 import org.eclipse.ui.internal.WorkbenchPlugin;
53 import org.eclipse.ui.internal.ide.actions.BuildSetMenu;
54 import org.eclipse.ui.internal.ide.actions.BuildUtilities;
55 import org.eclipse.ui.internal.ide.actions.QuickMenuAction;
56 import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault;
57 import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
58 import org.eclipse.ui.internal.util.StatusLineContributionItem;
59 import org.eclipse.ui.menus.IMenuService;
60
61 /**
62  * Adds actions to a workbench window.
63  */

64 public final class WorkbenchActionBuilder extends ActionBarAdvisor {
65     private final IWorkbenchWindow window;
66
67     // generic actions
68
private IWorkbenchAction closeAction;
69
70     private IWorkbenchAction closeAllAction;
71     
72     private IWorkbenchAction closeOthersAction;
73
74     private IWorkbenchAction closeAllSavedAction;
75
76     private IWorkbenchAction saveAction;
77
78     private IWorkbenchAction saveAllAction;
79
80     private IWorkbenchAction newWindowAction;
81     
82     private IWorkbenchAction newEditorAction;
83
84     private IWorkbenchAction helpContentsAction;
85
86     private IWorkbenchAction helpSearchAction;
87     
88     private IWorkbenchAction dynamicHelpAction;
89     
90     private IWorkbenchAction aboutAction;
91
92     private IWorkbenchAction openPreferencesAction;
93
94     private IWorkbenchAction saveAsAction;
95
96     private IWorkbenchAction hideShowEditorAction;
97
98     private IWorkbenchAction savePerspectiveAction;
99
100     private IWorkbenchAction resetPerspectiveAction;
101
102     private IWorkbenchAction editActionSetAction;
103
104     private IWorkbenchAction closePerspAction;
105
106     private IWorkbenchAction lockToolBarAction;
107
108     private IWorkbenchAction closeAllPerspsAction;
109
110     private IWorkbenchAction showViewMenuAction;
111
112     private IWorkbenchAction showPartPaneMenuAction;
113
114     private IWorkbenchAction nextPartAction;
115
116     private IWorkbenchAction prevPartAction;
117
118     private IWorkbenchAction nextEditorAction;
119
120     private IWorkbenchAction prevEditorAction;
121
122     private IWorkbenchAction nextPerspectiveAction;
123
124     private IWorkbenchAction prevPerspectiveAction;
125
126     private IWorkbenchAction activateEditorAction;
127
128     private IWorkbenchAction maximizePartAction;
129     
130     private IWorkbenchAction minimizePartAction;
131
132     private IWorkbenchAction switchToEditorAction;
133
134     private IWorkbenchAction workbookEditorsAction;
135
136     private IWorkbenchAction quickAccessAction;
137
138     private IWorkbenchAction backwardHistoryAction;
139
140     private IWorkbenchAction forwardHistoryAction;
141
142     // generic retarget actions
143
private IWorkbenchAction undoAction;
144
145     private IWorkbenchAction redoAction;
146
147     private IWorkbenchAction cutAction;
148
149     private IWorkbenchAction copyAction;
150
151     private IWorkbenchAction pasteAction;
152
153     private IWorkbenchAction deleteAction;
154
155     private IWorkbenchAction selectAllAction;
156
157     private IWorkbenchAction findAction;
158
159     private IWorkbenchAction printAction;
160
161     private IWorkbenchAction revertAction;
162
163     private IWorkbenchAction refreshAction;
164
165     private IWorkbenchAction propertiesAction;
166
167     private IWorkbenchAction quitAction;
168
169     private IWorkbenchAction moveAction;
170
171     private IWorkbenchAction renameAction;
172
173     private IWorkbenchAction goIntoAction;
174
175     private IWorkbenchAction backAction;
176
177     private IWorkbenchAction forwardAction;
178
179     private IWorkbenchAction upAction;
180
181     private IWorkbenchAction nextAction;
182
183     private IWorkbenchAction previousAction;
184
185     // IDE-specific actions
186
private IWorkbenchAction openWorkspaceAction;
187
188     private IWorkbenchAction projectPropertyDialogAction;
189
190     private IWorkbenchAction newWizardAction;
191
192     private IWorkbenchAction newWizardDropDownAction;
193
194     private IWorkbenchAction importResourcesAction;
195     
196     private IWorkbenchAction exportResourcesAction;
197
198     IWorkbenchAction buildAllAction; // Incremental workspace build
199

200     private IWorkbenchAction cleanAction;
201
202     private IWorkbenchAction toggleAutoBuildAction;
203
204     MenuManager buildWorkingSetMenu;
205
206     private IWorkbenchAction quickStartAction;
207
208     private IWorkbenchAction tipsAndTricksAction;
209
210     private QuickMenuAction showInQuickMenu;
211
212     private QuickMenuAction newQuickMenu;
213
214     private IWorkbenchAction introAction;
215
216     // IDE-specific retarget actions
217
private IWorkbenchAction addBookmarkAction;
218
219     private IWorkbenchAction addTaskAction;
220
221     IWorkbenchAction buildProjectAction;
222
223     private IWorkbenchAction openProjectAction;
224
225     private IWorkbenchAction closeProjectAction;
226
227     // contribution items
228
// @issue should obtain from ContributionItemFactory
229
private NewWizardMenu newWizardMenu;
230
231     private IContributionItem pinEditorContributionItem;
232
233 // private IContributionItem searchComboItem;
234

235     // @issue class is workbench internal
236
private StatusLineContributionItem statusLineItem;
237
238     private Preferences.IPropertyChangeListener prefListener;
239
240     // listener for the "close editors automatically"
241
// preference change
242
private IPropertyChangeListener propPrefListener;
243
244     private IPageListener pageListener;
245
246     private IResourceChangeListener resourceListener;
247     
248     /**
249      * Indicates if the action builder has been disposed
250      */

251     private boolean isDisposed = false;
252
253     /**
254      * The coolbar context menu manager.
255      * @since 3.3
256      */

257     private MenuManager coolbarPopupMenuManager;
258
259     /**
260      * Constructs a new action builder which contributes actions
261      * to the given window.
262      *
263      * @param configurer the action bar configurer for the window
264      */

265     public WorkbenchActionBuilder(IActionBarConfigurer configurer) {
266         super(configurer);
267         window = configurer.getWindowConfigurer().getWindow();
268     }
269
270     /**
271      * Returns the window to which this action builder is contributing.
272      */

273     private IWorkbenchWindow getWindow() {
274         return window;
275     }
276
277     /**
278      * Hooks listeners on the preference store and the window's page, perspective and selection services.
279      */

280     private void hookListeners() {
281
282         pageListener = new IPageListener() {
283             public void pageActivated(IWorkbenchPage page) {
284                 // do nothing
285
}
286
287             public void pageClosed(IWorkbenchPage page) {
288                 // do nothing
289
}
290
291             public void pageOpened(IWorkbenchPage page) {
292                 // set default build handler -- can't be done until the shell is available
293
IAction buildHandler = new BuildAction(page.getWorkbenchWindow().getShell(), IncrementalProjectBuilder.INCREMENTAL_BUILD);
294                 ((RetargetActionWithDefault)buildProjectAction).setDefaultHandler(buildHandler);
295             }
296         };
297         getWindow().addPageListener(pageListener);
298
299         prefListener = new Preferences.IPropertyChangeListener() {
300             public void propertyChange(Preferences.PropertyChangeEvent event) {
301                 if (event.getProperty().equals(
302                         ResourcesPlugin.PREF_AUTO_BUILDING)) {
303                     updateBuildActions(false);
304                 }
305             }
306         };
307         ResourcesPlugin.getPlugin().getPluginPreferences()
308                 .addPropertyChangeListener(prefListener);
309
310         // listener for the "close editors automatically"
311
// preference change
312
propPrefListener = new IPropertyChangeListener() {
313             public void propertyChange(PropertyChangeEvent event) {
314                 if (event.getProperty().equals(
315                         IPreferenceConstants.REUSE_EDITORS_BOOLEAN)) {
316                     if (window.getShell() != null
317                             && !window.getShell().isDisposed()) {
318                         // this property change notification could be from a non-ui thread
319
window.getShell().getDisplay().syncExec(new Runnable JavaDoc() {
320                             public void run() {
321                                 updatePinActionToolbar();
322                             }
323                         });
324                     }
325                 }
326             }
327         };
328         /*
329          * In order to ensure that the pin action toolbar sets its size
330          * correctly, the pin action should set its visiblity before we call updatePinActionToolbar().
331          *
332          * In other words we always want the PinActionContributionItem to be notified before the
333          * WorkbenchActionBuilder.
334          */

335         WorkbenchPlugin.getDefault().getPreferenceStore()
336                 .addPropertyChangeListener(propPrefListener);
337         //listen for project description changes, which can affect enablement of build actions
338
resourceListener = new IResourceChangeListener() {
339             public void resourceChanged(IResourceChangeEvent event) {
340                 IResourceDelta delta = event.getDelta();
341                 if (delta == null) {
342                     return;
343                 }
344                 IResourceDelta[] projectDeltas = delta.getAffectedChildren();
345                 for (int i = 0; i < projectDeltas.length; i++) {
346                     int kind = projectDeltas[i].getKind();
347                     //affected by projects being opened/closed or description changes
348
boolean changed = (projectDeltas[i].getFlags() & (IResourceDelta.DESCRIPTION | IResourceDelta.OPEN)) != 0;
349                     if (kind != IResourceDelta.CHANGED || changed) {
350                         updateBuildActions(false);
351                         return;
352                     }
353                 }
354             }
355         };
356         ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceListener, IResourceChangeEvent.POST_CHANGE);
357     }
358
359     public void fillActionBars(int flags) {
360         super.fillActionBars(flags);
361         if ((flags & FILL_PROXY) == 0) {
362             updateBuildActions(true);
363             hookListeners();
364         }
365     }
366
367     /**
368      * Fills the coolbar with the workbench actions.
369      */

370     protected void fillCoolBar(ICoolBarManager coolBar) {
371
372         IActionBarConfigurer2 actionBarConfigurer = (IActionBarConfigurer2) getActionBarConfigurer();
373         { // Set up the context Menu
374
coolbarPopupMenuManager = new MenuManager();
375             coolbarPopupMenuManager.add(new ActionContributionItem(lockToolBarAction));
376             coolbarPopupMenuManager.add(new ActionContributionItem(editActionSetAction));
377             coolBar.setContextMenuManager(coolbarPopupMenuManager);
378             IMenuService menuService = (IMenuService) window.getService(IMenuService.class);
379             menuService.populateContributionManager(coolbarPopupMenuManager, "popup:windowCoolbarContextMenu"); //$NON-NLS-1$
380
}
381         coolBar.add(new GroupMarker(IIDEActionConstants.GROUP_FILE));
382         { // File Group
383
IToolBarManager fileToolBar = actionBarConfigurer.createToolBarManager();
384             fileToolBar.add(new Separator(IWorkbenchActionConstants.NEW_GROUP));
385             fileToolBar.add(newWizardDropDownAction);
386             fileToolBar.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
387             fileToolBar.add(new GroupMarker(
388                     IWorkbenchActionConstants.SAVE_GROUP));
389             fileToolBar.add(saveAction);
390             fileToolBar
391                     .add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
392             fileToolBar.add(printAction);
393             fileToolBar
394                     .add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
395
396             fileToolBar
397                     .add(new Separator(IWorkbenchActionConstants.BUILD_GROUP));
398             fileToolBar
399                     .add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));
400             fileToolBar.add(new Separator(
401                     IWorkbenchActionConstants.MB_ADDITIONS));
402
403             // Add to the cool bar manager
404
coolBar.add(actionBarConfigurer.createToolBarContributionItem(fileToolBar,
405                     IWorkbenchActionConstants.TOOLBAR_FILE));
406         }
407
408         coolBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
409
410         coolBar.add(new GroupMarker(IIDEActionConstants.GROUP_NAV));
411         { // Navigate group
412
IToolBarManager navToolBar = actionBarConfigurer.createToolBarManager();
413             navToolBar.add(new Separator(
414                     IWorkbenchActionConstants.HISTORY_GROUP));
415             navToolBar
416                     .add(new GroupMarker(IWorkbenchActionConstants.GROUP_APP));
417             navToolBar.add(backwardHistoryAction);
418             navToolBar.add(forwardHistoryAction);
419             navToolBar.add(new Separator(IWorkbenchActionConstants.PIN_GROUP));
420             navToolBar.add(pinEditorContributionItem);
421
422             // Add to the cool bar manager
423
coolBar.add(actionBarConfigurer.createToolBarContributionItem(navToolBar,
424                     IWorkbenchActionConstants.TOOLBAR_NAVIGATE));
425         }
426
427         coolBar.add(new GroupMarker(IWorkbenchActionConstants.GROUP_EDITOR));
428      
429         coolBar.add(new GroupMarker(IWorkbenchActionConstants.GROUP_HELP));
430         
431         { // Help group
432
IToolBarManager helpToolBar = actionBarConfigurer.createToolBarManager();
433             helpToolBar.add(new Separator(IWorkbenchActionConstants.GROUP_HELP));
434 // helpToolBar.add(searchComboItem);
435
// Add the group for applications to contribute
436
helpToolBar.add(new GroupMarker(IWorkbenchActionConstants.GROUP_APP));
437             // Add to the cool bar manager
438
coolBar.add(actionBarConfigurer.createToolBarContributionItem(helpToolBar,
439                     IWorkbenchActionConstants.TOOLBAR_HELP));
440         }
441
442     }
443
444     /**
445      * Fills the menu bar with the workbench actions.
446      */

447     protected void fillMenuBar(IMenuManager menuBar) {
448         menuBar.add(createFileMenu());
449         menuBar.add(createEditMenu());
450         menuBar.add(createNavigateMenu());
451         menuBar.add(createProjectMenu());
452         menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
453         menuBar.add(createWindowMenu());
454         menuBar.add(createHelpMenu());
455     }
456
457     /**
458      * Creates and returns the File menu.
459      */

460     private MenuManager createFileMenu() {
461         MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_file, IWorkbenchActionConstants.M_FILE);
462         menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
463         {
464             // create the New submenu, using the same id for it as the New action
465
String JavaDoc newText = IDEWorkbenchMessages.Workbench_new;
466             String JavaDoc newId = ActionFactory.NEW.getId();
467             MenuManager newMenu = new MenuManager(newText, newId) {
468                 public String JavaDoc getMenuText() {
469                     String JavaDoc result = super.getMenuText();
470                     if (newQuickMenu == null) {
471                         return result;
472                     }
473                     String JavaDoc shortCut = newQuickMenu.getShortCutString();
474                     if (shortCut == null) {
475                         return result;
476                     }
477                     return result + "\t" + shortCut; //$NON-NLS-1$
478
}
479             };
480             newMenu.add(new Separator(newId));
481             this.newWizardMenu = new NewWizardMenu(getWindow());
482             newMenu.add(this.newWizardMenu);
483             newMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
484             menu.add(newMenu);
485         }
486         
487         menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
488         menu.add(new Separator());
489
490         menu.add(closeAction);
491         menu.add(closeAllAction);
492         // menu.add(closeAllSavedAction);
493
menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
494         menu.add(new Separator());
495         menu.add(saveAction);
496         menu.add(saveAsAction);
497         menu.add(saveAllAction);
498         menu.add(revertAction);
499         menu.add(new Separator());
500         menu.add(moveAction);
501         menu.add(renameAction);
502         menu.add(refreshAction);
503
504         menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
505         menu.add(new Separator());
506         menu.add(printAction);
507         menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
508         menu.add(new Separator());
509         menu.add(openWorkspaceAction);
510         menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
511         menu.add(new Separator());
512         menu.add(importResourcesAction);
513         menu.add(exportResourcesAction);
514         menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
515         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
516
517         menu.add(new Separator());
518         menu.add(propertiesAction);
519
520         menu.add(ContributionItemFactory.REOPEN_EDITORS.create(getWindow()));
521         menu.add(new GroupMarker(IWorkbenchActionConstants.MRU));
522         menu.add(new Separator());
523         
524         // If we're on OS X we shouldn't show this command in the File menu. It
525
// should be invisible to the user. However, we should not remove it -
526
// the carbon UI code will do a search through our menu structure
527
// looking for it when Cmd-Q is invoked (or Quit is chosen from the
528
// application menu.
529
ActionContributionItem quitItem = new ActionContributionItem(quitAction);
530         quitItem.setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
531
menu.add(quitItem);
532         menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
533         return menu;
534     }
535
536     /**
537      * Creates and returns the Edit menu.
538      */

539     private MenuManager createEditMenu() {
540         MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_edit, IWorkbenchActionConstants.M_EDIT);
541         menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
542
543         menu.add(undoAction);
544         menu.add(redoAction);
545         menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
546         menu.add(new Separator());
547
548         menu.add(cutAction);
549         menu.add(copyAction);
550         menu.add(pasteAction);
551         menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
552         menu.add(new Separator());
553
554         menu.add(deleteAction);
555         menu.add(selectAllAction);
556         menu.add(new Separator());
557
558         menu.add(findAction);
559         menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));
560         menu.add(new Separator());
561
562         menu.add(addBookmarkAction);
563         menu.add(addTaskAction);
564         menu.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT));
565
566         menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
567         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
568         return menu;
569     }
570
571     /**
572      * Creates and returns the Navigate menu.
573      */

574     private MenuManager createNavigateMenu() {
575         MenuManager menu = new MenuManager(
576                 IDEWorkbenchMessages.Workbench_navigate, IWorkbenchActionConstants.M_NAVIGATE);
577         menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_START));
578         menu.add(goIntoAction);
579
580         MenuManager goToSubMenu = new MenuManager(IDEWorkbenchMessages.Workbench_goTo, IWorkbenchActionConstants.GO_TO);
581         menu.add(goToSubMenu);
582         goToSubMenu.add(backAction);
583         goToSubMenu.add(forwardAction);
584         goToSubMenu.add(upAction);
585         goToSubMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
586
587         menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT));
588         for (int i = 2; i < 5; ++i) {
589             menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT + i));
590         }
591         menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT));
592         {
593
594             MenuManager showInSubMenu = new MenuManager(IDEWorkbenchMessages.Workbench_showIn, "showIn") { //$NON-NLS-1$
595
public String JavaDoc getMenuText() {
596                     String JavaDoc result = super.getMenuText();
597                     if (showInQuickMenu == null) {
598                         return null;
599                     }
600                     String JavaDoc shortCut = showInQuickMenu.getShortCutString();
601                     if (shortCut == null) {
602                         return result;
603                     }
604                     return result + "\t" + shortCut; //$NON-NLS-1$
605
}
606             };
607             showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
608                     .create(getWindow()));
609             menu.add(showInSubMenu);
610         }
611         for (int i = 2; i < 5; ++i) {
612             menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT + i));
613         }
614         menu.add(new Separator());
615         menu.add(nextAction);
616         menu.add(previousAction);
617         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
618         menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_END));
619
620         //TBD: Location of this actions
621
menu.add(new Separator());
622         menu.add(backwardHistoryAction);
623         menu.add(forwardHistoryAction);
624         return menu;
625     }
626
627     /**
628      * Creates and returns the Project menu.
629      */

630     private MenuManager createProjectMenu() {
631         MenuManager menu = new MenuManager(
632                 IDEWorkbenchMessages.Workbench_project, IWorkbenchActionConstants.M_PROJECT);
633         menu.add(new Separator(IWorkbenchActionConstants.PROJ_START));
634
635         menu.add(openProjectAction);
636         menu.add(closeProjectAction);
637         menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
638         menu.add(new Separator());
639         menu.add(buildAllAction);
640         menu.add(buildProjectAction);
641         addWorkingSetBuildActions(menu);
642         menu.add(cleanAction);
643         menu.add(toggleAutoBuildAction);
644         menu.add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));
645         menu.add(new Separator());
646
647         menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
648         menu.add(new GroupMarker(IWorkbenchActionConstants.PROJ_END));
649         menu.add(new Separator());
650         menu.add(projectPropertyDialogAction);
651         return menu;
652     }
653
654     /**
655      * Creates and returns the Window menu.
656      */

657     private MenuManager createWindowMenu() {
658         MenuManager menu = new MenuManager(
659                 IDEWorkbenchMessages.Workbench_window, IWorkbenchActionConstants.M_WINDOW);
660
661         menu.add(newWindowAction);
662         menu.add(newEditorAction);
663         
664         menu.add(new Separator());
665         addPerspectiveActions(menu);
666         menu.add(new Separator());
667         addKeyboardShortcuts(menu);
668         menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
669         
670         // See the comment for quit in createFileMenu
671
ActionContributionItem openPreferencesItem = new ActionContributionItem(openPreferencesAction);
672         openPreferencesItem.setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
673
menu.add(openPreferencesItem);
674
675         menu.add(ContributionItemFactory.OPEN_WINDOWS.create(getWindow()));
676         return menu;
677     }
678
679     /**
680      * Adds the perspective actions to the specified menu.
681      */

682     private void addPerspectiveActions(MenuManager menu) {
683         {
684             String JavaDoc openText = IDEWorkbenchMessages.Workbench_openPerspective;
685             MenuManager changePerspMenuMgr = new MenuManager(openText,
686                     "openPerspective"); //$NON-NLS-1$
687
IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST
688                     .create(getWindow());
689             changePerspMenuMgr.add(changePerspMenuItem);
690             menu.add(changePerspMenuMgr);
691         }
692         {
693             MenuManager showViewMenuMgr = new MenuManager(IDEWorkbenchMessages.Workbench_showView, "showView"); //$NON-NLS-1$
694
IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST
695                     .create(getWindow());
696             showViewMenuMgr.add(showViewMenu);
697             menu.add(showViewMenuMgr);
698         }
699         menu.add(new Separator());
700         menu.add(editActionSetAction);
701         menu.add(savePerspectiveAction);
702         menu.add(resetPerspectiveAction);
703         menu.add(closePerspAction);
704         menu.add(closeAllPerspsAction);
705     }
706
707     /**
708      * Adds the keyboard navigation submenu to the specified menu.
709      */

710     private void addWorkingSetBuildActions(MenuManager menu) {
711         buildWorkingSetMenu = new MenuManager(IDEWorkbenchMessages.Workbench_buildSet);
712         IContributionItem workingSetBuilds = new BuildSetMenu(window,
713                 getActionBarConfigurer());
714         buildWorkingSetMenu.add(workingSetBuilds);
715         menu.add(buildWorkingSetMenu);
716     }
717
718     /**
719      * Adds the keyboard navigation submenu to the specified menu.
720      */

721     private void addKeyboardShortcuts(MenuManager menu) {
722         MenuManager subMenu = new MenuManager(IDEWorkbenchMessages.Workbench_shortcuts, "shortcuts"); //$NON-NLS-1$
723
menu.add(subMenu);
724         subMenu.add(showPartPaneMenuAction);
725         subMenu.add(showViewMenuAction);
726         subMenu.add(quickAccessAction);
727         subMenu.add(new Separator());
728         subMenu.add(maximizePartAction);
729         subMenu.add(minimizePartAction);
730         subMenu.add(new Separator());
731         subMenu.add(activateEditorAction);
732         subMenu.add(nextEditorAction);
733         subMenu.add(prevEditorAction);
734         subMenu.add(switchToEditorAction);
735         subMenu.add(new Separator());
736         subMenu.add(nextPartAction);
737         subMenu.add(prevPartAction);
738         subMenu.add(new Separator());
739         subMenu.add(nextPerspectiveAction);
740         subMenu.add(prevPerspectiveAction);
741     }
742
743     /**
744      * Creates and returns the Help menu.
745      */

746     private MenuManager createHelpMenu() {
747         MenuManager menu = new MenuManager(IDEWorkbenchMessages.Workbench_help, IWorkbenchActionConstants.M_HELP);
748         addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
749
// See if a welcome or intro page is specified
750
if (introAction != null) {
751             menu.add(introAction);
752         } else if (quickStartAction != null) {
753             menu.add(quickStartAction);
754         }
755         menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
756
addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
757
menu.add(helpContentsAction);
758         menu.add(helpSearchAction);
759         menu.add(dynamicHelpAction);
760         addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
761
// See if a tips and tricks page is specified
762
if (tipsAndTricksAction != null) {
763             menu.add(tipsAndTricksAction);
764         }
765         // HELP_START should really be the first item, but it was after
766
// quickStartAction and tipsAndTricksAction in 2.1.
767
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
768         menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
769
addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
770
addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
771
addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
772
menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
773         addSeparatorOrGroupMarker(menu, IWorkbenchActionConstants.MB_ADDITIONS);
774         // about should always be at the bottom
775
menu.add(new Separator("group.about")); //$NON-NLS-1$
776

777         ActionContributionItem aboutItem = new ActionContributionItem(aboutAction);
778         aboutItem.setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
779
menu.add(aboutItem);
780         menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
781
return menu;
782     }
783
784     /**
785      * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu.
786      * The test for whether a separator should be added is done by checking for
787      * the existence of a preference matching the string
788      * useSeparator.MENUID.GROUPID that is set to <code>true</code>.
789      *
790      * @param menu
791      * the menu to add to
792      * @param groupId
793      * the group id for the added separator or group marker
794      */

795     private void addSeparatorOrGroupMarker(MenuManager menu, String JavaDoc groupId) {
796         String JavaDoc prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
797
boolean addExtraSeparators = IDEWorkbenchPlugin.getDefault()
798                 .getPreferenceStore().getBoolean(prefId);
799         if (addExtraSeparators) {
800             menu.add(new Separator(groupId));
801         } else {
802             menu.add(new GroupMarker(groupId));
803         }
804     }
805     
806     /**
807      * Disposes any resources and unhooks any listeners that are no longer needed.
808      * Called when the window is closed.
809      */

810     public void dispose() {
811         if (isDisposed) {
812             return;
813         }
814         isDisposed = true;
815         IMenuService menuService = (IMenuService) window.getService(IMenuService.class);
816         menuService.releaseContributions(coolbarPopupMenuManager);
817         coolbarPopupMenuManager.dispose();
818         
819         getActionBarConfigurer().getStatusLineManager().remove(statusLineItem);
820         if (pageListener != null) {
821             window.removePageListener(pageListener);
822             pageListener = null;
823         }
824         if (prefListener != null) {
825             ResourcesPlugin.getPlugin().getPluginPreferences()
826                     .removePropertyChangeListener(prefListener);
827             prefListener = null;
828         }
829         if (propPrefListener != null) {
830             WorkbenchPlugin.getDefault().getPreferenceStore()
831                     .removePropertyChangeListener(propPrefListener);
832             propPrefListener = null;
833         }
834         if (resourceListener != null) {
835             ResourcesPlugin.getWorkspace().removeResourceChangeListener(resourceListener);
836             resourceListener = null;
837         }
838
839         pinEditorContributionItem.dispose();
840         showInQuickMenu.dispose();
841         newQuickMenu.dispose();
842 // searchComboItem.dispose();
843

844         // null out actions to make leak debugging easier
845
closeAction = null;
846         closeAllAction = null;
847         closeAllSavedAction = null;
848         closeOthersAction = null;
849         saveAction = null;
850         saveAllAction = null;
851         newWindowAction = null;
852         newEditorAction = null;
853         helpContentsAction = null;
854         helpSearchAction = null;
855         dynamicHelpAction = null;
856         aboutAction = null;
857         openPreferencesAction = null;
858         saveAsAction = null;
859         hideShowEditorAction = null;
860         savePerspectiveAction = null;
861         resetPerspectiveAction = null;
862         editActionSetAction = null;
863         closePerspAction = null;
864         lockToolBarAction = null;
865         closeAllPerspsAction = null;
866         showViewMenuAction = null;
867         showPartPaneMenuAction = null;
868         nextPartAction = null;
869         prevPartAction = null;
870         nextEditorAction = null;
871         prevEditorAction = null;
872         nextPerspectiveAction = null;
873         prevPerspectiveAction = null;
874         activateEditorAction = null;
875         maximizePartAction = null;
876         minimizePartAction = null;
877         switchToEditorAction = null;
878         quickAccessAction = null;
879         backwardHistoryAction = null;
880         forwardHistoryAction = null;
881         undoAction = null;
882         redoAction = null;
883         cutAction = null;
884         copyAction = null;
885         pasteAction = null;
886         deleteAction = null;
887         selectAllAction = null;
888         findAction = null;
889         printAction = null;
890         revertAction = null;
891         refreshAction = null;
892         propertiesAction = null;
893         quitAction = null;
894         moveAction = null;
895         renameAction = null;
896         goIntoAction = null;
897         backAction = null;
898         forwardAction = null;
899         upAction = null;
900         nextAction = null;
901         previousAction = null;
902         openWorkspaceAction = null;
903         projectPropertyDialogAction = null;
904         newWizardAction = null;
905         newWizardDropDownAction = null;
906         importResourcesAction = null;
907         exportResourcesAction = null;
908         buildAllAction = null;
909         cleanAction = null;
910         toggleAutoBuildAction = null;
911         buildWorkingSetMenu = null;
912         quickStartAction = null;
913         tipsAndTricksAction = null;
914         showInQuickMenu = null;
915         newQuickMenu = null;
916         addBookmarkAction = null;
917         addTaskAction = null;
918         buildProjectAction = null;
919         openProjectAction = null;
920         closeProjectAction = null;
921         newWizardMenu = null;
922         pinEditorContributionItem = null;
923 // searchComboItem = null;
924
statusLineItem = null;
925         prefListener = null;
926         propPrefListener = null;
927         introAction = null;
928         
929         super.dispose();
930     }
931
932     void updateModeLine(final String JavaDoc text) {
933         statusLineItem.setText(text);
934     }
935
936     /**
937      * Returns true if the menu with the given ID should
938      * be considered as an OLE container menu. Container menus
939      * are preserved in OLE menu merging.
940      */

941     public boolean isApplicationMenu(String JavaDoc menuId) {
942         if (menuId.equals(IWorkbenchActionConstants.M_FILE)) {
943             return true;
944         }
945         if (menuId.equals(IWorkbenchActionConstants.M_WINDOW)) {
946             return true;
947         }
948         return false;
949     }
950
951     /**
952      * Return whether or not given id matches the id of the coolitems that
953      * the workbench creates.
954      */

955     public boolean isWorkbenchCoolItemId(String JavaDoc id) {
956         if (IWorkbenchActionConstants.TOOLBAR_FILE.equalsIgnoreCase(id)) {
957             return true;
958         }
959         if (IWorkbenchActionConstants.TOOLBAR_NAVIGATE.equalsIgnoreCase(id)) {
960             return true;
961         }
962         return false;
963     }
964
965     /**
966      * Fills the status line with the workbench contribution items.
967      */

968     protected void fillStatusLine(IStatusLineManager statusLine) {
969         statusLine.add(statusLineItem);
970     }
971
972     /**
973      * Creates actions (and contribution items) for the menu bar, toolbar and status line.
974      */

975     protected void makeActions(final IWorkbenchWindow window) {
976
977         // @issue should obtain from ConfigurationItemFactory
978
statusLineItem = new StatusLineContributionItem("ModeContributionItem"); //$NON-NLS-1$
979

980         newWizardAction = ActionFactory.NEW.create(window);
981         register(newWizardAction);
982
983         newWizardDropDownAction = IDEActionFactory.NEW_WIZARD_DROP_DOWN
984                 .create(window);
985         register(newWizardDropDownAction);
986
987         importResourcesAction = ActionFactory.IMPORT.create(window);
988         register(importResourcesAction);
989
990         exportResourcesAction = ActionFactory.EXPORT.create(window);
991         register(exportResourcesAction);
992         
993         buildAllAction = IDEActionFactory.BUILD.create(window);
994         register(buildAllAction);
995
996         cleanAction = IDEActionFactory.BUILD_CLEAN.create(window);
997         register(cleanAction);
998
999         toggleAutoBuildAction = IDEActionFactory.BUILD_AUTOMATICALLY
1000                .create(window);
1001        register(toggleAutoBuildAction);
1002
1003        saveAction = ActionFactory.SAVE.create(window);
1004        register(saveAction);
1005
1006        saveAsAction = ActionFactory.SAVE_AS.create(window);
1007        register(saveAsAction);
1008
1009        saveAllAction = ActionFactory.SAVE_ALL.create(window);
1010        register(saveAllAction);
1011        
1012        newWindowAction = ActionFactory.OPEN_NEW_WINDOW.create(getWindow());
1013        newWindowAction.setText(IDEWorkbenchMessages.Workbench_openNewWindow);
1014        register(newWindowAction);
1015
1016        newEditorAction = ActionFactory.NEW_EDITOR.create(window);
1017        register(newEditorAction);
1018
1019        undoAction = ActionFactory.UNDO.create(window);
1020        register(undoAction);
1021
1022        redoAction = ActionFactory.REDO.create(window);
1023        register(redoAction);
1024
1025        cutAction = ActionFactory.CUT.create(window);
1026        register(cutAction);
1027
1028        copyAction = ActionFactory.COPY.create(window);
1029        register(copyAction);
1030
1031        pasteAction = ActionFactory.PASTE.create(window);
1032        register(pasteAction);
1033
1034        printAction = ActionFactory.PRINT.create(window);
1035        register(printAction);
1036
1037        selectAllAction = ActionFactory.SELECT_ALL.create(window);
1038        register(selectAllAction);
1039
1040        findAction = ActionFactory.FIND.create(window);
1041        register(findAction);
1042
1043        closeAction = ActionFactory.CLOSE.create(window);
1044        register(closeAction);
1045
1046        closeAllAction = ActionFactory.CLOSE_ALL.create(window);
1047        register(closeAllAction);
1048
1049        closeOthersAction = ActionFactory.CLOSE_OTHERS.create(window);
1050        register(closeOthersAction);
1051
1052        closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED.create(window);
1053        register(closeAllSavedAction);
1054
1055        helpContentsAction = ActionFactory.HELP_CONTENTS.create(window);
1056        register(helpContentsAction);
1057
1058        helpSearchAction = ActionFactory.HELP_SEARCH.create(window);
1059        register(helpSearchAction);
1060        
1061        dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);
1062        register(dynamicHelpAction);
1063        
1064        aboutAction = ActionFactory.ABOUT.create(window);
1065        aboutAction
1066                .setImageDescriptor(IDEInternalWorkbenchImages
1067                        .getImageDescriptor(IDEInternalWorkbenchImages.IMG_OBJS_DEFAULT_PROD));
1068        register(aboutAction);
1069
1070        openPreferencesAction = ActionFactory.PREFERENCES.create(window);
1071        register(openPreferencesAction);
1072
1073        addBookmarkAction = IDEActionFactory.BOOKMARK.create(window);
1074        register(addBookmarkAction);
1075
1076        addTaskAction = IDEActionFactory.ADD_TASK.create(window);
1077        register(addTaskAction);
1078
1079        deleteAction = ActionFactory.DELETE.create(window);
1080        register(deleteAction);
1081
1082        makeFeatureDependentActions(window);
1083
1084        // Actions for invisible accelerators
1085
showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
1086        register(showViewMenuAction);
1087
1088        showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU
1089                .create(window);
1090        register(showPartPaneMenuAction);
1091
1092        nextEditorAction = ActionFactory.NEXT_EDITOR.create(window);
1093        register(nextEditorAction);
1094        prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create(window);
1095        register(prevEditorAction);
1096        ActionFactory.linkCycleActionPair(nextEditorAction, prevEditorAction);
1097
1098        nextPartAction = ActionFactory.NEXT_PART.create(window);
1099        register(nextPartAction);
1100        prevPartAction = ActionFactory.PREVIOUS_PART.create(window);
1101        register(prevPartAction);
1102        ActionFactory.linkCycleActionPair(nextPartAction, prevPartAction);
1103
1104        nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE
1105                .create(window);
1106        register(nextPerspectiveAction);
1107        prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE
1108                .create(window);
1109        register(prevPerspectiveAction);
1110        ActionFactory.linkCycleActionPair(nextPerspectiveAction,
1111                prevPerspectiveAction);
1112
1113        activateEditorAction = ActionFactory.ACTIVATE_EDITOR
1114                .create(window);
1115        register(activateEditorAction);
1116
1117        maximizePartAction = ActionFactory.MAXIMIZE.create(window);
1118        register(maximizePartAction);
1119
1120        minimizePartAction = ActionFactory.MINIMIZE.create(window);
1121        register(minimizePartAction);
1122        
1123        switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS
1124                .create(window);
1125        register(switchToEditorAction);
1126
1127        workbookEditorsAction = ActionFactory.SHOW_WORKBOOK_EDITORS
1128                .create(window);
1129        register(workbookEditorsAction);
1130        
1131        quickAccessAction = ActionFactory.SHOW_QUICK_ACCESS
1132            .create(window);
1133
1134        hideShowEditorAction = ActionFactory.SHOW_EDITOR.create(window);
1135        register(hideShowEditorAction);
1136        savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE
1137                .create(window);
1138        register(savePerspectiveAction);
1139        editActionSetAction = ActionFactory.EDIT_ACTION_SETS
1140                .create(window);
1141        register(editActionSetAction);
1142        lockToolBarAction = ActionFactory.LOCK_TOOL_BAR.create(window);
1143        register(lockToolBarAction);
1144        resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE
1145                .create(window);
1146        register(resetPerspectiveAction);
1147        closePerspAction = ActionFactory.CLOSE_PERSPECTIVE.create(window);
1148        register(closePerspAction);
1149        closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES
1150                .create(window);
1151        register(closeAllPerspsAction);
1152
1153        forwardHistoryAction = ActionFactory.FORWARD_HISTORY
1154                .create(window);
1155        register(forwardHistoryAction);
1156
1157        backwardHistoryAction = ActionFactory.BACKWARD_HISTORY
1158                .create(window);
1159        register(backwardHistoryAction);
1160
1161        revertAction = ActionFactory.REVERT.create(window);
1162        register(revertAction);
1163
1164        refreshAction = ActionFactory.REFRESH.create(window);
1165        register(refreshAction);
1166
1167        propertiesAction = ActionFactory.PROPERTIES.create(window);
1168        register(propertiesAction);
1169
1170        quitAction = ActionFactory.QUIT.create(window);
1171        register(quitAction);
1172
1173        moveAction = ActionFactory.MOVE.create(window);
1174        register(moveAction);
1175
1176        renameAction = ActionFactory.RENAME.create(window);
1177        register(renameAction);
1178
1179        goIntoAction = ActionFactory.GO_INTO.create(window);
1180        register(goIntoAction);
1181
1182        backAction = ActionFactory.BACK.create(window);
1183        register(backAction);
1184
1185        forwardAction = ActionFactory.FORWARD.create(window);
1186        register(forwardAction);
1187
1188        upAction = ActionFactory.UP.create(window);
1189        register(upAction);
1190
1191        nextAction = ActionFactory.NEXT.create(window);
1192        nextAction
1193                .setImageDescriptor(IDEInternalWorkbenchImages
1194                        .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV));
1195        register(nextAction);
1196
1197        previousAction = ActionFactory.PREVIOUS.create(window);
1198        previousAction
1199                .setImageDescriptor(IDEInternalWorkbenchImages
1200                        .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV));
1201        register(previousAction);
1202
1203        buildProjectAction = IDEActionFactory.BUILD_PROJECT.create(window);
1204        register(buildProjectAction);
1205
1206        openProjectAction = IDEActionFactory.OPEN_PROJECT.create(window);
1207        register(openProjectAction);
1208
1209        closeProjectAction = IDEActionFactory.CLOSE_PROJECT.create(window);
1210        register(closeProjectAction);
1211
1212        openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE
1213                .create(window);
1214        register(openWorkspaceAction);
1215
1216        projectPropertyDialogAction = IDEActionFactory.OPEN_PROJECT_PROPERTIES
1217                .create(window);
1218        register(projectPropertyDialogAction);
1219
1220        if (window.getWorkbench().getIntroManager().hasIntro()) {
1221            introAction = ActionFactory.INTRO.create(window);
1222            register(introAction);
1223        }
1224
1225        String JavaDoc showInQuickMenuId = "org.eclipse.ui.navigate.showInQuickMenu"; //$NON-NLS-1$
1226
showInQuickMenu = new QuickMenuAction(showInQuickMenuId) {
1227            protected void fillMenu(IMenuManager menu) {
1228                menu.add(ContributionItemFactory.VIEWS_SHOW_IN
1229                        .create(window));
1230            }
1231        };
1232        register(showInQuickMenu);
1233
1234        final String JavaDoc newQuickMenuId = "org.eclipse.ui.file.newQuickMenu"; //$NON-NLS-1$
1235
newQuickMenu = new QuickMenuAction(newQuickMenuId) {
1236            protected void fillMenu(IMenuManager menu) {
1237                menu.add(new NewWizardMenu(window));
1238            }
1239        };
1240        register(newQuickMenu);
1241
1242        pinEditorContributionItem = ContributionItemFactory.PIN_EDITOR
1243                .create(window);
1244        
1245// searchComboItem = ContributionItemFactory.HELP_SEARCH.create(window);
1246
}
1247
1248    /**
1249     * Creates the feature-dependent actions for the menu bar.
1250     */

1251    private void makeFeatureDependentActions(IWorkbenchWindow window) {
1252        AboutInfo[] infos = null;
1253        
1254        IPreferenceStore prefs = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
1255
1256        // Optimization: avoid obtaining the about infos if the platform state is
1257
// unchanged from last time. See bug 75130 for details.
1258
String JavaDoc stateKey = "platformState"; //$NON-NLS-1$
1259
String JavaDoc prevState = prefs.getString(stateKey);
1260        String JavaDoc currentState = String.valueOf(Platform.getStateStamp());
1261        boolean sameState = currentState.equals(prevState);
1262        if (!sameState) {
1263            prefs.putValue(stateKey, currentState);
1264        }
1265        
1266        // See if a welcome page is specified.
1267
// Optimization: if welcome pages were found on a previous run, then just add the action.
1268
String JavaDoc quickStartKey = IDEActionFactory.QUICK_START.getId();
1269        String JavaDoc showQuickStart = prefs.getString(quickStartKey);
1270        if (sameState && "true".equals(showQuickStart)) { //$NON-NLS-1$
1271
quickStartAction = IDEActionFactory.QUICK_START.create(window);
1272            register(quickStartAction);
1273        }
1274        else if (sameState && "false".equals(showQuickStart)) { //$NON-NLS-1$
1275
// do nothing
1276
}
1277        else {
1278            // do the work
1279
infos = IDEWorkbenchPlugin.getDefault().getFeatureInfos();
1280            boolean found = hasWelcomePage(infos);
1281            prefs.setValue(quickStartKey, found);
1282            if (found) {
1283                quickStartAction = IDEActionFactory.QUICK_START.create(window);
1284                register(quickStartAction);
1285            }
1286        }
1287        
1288        // See if a tips and tricks page is specified.
1289
// Optimization: if tips and tricks were found on a previous run, then just add the action.
1290
String JavaDoc tipsAndTricksKey = IDEActionFactory.TIPS_AND_TRICKS.getId();
1291        String JavaDoc showTipsAndTricks = prefs.getString(tipsAndTricksKey);
1292        if (sameState && "true".equals(showTipsAndTricks)) { //$NON-NLS-1$
1293
tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS
1294                    .create(window);
1295            register(tipsAndTricksAction);
1296        }
1297        else if (sameState && "false".equals(showTipsAndTricks)) { //$NON-NLS-1$
1298
// do nothing
1299
}
1300        else {
1301            // do the work
1302
if (infos == null) {
1303                infos = IDEWorkbenchPlugin.getDefault().getFeatureInfos();
1304            }
1305            boolean found = hasTipsAndTricks(infos);
1306            prefs.setValue(tipsAndTricksKey, found);
1307            if (found) {
1308                tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS
1309                        .create(window);
1310                register(tipsAndTricksAction);
1311            }
1312        }
1313    }
1314
1315    /**
1316     * Returns whether any of the given infos have a welcome page.
1317     *
1318     * @param infos the infos
1319     * @return <code>true</code> if a welcome page was found, <code>false</code> if not
1320     */

1321    private boolean hasWelcomePage(AboutInfo[] infos) {
1322        for (int i = 0; i < infos.length; i++) {
1323            if (infos[i].getWelcomePageURL() != null) {
1324                return true;
1325            }
1326        }
1327        return false;
1328    }
1329
1330    /**
1331     * Returns whether any of the given infos have tips and tricks.
1332     *
1333     * @param infos the infos
1334     * @return <code>true</code> if tips and tricks were found, <code>false</code> if not
1335     */

1336    private boolean hasTipsAndTricks(AboutInfo[] infos) {
1337        for (int i = 0; i < infos.length; i++) {
1338            if (infos[i].getTipsAndTricksHref() != null) {
1339                return true;
1340            }
1341        }
1342        return false;
1343    }
1344
1345    /**
1346     * Update the build actions on the toolbar and menu bar based on the current
1347     * state of autobuild. This method can be called from any thread.
1348     *
1349     * @param immediately
1350     * <code>true</code> to update the actions immediately,
1351     * <code>false</code> to queue the update to be run in the
1352     * event loop
1353     */

1354    void updateBuildActions(boolean immediately) {
1355        // this can be triggered by property or resource change notifications
1356
Runnable JavaDoc update = new Runnable JavaDoc() {
1357            public void run() {
1358                if (isDisposed) {
1359                    return;
1360                }
1361                IWorkspace workspace = ResourcesPlugin.getWorkspace();
1362                IProject[] projects = workspace.getRoot().getProjects();
1363                boolean enabled = BuildUtilities.isEnabled(projects, IncrementalProjectBuilder.INCREMENTAL_BUILD);
1364                //update menu bar actions in project menu
1365
buildAllAction.setEnabled(enabled);
1366                buildProjectAction.setEnabled(enabled);
1367                toggleAutoBuildAction.setChecked(workspace.isAutoBuilding());
1368                cleanAction.setEnabled(BuildUtilities.isEnabled(projects, IncrementalProjectBuilder.CLEAN_BUILD));
1369        
1370                //update the cool bar build button
1371
ICoolBarManager coolBarManager = getActionBarConfigurer()
1372                        .getCoolBarManager();
1373                IContributionItem cbItem = coolBarManager
1374                        .find(IWorkbenchActionConstants.TOOLBAR_FILE);
1375                if (!(cbItem instanceof IToolBarContributionItem)) {
1376                    // This should not happen
1377
IDEWorkbenchPlugin.log("File toolbar contribution item is missing"); //$NON-NLS-1$
1378
return;
1379                }
1380                IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
1381                IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
1382                if (toolBarManager == null) {
1383                    // error if this happens, file toolbar assumed to always exist
1384
IDEWorkbenchPlugin.log("File toolbar is missing"); //$NON-NLS-1$
1385
return;
1386                }
1387                //add the build button if build actions are enabled, and remove it otherwise
1388
boolean found = toolBarManager.find(buildAllAction.getId()) != null;
1389                if (enabled && !found) {
1390                    toolBarManager.appendToGroup(IWorkbenchActionConstants.BUILD_GROUP,
1391                            buildAllAction);
1392                    toolBarManager.update(false);
1393                    toolBarItem.update(ICoolBarManager.SIZE);
1394                } else if (buildAllAction != null && found && !enabled) {
1395                    toolBarManager.remove(buildAllAction.getId());
1396                    toolBarManager.update(false);
1397                    toolBarItem.update(ICoolBarManager.SIZE);
1398                }
1399            }
1400        };
1401        if (immediately) {
1402            update.run();
1403        }
1404        else {
1405            // Dispatch the update to be run later in the UI thread.
1406
// This helps to reduce flicker if autobuild is being temporarily disabled programmatically.
1407
Shell shell = window.getShell();
1408            if (shell != null && !shell.isDisposed()) {
1409                shell.getDisplay().asyncExec(update);
1410            }
1411        }
1412    }
1413
1414    /**
1415     * Update the pin action's tool bar
1416     */

1417    void updatePinActionToolbar() {
1418
1419        ICoolBarManager coolBarManager = getActionBarConfigurer()
1420                .getCoolBarManager();
1421        IContributionItem cbItem = coolBarManager
1422                .find(IWorkbenchActionConstants.TOOLBAR_NAVIGATE);
1423        if (!(cbItem instanceof IToolBarContributionItem)) {
1424            // This should not happen
1425
IDEWorkbenchPlugin
1426                    .log("Navigation toolbar contribution item is missing"); //$NON-NLS-1$
1427
return;
1428        }
1429        IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
1430        IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
1431        if (toolBarManager == null) {
1432            // error if this happens, navigation toolbar assumed to always exist
1433
IDEWorkbenchPlugin.log("Navigate toolbar is missing"); //$NON-NLS-1$
1434
return;
1435        }
1436
1437        toolBarManager.update(false);
1438        toolBarItem.update(ICoolBarManager.SIZE);
1439    }
1440}
1441
Popular Tags