Source Code Cross Referenced for PluginActionSetBuilder.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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 workbench » org.eclipse.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal;
011:
012:        import java.util.ArrayList;
013:        import java.util.Iterator;
014:
015:        import org.eclipse.core.runtime.IConfigurationElement;
016:        import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
017:        import org.eclipse.jface.action.AbstractGroupMarker;
018:        import org.eclipse.jface.action.ActionContributionItem;
019:        import org.eclipse.jface.action.GroupMarker;
020:        import org.eclipse.jface.action.IContributionItem;
021:        import org.eclipse.jface.action.IContributionManager;
022:        import org.eclipse.jface.action.ICoolBarManager;
023:        import org.eclipse.jface.action.IMenuManager;
024:        import org.eclipse.jface.action.IToolBarManager;
025:        import org.eclipse.jface.action.Separator;
026:        import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
027:        import org.eclipse.ui.IActionBars;
028:        import org.eclipse.ui.IWorkbenchActionConstants;
029:        import org.eclipse.ui.IWorkbenchWindow;
030:        import org.eclipse.ui.internal.registry.ActionSetRegistry;
031:        import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
032:
033:        /**
034:         * This builder reads the actions for an action set from the registry.
035:         */
036:        public class PluginActionSetBuilder extends PluginActionBuilder {
037:
038:            private PluginActionSet actionSet;
039:
040:            private IWorkbenchWindow window;
041:
042:            private ArrayList adjunctContributions = new ArrayList(0);
043:
044:            /**
045:             * Used by the workbench window extension handler to unhook action sets from
046:             * their associated window.
047:             * 
048:             * @since 3.1
049:             */
050:            public static class Binding {
051:                PluginActionSetBuilder builder;
052:                PluginActionSet set;
053:                IWorkbenchWindow window;
054:            }
055:
056:            /**
057:             * Constructs a new builder.
058:             */
059:            public PluginActionSetBuilder() {
060:            }
061:
062:            /**
063:             * Read the actions within a config element. Called by customize perspective
064:             * 
065:             * @param set the action set
066:             * @param window the window to contribute to
067:             */
068:            public void buildMenuAndToolBarStructure(PluginActionSet set,
069:                    IWorkbenchWindow window) {
070:                this .actionSet = set;
071:                this .window = window;
072:                cache = null;
073:                currentContribution = null;
074:                targetID = null;
075:                targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
076:
077:                readElements(new IConfigurationElement[] { set
078:                        .getConfigElement() });
079:
080:                if (cache != null) {
081:                    for (int i = 0; i < cache.size(); i++) {
082:                        ActionSetContribution contribution = (ActionSetContribution) cache
083:                                .get(i);
084:                        contribution
085:                                .contribute(actionSet.getBars(), true, true);
086:                        if (contribution.isAdjunctContributor()) {
087:                            adjunctContributions.add(contribution);
088:                        }
089:                    }
090:                }
091:                for (int i = 0; i < adjunctContributions.size(); i++) {
092:                    ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
093:                            .get(i);
094:                    ActionSetActionBars bars = actionSet.getBars();
095:                    for (int j = 0; j < contribution.adjunctActions.size(); j++) {
096:                        ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
097:                                .get(j);
098:                        contribution.contributeAdjunctCoolbarAction(
099:                                adjunctAction, bars);
100:                    }
101:                }
102:
103:                Binding binding = new Binding();
104:                binding.builder = this ;
105:                binding.set = set;
106:                binding.window = window;
107:                window.getExtensionTracker().registerObject(
108:                        set.getConfigElement().getDeclaringExtension(),
109:                        binding, IExtensionTracker.REF_STRONG);
110:            }
111:
112:            /* (non-Javadoc)
113:             * Method declared on PluginActionBuilder.
114:             */
115:            protected ActionDescriptor createActionDescriptor(
116:                    IConfigurationElement element) {
117:                // As of 2.1, the "pulldown" attribute was deprecated and replaced by
118:                // the attribute "style". See doc for more details.
119:                boolean pullDownStyle = false;
120:                String style = element
121:                        .getAttribute(IWorkbenchRegistryConstants.ATT_STYLE);
122:                if (style != null) {
123:                    pullDownStyle = style
124:                            .equals(ActionDescriptor.STYLE_PULLDOWN);
125:                } else {
126:                    String pulldown = element
127:                            .getAttribute(ActionDescriptor.STYLE_PULLDOWN);
128:                    pullDownStyle = pulldown != null && pulldown.equals("true"); //$NON-NLS-1$
129:                }
130:
131:                ActionDescriptor desc = null;
132:                if (pullDownStyle) {
133:                    desc = new ActionDescriptor(element,
134:                            ActionDescriptor.T_WORKBENCH_PULLDOWN, window);
135:                } else {
136:                    desc = new ActionDescriptor(element,
137:                            ActionDescriptor.T_WORKBENCH, window);
138:                }
139:                WWinPluginAction action = (WWinPluginAction) desc.getAction();
140:                action.setActionSetId(actionSet.getDesc().getId());
141:                actionSet.addPluginAction(action);
142:                return desc;
143:            }
144:
145:            /* (non-Javadoc)
146:             * Method declared on PluginActionBuilder.
147:             */
148:            protected BasicContribution createContribution() {
149:                return new ActionSetContribution(actionSet.getDesc().getId(),
150:                        window);
151:            }
152:
153:            /**
154:             * Returns the insertion point for a new contribution item.  Clients should
155:             * use this item as a reference point for insertAfter.
156:             *
157:             * @param startId the reference id for insertion
158:             * @param sortId the sorting id for the insertion.  If null then the item
159:             *		will be inserted at the end of all action sets.
160:             * @param mgr the target menu manager.
161:             * @param startVsEnd if <code>true</code> the items are added at the start of
162:             *		action with the same id; else they are added to the end
163:             * @return the insertion point, or null if not found.
164:             */
165:            public static IContributionItem findInsertionPoint(String startId,
166:                    String sortId, IContributionManager mgr, boolean startVsEnd) {
167:                // Get items.
168:                IContributionItem[] items = mgr.getItems();
169:
170:                // Find the reference item.
171:                int insertIndex = 0;
172:                while (insertIndex < items.length) {
173:                    if (startId.equals(items[insertIndex].getId())) {
174:                        break;
175:                    }
176:                    ++insertIndex;
177:                }
178:                if (insertIndex >= items.length) {
179:                    return null;
180:                }
181:
182:                // Calculate startVsEnd comparison value.
183:                int compareMetric = 0;
184:                if (startVsEnd) {
185:                    compareMetric = 1;
186:                }
187:
188:                // Find the insertion point for the new item.
189:                // We do this by iterating through all of the previous
190:                // action set contributions define within the current group.
191:                for (int nX = insertIndex + 1; nX < items.length; nX++) {
192:                    IContributionItem item = items[nX];
193:                    if (item.isSeparator() || item.isGroupMarker()) {
194:                        // Fix for bug report 18357
195:                        break;
196:                    }
197:                    if (item instanceof  IActionSetContributionItem) {
198:                        if (sortId != null) {
199:                            String testId = ((IActionSetContributionItem) item)
200:                                    .getActionSetId();
201:                            if (sortId.compareTo(testId) < compareMetric) {
202:                                break;
203:                            }
204:                        }
205:                        insertIndex = nX;
206:                    } else {
207:                        break;
208:                    }
209:                }
210:                // Return item.
211:                return items[insertIndex];
212:            }
213:
214:            /**
215:             */
216:            /* package */static void processActionSets(
217:                    ArrayList pluginActionSets, WorkbenchWindow window) {
218:                // Process the action sets in two passes.  On the first pass the pluginActionSetBuilder
219:                // will process base contributions and cache adjunct contributions.  On the second
220:                // pass the adjunct contributions will be processed.
221:                PluginActionSetBuilder[] builders = new PluginActionSetBuilder[pluginActionSets
222:                        .size()];
223:                for (int i = 0; i < pluginActionSets.size(); i++) {
224:                    PluginActionSet set = (PluginActionSet) pluginActionSets
225:                            .get(i);
226:                    PluginActionSetBuilder builder = new PluginActionSetBuilder();
227:                    builder.readActionExtensions(set, window);
228:                    builders[i] = builder;
229:                }
230:                for (int i = 0; i < builders.length; i++) {
231:                    PluginActionSetBuilder builder = builders[i];
232:                    builder.processAdjunctContributions();
233:                }
234:            }
235:
236:            /**
237:             */
238:            protected void processAdjunctContributions() {
239:                // Contribute the adjunct contributions.
240:                for (int i = 0; i < adjunctContributions.size(); i++) {
241:                    ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
242:                            .get(i);
243:                    ActionSetActionBars bars = actionSet.getBars();
244:                    for (int j = 0; j < contribution.adjunctActions.size(); j++) {
245:                        ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
246:                                .get(j);
247:                        contribution.contributeAdjunctCoolbarAction(
248:                                adjunctAction, bars);
249:                    }
250:                }
251:            }
252:
253:            /**
254:             * Read the actions within a config element.
255:             */
256:            protected void readActionExtensions(PluginActionSet set,
257:                    IWorkbenchWindow window) {
258:                this .actionSet = set;
259:                this .window = window;
260:                cache = null;
261:                currentContribution = null;
262:                targetID = null;
263:                targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
264:
265:                readElements(new IConfigurationElement[] { set
266:                        .getConfigElement() });
267:
268:                if (cache != null) {
269:                    // for dynamic UI - save cache for future removal lf actionset extensions
270:                    //        Don't call addCache -- it's broken, and is only used for dynamic plugin removal,
271:                    //        which the workbench doesn't currently support.
272:                    //        See bug 66374 for more details.
273:                    //			WorkbenchPlugin.getDefault().getActionSetRegistry().addCache(set.getDesc().getId(), cache);
274:                    for (int i = 0; i < cache.size(); i++) {
275:                        ActionSetContribution contribution = (ActionSetContribution) cache
276:                                .get(i);
277:                        contribution
278:                                .contribute(actionSet.getBars(), true, true);
279:                        if (contribution.isAdjunctContributor()) {
280:                            adjunctContributions.add(contribution);
281:                        }
282:                    }
283:
284:                    Binding binding = new Binding();
285:                    binding.builder = this ;
286:                    binding.set = set;
287:                    binding.window = window;
288:                    window.getExtensionTracker().registerObject(
289:                            set.getConfigElement().getDeclaringExtension(),
290:                            binding, IExtensionTracker.REF_STRONG);
291:                } else {
292:                    WorkbenchPlugin
293:                            .log("Action Set is empty: " + set.getDesc().getId()); //$NON-NLS-1$
294:                }
295:            }
296:
297:            /**
298:             * Helper class to collect the menus and actions defined within a
299:             * contribution element.
300:             */
301:            private static class ActionSetContribution extends
302:                    BasicContribution {
303:                private String actionSetId;
304:
305:                private WorkbenchWindow window;
306:
307:                protected ArrayList adjunctActions = new ArrayList(0);
308:
309:                /**
310:                 * Create a new instance of <code>ActionSetContribution</code>.
311:                 * 
312:                 * @param id the id
313:                 * @param window the window to contribute to
314:                 */
315:                public ActionSetContribution(String id, IWorkbenchWindow window) {
316:                    super ();
317:                    actionSetId = id;
318:                    this .window = (WorkbenchWindow) window;
319:                }
320:
321:                /**
322:                 * This implementation inserts the group into the action set additions group.  
323:                 */
324:                protected void addGroup(IContributionManager mgr, String name) {
325:                    IContributionItem refItem = findInsertionPoint(
326:                            IWorkbenchActionConstants.MB_ADDITIONS,
327:                            actionSetId, mgr, true);
328:                    // Insert the new group marker.
329:                    ActionSetSeparator group = new ActionSetSeparator(name,
330:                            actionSetId);
331:                    if (refItem == null) {
332:                        mgr.add(group);
333:                    } else {
334:                        mgr.insertAfter(refItem.getId(), group);
335:                    }
336:                }
337:
338:                /**
339:                 * Contributes submenus and/or actions into the provided menu and tool bar
340:                 * managers.
341:                 * 
342:                 * @param bars the action bars to contribute to
343:                 * @param menuAppendIfMissing append to the menubar if missing
344:                 * @param toolAppendIfMissing append to the toolbar if missing
345:                 */
346:                public void contribute(IActionBars bars,
347:                        boolean menuAppendIfMissing, boolean toolAppendIfMissing) {
348:
349:                    IMenuManager menuMgr = bars.getMenuManager();
350:                    IToolBarManager toolBarMgr = bars.getToolBarManager();
351:                    if (menus != null && menuMgr != null) {
352:                        for (int i = 0; i < menus.size(); i++) {
353:                            IConfigurationElement menuElement = (IConfigurationElement) menus
354:                                    .get(i);
355:                            contributeMenu(menuElement, menuMgr,
356:                                    menuAppendIfMissing);
357:                        }
358:                    }
359:
360:                    if (actions != null) {
361:                        for (int i = 0; i < actions.size(); i++) {
362:                            ActionDescriptor ad = (ActionDescriptor) actions
363:                                    .get(i);
364:                            if (menuMgr != null) {
365:                                contributeMenuAction(ad, menuMgr,
366:                                        menuAppendIfMissing);
367:                            }
368:                            if (toolBarMgr != null) {
369:                                if (bars instanceof  ActionSetActionBars) {
370:                                    contributeCoolbarAction(ad,
371:                                            (ActionSetActionBars) bars);
372:                                } else {
373:                                    contributeToolbarAction(ad, toolBarMgr,
374:                                            toolAppendIfMissing);
375:                                }
376:                            }
377:                        }
378:                    }
379:                }
380:
381:                /**
382:                 * Contributes action from the action descriptor into the cool bar manager.
383:                 */
384:                protected void contributeAdjunctCoolbarAction(
385:                        ActionDescriptor ad, ActionSetActionBars bars) {
386:                    String toolBarId = ad.getToolbarId();
387:                    String toolGroupId = ad.getToolbarGroupId();
388:
389:                    String contributingId = bars.getActionSetId();
390:                    ICoolBarManager coolBarMgr = bars.getCoolBarManager();
391:                    if (coolBarMgr == null) {
392:                        return;
393:                    }
394:
395:                    PluginAction action = ad.getAction();
396:                    ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
397:                            action);
398:
399:                    bars.addAdjunctContribution(actionContribution);
400:
401:                    // create a coolitem for the toolbar id if it does not yet exist				
402:                    IToolBarManager toolBarManager = bars
403:                            .getToolBarManager(toolBarId);
404:
405:                    // Check to see if the group already exists
406:                    IContributionItem groupMarker = toolBarManager
407:                            .find(toolGroupId);
408:                    // Add a group marker if one does not exist
409:                    if (groupMarker == null) {
410:                        toolBarManager.add(new Separator(toolGroupId));
411:                    }
412:                    IContributionItem refItem = findAlphabeticalOrder(
413:                            toolGroupId, contributingId, toolBarManager);
414:                    if (refItem != null && refItem.getId() != null) {
415:                        toolBarManager.insertAfter(refItem.getId(),
416:                                actionContribution);
417:                    } else {
418:                        toolBarManager.add(actionContribution);
419:                    }
420:                    toolBarManager.update(false);
421:
422:                }
423:
424:                /**
425:                 * Contributes action from the action descriptor into the cool bar manager.
426:                 */
427:                protected void contributeCoolbarAction(ActionDescriptor ad,
428:                        ActionSetActionBars bars) {
429:                    String toolBarId = ad.getToolbarId();
430:                    String toolGroupId = ad.getToolbarGroupId();
431:                    if (toolBarId == null && toolGroupId == null) {
432:                        return;
433:                    }
434:
435:                    String contributingId = bars.getActionSetId();
436:
437:                    if (toolBarId == null || toolBarId.equals("")) { //$NON-NLS-1$ 
438:                        // the item is being added to the coolitem for its action set
439:                        toolBarId = contributingId;
440:                    }
441:
442:                    if (!toolBarId.equals(contributingId)) {
443:                        // adding to another action set, validate the id
444:                        if (!isValidCoolItemId(toolBarId, window)) {
445:                            // toolbarid not valid, add the item to the coolitem for its action set
446:                            toolBarId = contributingId;
447:                        } else {
448:                            adjunctActions.add(ad);
449:                            return;
450:                        }
451:                    }
452:
453:                    // Create the action
454:                    PluginAction action = ad.getAction();
455:                    ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
456:                            action);
457:
458:                    // retreive the toolbar from the action bars.
459:                    IToolBarManager toolBar = bars.getToolBarManager(toolBarId);
460:
461:                    // Check to see if the group already exists
462:                    IContributionItem groupMarker = toolBar.find(toolGroupId);
463:                    // Add a group marker if one does not exist
464:                    if (groupMarker == null) {
465:                        // @issue should this be a GroupMarker?
466:                        toolBar.add(new Separator(toolGroupId));
467:                    }
468:                    toolBar.prependToGroup(toolGroupId, actionContribution);
469:                    toolBar.update(false);
470:
471:                }
472:
473:                /**
474:                 * Checks to see if the cool item id is in the given window.
475:                 */
476:                private boolean isValidCoolItemId(String id,
477:                        WorkbenchWindow window) {
478:                    ActionSetRegistry registry = WorkbenchPlugin.getDefault()
479:                            .getActionSetRegistry();
480:                    if (registry.findActionSet(id) != null) {
481:                        return true;
482:                    }
483:                    if (window != null) {
484:                        return window.isWorkbenchCoolItemId(id);
485:                    }
486:                    return false;
487:                }
488:
489:                /* (non-Javadoc)
490:                 * Method declared on Basic Contribution.
491:                 */
492:                protected void insertMenuGroup(IMenuManager menu,
493:                        AbstractGroupMarker marker) {
494:                    if (actionSetId != null) {
495:                        IContributionItem[] items = menu.getItems();
496:                        // Loop thru all the current groups looking for the first
497:                        // group whose id > than the current action set id. Insert
498:                        // current marker just before this item then.
499:                        for (int i = 0; i < items.length; i++) {
500:                            IContributionItem item = items[i];
501:                            if (item.isSeparator() || item.isGroupMarker()) {
502:                                if (item instanceof  IActionSetContributionItem) {
503:                                    String testId = ((IActionSetContributionItem) item)
504:                                            .getActionSetId();
505:                                    if (actionSetId.compareTo(testId) < 0) {
506:                                        menu.insertBefore(items[i].getId(),
507:                                                marker);
508:                                        return;
509:                                    }
510:                                }
511:                            }
512:                        }
513:                    }
514:
515:                    menu.add(marker);
516:                }
517:
518:                private IContributionItem findAlphabeticalOrder(String startId,
519:                        String itemId, IContributionManager mgr) {
520:                    IContributionItem[] items = mgr.getItems();
521:                    int insertIndex = 0;
522:
523:                    // look for starting point
524:                    while (insertIndex < items.length) {
525:                        IContributionItem item = items[insertIndex];
526:                        if (startId != null && startId.equals(item.getId())) {
527:                            break;
528:                        }
529:                        ++insertIndex;
530:                    }
531:
532:                    // Find the index that this item should be inserted in
533:                    for (int i = insertIndex + 1; i < items.length; i++) {
534:                        IContributionItem item = items[i];
535:                        if (item.isGroupMarker()) {
536:                            break;
537:                        }
538:
539:                        String testId = null;
540:                        if (item instanceof  PluginActionCoolBarContributionItem) {
541:                            testId = ((PluginActionCoolBarContributionItem) item)
542:                                    .getActionSetId();
543:                        }
544:                        if (testId == null) {
545:                            break;
546:                        }
547:
548:                        if (itemId != null && testId != null) {
549:                            if (itemId.compareTo(testId) < 1) {
550:                                break;
551:                            }
552:                        }
553:                        insertIndex = i;
554:                    }
555:                    if (insertIndex >= items.length) {
556:                        return null;
557:                    }
558:                    return items[insertIndex];
559:                }
560:
561:                /**
562:                 * Returns whether the contributor is an adjunct contributor.
563:                 * 
564:                 * @return whether the contributor is an adjunct contributor
565:                 */
566:                public boolean isAdjunctContributor() {
567:                    return adjunctActions.size() > 0;
568:                }
569:
570:                /* (non-Javadoc)
571:                 * Method declared on Basic Contribution.
572:                 */
573:                protected void insertAfter(IContributionManager mgr,
574:                        String refId, IContributionItem item) {
575:                    IContributionItem refItem = findInsertionPoint(refId,
576:                            actionSetId, mgr, true);
577:                    if (refItem != null) {
578:                        mgr.insertAfter(refItem.getId(), item);
579:                    } else {
580:                        WorkbenchPlugin
581:                                .log("Reference item " + refId + " not found for action " + item.getId()); //$NON-NLS-1$ //$NON-NLS-2$
582:                    }
583:                }
584:
585:                //for dynamic UI
586:                protected void revokeContribution(WorkbenchWindow window,
587:                        IActionBars bars, String id) {
588:                    revokeActionSetFromMenu(window.getMenuManager(), id);
589:                    //			IMenuManager menuMgr = bars.getMenuManager();
590:                    //			if (menuMgr != null) 
591:                    //				revokeActionSetFromMenu(menuMgr, id);
592:
593:                    revokeActionSetFromCoolbar(window.getCoolBarManager2(), id);
594:                    //			IToolBarManager toolBarMgr = bars.getToolBarManager();
595:                    //			if (toolBarMgr != null && toolBarMgr instanceof CoolItemToolBarManager) 
596:                    //				revokeActionSetFromToolbar(toolBarMgr, id);
597:                }
598:
599:                //for dynamic UI
600:                protected void revokeAdjunctCoolbarAction(ActionDescriptor ad,
601:                        ActionSetActionBars bars) {
602:                    String toolBarId = ad.getToolbarId();
603:                    //            String toolGroupId = ad.getToolbarGroupId();
604:                    //
605:                    //            String contributingId = bars.getActionSetId();
606:                    ICoolBarManager coolBarMgr = bars.getCoolBarManager();
607:                    //				((CoolItemToolBarManager)bars.getToolBarManager()).getParentManager();
608:                    PluginAction action = ad.getAction();
609:                    PluginActionCoolBarContributionItem actionContribution = new PluginActionCoolBarContributionItem(
610:                            action);
611:
612:                    bars.removeAdjunctContribution(actionContribution);
613:
614:                    // remove a coolitem for the toolbar id if it exists 			
615:                    IContributionItem cbItem = coolBarMgr.find(toolBarId);
616:                    if (cbItem != null) {
617:                        coolBarMgr.remove(cbItem);
618:                    }
619:
620:                    //			activeManager = cbItem.getToolBarManager();	
621:                    //			activeManager.remove(contributingId);	
622:                    //			IContributionItem groupMarker = activeManager.find(toolGroupId);
623:                    //			if (groupMarker != null) {
624:                    //				int idx = activeManager.indexOf(toolGroupId);
625:                    //				IContributionItem[] items = activeManager.getItems();
626:                    //				if (items.length == idx+1 || 
627:                    //						((items.length > idx && items[idx+1] instanceof Separator)))
628:                    //					if (activeManager.find(toolGroupId) != null)
629:                    //						activeManager.remove(toolGroupId);
630:                    //			} 			
631:                    //			activeManager.addAdjunctItemToGroup(toolGroupId, contributingId, actionContribution);		 
632:                }
633:
634:                //for dynamic UI
635:                private void revokeActionSetFromMenu(IMenuManager menuMgr,
636:                        String actionsetId) {
637:                    IContributionItem[] items = menuMgr.getItems();
638:                    ArrayList itemsToRemove = new ArrayList();
639:                    String id;
640:                    for (int i = 0; i < items.length; i++) {
641:                        if (items[i] instanceof  IMenuManager) {
642:                            revokeActionSetFromMenu((IMenuManager) items[i],
643:                                    actionsetId);
644:                        } else if (items[i] instanceof  ActionSetContributionItem) {
645:                            id = ((ActionSetContributionItem) items[i])
646:                                    .getActionSetId();
647:                            if (actionsetId.equals(id)) {
648:                                itemsToRemove.add(items[i]);
649:                            }
650:                        } else if (items[i] instanceof  Separator) {
651:                            id = ((Separator) items[i]).getId();
652:                            if (actionsetId.equals(id)) {
653:                                itemsToRemove.add(items[i]);
654:                            }
655:                        } else if (items[i] instanceof  GroupMarker) {
656:                            id = ((GroupMarker) items[i]).getId();
657:                            if (actionsetId.equals(id)) {
658:                                itemsToRemove.add(items[i]);
659:                            }
660:                        }
661:                    }
662:                    Iterator iter = itemsToRemove.iterator();
663:                    while (iter.hasNext()) {
664:                        IContributionItem item = (IContributionItem) iter
665:                                .next();
666:                        menuMgr.remove(item);
667:                    }
668:                    menuMgr.update(true);
669:                }
670:
671:                // for dynamic UI
672:                private void revokeActionSetFromCoolbar(
673:                        ICoolBarManager coolbarMgr, String actionsetId) {
674:                    IContributionItem[] items = coolbarMgr.getItems();
675:                    ArrayList itemsToRemove = new ArrayList();
676:                    String id;
677:                    for (int i = 0; i < items.length; i++) {
678:                        id = items[i].getId();
679:                        if (actionsetId.equals(id)) {
680:                            itemsToRemove.add(items[i]);
681:                            continue;
682:                        }
683:                        if (items[i] instanceof  IToolBarManager) {
684:                            revokeActionSetFromToolbar(
685:                                    (IToolBarManager) items[i], actionsetId);
686:                        } else if (items[i] instanceof  IToolBarContributionItem) {
687:                            id = ((IToolBarContributionItem) items[i]).getId();
688:                            if (actionsetId.equals(id)) {
689:                                itemsToRemove.add(items[i]);
690:                            }
691:                        } else if (items[i] instanceof  GroupMarker) {
692:                            id = ((GroupMarker) items[i]).getId();
693:                            if (actionsetId.equals(id)) {
694:                                itemsToRemove.add(items[i]);
695:                            }
696:                        }
697:                    }
698:                    Iterator iter = itemsToRemove.iterator();
699:                    while (iter.hasNext()) {
700:                        coolbarMgr.remove((IContributionItem) iter.next());
701:                    }
702:                    coolbarMgr.update(true);
703:                }
704:
705:                // for dynamic UI
706:                private void revokeActionSetFromToolbar(
707:                        IToolBarManager toolbarMgr, String actionsetId) {
708:                    IContributionItem[] items = toolbarMgr.getItems();
709:                    ArrayList itemsToRemove = new ArrayList();
710:                    String id;
711:                    for (int i = 0; i < items.length; i++) {
712:                        id = items[i].getId();
713:                        if (id.equals(actionsetId)) {
714:                            itemsToRemove.add(items[i]);
715:                            continue;
716:                        }
717:                        if (items[i] instanceof  PluginActionCoolBarContributionItem) {
718:                            id = ((PluginActionCoolBarContributionItem) items[i])
719:                                    .getActionSetId();
720:                            if (actionsetId.equals(id)) {
721:                                itemsToRemove.add(items[i]);
722:                            }
723:                        } else if (items[i] instanceof  ActionContributionItem) {
724:                            id = ((ActionContributionItem) items[i]).getId();
725:                            if (actionsetId.equals(id)) {
726:                                itemsToRemove.add(items[i]);
727:                            }
728:                        } else if (items[i] instanceof  GroupMarker) {
729:                            id = ((GroupMarker) items[i]).getId();
730:                            if (actionsetId.equals(id)) {
731:                                itemsToRemove.add(items[i]);
732:                            }
733:                        }
734:                    }
735:                    Iterator iter = itemsToRemove.iterator();
736:                    while (iter.hasNext()) {
737:                        toolbarMgr.remove((IContributionItem) iter.next());
738:                    }
739:                    toolbarMgr.update(true);
740:                }
741:            }
742:
743:            /**
744:             * Remove the given action set from the window.
745:             * 
746:             * @param set the set to remove
747:             * @param window the window to remove from
748:             */
749:            protected void removeActionExtensions(PluginActionSet set,
750:                    IWorkbenchWindow window) {
751:                this .actionSet = set;
752:                this .window = window;
753:                currentContribution = null;
754:                targetID = null;
755:                targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
756:                String id = set.getDesc().getId();
757:
758:                if (cache != null) {
759:                    for (int i = 0; i < cache.size(); i++) {
760:                        ActionSetContribution contribution = (ActionSetContribution) cache
761:                                .get(i);
762:                        contribution.revokeContribution(
763:                                (WorkbenchWindow) window, actionSet.getBars(),
764:                                id);
765:                        if (contribution.isAdjunctContributor()) {
766:                            for (int j = 0; j < contribution.adjunctActions
767:                                    .size(); j++) {
768:                                ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
769:                                        .get(j);
770:                                contribution.revokeAdjunctCoolbarAction(
771:                                        adjunctAction, actionSet.getBars());
772:                            }
773:                        }
774:                    }
775:                }
776:            }
777:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.