KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > PluginActionSetBuilder


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

11 package org.eclipse.ui.internal;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.runtime.IConfigurationElement;
17 import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker;
18 import org.eclipse.jface.action.AbstractGroupMarker;
19 import org.eclipse.jface.action.ActionContributionItem;
20 import org.eclipse.jface.action.GroupMarker;
21 import org.eclipse.jface.action.IContributionItem;
22 import org.eclipse.jface.action.IContributionManager;
23 import org.eclipse.jface.action.ICoolBarManager;
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.IToolBarManager;
26 import org.eclipse.jface.action.Separator;
27 import org.eclipse.jface.internal.provisional.action.IToolBarContributionItem;
28 import org.eclipse.ui.IActionBars;
29 import org.eclipse.ui.IWorkbenchActionConstants;
30 import org.eclipse.ui.IWorkbenchWindow;
31 import org.eclipse.ui.internal.registry.ActionSetRegistry;
32 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
33
34 /**
35  * This builder reads the actions for an action set from the registry.
36  */

37 public class PluginActionSetBuilder extends PluginActionBuilder {
38
39     private PluginActionSet actionSet;
40
41     private IWorkbenchWindow window;
42
43     private ArrayList JavaDoc adjunctContributions = new ArrayList JavaDoc(0);
44     
45     /**
46      * Used by the workbench window extension handler to unhook action sets from
47      * their associated window.
48      *
49      * @since 3.1
50      */

51     public static class Binding {
52         PluginActionSetBuilder builder;
53         PluginActionSet set;
54         IWorkbenchWindow window;
55     }
56
57     /**
58      * Constructs a new builder.
59      */

60     public PluginActionSetBuilder() {
61     }
62
63     /**
64      * Read the actions within a config element. Called by customize perspective
65      *
66      * @param set the action set
67      * @param window the window to contribute to
68      */

69     public void buildMenuAndToolBarStructure(PluginActionSet set,
70             IWorkbenchWindow window) {
71         this.actionSet = set;
72         this.window = window;
73         cache = null;
74         currentContribution = null;
75         targetID = null;
76         targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
77
78         readElements(new IConfigurationElement[] { set.getConfigElement() });
79
80         if (cache != null) {
81             for (int i = 0; i < cache.size(); i++) {
82                 ActionSetContribution contribution = (ActionSetContribution) cache
83                         .get(i);
84                 contribution.contribute(actionSet.getBars(), true, true);
85                 if (contribution.isAdjunctContributor()) {
86                     adjunctContributions.add(contribution);
87                 }
88             }
89         }
90         for (int i = 0; i < adjunctContributions.size(); i++) {
91             ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
92                     .get(i);
93             ActionSetActionBars bars = actionSet.getBars();
94             for (int j = 0; j < contribution.adjunctActions.size(); j++) {
95                 ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
96                         .get(j);
97                 contribution
98                         .contributeAdjunctCoolbarAction(adjunctAction, bars);
99             }
100         }
101         
102         Binding binding = new Binding();
103         binding.builder = this;
104         binding.set = set;
105         binding.window = window;
106         window.getExtensionTracker().registerObject(
107                 set.getConfigElement().getDeclaringExtension(), binding,
108                 IExtensionTracker.REF_STRONG);
109     }
110
111     /* (non-Javadoc)
112      * Method declared on PluginActionBuilder.
113      */

114     protected ActionDescriptor createActionDescriptor(
115             IConfigurationElement element) {
116         // As of 2.1, the "pulldown" attribute was deprecated and replaced by
117
// the attribute "style". See doc for more details.
118
boolean pullDownStyle = false;
119         String JavaDoc style = element.getAttribute(IWorkbenchRegistryConstants.ATT_STYLE);
120         if (style != null) {
121             pullDownStyle = style.equals(ActionDescriptor.STYLE_PULLDOWN);
122         } else {
123             String JavaDoc pulldown = element.getAttribute(ActionDescriptor.STYLE_PULLDOWN);
124             pullDownStyle = pulldown != null && pulldown.equals("true"); //$NON-NLS-1$
125
}
126
127         ActionDescriptor desc = null;
128         if (pullDownStyle) {
129             desc = new ActionDescriptor(element,
130                     ActionDescriptor.T_WORKBENCH_PULLDOWN, window);
131         } else {
132             desc = new ActionDescriptor(element, ActionDescriptor.T_WORKBENCH,
133                     window);
134         }
135         WWinPluginAction action = (WWinPluginAction) desc.getAction();
136         action.setActionSetId(actionSet.getDesc().getId());
137         actionSet.addPluginAction(action);
138         return desc;
139     }
140
141     /* (non-Javadoc)
142      * Method declared on PluginActionBuilder.
143      */

144     protected BasicContribution createContribution() {
145         return new ActionSetContribution(actionSet.getDesc().getId(), window);
146     }
147
148     /**
149      * Returns the insertion point for a new contribution item. Clients should
150      * use this item as a reference point for insertAfter.
151      *
152      * @param startId the reference id for insertion
153      * @param sortId the sorting id for the insertion. If null then the item
154      * will be inserted at the end of all action sets.
155      * @param mgr the target menu manager.
156      * @param startVsEnd if <code>true</code> the items are added at the start of
157      * action with the same id; else they are added to the end
158      * @return the insertion point, or null if not found.
159      */

160     public static IContributionItem findInsertionPoint(String JavaDoc startId,
161             String JavaDoc sortId, IContributionManager mgr, boolean startVsEnd) {
162         // Get items.
163
IContributionItem[] items = mgr.getItems();
164
165         // Find the reference item.
166
int insertIndex = 0;
167         while (insertIndex < items.length) {
168             if (startId.equals(items[insertIndex].getId())) {
169                 break;
170             }
171             ++insertIndex;
172         }
173         if (insertIndex >= items.length) {
174             return null;
175         }
176
177         // Calculate startVsEnd comparison value.
178
int compareMetric = 0;
179         if (startVsEnd) {
180             compareMetric = 1;
181         }
182
183         // Find the insertion point for the new item.
184
// We do this by iterating through all of the previous
185
// action set contributions define within the current group.
186
for (int nX = insertIndex + 1; nX < items.length; nX++) {
187             IContributionItem item = items[nX];
188             if (item.isSeparator() || item.isGroupMarker()) {
189                 // Fix for bug report 18357
190
break;
191             }
192             if (item instanceof IActionSetContributionItem) {
193                 if (sortId != null) {
194                     String JavaDoc testId = ((IActionSetContributionItem) item)
195                             .getActionSetId();
196                     if (sortId.compareTo(testId) < compareMetric) {
197                         break;
198                     }
199                 }
200                 insertIndex = nX;
201             } else {
202                 break;
203             }
204         }
205         // Return item.
206
return items[insertIndex];
207     }
208
209     /**
210      */

211     /* package */static void processActionSets(ArrayList JavaDoc pluginActionSets,
212             WorkbenchWindow window) {
213         // Process the action sets in two passes. On the first pass the pluginActionSetBuilder
214
// will process base contributions and cache adjunct contributions. On the second
215
// pass the adjunct contributions will be processed.
216
PluginActionSetBuilder[] builders = new PluginActionSetBuilder[pluginActionSets
217                 .size()];
218         for (int i = 0; i < pluginActionSets.size(); i++) {
219             PluginActionSet set = (PluginActionSet) pluginActionSets.get(i);
220             PluginActionSetBuilder builder = new PluginActionSetBuilder();
221             builder.readActionExtensions(set, window);
222             builders[i] = builder;
223         }
224         for (int i = 0; i < builders.length; i++) {
225             PluginActionSetBuilder builder = builders[i];
226             builder.processAdjunctContributions();
227         }
228     }
229
230     /**
231      */

232     protected void processAdjunctContributions() {
233         // Contribute the adjunct contributions.
234
for (int i = 0; i < adjunctContributions.size(); i++) {
235             ActionSetContribution contribution = (ActionSetContribution) adjunctContributions
236                     .get(i);
237             ActionSetActionBars bars = actionSet.getBars();
238             for (int j = 0; j < contribution.adjunctActions.size(); j++) {
239                 ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
240                         .get(j);
241                 contribution
242                         .contributeAdjunctCoolbarAction(adjunctAction, bars);
243             }
244         }
245     }
246
247     /**
248      * Read the actions within a config element.
249      */

250     protected void readActionExtensions(PluginActionSet set,
251             IWorkbenchWindow window) {
252         this.actionSet = set;
253         this.window = window;
254         cache = null;
255         currentContribution = null;
256         targetID = null;
257         targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
258
259         readElements(new IConfigurationElement[] { set.getConfigElement() });
260
261         if (cache != null) {
262             // for dynamic UI - save cache for future removal lf actionset extensions
263
// Don't call addCache -- it's broken, and is only used for dynamic plugin removal,
264
// which the workbench doesn't currently support.
265
// See bug 66374 for more details.
266
// WorkbenchPlugin.getDefault().getActionSetRegistry().addCache(set.getDesc().getId(), cache);
267
for (int i = 0; i < cache.size(); i++) {
268                 ActionSetContribution contribution = (ActionSetContribution) cache
269                         .get(i);
270                 contribution.contribute(actionSet.getBars(), true, true);
271                 if (contribution.isAdjunctContributor()) {
272                     adjunctContributions.add(contribution);
273                 }
274             }
275             
276             Binding binding = new Binding();
277             binding.builder = this;
278             binding.set = set;
279             binding.window = window;
280             window.getExtensionTracker().registerObject(
281                     set.getConfigElement().getDeclaringExtension(), binding,
282                     IExtensionTracker.REF_STRONG);
283         } else {
284             WorkbenchPlugin
285                     .log("Action Set is empty: " + set.getDesc().getId()); //$NON-NLS-1$
286
}
287     }
288
289     /**
290      * Helper class to collect the menus and actions defined within a
291      * contribution element.
292      */

293     private static class ActionSetContribution extends BasicContribution {
294         private String JavaDoc actionSetId;
295
296         private WorkbenchWindow window;
297
298         protected ArrayList JavaDoc adjunctActions = new ArrayList JavaDoc(0);
299
300         /**
301          * Create a new instance of <code>ActionSetContribution</code>.
302          *
303          * @param id the id
304          * @param window the window to contribute to
305          */

306         public ActionSetContribution(String JavaDoc id, IWorkbenchWindow window) {
307             super();
308             actionSetId = id;
309             this.window = (WorkbenchWindow) window;
310         }
311
312         /**
313          * This implementation inserts the group into the action set additions group.
314          */

315         protected void addGroup(IContributionManager mgr, String JavaDoc name) {
316             IContributionItem refItem = findInsertionPoint(
317                     IWorkbenchActionConstants.MB_ADDITIONS, actionSetId, mgr,
318                     true);
319             // Insert the new group marker.
320
ActionSetSeparator group = new ActionSetSeparator(name, actionSetId);
321             if (refItem == null) {
322                 mgr.add(group);
323             } else {
324                 mgr.insertAfter(refItem.getId(), group);
325             }
326         }
327
328         /**
329          * Contributes submenus and/or actions into the provided menu and tool bar
330          * managers.
331          *
332          * @param bars the action bars to contribute to
333          * @param menuAppendIfMissing append to the menubar if missing
334          * @param toolAppendIfMissing append to the toolbar if missing
335          */

336         public void contribute(IActionBars bars, boolean menuAppendIfMissing,
337                 boolean toolAppendIfMissing) {
338
339             IMenuManager menuMgr = bars.getMenuManager();
340             IToolBarManager toolBarMgr = bars.getToolBarManager();
341             if (menus != null && menuMgr != null) {
342                 for (int i = 0; i < menus.size(); i++) {
343                     IConfigurationElement menuElement = (IConfigurationElement) menus
344                             .get(i);
345                     contributeMenu(menuElement, menuMgr, menuAppendIfMissing);
346                 }
347             }
348
349             if (actions != null) {
350                 for (int i = 0; i < actions.size(); i++) {
351                     ActionDescriptor ad = (ActionDescriptor) actions.get(i);
352                     if (menuMgr != null) {
353                         contributeMenuAction(ad, menuMgr, menuAppendIfMissing);
354                     }
355                     if (toolBarMgr != null) {
356                         if (bars instanceof ActionSetActionBars) {
357                             contributeCoolbarAction(ad,
358                                     (ActionSetActionBars) bars);
359                         } else {
360                             contributeToolbarAction(ad, toolBarMgr,
361                                     toolAppendIfMissing);
362                         }
363                     }
364                 }
365             }
366         }
367
368         /**
369          * Contributes action from the action descriptor into the cool bar manager.
370          */

371         protected void contributeAdjunctCoolbarAction(ActionDescriptor ad,
372                 ActionSetActionBars bars) {
373             String JavaDoc toolBarId = ad.getToolbarId();
374             String JavaDoc toolGroupId = ad.getToolbarGroupId();
375
376             String JavaDoc contributingId = bars.getActionSetId();
377             ICoolBarManager coolBarMgr = bars.getCoolBarManager();
378             if (coolBarMgr == null) {
379                 return;
380             }
381
382             PluginAction action = ad.getAction();
383             ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
384                     action);
385
386             bars.addAdjunctContribution(actionContribution);
387
388             // create a coolitem for the toolbar id if it does not yet exist
389
IToolBarManager toolBarManager = bars.getToolBarManager(toolBarId);
390
391             // Check to see if the group already exists
392
IContributionItem groupMarker = toolBarManager.find(toolGroupId);
393             // Add a group marker if one does not exist
394
if (groupMarker == null) {
395                 toolBarManager.add(new Separator(toolGroupId));
396             }
397             IContributionItem refItem = findAlphabeticalOrder(toolGroupId,
398                     contributingId, toolBarManager);
399             if (refItem != null && refItem.getId() != null) {
400                 toolBarManager.insertAfter(refItem.getId(), actionContribution);
401             } else {
402                 toolBarManager.add(actionContribution);
403             }
404             toolBarManager.update(false);
405
406         }
407
408         /**
409          * Contributes action from the action descriptor into the cool bar manager.
410          */

411         protected void contributeCoolbarAction(ActionDescriptor ad,
412                 ActionSetActionBars bars) {
413             String JavaDoc toolBarId = ad.getToolbarId();
414             String JavaDoc toolGroupId = ad.getToolbarGroupId();
415             if (toolBarId == null && toolGroupId == null) {
416                 return;
417             }
418
419             String JavaDoc contributingId = bars.getActionSetId();
420
421             if (toolBarId == null || toolBarId.equals("")) { //$NON-NLS-1$
422
// the item is being added to the coolitem for its action set
423
toolBarId = contributingId;
424             }
425
426             if (!toolBarId.equals(contributingId)) {
427                 // adding to another action set, validate the id
428
if (!isValidCoolItemId(toolBarId, window)) {
429                     // toolbarid not valid, add the item to the coolitem for its action set
430
toolBarId = contributingId;
431                 } else {
432                     adjunctActions.add(ad);
433                     return;
434                 }
435             }
436
437             // Create the action
438
PluginAction action = ad.getAction();
439             ActionContributionItem actionContribution = new PluginActionCoolBarContributionItem(
440                     action);
441
442             // retreive the toolbar from the action bars.
443
IToolBarManager toolBar = bars.getToolBarManager(toolBarId);
444
445             // Check to see if the group already exists
446
IContributionItem groupMarker = toolBar.find(toolGroupId);
447             // Add a group marker if one does not exist
448
if (groupMarker == null) {
449                 // @issue should this be a GroupMarker?
450
toolBar.add(new Separator(toolGroupId));
451             }
452             toolBar.prependToGroup(toolGroupId, actionContribution);
453             toolBar.update(false);
454
455         }
456
457         /**
458          * Checks to see if the cool item id is in the given window.
459          */

460         private boolean isValidCoolItemId(String JavaDoc id, WorkbenchWindow window) {
461             ActionSetRegistry registry = WorkbenchPlugin.getDefault()
462                     .getActionSetRegistry();
463             if (registry.findActionSet(id) != null) {
464                 return true;
465             }
466             if (window != null) {
467                 return window.isWorkbenchCoolItemId(id);
468             }
469             return false;
470         }
471
472         /* (non-Javadoc)
473          * Method declared on Basic Contribution.
474          */

475         protected void insertMenuGroup(IMenuManager menu,
476                 AbstractGroupMarker marker) {
477             if (actionSetId != null) {
478                 IContributionItem[] items = menu.getItems();
479                 // Loop thru all the current groups looking for the first
480
// group whose id > than the current action set id. Insert
481
// current marker just before this item then.
482
for (int i = 0; i < items.length; i++) {
483                     IContributionItem item = items[i];
484                     if (item.isSeparator() || item.isGroupMarker()) {
485                         if (item instanceof IActionSetContributionItem) {
486                             String JavaDoc testId = ((IActionSetContributionItem) item)
487                                     .getActionSetId();
488                             if (actionSetId.compareTo(testId) < 0) {
489                                 menu.insertBefore(items[i].getId(), marker);
490                                 return;
491                             }
492                         }
493                     }
494                 }
495             }
496
497             menu.add(marker);
498         }
499
500         private IContributionItem findAlphabeticalOrder(String JavaDoc startId,
501                 String JavaDoc itemId, IContributionManager mgr) {
502             IContributionItem[] items = mgr.getItems();
503             int insertIndex = 0;
504
505             // look for starting point
506
while (insertIndex < items.length) {
507                 IContributionItem item = items[insertIndex];
508                 if (startId != null && startId.equals(item.getId())) {
509                     break;
510                 }
511                 ++insertIndex;
512             }
513
514             // Find the index that this item should be inserted in
515
for (int i = insertIndex + 1; i < items.length; i++) {
516                 IContributionItem item = items[i];
517                 if (item.isGroupMarker()) {
518                     break;
519                 }
520
521                 String JavaDoc testId = null;
522                 if (item instanceof PluginActionCoolBarContributionItem) {
523                     testId = ((PluginActionCoolBarContributionItem) item)
524                             .getActionSetId();
525                 }
526                 if (testId == null) {
527                     break;
528                 }
529
530                 if (itemId != null && testId != null) {
531                     if (itemId.compareTo(testId) < 1) {
532                         break;
533                     }
534                 }
535                 insertIndex = i;
536             }
537             if (insertIndex >= items.length) {
538                 return null;
539             }
540             return items[insertIndex];
541         }
542
543         /**
544          * Returns whether the contributor is an adjunct contributor.
545          *
546          * @return whether the contributor is an adjunct contributor
547          */

548         public boolean isAdjunctContributor() {
549             return adjunctActions.size() > 0;
550         }
551
552         /* (non-Javadoc)
553          * Method declared on Basic Contribution.
554          */

555         protected void insertAfter(IContributionManager mgr, String JavaDoc refId,
556                 IContributionItem item) {
557             IContributionItem refItem = findInsertionPoint(refId, actionSetId,
558                     mgr, true);
559             if (refItem != null) {
560                 mgr.insertAfter(refItem.getId(), item);
561             } else {
562                 WorkbenchPlugin
563                         .log("Reference item " + refId + " not found for action " + item.getId()); //$NON-NLS-1$ //$NON-NLS-2$
564
}
565         }
566
567         //for dynamic UI
568
protected void revokeContribution(WorkbenchWindow window,
569                 IActionBars bars, String JavaDoc id) {
570             revokeActionSetFromMenu(window.getMenuManager(), id);
571             // IMenuManager menuMgr = bars.getMenuManager();
572
// if (menuMgr != null)
573
// revokeActionSetFromMenu(menuMgr, id);
574

575             revokeActionSetFromCoolbar(window.getCoolBarManager2(), id);
576             // IToolBarManager toolBarMgr = bars.getToolBarManager();
577
// if (toolBarMgr != null && toolBarMgr instanceof CoolItemToolBarManager)
578
// revokeActionSetFromToolbar(toolBarMgr, id);
579
}
580
581         //for dynamic UI
582
protected void revokeAdjunctCoolbarAction(ActionDescriptor ad,
583                 ActionSetActionBars bars) {
584             String JavaDoc toolBarId = ad.getToolbarId();
585 // String toolGroupId = ad.getToolbarGroupId();
586
//
587
// String contributingId = bars.getActionSetId();
588
ICoolBarManager coolBarMgr = bars.getCoolBarManager();
589             // ((CoolItemToolBarManager)bars.getToolBarManager()).getParentManager();
590
PluginAction action = ad.getAction();
591             PluginActionCoolBarContributionItem actionContribution = new PluginActionCoolBarContributionItem(
592                     action);
593
594             bars.removeAdjunctContribution(actionContribution);
595
596             // remove a coolitem for the toolbar id if it exists
597
IContributionItem cbItem = coolBarMgr.find(toolBarId);
598             if (cbItem != null) {
599                 coolBarMgr.remove(cbItem);
600             }
601
602             // activeManager = cbItem.getToolBarManager();
603
// activeManager.remove(contributingId);
604
// IContributionItem groupMarker = activeManager.find(toolGroupId);
605
// if (groupMarker != null) {
606
// int idx = activeManager.indexOf(toolGroupId);
607
// IContributionItem[] items = activeManager.getItems();
608
// if (items.length == idx+1 ||
609
// ((items.length > idx && items[idx+1] instanceof Separator)))
610
// if (activeManager.find(toolGroupId) != null)
611
// activeManager.remove(toolGroupId);
612
// }
613
// activeManager.addAdjunctItemToGroup(toolGroupId, contributingId, actionContribution);
614
}
615
616         //for dynamic UI
617
private void revokeActionSetFromMenu(IMenuManager menuMgr,
618                 String JavaDoc actionsetId) {
619             IContributionItem[] items = menuMgr.getItems();
620             ArrayList JavaDoc itemsToRemove = new ArrayList JavaDoc();
621             String JavaDoc id;
622             for (int i = 0; i < items.length; i++) {
623                 if (items[i] instanceof IMenuManager) {
624                     revokeActionSetFromMenu((IMenuManager) items[i],
625                             actionsetId);
626                 } else if (items[i] instanceof ActionSetContributionItem) {
627                     id = ((ActionSetContributionItem) items[i])
628                             .getActionSetId();
629                     if (actionsetId.equals(id)) {
630                         itemsToRemove.add(items[i]);
631                     }
632                 } else if (items[i] instanceof Separator) {
633                     id = ((Separator) items[i]).getId();
634                     if (actionsetId.equals(id)) {
635                         itemsToRemove.add(items[i]);
636                     }
637                 } else if (items[i] instanceof GroupMarker) {
638                     id = ((GroupMarker) items[i]).getId();
639                     if (actionsetId.equals(id)) {
640                         itemsToRemove.add(items[i]);
641                     }
642                 }
643             }
644             Iterator JavaDoc iter = itemsToRemove.iterator();
645             while (iter.hasNext()) {
646                 IContributionItem item = (IContributionItem) iter.next();
647                 menuMgr.remove(item);
648             }
649             menuMgr.update(true);
650         }
651
652         // for dynamic UI
653
private void revokeActionSetFromCoolbar(ICoolBarManager coolbarMgr,
654                 String JavaDoc actionsetId) {
655             IContributionItem[] items = coolbarMgr.getItems();
656             ArrayList JavaDoc itemsToRemove = new ArrayList JavaDoc();
657             String JavaDoc id;
658             for (int i = 0; i < items.length; i++) {
659                 id = items[i].getId();
660                 if (actionsetId.equals(id)) {
661                     itemsToRemove.add(items[i]);
662                     continue;
663                 }
664                 if (items[i] instanceof IToolBarManager) {
665                     revokeActionSetFromToolbar((IToolBarManager) items[i],
666                             actionsetId);
667                 } else if (items[i] instanceof IToolBarContributionItem) {
668                     id = ((IToolBarContributionItem) items[i]).getId();
669                     if (actionsetId.equals(id)) {
670                         itemsToRemove.add(items[i]);
671                     }
672                 } else if (items[i] instanceof GroupMarker) {
673                     id = ((GroupMarker) items[i]).getId();
674                     if (actionsetId.equals(id)) {
675                         itemsToRemove.add(items[i]);
676                     }
677                 }
678             }
679             Iterator JavaDoc iter = itemsToRemove.iterator();
680             while (iter.hasNext()) {
681                 coolbarMgr.remove((IContributionItem) iter.next());
682             }
683             coolbarMgr.update(true);
684         }
685
686         // for dynamic UI
687
private void revokeActionSetFromToolbar(IToolBarManager toolbarMgr,
688                 String JavaDoc actionsetId) {
689             IContributionItem[] items = toolbarMgr.getItems();
690             ArrayList JavaDoc itemsToRemove = new ArrayList JavaDoc();
691             String JavaDoc id;
692             for (int i = 0; i < items.length; i++) {
693                 id = items[i].getId();
694                 if (id.equals(actionsetId)) {
695                     itemsToRemove.add(items[i]);
696                     continue;
697                 }
698                 if (items[i] instanceof PluginActionCoolBarContributionItem) {
699                     id = ((PluginActionCoolBarContributionItem) items[i])
700                             .getActionSetId();
701                     if (actionsetId.equals(id)) {
702                         itemsToRemove.add(items[i]);
703                     }
704                 } else if (items[i] instanceof ActionContributionItem) {
705                     id = ((ActionContributionItem) items[i]).getId();
706                     if (actionsetId.equals(id)) {
707                         itemsToRemove.add(items[i]);
708                     }
709                 } else if (items[i] instanceof GroupMarker) {
710                     id = ((GroupMarker) items[i]).getId();
711                     if (actionsetId.equals(id)) {
712                         itemsToRemove.add(items[i]);
713                     }
714                 }
715             }
716             Iterator JavaDoc iter = itemsToRemove.iterator();
717             while (iter.hasNext()) {
718                 toolbarMgr.remove((IContributionItem) iter.next());
719             }
720             toolbarMgr.update(true);
721         }
722     }
723
724
725     /**
726      * Remove the given action set from the window.
727      *
728      * @param set the set to remove
729      * @param window the window to remove from
730      */

731     protected void removeActionExtensions(PluginActionSet set,
732             IWorkbenchWindow window) {
733         this.actionSet = set;
734         this.window = window;
735         currentContribution = null;
736         targetID = null;
737         targetContributionTag = IWorkbenchRegistryConstants.TAG_ACTION_SET;
738         String JavaDoc id = set.getDesc().getId();
739         
740         if (cache != null) {
741             for (int i = 0; i < cache.size(); i++) {
742                 ActionSetContribution contribution = (ActionSetContribution) cache
743                         .get(i);
744                 contribution.revokeContribution((WorkbenchWindow) window,
745                         actionSet.getBars(), id);
746                 if (contribution.isAdjunctContributor()) {
747                     for (int j = 0; j < contribution.adjunctActions.size(); j++) {
748                         ActionDescriptor adjunctAction = (ActionDescriptor) contribution.adjunctActions
749                                 .get(j);
750                         contribution.revokeAdjunctCoolbarAction(adjunctAction,
751                                 actionSet.getBars());
752                     }
753                 }
754             }
755         }
756     }
757 }
758
Popular Tags