Source Code Cross Referenced for WorkbenchActionBuilder.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » internal » ide » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui ide » org.eclipse.ui.internal.ide 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*******************************************************************************
0002:         * Copyright (c) 2000, 2007 IBM Corporation and others.
0003:         * All rights reserved. This program and the accompanying materials
0004:         * are made available under the terms of the Eclipse Public License v1.0
0005:         * which accompanies this distribution, and is available at
0006:         * http://www.eclipse.org/legal/epl-v10.html
0007:         *
0008:         * Contributors:
0009:         *     IBM Corporation - initial API and implementation
0010:         *******************************************************************************/package org.eclipse.ui.internal.ide;
0011:
0012:        import org.eclipse.core.resources.IProject;
0013:        import org.eclipse.core.resources.IResourceChangeEvent;
0014:        import org.eclipse.core.resources.IResourceChangeListener;
0015:        import org.eclipse.core.resources.IResourceDelta;
0016:        import org.eclipse.core.resources.IWorkspace;
0017:        import org.eclipse.core.resources.IncrementalProjectBuilder;
0018:        import org.eclipse.core.resources.ResourcesPlugin;
0019:        import org.eclipse.core.runtime.Platform;
0020:        import org.eclipse.core.runtime.Preferences;
0021:        import org.eclipse.jface.action.ActionContributionItem;
0022:        import org.eclipse.jface.action.GroupMarker;
0023:        import org.eclipse.jface.action.IAction;
0024:        import org.eclipse.jface.action.IContributionItem;
0025:        import org.eclipse.jface.action.ICoolBarManager;
0026:        import org.eclipse.jface.action.IMenuManager;
0027:        import org.eclipse.jface.action.IStatusLineManager;
0028:        import org.eclipse.jface.action.IToolBarManager;
0029:        import org.eclipse.jface.action.MenuManager;
0030:        import org.eclipse.jface.action.Separator;
0031:        import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
0032:        import org.eclipse.jface.preference.IPreferenceStore;
0033:        import org.eclipse.jface.util.IPropertyChangeListener;
0034:        import org.eclipse.jface.util.PropertyChangeEvent;
0035:        import org.eclipse.swt.SWT;
0036:        import org.eclipse.swt.widgets.Shell;
0037:        import org.eclipse.ui.IPageListener;
0038:        import org.eclipse.ui.IWorkbenchActionConstants;
0039:        import org.eclipse.ui.IWorkbenchPage;
0040:        import org.eclipse.ui.IWorkbenchWindow;
0041:        import org.eclipse.ui.actions.ActionFactory;
0042:        import org.eclipse.ui.actions.BuildAction;
0043:        import org.eclipse.ui.actions.ContributionItemFactory;
0044:        import org.eclipse.ui.actions.NewWizardMenu;
0045:        import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
0046:        import org.eclipse.ui.application.ActionBarAdvisor;
0047:        import org.eclipse.ui.application.IActionBarConfigurer;
0048:        import org.eclipse.ui.ide.IDEActionFactory;
0049:        import org.eclipse.ui.ide.IIDEActionConstants;
0050:        import org.eclipse.ui.internal.IPreferenceConstants;
0051:        import org.eclipse.ui.internal.WorkbenchPlugin;
0052:        import org.eclipse.ui.internal.ide.actions.BuildSetMenu;
0053:        import org.eclipse.ui.internal.ide.actions.BuildUtilities;
0054:        import org.eclipse.ui.internal.ide.actions.QuickMenuAction;
0055:        import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault;
0056:        import org.eclipse.ui.internal.provisional.application.IActionBarConfigurer2;
0057:        import org.eclipse.ui.internal.util.StatusLineContributionItem;
0058:        import org.eclipse.ui.menus.IMenuService;
0059:
0060:        /**
0061:         * Adds actions to a workbench window.
0062:         */
0063:        public final class WorkbenchActionBuilder extends ActionBarAdvisor {
0064:            private final IWorkbenchWindow window;
0065:
0066:            // generic actions
0067:            private IWorkbenchAction closeAction;
0068:
0069:            private IWorkbenchAction closeAllAction;
0070:
0071:            private IWorkbenchAction closeOthersAction;
0072:
0073:            private IWorkbenchAction closeAllSavedAction;
0074:
0075:            private IWorkbenchAction saveAction;
0076:
0077:            private IWorkbenchAction saveAllAction;
0078:
0079:            private IWorkbenchAction newWindowAction;
0080:
0081:            private IWorkbenchAction newEditorAction;
0082:
0083:            private IWorkbenchAction helpContentsAction;
0084:
0085:            private IWorkbenchAction helpSearchAction;
0086:
0087:            private IWorkbenchAction dynamicHelpAction;
0088:
0089:            private IWorkbenchAction aboutAction;
0090:
0091:            private IWorkbenchAction openPreferencesAction;
0092:
0093:            private IWorkbenchAction saveAsAction;
0094:
0095:            private IWorkbenchAction hideShowEditorAction;
0096:
0097:            private IWorkbenchAction savePerspectiveAction;
0098:
0099:            private IWorkbenchAction resetPerspectiveAction;
0100:
0101:            private IWorkbenchAction editActionSetAction;
0102:
0103:            private IWorkbenchAction closePerspAction;
0104:
0105:            private IWorkbenchAction lockToolBarAction;
0106:
0107:            private IWorkbenchAction closeAllPerspsAction;
0108:
0109:            private IWorkbenchAction showViewMenuAction;
0110:
0111:            private IWorkbenchAction showPartPaneMenuAction;
0112:
0113:            private IWorkbenchAction nextPartAction;
0114:
0115:            private IWorkbenchAction prevPartAction;
0116:
0117:            private IWorkbenchAction nextEditorAction;
0118:
0119:            private IWorkbenchAction prevEditorAction;
0120:
0121:            private IWorkbenchAction nextPerspectiveAction;
0122:
0123:            private IWorkbenchAction prevPerspectiveAction;
0124:
0125:            private IWorkbenchAction activateEditorAction;
0126:
0127:            private IWorkbenchAction maximizePartAction;
0128:
0129:            private IWorkbenchAction minimizePartAction;
0130:
0131:            private IWorkbenchAction switchToEditorAction;
0132:
0133:            private IWorkbenchAction workbookEditorsAction;
0134:
0135:            private IWorkbenchAction quickAccessAction;
0136:
0137:            private IWorkbenchAction backwardHistoryAction;
0138:
0139:            private IWorkbenchAction forwardHistoryAction;
0140:
0141:            // generic retarget actions
0142:            private IWorkbenchAction undoAction;
0143:
0144:            private IWorkbenchAction redoAction;
0145:
0146:            private IWorkbenchAction cutAction;
0147:
0148:            private IWorkbenchAction copyAction;
0149:
0150:            private IWorkbenchAction pasteAction;
0151:
0152:            private IWorkbenchAction deleteAction;
0153:
0154:            private IWorkbenchAction selectAllAction;
0155:
0156:            private IWorkbenchAction findAction;
0157:
0158:            private IWorkbenchAction printAction;
0159:
0160:            private IWorkbenchAction revertAction;
0161:
0162:            private IWorkbenchAction refreshAction;
0163:
0164:            private IWorkbenchAction propertiesAction;
0165:
0166:            private IWorkbenchAction quitAction;
0167:
0168:            private IWorkbenchAction moveAction;
0169:
0170:            private IWorkbenchAction renameAction;
0171:
0172:            private IWorkbenchAction goIntoAction;
0173:
0174:            private IWorkbenchAction backAction;
0175:
0176:            private IWorkbenchAction forwardAction;
0177:
0178:            private IWorkbenchAction upAction;
0179:
0180:            private IWorkbenchAction nextAction;
0181:
0182:            private IWorkbenchAction previousAction;
0183:
0184:            // IDE-specific actions
0185:            private IWorkbenchAction openWorkspaceAction;
0186:
0187:            private IWorkbenchAction projectPropertyDialogAction;
0188:
0189:            private IWorkbenchAction newWizardAction;
0190:
0191:            private IWorkbenchAction newWizardDropDownAction;
0192:
0193:            private IWorkbenchAction importResourcesAction;
0194:
0195:            private IWorkbenchAction exportResourcesAction;
0196:
0197:            IWorkbenchAction buildAllAction; // Incremental workspace build
0198:
0199:            private IWorkbenchAction cleanAction;
0200:
0201:            private IWorkbenchAction toggleAutoBuildAction;
0202:
0203:            MenuManager buildWorkingSetMenu;
0204:
0205:            private IWorkbenchAction quickStartAction;
0206:
0207:            private IWorkbenchAction tipsAndTricksAction;
0208:
0209:            private QuickMenuAction showInQuickMenu;
0210:
0211:            private QuickMenuAction newQuickMenu;
0212:
0213:            private IWorkbenchAction introAction;
0214:
0215:            // IDE-specific retarget actions
0216:            private IWorkbenchAction addBookmarkAction;
0217:
0218:            private IWorkbenchAction addTaskAction;
0219:
0220:            IWorkbenchAction buildProjectAction;
0221:
0222:            private IWorkbenchAction openProjectAction;
0223:
0224:            private IWorkbenchAction closeProjectAction;
0225:
0226:            // contribution items
0227:            // @issue should obtain from ContributionItemFactory
0228:            private NewWizardMenu newWizardMenu;
0229:
0230:            private IContributionItem pinEditorContributionItem;
0231:
0232:            //    private IContributionItem searchComboItem;
0233:
0234:            // @issue class is workbench internal
0235:            private StatusLineContributionItem statusLineItem;
0236:
0237:            private Preferences.IPropertyChangeListener prefListener;
0238:
0239:            // listener for the "close editors automatically"
0240:            // preference change
0241:            private IPropertyChangeListener propPrefListener;
0242:
0243:            private IPageListener pageListener;
0244:
0245:            private IResourceChangeListener resourceListener;
0246:
0247:            /**
0248:             * Indicates if the action builder has been disposed
0249:             */
0250:            private boolean isDisposed = false;
0251:
0252:            /**
0253:             * The coolbar context menu manager.
0254:             * @since 3.3
0255:             */
0256:            private MenuManager coolbarPopupMenuManager;
0257:
0258:            /**
0259:             * Constructs a new action builder which contributes actions
0260:             * to the given window.
0261:             * 
0262:             * @param configurer the action bar configurer for the window
0263:             */
0264:            public WorkbenchActionBuilder(IActionBarConfigurer configurer) {
0265:                super (configurer);
0266:                window = configurer.getWindowConfigurer().getWindow();
0267:            }
0268:
0269:            /**
0270:             * Returns the window to which this action builder is contributing.
0271:             */
0272:            private IWorkbenchWindow getWindow() {
0273:                return window;
0274:            }
0275:
0276:            /**
0277:             * Hooks listeners on the preference store and the window's page, perspective and selection services.
0278:             */
0279:            private void hookListeners() {
0280:
0281:                pageListener = new IPageListener() {
0282:                    public void pageActivated(IWorkbenchPage page) {
0283:                        // do nothing
0284:                    }
0285:
0286:                    public void pageClosed(IWorkbenchPage page) {
0287:                        // do nothing
0288:                    }
0289:
0290:                    public void pageOpened(IWorkbenchPage page) {
0291:                        // set default build handler -- can't be done until the shell is available
0292:                        IAction buildHandler = new BuildAction(page
0293:                                .getWorkbenchWindow().getShell(),
0294:                                IncrementalProjectBuilder.INCREMENTAL_BUILD);
0295:                        ((RetargetActionWithDefault) buildProjectAction)
0296:                                .setDefaultHandler(buildHandler);
0297:                    }
0298:                };
0299:                getWindow().addPageListener(pageListener);
0300:
0301:                prefListener = new Preferences.IPropertyChangeListener() {
0302:                    public void propertyChange(
0303:                            Preferences.PropertyChangeEvent event) {
0304:                        if (event.getProperty().equals(
0305:                                ResourcesPlugin.PREF_AUTO_BUILDING)) {
0306:                            updateBuildActions(false);
0307:                        }
0308:                    }
0309:                };
0310:                ResourcesPlugin.getPlugin().getPluginPreferences()
0311:                        .addPropertyChangeListener(prefListener);
0312:
0313:                // listener for the "close editors automatically"
0314:                // preference change
0315:                propPrefListener = new IPropertyChangeListener() {
0316:                    public void propertyChange(PropertyChangeEvent event) {
0317:                        if (event.getProperty().equals(
0318:                                IPreferenceConstants.REUSE_EDITORS_BOOLEAN)) {
0319:                            if (window.getShell() != null
0320:                                    && !window.getShell().isDisposed()) {
0321:                                // this property change notification could be from a non-ui thread
0322:                                window.getShell().getDisplay().syncExec(
0323:                                        new Runnable() {
0324:                                            public void run() {
0325:                                                updatePinActionToolbar();
0326:                                            }
0327:                                        });
0328:                            }
0329:                        }
0330:                    }
0331:                };
0332:                /*
0333:                 * In order to ensure that the pin action toolbar sets its size 
0334:                 * correctly, the pin action should set its visiblity before we call updatePinActionToolbar().
0335:                 * 
0336:                 * In other words we always want the PinActionContributionItem to be notified before the 
0337:                 * WorkbenchActionBuilder.
0338:                 */
0339:                WorkbenchPlugin.getDefault().getPreferenceStore()
0340:                        .addPropertyChangeListener(propPrefListener);
0341:                //listen for project description changes, which can affect enablement of build actions
0342:                resourceListener = new IResourceChangeListener() {
0343:                    public void resourceChanged(IResourceChangeEvent event) {
0344:                        IResourceDelta delta = event.getDelta();
0345:                        if (delta == null) {
0346:                            return;
0347:                        }
0348:                        IResourceDelta[] projectDeltas = delta
0349:                                .getAffectedChildren();
0350:                        for (int i = 0; i < projectDeltas.length; i++) {
0351:                            int kind = projectDeltas[i].getKind();
0352:                            //affected by projects being opened/closed or description changes
0353:                            boolean changed = (projectDeltas[i].getFlags() & (IResourceDelta.DESCRIPTION | IResourceDelta.OPEN)) != 0;
0354:                            if (kind != IResourceDelta.CHANGED || changed) {
0355:                                updateBuildActions(false);
0356:                                return;
0357:                            }
0358:                        }
0359:                    }
0360:                };
0361:                ResourcesPlugin.getWorkspace().addResourceChangeListener(
0362:                        resourceListener, IResourceChangeEvent.POST_CHANGE);
0363:            }
0364:
0365:            public void fillActionBars(int flags) {
0366:                super .fillActionBars(flags);
0367:                if ((flags & FILL_PROXY) == 0) {
0368:                    updateBuildActions(true);
0369:                    hookListeners();
0370:                }
0371:            }
0372:
0373:            /**
0374:             * Fills the coolbar with the workbench actions.
0375:             */
0376:            protected void fillCoolBar(ICoolBarManager coolBar) {
0377:
0378:                IActionBarConfigurer2 actionBarConfigurer = (IActionBarConfigurer2) getActionBarConfigurer();
0379:                { // Set up the context Menu
0380:                    coolbarPopupMenuManager = new MenuManager();
0381:                    coolbarPopupMenuManager.add(new ActionContributionItem(
0382:                            lockToolBarAction));
0383:                    coolbarPopupMenuManager.add(new ActionContributionItem(
0384:                            editActionSetAction));
0385:                    coolBar.setContextMenuManager(coolbarPopupMenuManager);
0386:                    IMenuService menuService = (IMenuService) window
0387:                            .getService(IMenuService.class);
0388:                    menuService.populateContributionManager(
0389:                            coolbarPopupMenuManager,
0390:                            "popup:windowCoolbarContextMenu"); //$NON-NLS-1$
0391:                }
0392:                coolBar.add(new GroupMarker(IIDEActionConstants.GROUP_FILE));
0393:                { // File Group
0394:                    IToolBarManager fileToolBar = actionBarConfigurer
0395:                            .createToolBarManager();
0396:                    fileToolBar.add(new Separator(
0397:                            IWorkbenchActionConstants.NEW_GROUP));
0398:                    fileToolBar.add(newWizardDropDownAction);
0399:                    fileToolBar.add(new GroupMarker(
0400:                            IWorkbenchActionConstants.NEW_EXT));
0401:                    fileToolBar.add(new GroupMarker(
0402:                            IWorkbenchActionConstants.SAVE_GROUP));
0403:                    fileToolBar.add(saveAction);
0404:                    fileToolBar.add(new GroupMarker(
0405:                            IWorkbenchActionConstants.SAVE_EXT));
0406:                    fileToolBar.add(printAction);
0407:                    fileToolBar.add(new GroupMarker(
0408:                            IWorkbenchActionConstants.PRINT_EXT));
0409:
0410:                    fileToolBar.add(new Separator(
0411:                            IWorkbenchActionConstants.BUILD_GROUP));
0412:                    fileToolBar.add(new GroupMarker(
0413:                            IWorkbenchActionConstants.BUILD_EXT));
0414:                    fileToolBar.add(new Separator(
0415:                            IWorkbenchActionConstants.MB_ADDITIONS));
0416:
0417:                    // Add to the cool bar manager
0418:                    coolBar.add(actionBarConfigurer
0419:                            .createToolBarContributionItem(fileToolBar,
0420:                                    IWorkbenchActionConstants.TOOLBAR_FILE));
0421:                }
0422:
0423:                coolBar.add(new GroupMarker(
0424:                        IWorkbenchActionConstants.MB_ADDITIONS));
0425:
0426:                coolBar.add(new GroupMarker(IIDEActionConstants.GROUP_NAV));
0427:                { // Navigate group
0428:                    IToolBarManager navToolBar = actionBarConfigurer
0429:                            .createToolBarManager();
0430:                    navToolBar.add(new Separator(
0431:                            IWorkbenchActionConstants.HISTORY_GROUP));
0432:                    navToolBar.add(new GroupMarker(
0433:                            IWorkbenchActionConstants.GROUP_APP));
0434:                    navToolBar.add(backwardHistoryAction);
0435:                    navToolBar.add(forwardHistoryAction);
0436:                    navToolBar.add(new Separator(
0437:                            IWorkbenchActionConstants.PIN_GROUP));
0438:                    navToolBar.add(pinEditorContributionItem);
0439:
0440:                    // Add to the cool bar manager
0441:                    coolBar
0442:                            .add(actionBarConfigurer
0443:                                    .createToolBarContributionItem(
0444:                                            navToolBar,
0445:                                            IWorkbenchActionConstants.TOOLBAR_NAVIGATE));
0446:                }
0447:
0448:                coolBar.add(new GroupMarker(
0449:                        IWorkbenchActionConstants.GROUP_EDITOR));
0450:
0451:                coolBar.add(new GroupMarker(
0452:                        IWorkbenchActionConstants.GROUP_HELP));
0453:
0454:                { // Help group
0455:                    IToolBarManager helpToolBar = actionBarConfigurer
0456:                            .createToolBarManager();
0457:                    helpToolBar.add(new Separator(
0458:                            IWorkbenchActionConstants.GROUP_HELP));
0459:                    //            helpToolBar.add(searchComboItem);
0460:                    // Add the group for applications to contribute
0461:                    helpToolBar.add(new GroupMarker(
0462:                            IWorkbenchActionConstants.GROUP_APP));
0463:                    // Add to the cool bar manager
0464:                    coolBar.add(actionBarConfigurer
0465:                            .createToolBarContributionItem(helpToolBar,
0466:                                    IWorkbenchActionConstants.TOOLBAR_HELP));
0467:                }
0468:
0469:            }
0470:
0471:            /**
0472:             * Fills the menu bar with the workbench actions.
0473:             */
0474:            protected void fillMenuBar(IMenuManager menuBar) {
0475:                menuBar.add(createFileMenu());
0476:                menuBar.add(createEditMenu());
0477:                menuBar.add(createNavigateMenu());
0478:                menuBar.add(createProjectMenu());
0479:                menuBar.add(new GroupMarker(
0480:                        IWorkbenchActionConstants.MB_ADDITIONS));
0481:                menuBar.add(createWindowMenu());
0482:                menuBar.add(createHelpMenu());
0483:            }
0484:
0485:            /**
0486:             * Creates and returns the File menu.
0487:             */
0488:            private MenuManager createFileMenu() {
0489:                MenuManager menu = new MenuManager(
0490:                        IDEWorkbenchMessages.Workbench_file,
0491:                        IWorkbenchActionConstants.M_FILE);
0492:                menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_START));
0493:                {
0494:                    // create the New submenu, using the same id for it as the New action
0495:                    String newText = IDEWorkbenchMessages.Workbench_new;
0496:                    String newId = ActionFactory.NEW.getId();
0497:                    MenuManager newMenu = new MenuManager(newText, newId) {
0498:                        public String getMenuText() {
0499:                            String result = super .getMenuText();
0500:                            if (newQuickMenu == null) {
0501:                                return result;
0502:                            }
0503:                            String shortCut = newQuickMenu.getShortCutString();
0504:                            if (shortCut == null) {
0505:                                return result;
0506:                            }
0507:                            return result + "\t" + shortCut; //$NON-NLS-1$
0508:                        }
0509:                    };
0510:                    newMenu.add(new Separator(newId));
0511:                    this .newWizardMenu = new NewWizardMenu(getWindow());
0512:                    newMenu.add(this .newWizardMenu);
0513:                    newMenu.add(new Separator(
0514:                            IWorkbenchActionConstants.MB_ADDITIONS));
0515:                    menu.add(newMenu);
0516:                }
0517:
0518:                menu.add(new GroupMarker(IWorkbenchActionConstants.NEW_EXT));
0519:                menu.add(new Separator());
0520:
0521:                menu.add(closeAction);
0522:                menu.add(closeAllAction);
0523:                //		menu.add(closeAllSavedAction);
0524:                menu.add(new GroupMarker(IWorkbenchActionConstants.CLOSE_EXT));
0525:                menu.add(new Separator());
0526:                menu.add(saveAction);
0527:                menu.add(saveAsAction);
0528:                menu.add(saveAllAction);
0529:                menu.add(revertAction);
0530:                menu.add(new Separator());
0531:                menu.add(moveAction);
0532:                menu.add(renameAction);
0533:                menu.add(refreshAction);
0534:
0535:                menu.add(new GroupMarker(IWorkbenchActionConstants.SAVE_EXT));
0536:                menu.add(new Separator());
0537:                menu.add(printAction);
0538:                menu.add(new GroupMarker(IWorkbenchActionConstants.PRINT_EXT));
0539:                menu.add(new Separator());
0540:                menu.add(openWorkspaceAction);
0541:                menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
0542:                menu.add(new Separator());
0543:                menu.add(importResourcesAction);
0544:                menu.add(exportResourcesAction);
0545:                menu.add(new GroupMarker(IWorkbenchActionConstants.IMPORT_EXT));
0546:                menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
0547:
0548:                menu.add(new Separator());
0549:                menu.add(propertiesAction);
0550:
0551:                menu.add(ContributionItemFactory.REOPEN_EDITORS
0552:                        .create(getWindow()));
0553:                menu.add(new GroupMarker(IWorkbenchActionConstants.MRU));
0554:                menu.add(new Separator());
0555:
0556:                // If we're on OS X we shouldn't show this command in the File menu. It
0557:                // should be invisible to the user. However, we should not remove it -
0558:                // the carbon UI code will do a search through our menu structure
0559:                // looking for it when Cmd-Q is invoked (or Quit is chosen from the
0560:                // application menu.
0561:                ActionContributionItem quitItem = new ActionContributionItem(
0562:                        quitAction);
0563:                quitItem.setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
0564:                menu.add(quitItem);
0565:                menu.add(new GroupMarker(IWorkbenchActionConstants.FILE_END));
0566:                return menu;
0567:            }
0568:
0569:            /**
0570:             * Creates and returns the Edit menu.
0571:             */
0572:            private MenuManager createEditMenu() {
0573:                MenuManager menu = new MenuManager(
0574:                        IDEWorkbenchMessages.Workbench_edit,
0575:                        IWorkbenchActionConstants.M_EDIT);
0576:                menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_START));
0577:
0578:                menu.add(undoAction);
0579:                menu.add(redoAction);
0580:                menu.add(new GroupMarker(IWorkbenchActionConstants.UNDO_EXT));
0581:                menu.add(new Separator());
0582:
0583:                menu.add(cutAction);
0584:                menu.add(copyAction);
0585:                menu.add(pasteAction);
0586:                menu.add(new GroupMarker(IWorkbenchActionConstants.CUT_EXT));
0587:                menu.add(new Separator());
0588:
0589:                menu.add(deleteAction);
0590:                menu.add(selectAllAction);
0591:                menu.add(new Separator());
0592:
0593:                menu.add(findAction);
0594:                menu.add(new GroupMarker(IWorkbenchActionConstants.FIND_EXT));
0595:                menu.add(new Separator());
0596:
0597:                menu.add(addBookmarkAction);
0598:                menu.add(addTaskAction);
0599:                menu.add(new GroupMarker(IWorkbenchActionConstants.ADD_EXT));
0600:
0601:                menu.add(new GroupMarker(IWorkbenchActionConstants.EDIT_END));
0602:                menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
0603:                return menu;
0604:            }
0605:
0606:            /**
0607:             * Creates and returns the Navigate menu.
0608:             */
0609:            private MenuManager createNavigateMenu() {
0610:                MenuManager menu = new MenuManager(
0611:                        IDEWorkbenchMessages.Workbench_navigate,
0612:                        IWorkbenchActionConstants.M_NAVIGATE);
0613:                menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_START));
0614:                menu.add(goIntoAction);
0615:
0616:                MenuManager goToSubMenu = new MenuManager(
0617:                        IDEWorkbenchMessages.Workbench_goTo,
0618:                        IWorkbenchActionConstants.GO_TO);
0619:                menu.add(goToSubMenu);
0620:                goToSubMenu.add(backAction);
0621:                goToSubMenu.add(forwardAction);
0622:                goToSubMenu.add(upAction);
0623:                goToSubMenu.add(new Separator(
0624:                        IWorkbenchActionConstants.MB_ADDITIONS));
0625:
0626:                menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT));
0627:                for (int i = 2; i < 5; ++i) {
0628:                    menu.add(new Separator(IWorkbenchActionConstants.OPEN_EXT
0629:                            + i));
0630:                }
0631:                menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT));
0632:                {
0633:
0634:                    MenuManager showInSubMenu = new MenuManager(
0635:                            IDEWorkbenchMessages.Workbench_showIn, "showIn") { //$NON-NLS-1$
0636:                        public String getMenuText() {
0637:                            String result = super .getMenuText();
0638:                            if (showInQuickMenu == null) {
0639:                                return null;
0640:                            }
0641:                            String shortCut = showInQuickMenu
0642:                                    .getShortCutString();
0643:                            if (shortCut == null) {
0644:                                return result;
0645:                            }
0646:                            return result + "\t" + shortCut; //$NON-NLS-1$
0647:                        }
0648:                    };
0649:                    showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN
0650:                            .create(getWindow()));
0651:                    menu.add(showInSubMenu);
0652:                }
0653:                for (int i = 2; i < 5; ++i) {
0654:                    menu.add(new Separator(IWorkbenchActionConstants.SHOW_EXT
0655:                            + i));
0656:                }
0657:                menu.add(new Separator());
0658:                menu.add(nextAction);
0659:                menu.add(previousAction);
0660:                menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
0661:                menu.add(new GroupMarker(IWorkbenchActionConstants.NAV_END));
0662:
0663:                //TBD: Location of this actions
0664:                menu.add(new Separator());
0665:                menu.add(backwardHistoryAction);
0666:                menu.add(forwardHistoryAction);
0667:                return menu;
0668:            }
0669:
0670:            /**
0671:             * Creates and returns the Project menu.
0672:             */
0673:            private MenuManager createProjectMenu() {
0674:                MenuManager menu = new MenuManager(
0675:                        IDEWorkbenchMessages.Workbench_project,
0676:                        IWorkbenchActionConstants.M_PROJECT);
0677:                menu.add(new Separator(IWorkbenchActionConstants.PROJ_START));
0678:
0679:                menu.add(openProjectAction);
0680:                menu.add(closeProjectAction);
0681:                menu.add(new GroupMarker(IWorkbenchActionConstants.OPEN_EXT));
0682:                menu.add(new Separator());
0683:                menu.add(buildAllAction);
0684:                menu.add(buildProjectAction);
0685:                addWorkingSetBuildActions(menu);
0686:                menu.add(cleanAction);
0687:                menu.add(toggleAutoBuildAction);
0688:                menu.add(new GroupMarker(IWorkbenchActionConstants.BUILD_EXT));
0689:                menu.add(new Separator());
0690:
0691:                menu
0692:                        .add(new GroupMarker(
0693:                                IWorkbenchActionConstants.MB_ADDITIONS));
0694:                menu.add(new GroupMarker(IWorkbenchActionConstants.PROJ_END));
0695:                menu.add(new Separator());
0696:                menu.add(projectPropertyDialogAction);
0697:                return menu;
0698:            }
0699:
0700:            /**
0701:             * Creates and returns the Window menu.
0702:             */
0703:            private MenuManager createWindowMenu() {
0704:                MenuManager menu = new MenuManager(
0705:                        IDEWorkbenchMessages.Workbench_window,
0706:                        IWorkbenchActionConstants.M_WINDOW);
0707:
0708:                menu.add(newWindowAction);
0709:                menu.add(newEditorAction);
0710:
0711:                menu.add(new Separator());
0712:                addPerspectiveActions(menu);
0713:                menu.add(new Separator());
0714:                addKeyboardShortcuts(menu);
0715:                menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
0716:
0717:                // See the comment for quit in createFileMenu
0718:                ActionContributionItem openPreferencesItem = new ActionContributionItem(
0719:                        openPreferencesAction);
0720:                openPreferencesItem
0721:                        .setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
0722:                menu.add(openPreferencesItem);
0723:
0724:                menu.add(ContributionItemFactory.OPEN_WINDOWS
0725:                        .create(getWindow()));
0726:                return menu;
0727:            }
0728:
0729:            /**
0730:             * Adds the perspective actions to the specified menu.
0731:             */
0732:            private void addPerspectiveActions(MenuManager menu) {
0733:                {
0734:                    String openText = IDEWorkbenchMessages.Workbench_openPerspective;
0735:                    MenuManager changePerspMenuMgr = new MenuManager(openText,
0736:                            "openPerspective"); //$NON-NLS-1$
0737:                    IContributionItem changePerspMenuItem = ContributionItemFactory.PERSPECTIVES_SHORTLIST
0738:                            .create(getWindow());
0739:                    changePerspMenuMgr.add(changePerspMenuItem);
0740:                    menu.add(changePerspMenuMgr);
0741:                }
0742:                {
0743:                    MenuManager showViewMenuMgr = new MenuManager(
0744:                            IDEWorkbenchMessages.Workbench_showView, "showView"); //$NON-NLS-1$
0745:                    IContributionItem showViewMenu = ContributionItemFactory.VIEWS_SHORTLIST
0746:                            .create(getWindow());
0747:                    showViewMenuMgr.add(showViewMenu);
0748:                    menu.add(showViewMenuMgr);
0749:                }
0750:                menu.add(new Separator());
0751:                menu.add(editActionSetAction);
0752:                menu.add(savePerspectiveAction);
0753:                menu.add(resetPerspectiveAction);
0754:                menu.add(closePerspAction);
0755:                menu.add(closeAllPerspsAction);
0756:            }
0757:
0758:            /**
0759:             * Adds the keyboard navigation submenu to the specified menu.
0760:             */
0761:            private void addWorkingSetBuildActions(MenuManager menu) {
0762:                buildWorkingSetMenu = new MenuManager(
0763:                        IDEWorkbenchMessages.Workbench_buildSet);
0764:                IContributionItem workingSetBuilds = new BuildSetMenu(window,
0765:                        getActionBarConfigurer());
0766:                buildWorkingSetMenu.add(workingSetBuilds);
0767:                menu.add(buildWorkingSetMenu);
0768:            }
0769:
0770:            /**
0771:             * Adds the keyboard navigation submenu to the specified menu.
0772:             */
0773:            private void addKeyboardShortcuts(MenuManager menu) {
0774:                MenuManager subMenu = new MenuManager(
0775:                        IDEWorkbenchMessages.Workbench_shortcuts, "shortcuts"); //$NON-NLS-1$
0776:                menu.add(subMenu);
0777:                subMenu.add(showPartPaneMenuAction);
0778:                subMenu.add(showViewMenuAction);
0779:                subMenu.add(quickAccessAction);
0780:                subMenu.add(new Separator());
0781:                subMenu.add(maximizePartAction);
0782:                subMenu.add(minimizePartAction);
0783:                subMenu.add(new Separator());
0784:                subMenu.add(activateEditorAction);
0785:                subMenu.add(nextEditorAction);
0786:                subMenu.add(prevEditorAction);
0787:                subMenu.add(switchToEditorAction);
0788:                subMenu.add(new Separator());
0789:                subMenu.add(nextPartAction);
0790:                subMenu.add(prevPartAction);
0791:                subMenu.add(new Separator());
0792:                subMenu.add(nextPerspectiveAction);
0793:                subMenu.add(prevPerspectiveAction);
0794:            }
0795:
0796:            /**
0797:             * Creates and returns the Help menu.
0798:             */
0799:            private MenuManager createHelpMenu() {
0800:                MenuManager menu = new MenuManager(
0801:                        IDEWorkbenchMessages.Workbench_help,
0802:                        IWorkbenchActionConstants.M_HELP);
0803:                addSeparatorOrGroupMarker(menu, "group.intro"); //$NON-NLS-1$
0804:                // See if a welcome or intro page is specified
0805:                if (introAction != null) {
0806:                    menu.add(introAction);
0807:                } else if (quickStartAction != null) {
0808:                    menu.add(quickStartAction);
0809:                }
0810:                menu.add(new GroupMarker("group.intro.ext")); //$NON-NLS-1$
0811:                addSeparatorOrGroupMarker(menu, "group.main"); //$NON-NLS-1$
0812:                menu.add(helpContentsAction);
0813:                menu.add(helpSearchAction);
0814:                menu.add(dynamicHelpAction);
0815:                addSeparatorOrGroupMarker(menu, "group.assist"); //$NON-NLS-1$
0816:                // See if a tips and tricks page is specified
0817:                if (tipsAndTricksAction != null) {
0818:                    menu.add(tipsAndTricksAction);
0819:                }
0820:                // HELP_START should really be the first item, but it was after
0821:                // quickStartAction and tipsAndTricksAction in 2.1.
0822:                menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_START));
0823:                menu.add(new GroupMarker("group.main.ext")); //$NON-NLS-1$
0824:                addSeparatorOrGroupMarker(menu, "group.tutorials"); //$NON-NLS-1$
0825:                addSeparatorOrGroupMarker(menu, "group.tools"); //$NON-NLS-1$
0826:                addSeparatorOrGroupMarker(menu, "group.updates"); //$NON-NLS-1$
0827:                menu.add(new GroupMarker(IWorkbenchActionConstants.HELP_END));
0828:                addSeparatorOrGroupMarker(menu,
0829:                        IWorkbenchActionConstants.MB_ADDITIONS);
0830:                // about should always be at the bottom
0831:                menu.add(new Separator("group.about")); //$NON-NLS-1$
0832:
0833:                ActionContributionItem aboutItem = new ActionContributionItem(
0834:                        aboutAction);
0835:                aboutItem.setVisible(!"carbon".equals(SWT.getPlatform())); //$NON-NLS-1$
0836:                menu.add(aboutItem);
0837:                menu.add(new GroupMarker("group.about.ext")); //$NON-NLS-1$
0838:                return menu;
0839:            }
0840:
0841:            /**
0842:             * Adds a <code>GroupMarker</code> or <code>Separator</code> to a menu.
0843:             * The test for whether a separator should be added is done by checking for
0844:             * the existence of a preference matching the string
0845:             * useSeparator.MENUID.GROUPID that is set to <code>true</code>.
0846:             * 
0847:             * @param menu
0848:             *            the menu to add to
0849:             * @param groupId
0850:             *            the group id for the added separator or group marker
0851:             */
0852:            private void addSeparatorOrGroupMarker(MenuManager menu,
0853:                    String groupId) {
0854:                String prefId = "useSeparator." + menu.getId() + "." + groupId; //$NON-NLS-1$ //$NON-NLS-2$
0855:                boolean addExtraSeparators = IDEWorkbenchPlugin.getDefault()
0856:                        .getPreferenceStore().getBoolean(prefId);
0857:                if (addExtraSeparators) {
0858:                    menu.add(new Separator(groupId));
0859:                } else {
0860:                    menu.add(new GroupMarker(groupId));
0861:                }
0862:            }
0863:
0864:            /**
0865:             * Disposes any resources and unhooks any listeners that are no longer needed.
0866:             * Called when the window is closed.
0867:             */
0868:            public void dispose() {
0869:                if (isDisposed) {
0870:                    return;
0871:                }
0872:                isDisposed = true;
0873:                IMenuService menuService = (IMenuService) window
0874:                        .getService(IMenuService.class);
0875:                menuService.releaseContributions(coolbarPopupMenuManager);
0876:                coolbarPopupMenuManager.dispose();
0877:
0878:                getActionBarConfigurer().getStatusLineManager().remove(
0879:                        statusLineItem);
0880:                if (pageListener != null) {
0881:                    window.removePageListener(pageListener);
0882:                    pageListener = null;
0883:                }
0884:                if (prefListener != null) {
0885:                    ResourcesPlugin.getPlugin().getPluginPreferences()
0886:                            .removePropertyChangeListener(prefListener);
0887:                    prefListener = null;
0888:                }
0889:                if (propPrefListener != null) {
0890:                    WorkbenchPlugin.getDefault().getPreferenceStore()
0891:                            .removePropertyChangeListener(propPrefListener);
0892:                    propPrefListener = null;
0893:                }
0894:                if (resourceListener != null) {
0895:                    ResourcesPlugin.getWorkspace()
0896:                            .removeResourceChangeListener(resourceListener);
0897:                    resourceListener = null;
0898:                }
0899:
0900:                pinEditorContributionItem.dispose();
0901:                showInQuickMenu.dispose();
0902:                newQuickMenu.dispose();
0903:                //        searchComboItem.dispose();
0904:
0905:                // null out actions to make leak debugging easier
0906:                closeAction = null;
0907:                closeAllAction = null;
0908:                closeAllSavedAction = null;
0909:                closeOthersAction = null;
0910:                saveAction = null;
0911:                saveAllAction = null;
0912:                newWindowAction = null;
0913:                newEditorAction = null;
0914:                helpContentsAction = null;
0915:                helpSearchAction = null;
0916:                dynamicHelpAction = null;
0917:                aboutAction = null;
0918:                openPreferencesAction = null;
0919:                saveAsAction = null;
0920:                hideShowEditorAction = null;
0921:                savePerspectiveAction = null;
0922:                resetPerspectiveAction = null;
0923:                editActionSetAction = null;
0924:                closePerspAction = null;
0925:                lockToolBarAction = null;
0926:                closeAllPerspsAction = null;
0927:                showViewMenuAction = null;
0928:                showPartPaneMenuAction = null;
0929:                nextPartAction = null;
0930:                prevPartAction = null;
0931:                nextEditorAction = null;
0932:                prevEditorAction = null;
0933:                nextPerspectiveAction = null;
0934:                prevPerspectiveAction = null;
0935:                activateEditorAction = null;
0936:                maximizePartAction = null;
0937:                minimizePartAction = null;
0938:                switchToEditorAction = null;
0939:                quickAccessAction = null;
0940:                backwardHistoryAction = null;
0941:                forwardHistoryAction = null;
0942:                undoAction = null;
0943:                redoAction = null;
0944:                cutAction = null;
0945:                copyAction = null;
0946:                pasteAction = null;
0947:                deleteAction = null;
0948:                selectAllAction = null;
0949:                findAction = null;
0950:                printAction = null;
0951:                revertAction = null;
0952:                refreshAction = null;
0953:                propertiesAction = null;
0954:                quitAction = null;
0955:                moveAction = null;
0956:                renameAction = null;
0957:                goIntoAction = null;
0958:                backAction = null;
0959:                forwardAction = null;
0960:                upAction = null;
0961:                nextAction = null;
0962:                previousAction = null;
0963:                openWorkspaceAction = null;
0964:                projectPropertyDialogAction = null;
0965:                newWizardAction = null;
0966:                newWizardDropDownAction = null;
0967:                importResourcesAction = null;
0968:                exportResourcesAction = null;
0969:                buildAllAction = null;
0970:                cleanAction = null;
0971:                toggleAutoBuildAction = null;
0972:                buildWorkingSetMenu = null;
0973:                quickStartAction = null;
0974:                tipsAndTricksAction = null;
0975:                showInQuickMenu = null;
0976:                newQuickMenu = null;
0977:                addBookmarkAction = null;
0978:                addTaskAction = null;
0979:                buildProjectAction = null;
0980:                openProjectAction = null;
0981:                closeProjectAction = null;
0982:                newWizardMenu = null;
0983:                pinEditorContributionItem = null;
0984:                //        searchComboItem = null;
0985:                statusLineItem = null;
0986:                prefListener = null;
0987:                propPrefListener = null;
0988:                introAction = null;
0989:
0990:                super .dispose();
0991:            }
0992:
0993:            void updateModeLine(final String text) {
0994:                statusLineItem.setText(text);
0995:            }
0996:
0997:            /**
0998:             * Returns true if the menu with the given ID should
0999:             * be considered as an OLE container menu. Container menus
1000:             * are preserved in OLE menu merging.
1001:             */
1002:            public boolean isApplicationMenu(String menuId) {
1003:                if (menuId.equals(IWorkbenchActionConstants.M_FILE)) {
1004:                    return true;
1005:                }
1006:                if (menuId.equals(IWorkbenchActionConstants.M_WINDOW)) {
1007:                    return true;
1008:                }
1009:                return false;
1010:            }
1011:
1012:            /**
1013:             * Return whether or not given id matches the id of the coolitems that
1014:             * the workbench creates.
1015:             */
1016:            public boolean isWorkbenchCoolItemId(String id) {
1017:                if (IWorkbenchActionConstants.TOOLBAR_FILE.equalsIgnoreCase(id)) {
1018:                    return true;
1019:                }
1020:                if (IWorkbenchActionConstants.TOOLBAR_NAVIGATE
1021:                        .equalsIgnoreCase(id)) {
1022:                    return true;
1023:                }
1024:                return false;
1025:            }
1026:
1027:            /**
1028:             * Fills the status line with the workbench contribution items.
1029:             */
1030:            protected void fillStatusLine(IStatusLineManager statusLine) {
1031:                statusLine.add(statusLineItem);
1032:            }
1033:
1034:            /**
1035:             * Creates actions (and contribution items) for the menu bar, toolbar and status line.
1036:             */
1037:            protected void makeActions(final IWorkbenchWindow window) {
1038:
1039:                // @issue should obtain from ConfigurationItemFactory
1040:                statusLineItem = new StatusLineContributionItem(
1041:                        "ModeContributionItem"); //$NON-NLS-1$
1042:
1043:                newWizardAction = ActionFactory.NEW.create(window);
1044:                register(newWizardAction);
1045:
1046:                newWizardDropDownAction = IDEActionFactory.NEW_WIZARD_DROP_DOWN
1047:                        .create(window);
1048:                register(newWizardDropDownAction);
1049:
1050:                importResourcesAction = ActionFactory.IMPORT.create(window);
1051:                register(importResourcesAction);
1052:
1053:                exportResourcesAction = ActionFactory.EXPORT.create(window);
1054:                register(exportResourcesAction);
1055:
1056:                buildAllAction = IDEActionFactory.BUILD.create(window);
1057:                register(buildAllAction);
1058:
1059:                cleanAction = IDEActionFactory.BUILD_CLEAN.create(window);
1060:                register(cleanAction);
1061:
1062:                toggleAutoBuildAction = IDEActionFactory.BUILD_AUTOMATICALLY
1063:                        .create(window);
1064:                register(toggleAutoBuildAction);
1065:
1066:                saveAction = ActionFactory.SAVE.create(window);
1067:                register(saveAction);
1068:
1069:                saveAsAction = ActionFactory.SAVE_AS.create(window);
1070:                register(saveAsAction);
1071:
1072:                saveAllAction = ActionFactory.SAVE_ALL.create(window);
1073:                register(saveAllAction);
1074:
1075:                newWindowAction = ActionFactory.OPEN_NEW_WINDOW
1076:                        .create(getWindow());
1077:                newWindowAction
1078:                        .setText(IDEWorkbenchMessages.Workbench_openNewWindow);
1079:                register(newWindowAction);
1080:
1081:                newEditorAction = ActionFactory.NEW_EDITOR.create(window);
1082:                register(newEditorAction);
1083:
1084:                undoAction = ActionFactory.UNDO.create(window);
1085:                register(undoAction);
1086:
1087:                redoAction = ActionFactory.REDO.create(window);
1088:                register(redoAction);
1089:
1090:                cutAction = ActionFactory.CUT.create(window);
1091:                register(cutAction);
1092:
1093:                copyAction = ActionFactory.COPY.create(window);
1094:                register(copyAction);
1095:
1096:                pasteAction = ActionFactory.PASTE.create(window);
1097:                register(pasteAction);
1098:
1099:                printAction = ActionFactory.PRINT.create(window);
1100:                register(printAction);
1101:
1102:                selectAllAction = ActionFactory.SELECT_ALL.create(window);
1103:                register(selectAllAction);
1104:
1105:                findAction = ActionFactory.FIND.create(window);
1106:                register(findAction);
1107:
1108:                closeAction = ActionFactory.CLOSE.create(window);
1109:                register(closeAction);
1110:
1111:                closeAllAction = ActionFactory.CLOSE_ALL.create(window);
1112:                register(closeAllAction);
1113:
1114:                closeOthersAction = ActionFactory.CLOSE_OTHERS.create(window);
1115:                register(closeOthersAction);
1116:
1117:                closeAllSavedAction = ActionFactory.CLOSE_ALL_SAVED
1118:                        .create(window);
1119:                register(closeAllSavedAction);
1120:
1121:                helpContentsAction = ActionFactory.HELP_CONTENTS.create(window);
1122:                register(helpContentsAction);
1123:
1124:                helpSearchAction = ActionFactory.HELP_SEARCH.create(window);
1125:                register(helpSearchAction);
1126:
1127:                dynamicHelpAction = ActionFactory.DYNAMIC_HELP.create(window);
1128:                register(dynamicHelpAction);
1129:
1130:                aboutAction = ActionFactory.ABOUT.create(window);
1131:                aboutAction
1132:                        .setImageDescriptor(IDEInternalWorkbenchImages
1133:                                .getImageDescriptor(IDEInternalWorkbenchImages.IMG_OBJS_DEFAULT_PROD));
1134:                register(aboutAction);
1135:
1136:                openPreferencesAction = ActionFactory.PREFERENCES
1137:                        .create(window);
1138:                register(openPreferencesAction);
1139:
1140:                addBookmarkAction = IDEActionFactory.BOOKMARK.create(window);
1141:                register(addBookmarkAction);
1142:
1143:                addTaskAction = IDEActionFactory.ADD_TASK.create(window);
1144:                register(addTaskAction);
1145:
1146:                deleteAction = ActionFactory.DELETE.create(window);
1147:                register(deleteAction);
1148:
1149:                makeFeatureDependentActions(window);
1150:
1151:                // Actions for invisible accelerators
1152:                showViewMenuAction = ActionFactory.SHOW_VIEW_MENU
1153:                        .create(window);
1154:                register(showViewMenuAction);
1155:
1156:                showPartPaneMenuAction = ActionFactory.SHOW_PART_PANE_MENU
1157:                        .create(window);
1158:                register(showPartPaneMenuAction);
1159:
1160:                nextEditorAction = ActionFactory.NEXT_EDITOR.create(window);
1161:                register(nextEditorAction);
1162:                prevEditorAction = ActionFactory.PREVIOUS_EDITOR.create(window);
1163:                register(prevEditorAction);
1164:                ActionFactory.linkCycleActionPair(nextEditorAction,
1165:                        prevEditorAction);
1166:
1167:                nextPartAction = ActionFactory.NEXT_PART.create(window);
1168:                register(nextPartAction);
1169:                prevPartAction = ActionFactory.PREVIOUS_PART.create(window);
1170:                register(prevPartAction);
1171:                ActionFactory.linkCycleActionPair(nextPartAction,
1172:                        prevPartAction);
1173:
1174:                nextPerspectiveAction = ActionFactory.NEXT_PERSPECTIVE
1175:                        .create(window);
1176:                register(nextPerspectiveAction);
1177:                prevPerspectiveAction = ActionFactory.PREVIOUS_PERSPECTIVE
1178:                        .create(window);
1179:                register(prevPerspectiveAction);
1180:                ActionFactory.linkCycleActionPair(nextPerspectiveAction,
1181:                        prevPerspectiveAction);
1182:
1183:                activateEditorAction = ActionFactory.ACTIVATE_EDITOR
1184:                        .create(window);
1185:                register(activateEditorAction);
1186:
1187:                maximizePartAction = ActionFactory.MAXIMIZE.create(window);
1188:                register(maximizePartAction);
1189:
1190:                minimizePartAction = ActionFactory.MINIMIZE.create(window);
1191:                register(minimizePartAction);
1192:
1193:                switchToEditorAction = ActionFactory.SHOW_OPEN_EDITORS
1194:                        .create(window);
1195:                register(switchToEditorAction);
1196:
1197:                workbookEditorsAction = ActionFactory.SHOW_WORKBOOK_EDITORS
1198:                        .create(window);
1199:                register(workbookEditorsAction);
1200:
1201:                quickAccessAction = ActionFactory.SHOW_QUICK_ACCESS
1202:                        .create(window);
1203:
1204:                hideShowEditorAction = ActionFactory.SHOW_EDITOR.create(window);
1205:                register(hideShowEditorAction);
1206:                savePerspectiveAction = ActionFactory.SAVE_PERSPECTIVE
1207:                        .create(window);
1208:                register(savePerspectiveAction);
1209:                editActionSetAction = ActionFactory.EDIT_ACTION_SETS
1210:                        .create(window);
1211:                register(editActionSetAction);
1212:                lockToolBarAction = ActionFactory.LOCK_TOOL_BAR.create(window);
1213:                register(lockToolBarAction);
1214:                resetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE
1215:                        .create(window);
1216:                register(resetPerspectiveAction);
1217:                closePerspAction = ActionFactory.CLOSE_PERSPECTIVE
1218:                        .create(window);
1219:                register(closePerspAction);
1220:                closeAllPerspsAction = ActionFactory.CLOSE_ALL_PERSPECTIVES
1221:                        .create(window);
1222:                register(closeAllPerspsAction);
1223:
1224:                forwardHistoryAction = ActionFactory.FORWARD_HISTORY
1225:                        .create(window);
1226:                register(forwardHistoryAction);
1227:
1228:                backwardHistoryAction = ActionFactory.BACKWARD_HISTORY
1229:                        .create(window);
1230:                register(backwardHistoryAction);
1231:
1232:                revertAction = ActionFactory.REVERT.create(window);
1233:                register(revertAction);
1234:
1235:                refreshAction = ActionFactory.REFRESH.create(window);
1236:                register(refreshAction);
1237:
1238:                propertiesAction = ActionFactory.PROPERTIES.create(window);
1239:                register(propertiesAction);
1240:
1241:                quitAction = ActionFactory.QUIT.create(window);
1242:                register(quitAction);
1243:
1244:                moveAction = ActionFactory.MOVE.create(window);
1245:                register(moveAction);
1246:
1247:                renameAction = ActionFactory.RENAME.create(window);
1248:                register(renameAction);
1249:
1250:                goIntoAction = ActionFactory.GO_INTO.create(window);
1251:                register(goIntoAction);
1252:
1253:                backAction = ActionFactory.BACK.create(window);
1254:                register(backAction);
1255:
1256:                forwardAction = ActionFactory.FORWARD.create(window);
1257:                register(forwardAction);
1258:
1259:                upAction = ActionFactory.UP.create(window);
1260:                register(upAction);
1261:
1262:                nextAction = ActionFactory.NEXT.create(window);
1263:                nextAction
1264:                        .setImageDescriptor(IDEInternalWorkbenchImages
1265:                                .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_NEXT_NAV));
1266:                register(nextAction);
1267:
1268:                previousAction = ActionFactory.PREVIOUS.create(window);
1269:                previousAction
1270:                        .setImageDescriptor(IDEInternalWorkbenchImages
1271:                                .getImageDescriptor(IDEInternalWorkbenchImages.IMG_ETOOL_PREVIOUS_NAV));
1272:                register(previousAction);
1273:
1274:                buildProjectAction = IDEActionFactory.BUILD_PROJECT
1275:                        .create(window);
1276:                register(buildProjectAction);
1277:
1278:                openProjectAction = IDEActionFactory.OPEN_PROJECT
1279:                        .create(window);
1280:                register(openProjectAction);
1281:
1282:                closeProjectAction = IDEActionFactory.CLOSE_PROJECT
1283:                        .create(window);
1284:                register(closeProjectAction);
1285:
1286:                openWorkspaceAction = IDEActionFactory.OPEN_WORKSPACE
1287:                        .create(window);
1288:                register(openWorkspaceAction);
1289:
1290:                projectPropertyDialogAction = IDEActionFactory.OPEN_PROJECT_PROPERTIES
1291:                        .create(window);
1292:                register(projectPropertyDialogAction);
1293:
1294:                if (window.getWorkbench().getIntroManager().hasIntro()) {
1295:                    introAction = ActionFactory.INTRO.create(window);
1296:                    register(introAction);
1297:                }
1298:
1299:                String showInQuickMenuId = "org.eclipse.ui.navigate.showInQuickMenu"; //$NON-NLS-1$
1300:                showInQuickMenu = new QuickMenuAction(showInQuickMenuId) {
1301:                    protected void fillMenu(IMenuManager menu) {
1302:                        menu.add(ContributionItemFactory.VIEWS_SHOW_IN
1303:                                .create(window));
1304:                    }
1305:                };
1306:                register(showInQuickMenu);
1307:
1308:                final String newQuickMenuId = "org.eclipse.ui.file.newQuickMenu"; //$NON-NLS-1$
1309:                newQuickMenu = new QuickMenuAction(newQuickMenuId) {
1310:                    protected void fillMenu(IMenuManager menu) {
1311:                        menu.add(new NewWizardMenu(window));
1312:                    }
1313:                };
1314:                register(newQuickMenu);
1315:
1316:                pinEditorContributionItem = ContributionItemFactory.PIN_EDITOR
1317:                        .create(window);
1318:
1319:                //        searchComboItem = ContributionItemFactory.HELP_SEARCH.create(window);
1320:            }
1321:
1322:            /**
1323:             * Creates the feature-dependent actions for the menu bar.
1324:             */
1325:            private void makeFeatureDependentActions(IWorkbenchWindow window) {
1326:                AboutInfo[] infos = null;
1327:
1328:                IPreferenceStore prefs = IDEWorkbenchPlugin.getDefault()
1329:                        .getPreferenceStore();
1330:
1331:                // Optimization: avoid obtaining the about infos if the platform state is
1332:                // unchanged from last time.  See bug 75130 for details.
1333:                String stateKey = "platformState"; //$NON-NLS-1$
1334:                String prevState = prefs.getString(stateKey);
1335:                String currentState = String.valueOf(Platform.getStateStamp());
1336:                boolean sameState = currentState.equals(prevState);
1337:                if (!sameState) {
1338:                    prefs.putValue(stateKey, currentState);
1339:                }
1340:
1341:                // See if a welcome page is specified.
1342:                // Optimization: if welcome pages were found on a previous run, then just add the action.
1343:                String quickStartKey = IDEActionFactory.QUICK_START.getId();
1344:                String showQuickStart = prefs.getString(quickStartKey);
1345:                if (sameState && "true".equals(showQuickStart)) { //$NON-NLS-1$
1346:                    quickStartAction = IDEActionFactory.QUICK_START
1347:                            .create(window);
1348:                    register(quickStartAction);
1349:                } else if (sameState && "false".equals(showQuickStart)) { //$NON-NLS-1$
1350:                    // do nothing
1351:                } else {
1352:                    // do the work
1353:                    infos = IDEWorkbenchPlugin.getDefault().getFeatureInfos();
1354:                    boolean found = hasWelcomePage(infos);
1355:                    prefs.setValue(quickStartKey, found);
1356:                    if (found) {
1357:                        quickStartAction = IDEActionFactory.QUICK_START
1358:                                .create(window);
1359:                        register(quickStartAction);
1360:                    }
1361:                }
1362:
1363:                // See if a tips and tricks page is specified.
1364:                // Optimization: if tips and tricks were found on a previous run, then just add the action.
1365:                String tipsAndTricksKey = IDEActionFactory.TIPS_AND_TRICKS
1366:                        .getId();
1367:                String showTipsAndTricks = prefs.getString(tipsAndTricksKey);
1368:                if (sameState && "true".equals(showTipsAndTricks)) { //$NON-NLS-1$
1369:                    tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS
1370:                            .create(window);
1371:                    register(tipsAndTricksAction);
1372:                } else if (sameState && "false".equals(showTipsAndTricks)) { //$NON-NLS-1$
1373:                    // do nothing
1374:                } else {
1375:                    // do the work
1376:                    if (infos == null) {
1377:                        infos = IDEWorkbenchPlugin.getDefault()
1378:                                .getFeatureInfos();
1379:                    }
1380:                    boolean found = hasTipsAndTricks(infos);
1381:                    prefs.setValue(tipsAndTricksKey, found);
1382:                    if (found) {
1383:                        tipsAndTricksAction = IDEActionFactory.TIPS_AND_TRICKS
1384:                                .create(window);
1385:                        register(tipsAndTricksAction);
1386:                    }
1387:                }
1388:            }
1389:
1390:            /**
1391:             * Returns whether any of the given infos have a welcome page.
1392:             * 
1393:             * @param infos the infos
1394:             * @return <code>true</code> if a welcome page was found, <code>false</code> if not
1395:             */
1396:            private boolean hasWelcomePage(AboutInfo[] infos) {
1397:                for (int i = 0; i < infos.length; i++) {
1398:                    if (infos[i].getWelcomePageURL() != null) {
1399:                        return true;
1400:                    }
1401:                }
1402:                return false;
1403:            }
1404:
1405:            /**
1406:             * Returns whether any of the given infos have tips and tricks.
1407:             * 
1408:             * @param infos the infos
1409:             * @return <code>true</code> if tips and tricks were found, <code>false</code> if not
1410:             */
1411:            private boolean hasTipsAndTricks(AboutInfo[] infos) {
1412:                for (int i = 0; i < infos.length; i++) {
1413:                    if (infos[i].getTipsAndTricksHref() != null) {
1414:                        return true;
1415:                    }
1416:                }
1417:                return false;
1418:            }
1419:
1420:            /**
1421:             * Update the build actions on the toolbar and menu bar based on the current
1422:             * state of autobuild. This method can be called from any thread.
1423:             * 
1424:             * @param immediately
1425:             *            <code>true</code> to update the actions immediately,
1426:             *            <code>false</code> to queue the update to be run in the
1427:             *            event loop
1428:             */
1429:            void updateBuildActions(boolean immediately) {
1430:                // this can be triggered by property or resource change notifications
1431:                Runnable update = new Runnable() {
1432:                    public void run() {
1433:                        if (isDisposed) {
1434:                            return;
1435:                        }
1436:                        IWorkspace workspace = ResourcesPlugin.getWorkspace();
1437:                        IProject[] projects = workspace.getRoot().getProjects();
1438:                        boolean enabled = BuildUtilities.isEnabled(projects,
1439:                                IncrementalProjectBuilder.INCREMENTAL_BUILD);
1440:                        //update menu bar actions in project menu
1441:                        buildAllAction.setEnabled(enabled);
1442:                        buildProjectAction.setEnabled(enabled);
1443:                        toggleAutoBuildAction.setChecked(workspace
1444:                                .isAutoBuilding());
1445:                        cleanAction.setEnabled(BuildUtilities
1446:                                .isEnabled(projects,
1447:                                        IncrementalProjectBuilder.CLEAN_BUILD));
1448:
1449:                        //update the cool bar build button
1450:                        ICoolBarManager coolBarManager = getActionBarConfigurer()
1451:                                .getCoolBarManager();
1452:                        IContributionItem cbItem = coolBarManager
1453:                                .find(IWorkbenchActionConstants.TOOLBAR_FILE);
1454:                        if (!(cbItem instanceof  IToolBarContributionItem)) {
1455:                            // This should not happen
1456:                            IDEWorkbenchPlugin
1457:                                    .log("File toolbar contribution item is missing"); //$NON-NLS-1$
1458:                            return;
1459:                        }
1460:                        IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
1461:                        IToolBarManager toolBarManager = toolBarItem
1462:                                .getToolBarManager();
1463:                        if (toolBarManager == null) {
1464:                            // error if this happens, file toolbar assumed to always exist
1465:                            IDEWorkbenchPlugin.log("File toolbar is missing"); //$NON-NLS-1$
1466:                            return;
1467:                        }
1468:                        //add the build button if build actions are enabled, and remove it otherwise
1469:                        boolean found = toolBarManager.find(buildAllAction
1470:                                .getId()) != null;
1471:                        if (enabled && !found) {
1472:                            toolBarManager.appendToGroup(
1473:                                    IWorkbenchActionConstants.BUILD_GROUP,
1474:                                    buildAllAction);
1475:                            toolBarManager.update(false);
1476:                            toolBarItem.update(ICoolBarManager.SIZE);
1477:                        } else if (buildAllAction != null && found && !enabled) {
1478:                            toolBarManager.remove(buildAllAction.getId());
1479:                            toolBarManager.update(false);
1480:                            toolBarItem.update(ICoolBarManager.SIZE);
1481:                        }
1482:                    }
1483:                };
1484:                if (immediately) {
1485:                    update.run();
1486:                } else {
1487:                    // Dispatch the update to be run later in the UI thread.
1488:                    // This helps to reduce flicker if autobuild is being temporarily disabled programmatically.
1489:                    Shell shell = window.getShell();
1490:                    if (shell != null && !shell.isDisposed()) {
1491:                        shell.getDisplay().asyncExec(update);
1492:                    }
1493:                }
1494:            }
1495:
1496:            /**
1497:             * Update the pin action's tool bar
1498:             */
1499:            void updatePinActionToolbar() {
1500:
1501:                ICoolBarManager coolBarManager = getActionBarConfigurer()
1502:                        .getCoolBarManager();
1503:                IContributionItem cbItem = coolBarManager
1504:                        .find(IWorkbenchActionConstants.TOOLBAR_NAVIGATE);
1505:                if (!(cbItem instanceof  IToolBarContributionItem)) {
1506:                    // This should not happen
1507:                    IDEWorkbenchPlugin
1508:                            .log("Navigation toolbar contribution item is missing"); //$NON-NLS-1$
1509:                    return;
1510:                }
1511:                IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
1512:                IToolBarManager toolBarManager = toolBarItem
1513:                        .getToolBarManager();
1514:                if (toolBarManager == null) {
1515:                    // error if this happens, navigation toolbar assumed to always exist
1516:                    IDEWorkbenchPlugin.log("Navigate toolbar is missing"); //$NON-NLS-1$
1517:                    return;
1518:                }
1519:
1520:                toolBarManager.update(false);
1521:                toolBarItem.update(ICoolBarManager.SIZE);
1522:            }
1523:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.