Source Code Cross Referenced for UDIGMenuBuilder.java in  » GIS » udig-1.1 » net » refractions » udig » ui » 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 » GIS » udig 1.1 » net.refractions.udig.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* uDig - User Friendly Desktop Internet GIS client
002:         * http://udig.refractions.net
003:         * (C) 2004, Refractions Research Inc.
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation;
008:         * version 2.1 of the License.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         */
015:        package net.refractions.udig.ui;
016:
017:        import java.io.Serializable;
018:        import java.util.ArrayList;
019:        import java.util.Collections;
020:        import java.util.Comparator;
021:        import java.util.List;
022:
023:        import net.refractions.udig.core.internal.ExtensionPointList;
024:        import net.refractions.udig.internal.ui.ImageConstants;
025:        import net.refractions.udig.internal.ui.Images;
026:        import net.refractions.udig.internal.ui.UiPlugin;
027:        import net.refractions.udig.ui.internal.Messages;
028:
029:        import org.eclipse.core.runtime.CoreException;
030:        import org.eclipse.core.runtime.IConfigurationElement;
031:        import org.eclipse.jface.action.Action;
032:        import org.eclipse.jface.action.ContributionItem;
033:        import org.eclipse.jface.action.GroupMarker;
034:        import org.eclipse.jface.action.IAction;
035:        import org.eclipse.jface.action.IContributionItem;
036:        import org.eclipse.jface.action.ICoolBarManager;
037:        import org.eclipse.jface.action.IMenuManager;
038:        import org.eclipse.jface.action.MenuManager;
039:        import org.eclipse.jface.action.Separator;
040:        import org.eclipse.jface.action.ToolBarContributionItem;
041:        import org.eclipse.jface.action.ToolBarManager;
042:        import org.eclipse.jface.internal.provisional.action.ToolBarContributionItem2;
043:        import org.eclipse.jface.resource.ImageDescriptor;
044:        import org.eclipse.jface.resource.ImageRegistry;
045:        import org.eclipse.jface.viewers.StructuredSelection;
046:        import org.eclipse.swt.SWT;
047:        import org.eclipse.swt.events.SelectionEvent;
048:        import org.eclipse.swt.events.SelectionListener;
049:        import org.eclipse.swt.graphics.Image;
050:        import org.eclipse.swt.widgets.Menu;
051:        import org.eclipse.swt.widgets.MenuItem;
052:        import org.eclipse.swt.widgets.ToolBar;
053:        import org.eclipse.swt.widgets.ToolItem;
054:        import org.eclipse.ui.IWorkbenchActionConstants;
055:        import org.eclipse.ui.IWorkbenchWindow;
056:        import org.eclipse.ui.IWorkbenchWindowActionDelegate;
057:        import org.eclipse.ui.actions.ActionFactory;
058:        import org.eclipse.ui.actions.ContributionItemFactory;
059:        import org.eclipse.ui.plugin.AbstractUIPlugin;
060:
061:        /**
062:         * This class builds the menus for the uDig application.
063:         * <p>
064:         * When uDig is run as a plugin, this class would need to be called by something other than the
065:         * WorkbenchAdvisor in order to setup the menus. Some of these menus might be possible to let
066:         * Eclipse manage through an extension point.
067:         * </p>
068:         * <p>
069:         * NewContribution should probably be moved to a factory class (e.g. UDIGContributionFactory). This
070:         * would be similar to the way ContributionItemFactory works for the "Open Perspecive" and "Show
071:         * View" submenus.
072:         * </p>
073:         * 
074:         * @author cole.markham
075:         * @since 1.0.1
076:         */
077:        public class UDIGMenuBuilder implements  MenuBuilder {
078:            private static final String NEW_ACTION_ID = "net.refractions.udig.ui.newObjectAction"; //$NON-NLS-1$
079:
080:            private static class NewObjectActionComparator implements 
081:                    Comparator<IConfigurationElement>, Serializable {
082:                /** long serialVersionUID field */
083:                private static final long serialVersionUID = 1L;
084:
085:                /**
086:                 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
087:                 */
088:                public int compare(IConfigurationElement arg0,
089:                        IConfigurationElement arg1) {
090:                    String id0 = arg0.getAttribute("id"); //$NON-NLS-1$
091:                    if (id0.equals("net.refractions.udig.project.ui.newLayer")) //$NON-NLS-1$
092:                        return -1;
093:                    String id1 = arg1.getAttribute("id"); //$NON-NLS-1$
094:                    if (id0.equals("net.refractions.udig.project.ui.newMap") && //$NON-NLS-1$
095:                            !id1
096:                                    .equals("net.refractions.udig.project.ui.newLayer")) //$NON-NLS-1$
097:                        return -1;
098:
099:                    return 1;
100:                }
101:
102:            }
103:
104:            /**
105:             * An item that parses the IConfigurationElement data for the newObjectAction extension point.
106:             * 
107:             * @author jones
108:             * @since 0.6.0
109:             */
110:            private static class NewItem {
111:                /** NewItem id field */
112:                public final String id;
113:                /** NewItem text field */
114:                public final String text;
115:                /** NewItem icon field */
116:                public final ImageDescriptor icon;
117:                /** NewItem element field */
118:                public final IConfigurationElement element;
119:                private IWorkbenchWindowActionDelegate delegate;
120:                private IWorkbenchWindow window;
121:
122:                /**
123:                 * Construct <code>UDIGActionBarAdvisor.NewContribution.NewItem</code>.
124:                 * 
125:                 * @param element The configuration element that holds the properties (from plugin.xml)
126:                 * @param window The window this action will operate in.
127:                 */
128:                public NewItem(IConfigurationElement element,
129:                        IWorkbenchWindow window) {
130:                    this .element = element;
131:                    this .text = element.getAttribute("label"); //$NON-NLS-1$
132:                    this .id = element.getAttribute("id"); //$NON-NLS-1$
133:                    String iconPath = element.getAttribute("icon"); //$NON-NLS-1$
134:                    if (iconPath != null) {
135:                        this .icon = AbstractUIPlugin.imageDescriptorFromPlugin(
136:                                element.getNamespaceIdentifier(), iconPath);
137:                    } else
138:                        this .icon = null;
139:                    this .window = window;
140:                }
141:
142:                /**
143:                 * DOCUMENT ME!!
144:                 */
145:                public void runAction() {
146:                    if (delegate == null) {
147:                        try {
148:                            delegate = (IWorkbenchWindowActionDelegate) element
149:                                    .createExecutableExtension("class"); //$NON-NLS-1$
150:                        } catch (CoreException e) {
151:                            UiPlugin.log(null, e);
152:                        }
153:                    }
154:                    if (delegate != null) {
155:                        delegate.init(window);
156:                        delegate.selectionChanged(null,
157:                                new StructuredSelection());
158:                        delegate.run(null);
159:                    }
160:                }
161:            }
162:
163:            /**
164:             * Contribution item that will add new actions to a drop down button
165:             * 
166:             * @author jeichar
167:             * @since 0.6.0
168:             */
169:            private static class NewContribution extends ContributionItem {
170:
171:                private ArrayList<NewItem> newItems;
172:                NewItem current;
173:
174:                /**
175:                 * Construct <code>UDIGActionBarAdvisor.NewContribution</code>.
176:                 * 
177:                 * @param window The window this action will operate in.
178:                 */
179:                public NewContribution(IWorkbenchWindow window) {
180:                    List<IConfigurationElement> extensions = ExtensionPointList
181:                            .getExtensionPointList(NEW_ACTION_ID);
182:                    Collections.sort(extensions,
183:                            new NewObjectActionComparator());
184:                    newItems = new ArrayList<NewItem>();
185:                    for (IConfigurationElement element : extensions) {
186:                        newItems.add(new NewItem(element, window));
187:                    }
188:                    if (newItems.size() > 0)
189:                        current = newItems.get(0);
190:                }
191:
192:                /**
193:                 * @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.ToolBar, int)
194:                 */
195:                @Override
196:                public void fill(final ToolBar parent, int index) {
197:                    ToolItem item = new ToolItem(parent, SWT.DROP_DOWN, index);
198:                    item.setImage(Images.get(ImageConstants.NEW_WIZ));
199:                    item.addSelectionListener(new SelectionListener() {
200:
201:                        protected ImageRegistry registry;
202:
203:                        public void widgetSelected(SelectionEvent e) {
204:                            widgetDefaultSelected(e);
205:                        }
206:
207:                        public void widgetDefaultSelected(SelectionEvent e) {
208:                            if (e.detail == SWT.ARROW) {
209:                                Menu menu = new Menu(parent);
210:                                registry = UiPlugin.getDefault()
211:                                        .getImageRegistry();
212:                                for (final NewItem newItem : newItems) {
213:                                    MenuItem menuItem = new MenuItem(menu,
214:                                            SWT.PUSH);
215:                                    if (newItem.text != null)
216:                                        menuItem.setText(newItem.text);
217:                                    menuItem.setImage(getImage(newItem.id,
218:                                            newItem.icon));
219:                                    menuItem
220:                                            .addSelectionListener(new SelectionListener() {
221:
222:                                                public void widgetSelected(
223:                                                        SelectionEvent se) {
224:                                                    widgetDefaultSelected(se);
225:                                                }
226:
227:                                                public void widgetDefaultSelected(
228:                                                        SelectionEvent se) {
229:                                                    current = newItem;
230:                                                    newItem.runAction();
231:                                                }
232:
233:                                            });
234:                                }
235:                                menu.setVisible(true);
236:                            } else {
237:                                if (current != null)
238:                                    current.runAction();
239:                            }
240:                        }
241:
242:                        private Image getImage(String id,
243:                                ImageDescriptor descriptor) {
244:                            if (registry.get(id) == null)
245:                                registry.put(id, descriptor);
246:                            return registry.get(id);
247:                        }
248:
249:                    });
250:                }
251:
252:            }
253:
254:            /**
255:             * @param menuBar
256:             * @param window The window that contains this menu
257:             */
258:            public void fillMenuBar(IMenuManager menuBar,
259:                    IWorkbenchWindow window) {
260:                IMenuManager fileMenu = menuBar
261:                        .findMenuUsingPath(IWorkbenchActionConstants.M_FILE);
262:                if (fileMenu == null) {
263:                    fileMenu = new MenuManager(
264:                            Messages.UDIGWorkbenchAdvisor_file,
265:                            IWorkbenchActionConstants.M_FILE);
266:                    if (menuBar.getItems().length > 0) {
267:                        menuBar.insertBefore(menuBar.getItems()[0].getId(),
268:                                fileMenu);
269:                    } else {
270:                        menuBar.add(fileMenu);
271:                    }
272:                }
273:                IMenuManager editMenu = menuBar
274:                        .findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
275:                if (editMenu == null) {
276:                    editMenu = new MenuManager(
277:                            Messages.UDIGWorkbenchAdvisor_edit,
278:                            IWorkbenchActionConstants.M_EDIT);
279:                    menuBar.insertAfter(IWorkbenchActionConstants.M_FILE,
280:                            editMenu);
281:                }
282:                if (menuBar
283:                        .findUsingPath(IWorkbenchActionConstants.MB_ADDITIONS) == null) {
284:                    menuBar.insertAfter(IWorkbenchActionConstants.M_EDIT,
285:                            new GroupMarker(
286:                                    IWorkbenchActionConstants.MB_ADDITIONS));
287:                }
288:                IMenuManager windowMenu = menuBar
289:                        .findMenuUsingPath(IWorkbenchActionConstants.M_WINDOW);
290:                if (windowMenu == null) {
291:                    windowMenu = new MenuManager(
292:                            Messages.UDIGWorkbenchAdvisor_window,
293:                            IWorkbenchActionConstants.M_WINDOW);
294:                    menuBar.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS,
295:                            windowMenu);
296:                }
297:                IMenuManager helpMenu = menuBar
298:                        .findMenuUsingPath(IWorkbenchActionConstants.M_HELP);
299:                if (helpMenu == null) {
300:                    helpMenu = new MenuManager(
301:                            Messages.UDIGWorkbenchAdvisor_help,
302:                            IWorkbenchActionConstants.M_HELP);
303:                    menuBar.insertAfter(IWorkbenchActionConstants.M_WINDOW,
304:                            helpMenu);
305:                }
306:
307:                fillFileMenu(window, fileMenu);
308:                fillEditMenu(window, editMenu);
309:                fillWindowMenu(window, windowMenu);
310:                fillHelpMenu(window, helpMenu);
311:                UiPlugin.getDefault().getOperationMenuFactory().setWindow(
312:                        window);
313:                menuBar.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS,
314:                        UiPlugin.getDefault().getOperationMenuFactory()
315:                                .getMenu());
316:                menuBar.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS,
317:                        createNavigationMenu());
318:                menuBar.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS,
319:                        createLayerMenu());
320:                menuBar.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS,
321:                        createToolMenu());
322:                UiPlugin.getDefault().getOperationMenuFactory()
323:                        .contributeActions(menuBar);
324:            }
325:
326:            /**
327:             * @param coolBar
328:             * @param window The window that contains the CoolBar
329:             */
330:            public void fillCoolBar(ICoolBarManager coolBar,
331:                    IWorkbenchWindow window) {
332:                coolBar.add(new ToolBarContributionItem(createFileBar(window),
333:                        IWorkbenchActionConstants.TOOLBAR_FILE));
334:            }
335:
336:            private ToolBarManager createFileBar(IWorkbenchWindow window) {
337:                ToolBarManager toolbar = new ToolBarManager(SWT.FLAT);
338:                toolbar.add(new NewContribution(window));
339:
340:                toolbar.add(ActionFactory.SAVE.create(window));
341:                toolbar.add(ActionFactory.SAVE_ALL.create(window));
342:
343:                toolbar.add(new GroupMarker(
344:                        IWorkbenchActionConstants.MB_ADDITIONS));
345:
346:                return toolbar;
347:            }
348:
349:            private void setupFileMenuStructure(IMenuManager fileMenu) {
350:                if (fileMenu
351:                        .findUsingPath(IWorkbenchActionConstants.FILE_START) == null) {
352:                    if (fileMenu.getItems().length > 0) {
353:                        fileMenu.insertBefore(fileMenu.getItems()[0].getId(),
354:                                new GroupMarker(Constants.FILE_START));
355:                    } else {
356:                        fileMenu.add(new GroupMarker(Constants.FILE_START));
357:                    }
358:                }
359:
360:                if (fileMenu.findUsingPath(Constants.OPEN_EXT) == null) {
361:                    fileMenu.insertAfter(Constants.FILE_START, new GroupMarker(
362:                            Constants.OPEN_EXT));
363:                }
364:
365:                if (fileMenu.findUsingPath(Constants.CLOSE_EXT) == null) {
366:                    fileMenu.insertAfter(Constants.OPEN_EXT, new GroupMarker(
367:                            Constants.CLOSE_EXT));
368:                }
369:
370:                if (fileMenu.findUsingPath(Constants.SAVE_EXT) == null) {
371:                    fileMenu.insertAfter(Constants.CLOSE_EXT, new GroupMarker(
372:                            Constants.SAVE_EXT));
373:                }
374:
375:                if (fileMenu
376:                        .findUsingPath(IWorkbenchActionConstants.MB_ADDITIONS) == null) {
377:                    fileMenu.insertAfter(Constants.SAVE_EXT, new GroupMarker(
378:                            IWorkbenchActionConstants.MB_ADDITIONS));
379:                }
380:
381:                if (fileMenu.findUsingPath(Constants.FILE_END) == null) {
382:                    fileMenu.insertAfter(
383:                            IWorkbenchActionConstants.MB_ADDITIONS,
384:                            new GroupMarker(Constants.FILE_END));
385:                }
386:
387:                fileMenu.insertAfter(Constants.OPEN_EXT, new Separator());
388:                fileMenu.insertAfter(Constants.CLOSE_EXT, new Separator());
389:                fileMenu.insertAfter(Constants.SAVE_EXT, new Separator());
390:                fileMenu.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS,
391:                        new Separator());
392:
393:            }
394:
395:            private void fillFileMenu(IWorkbenchWindow window,
396:                    IMenuManager fileMenu) {
397:                setupFileMenuStructure(fileMenu);
398:
399:                IMenuManager newMenu = fileMenu
400:                        .findMenuUsingPath(ActionFactory.NEW.getId());
401:                if (newMenu == null) {
402:                    newMenu = new MenuManager(
403:                            Messages.UDIGWorkbenchAdvisor_new,
404:                            ActionFactory.NEW.getId());
405:                    fileMenu.insertAfter(Constants.FILE_START, newMenu);
406:                }
407:
408:                newMenu.add(new GroupMarker(Constants.NEW_START));
409:                List<IConfigurationElement> list = ExtensionPointList
410:                        .getExtensionPointList(NEW_ACTION_ID);
411:                Collections.sort(list, new NewObjectActionComparator());
412:                for (IConfigurationElement element : list) {
413:                    final NewItem item = new NewItem(element, window);
414:                    Action newAction = new Action() {
415:                        @Override
416:                        public void runWithEvent(
417:                                org.eclipse.swt.widgets.Event event) {
418:                            item.runAction();
419:                        }
420:                    };
421:                    newAction.setText(item.text);
422:                    newAction.setImageDescriptor(item.icon);
423:                    newMenu.appendToGroup(Constants.NEW_START, newAction);
424:                }
425:                newMenu.add(ContributionItemFactory.NEW_WIZARD_SHORTLIST
426:                        .create(window));
427:
428:                if (fileMenu.findUsingPath(ActionFactory.CLOSE.getId()) == null) {
429:                    IAction close = ActionFactory.CLOSE.create(window);
430:                    fileMenu.insertAfter(Constants.CLOSE_EXT, close);
431:                }
432:
433:                if (fileMenu.findUsingPath(ActionFactory.CLOSE_ALL.getId()) == null) {
434:                    IAction closeAll = ActionFactory.CLOSE_ALL.create(window);
435:                    fileMenu.insertAfter(ActionFactory.CLOSE.getId(), closeAll);
436:                }
437:
438:                if (fileMenu.findUsingPath(ActionFactory.SAVE.getId()) == null) {
439:                    IAction save = ActionFactory.SAVE.create(window);
440:                    fileMenu.insertBefore(Constants.SAVE_EXT, save);
441:                }
442:
443:                if (fileMenu.findUsingPath(ActionFactory.SAVE_ALL.getId()) == null) {
444:                    IAction saveAll = ActionFactory.SAVE_ALL.create(window);
445:                    fileMenu.insertBefore(Constants.SAVE_EXT, saveAll);
446:                }
447:
448:                fileMenu.insertAfter(Constants.SAVE_EXT, new GroupMarker(
449:                        Constants.REVERT_EXT));
450:                fileMenu.insertAfter(Constants.SAVE_EXT, new GroupMarker(
451:                        Constants.COMMIT_EXT));
452:
453:                fileMenu.insertBefore(Constants.FILE_END, new GroupMarker(
454:                        Constants.RENAME_EXT));
455:                fileMenu.insertAfter(Constants.RENAME_EXT, new Separator());
456:
457:                if (fileMenu.findUsingPath(ActionFactory.REFRESH.getId()) == null) {
458:                    fileMenu.insertBefore(
459:                            IWorkbenchActionConstants.MB_ADDITIONS,
460:                            new GroupMarker(ActionFactory.REFRESH.getId()));
461:                }
462:
463:                if (fileMenu.findUsingPath(ActionFactory.IMPORT.getId()) == null) {
464:                    IAction _import = ActionFactory.IMPORT.create(window);
465:                    fileMenu.insertBefore(Constants.FILE_END, _import);
466:                    fileMenu.insertAfter(ActionFactory.IMPORT.getId(),
467:                            new Separator());
468:                }
469:
470:                if (fileMenu.findUsingPath(ActionFactory.EXPORT.getId()) == null) {
471:                    IAction _export = ActionFactory.EXPORT.create(window);
472:                    fileMenu.insertBefore(Constants.FILE_END, _export);
473:                    fileMenu.insertAfter(ActionFactory.EXPORT.getId(),
474:                            new Separator());
475:                }
476:
477:                fileMenu.insertBefore(Constants.FILE_END, new GroupMarker(
478:                        Constants.CONFIG_EXT));
479:                fileMenu.insertAfter(Constants.CONFIG_EXT, new Separator());
480:
481:                if (fileMenu.findUsingPath(ActionFactory.QUIT.getId()) == null) {
482:                    IAction exit = ActionFactory.QUIT.create(window);
483:                    fileMenu.insertAfter(Constants.FILE_END, exit);
484:                }
485:
486:                // fileMenu.insertAfter(Constants.REVERT_EXT, new Separator());
487:            }
488:
489:            private void fillEditMenu(IWorkbenchWindow window,
490:                    IMenuManager editMenu) {
491:                if (editMenu.findUsingPath(Constants.EDIT_START) == null) {
492:                    if (editMenu.getItems().length > 0) {
493:                        editMenu.insertBefore(editMenu.getItems()[0].getId(),
494:                                new GroupMarker(Constants.EDIT_START));
495:                    } else {
496:                        editMenu.add(new GroupMarker(Constants.EDIT_START));
497:                    }
498:                }
499:
500:                if (editMenu.findUsingPath(Constants.UNDO_EXT) == null) {
501:                    editMenu.insertAfter(Constants.EDIT_START, new GroupMarker(
502:                            Constants.UNDO_EXT));
503:                }
504:
505:                if (editMenu.findUsingPath(Constants.CUT_EXT) == null) {
506:                    editMenu.insertAfter(Constants.UNDO_EXT, new GroupMarker(
507:                            Constants.CUT_EXT));
508:                }
509:
510:                if (editMenu.findUsingPath(Constants.ADD_EXT) == null) {
511:                    editMenu.insertAfter(Constants.CUT_EXT, new GroupMarker(
512:                            Constants.ADD_EXT));
513:                }
514:
515:                if (editMenu.findUsingPath(Constants.EDIT_END) == null) {
516:                    editMenu.insertAfter(Constants.ADD_EXT, new GroupMarker(
517:                            Constants.EDIT_END));
518:                }
519:                if (editMenu
520:                        .findUsingPath(IWorkbenchActionConstants.MB_ADDITIONS) == null) {
521:                    editMenu.insertAfter(Constants.EDIT_END, new GroupMarker(
522:                            IWorkbenchActionConstants.MB_ADDITIONS));
523:                }
524:
525:                editMenu.appendToGroup(Constants.UNDO_EXT, ActionFactory.UNDO
526:                        .create(window));
527:                editMenu.appendToGroup(Constants.UNDO_EXT, ActionFactory.REDO
528:                        .create(window));
529:                editMenu.appendToGroup(Constants.CUT_EXT, ActionFactory.CUT
530:                        .create(window));
531:                editMenu.appendToGroup(Constants.CUT_EXT, ActionFactory.COPY
532:                        .create(window));
533:                editMenu.appendToGroup(Constants.CUT_EXT, ActionFactory.PASTE
534:                        .create(window));
535:                editMenu.appendToGroup(Constants.ADD_EXT, ActionFactory.DELETE
536:                        .create(window));
537:                // appendToGroup(Constants.ADD_EXT, ActionFactory.SELECT_ALL.create(window));
538:
539:                editMenu.insertAfter(Constants.UNDO_EXT, new Separator());
540:                editMenu.insertAfter(Constants.CUT_EXT, new Separator());
541:                editMenu.insertAfter(Constants.EDIT_END, new Separator());
542:            }
543:
544:            private IMenuManager createLayerMenu() {
545:                MenuManager menu = new MenuManager(
546:                        Messages.UDIGWorkbenchAdvisor_layerMenu,
547:                        Constants.M_LAYER);
548:                menu.add(new GroupMarker(Constants.LAYER_ADD_EXT));
549:                menu.add(new Separator());
550:                menu.add(new GroupMarker(Constants.LAYER_EDIT_EXT));
551:                menu.add(new Separator());
552:                menu.add(new GroupMarker(Constants.LAYER_MAPGRAPHIC_EXT));
553:                menu.add(new GroupMarker(Constants.LAYER_MAPGRAPHIC_OTHER));
554:
555:                menu.add(new Separator());
556:                menu
557:                        .add(new GroupMarker(
558:                                IWorkbenchActionConstants.MB_ADDITIONS));
559:
560:                return menu;
561:            }
562:
563:            private IMenuManager createNavigationMenu() {
564:                MenuManager menu = new MenuManager(
565:                        Messages.UDIGWorkbenchAdvisor_navigationMenu,
566:                        Constants.M_NAVIGATE);
567:                // menu.add(ActionFactory.BACKWARD_HISTORY.create(window));
568:                // menu.add(ActionFactory.FORWARD_HISTORY.create(window));
569:                menu.add(new GroupMarker(Constants.NAV_START));
570:                menu.add(new Separator());
571:                menu.add(new GroupMarker(Constants.NAV_ZOOM_EXT));
572:
573:                menu.add(new Separator());
574:                menu
575:                        .add(new GroupMarker(
576:                                IWorkbenchActionConstants.MB_ADDITIONS));
577:
578:                menu.add(new Separator());
579:                menu.add(new GroupMarker(Constants.NAV_BOTTOM));
580:
581:                return menu;
582:            }
583:
584:            private IMenuManager createToolMenu() {
585:                MenuManager menu = new MenuManager(
586:                        Messages.UDIGWorkbenchAdvisor_tools, Constants.M_TOOL);
587:                menu.add(new GroupMarker(Constants.TOOL_ACTION));
588:                menu.add(new Separator());
589:                menu.add(new GroupMarker(Constants.TOOL_MODAL));
590:                menu.add(new Separator());
591:                menu
592:                        .add(new GroupMarker(
593:                                IWorkbenchActionConstants.MB_ADDITIONS));
594:
595:                return menu;
596:            }
597:
598:            private void fillWindowMenu(IWorkbenchWindow window,
599:                    IMenuManager windowMenu) {
600:
601:                if (windowMenu.findUsingPath(ActionFactory.OPEN_NEW_WINDOW
602:                        .getId()) == null) {
603:                    IAction openNewWindow = ActionFactory.OPEN_NEW_WINDOW
604:                            .create(window);
605:                    openNewWindow
606:                            .setText(Messages.UDIGWorkbenchAdvisor_newWindow_text);
607:                    if (windowMenu.getItems().length > 0) {
608:                        windowMenu.insertBefore(windowMenu.getItems()[0]
609:                                .getId(), openNewWindow);
610:                    } else {
611:                        windowMenu.add(openNewWindow);
612:                    }
613:                }
614:
615:                IMenuManager perspectiveMenu = windowMenu
616:                        .findMenuUsingPath(ContributionItemFactory.PERSPECTIVES_SHORTLIST
617:                                .getId());
618:                if (perspectiveMenu == null) {
619:                    perspectiveMenu = new MenuManager(
620:                            Messages.UDIGWorkbenchAdvisor_open_perspective,
621:                            ContributionItemFactory.PERSPECTIVES_SHORTLIST
622:                                    .getId());
623:                    windowMenu.insertAfter(ActionFactory.OPEN_NEW_WINDOW
624:                            .getId(), perspectiveMenu);
625:                    IContributionItem perspectiveList = ContributionItemFactory.PERSPECTIVES_SHORTLIST
626:                            .create(window);
627:                    perspectiveMenu.add(perspectiveList);
628:                }
629:
630:                IMenuManager viewMenu = windowMenu
631:                        .findMenuUsingPath(ContributionItemFactory.VIEWS_SHORTLIST
632:                                .getId());
633:                if (viewMenu == null) {
634:                    viewMenu = new MenuManager(
635:                            Messages.UDIGWorkbenchAdvisor_show_view,
636:                            ContributionItemFactory.VIEWS_SHORTLIST.getId());
637:                    windowMenu.insertAfter(
638:                            ContributionItemFactory.PERSPECTIVES_SHORTLIST
639:                                    .getId(), viewMenu);
640:                    IContributionItem viewList = ContributionItemFactory.VIEWS_SHORTLIST
641:                            .create(window);
642:                    viewMenu.add(viewList);
643:                }
644:
645:                if (windowMenu
646:                        .findUsingPath(ContributionItemFactory.OPEN_WINDOWS
647:                                .getId()) == null) {
648:                    // append this one to the end and we'll work backward from it
649:                    windowMenu.add(ContributionItemFactory.OPEN_WINDOWS
650:                            .create(window));
651:                }
652:
653:                if (windowMenu.findUsingPath(ActionFactory.PREFERENCES.getId()) == null) {
654:                    IAction preferences = ActionFactory.PREFERENCES
655:                            .create(window);
656:                    preferences
657:                            .setText(Messages.UDIGWorkbenchAdvisor_preferences_text);
658:                    windowMenu.insertBefore(
659:                            ContributionItemFactory.OPEN_WINDOWS.getId(),
660:                            preferences);
661:                }
662:
663:                if (windowMenu
664:                        .findUsingPath(IWorkbenchActionConstants.MB_ADDITIONS) == null) {
665:                    windowMenu.insertBefore(ActionFactory.PREFERENCES.getId(),
666:                            new GroupMarker(
667:                                    IWorkbenchActionConstants.MB_ADDITIONS));
668:                }
669:
670:                if (windowMenu
671:                        .findUsingPath(ActionFactory.CLOSE_ALL_PERSPECTIVES
672:                                .getId()) == null) {
673:                    IAction closeAllPerspectives = ActionFactory.CLOSE_ALL_PERSPECTIVES
674:                            .create(window);
675:                    closeAllPerspectives
676:                            .setText(Messages.UDIGWorkbenchAdvisor_closeAllPerspectives_text);
677:                    windowMenu.insertBefore(
678:                            IWorkbenchActionConstants.MB_ADDITIONS,
679:                            closeAllPerspectives);
680:                }
681:
682:                if (windowMenu.findUsingPath(ActionFactory.CLOSE_PERSPECTIVE
683:                        .getId()) == null) {
684:                    IAction closePerspective = ActionFactory.CLOSE_PERSPECTIVE
685:                            .create(window);
686:                    closePerspective
687:                            .setText(Messages.UDIGWorkbenchAdvisor_closePerspective_text);
688:                    windowMenu.insertBefore(
689:                            ActionFactory.CLOSE_ALL_PERSPECTIVES.getId(),
690:                            closePerspective);
691:                }
692:
693:                if (windowMenu.findUsingPath(ActionFactory.RESET_PERSPECTIVE
694:                        .getId()) == null) {
695:                    IAction resetPerspective = ActionFactory.RESET_PERSPECTIVE
696:                            .create(window);
697:                    resetPerspective
698:                            .setText(Messages.UDIGWorkbenchAdvisor_resetPerspective_text);
699:                    windowMenu.insertBefore(ActionFactory.CLOSE_PERSPECTIVE
700:                            .getId(), resetPerspective);
701:                }
702:
703:                // Add the separators
704:                windowMenu.insertAfter(ActionFactory.OPEN_NEW_WINDOW.getId(),
705:                        new Separator());
706:                windowMenu.insertAfter(ContributionItemFactory.VIEWS_SHORTLIST
707:                        .getId(), new Separator());
708:                windowMenu.insertBefore(IWorkbenchActionConstants.MB_ADDITIONS,
709:                        new Separator());
710:                windowMenu.insertAfter(IWorkbenchActionConstants.MB_ADDITIONS,
711:                        new Separator());
712:            }
713:
714:            private void fillHelpMenu(IWorkbenchWindow window,
715:                    IMenuManager helpMenu) {
716:
717:                if (helpMenu.findUsingPath(ActionFactory.INTRO.getId()) == null) {
718:                    IAction welcome = ActionFactory.INTRO.create(window);
719:                    welcome.setText(Messages.UDIGWorkbenchAdvisor_welcome_text);
720:                    if (helpMenu.getItems().length > 0) {
721:                        helpMenu.insertBefore(helpMenu.getItems()[0].getId(),
722:                                welcome);
723:                    } else {
724:                        helpMenu.add(welcome);
725:                    }
726:                }
727:
728:                if (helpMenu.findUsingPath(Constants.HELP_START) == null) {
729:                    helpMenu.insertAfter(ActionFactory.INTRO.getId(),
730:                            new GroupMarker(Constants.HELP_START));
731:                }
732:
733:                if (helpMenu.findUsingPath(ActionFactory.HELP_CONTENTS.getId()) == null) {
734:                    IAction helpContents = ActionFactory.HELP_CONTENTS
735:                            .create(window);
736:                    helpContents
737:                            .setText(Messages.UDIGWorkbenchAdvisor_helpContents_text);
738:                    helpMenu.insertBefore(Constants.HELP_START, helpContents);
739:                }
740:
741:                if (helpMenu.findUsingPath(Constants.HELP_END) == null) {
742:                    helpMenu.insertAfter(Constants.HELP_START, new GroupMarker(
743:                            Constants.HELP_END));
744:                }
745:
746:                // Tips and tricks page would go after HELP_START
747:
748:                if (helpMenu
749:                        .findUsingPath(IWorkbenchActionConstants.MB_ADDITIONS) == null) {
750:                    helpMenu.insertAfter(Constants.HELP_END, new GroupMarker(
751:                            IWorkbenchActionConstants.MB_ADDITIONS));
752:                }
753:
754:                // Add the separators
755:                helpMenu.insertAfter(ActionFactory.INTRO.getId(),
756:                        new Separator());
757:                helpMenu.insertBefore(Constants.HELP_START, new Separator());
758:                helpMenu.insertAfter(Constants.HELP_END, new Separator());
759:                // helpMenu.insertAfter(, new Separator());
760:
761:                if (helpMenu.findUsingPath(ActionFactory.ABOUT.getId()) == null) {
762:                    IAction about = ActionFactory.ABOUT.create(window);
763:                    about.setText(Messages.UDIGWorkbenchAdvisor_aboutUDig_text);
764:                    // About should always be at the bottom, so just append it to the menu
765:                    helpMenu.add(about);
766:                }
767:            }
768:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.