01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.ui.IActionBars;
15: import org.eclipse.ui.IViewPart;
16: import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants;
17:
18: /**
19: * This class reads the registry for extensions that plug into
20: * 'viewActions' extension point.
21: */
22: public class ViewActionBuilder extends PluginActionBuilder {
23: public static final String TAG_CONTRIBUTION_TYPE = "viewContribution"; //$NON-NLS-1$
24:
25: private IViewPart targetPart;
26:
27: /**
28: * Basic constructor
29: */
30: public ViewActionBuilder() {
31: }
32:
33: /**
34: * Contribute the external menus and actions applicable for this view part.
35: */
36: private void contributeToPart(IViewPart part) {
37: IActionBars bars = part.getViewSite().getActionBars();
38: contribute(bars.getMenuManager(), bars.getToolBarManager(),
39: 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 results = new ArrayList();
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(),
77: TAG_CONTRIBUTION_TYPE,
78: IWorkbenchRegistryConstants.PL_VIEW_ACTIONS);
79: contributeToPart(targetPart);
80: }
81:
82: public void dispose() {
83: if (cache != null) {
84: for (int i = 0; i < cache.size(); i++) {
85: ((BasicContribution) cache.get(i)).disposeActions();
86: }
87: }
88: }
89: }
|