KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.ui.internal;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.ui.IActionBars;
16 import org.eclipse.ui.IViewPart;
17 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
18
19 /**
20  * This class reads the registry for extensions that plug into
21  * 'viewActions' extension point.
22  */

23 public class ViewActionBuilder extends PluginActionBuilder {
24     public static final String JavaDoc TAG_CONTRIBUTION_TYPE = "viewContribution"; //$NON-NLS-1$
25

26     private IViewPart targetPart;
27
28     /**
29      * Basic constructor
30      */

31     public ViewActionBuilder() {
32     }
33
34     /**
35      * Contribute the external menus and actions applicable for this view part.
36      */

37     private void contributeToPart(IViewPart part) {
38         IActionBars bars = part.getViewSite().getActionBars();
39         contribute(bars.getMenuManager(), bars.getToolBarManager(), true);
40     }
41
42     /* (non-Javadoc)
43      * Method declared on PluginActionBuilder.
44      */

45     protected ActionDescriptor createActionDescriptor(
46             org.eclipse.core.runtime.IConfigurationElement element) {
47         return new ActionDescriptor(element, ActionDescriptor.T_VIEW,
48                 targetPart);
49     }
50
51     /**
52      * Return all extended actions.
53      */

54     public ActionDescriptor[] getExtendedActions() {
55         if (cache == null) {
56             return new ActionDescriptor[0];
57         }
58
59         ArrayList JavaDoc results = new ArrayList JavaDoc();
60         for (int i = 0; i < cache.size(); i++) {
61             BasicContribution bc = (BasicContribution) cache.get(i);
62             if (bc.actions != null) {
63                 results.addAll(bc.actions);
64             }
65         }
66         return (ActionDescriptor[]) results
67                 .toArray(new ActionDescriptor[results.size()]);
68     }
69
70     /**
71      * Reads and apply all external contributions for this view's ID registered
72      * in 'viewActions' extension point.
73      */

74     public void readActionExtensions(IViewPart viewPart) {
75         targetPart = viewPart;
76         readContributions(viewPart.getSite().getId(), TAG_CONTRIBUTION_TYPE,
77                 IWorkbenchRegistryConstants.PL_VIEW_ACTIONS);
78         contributeToPart(targetPart);
79     }
80     
81     public void dispose() {
82         if (cache != null) {
83             for (int i = 0; i < cache.size(); i++) {
84                 ((BasicContribution) cache.get(i)).disposeActions();
85             }
86         }
87     }
88 }
89
Popular Tags