001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.jface.action.IAction;
017: import org.eclipse.ui.IActionBars;
018: import org.eclipse.ui.IWorkbenchWindow;
019: import org.eclipse.ui.internal.registry.ActionSetDescriptor;
020: import org.eclipse.ui.internal.registry.IActionSet;
021:
022: /**
023: * A PluginActionSet is a proxy for an action set defined in XML.
024: * It creates a PluginAction for each action and does the required
025: * cleanup on dispose.
026: */
027: public class PluginActionSet implements IActionSet {
028: private ActionSetDescriptor desc;
029:
030: private ArrayList pluginActions = new ArrayList(4);
031:
032: private ActionSetActionBars bars;
033:
034: /**
035: * PluginActionSet constructor comment.
036: *
037: * @param desc the descriptor
038: */
039: public PluginActionSet(ActionSetDescriptor desc) {
040: super ();
041: this .desc = desc;
042: }
043:
044: /**
045: * Adds one plugin action ref to the list.
046: *
047: * @param action the action
048: */
049: public void addPluginAction(WWinPluginAction action) {
050: pluginActions.add(action);
051: }
052:
053: /**
054: * Returns the list of plugin actions for the set.
055: *
056: * @return the actions for the set
057: */
058: public IAction[] getPluginActions() {
059: IAction result[] = new IAction[pluginActions.size()];
060: pluginActions.toArray(result);
061: return result;
062: }
063:
064: /**
065: * Disposes of this action set.
066: */
067: public void dispose() {
068: Iterator iter = pluginActions.iterator();
069: while (iter.hasNext()) {
070: WWinPluginAction action = (WWinPluginAction) iter.next();
071: action.dispose();
072: }
073: pluginActions.clear();
074: bars = null;
075: }
076:
077: /**
078: */
079: /* package */ActionSetActionBars getBars() {
080: return bars;
081: }
082:
083: /**
084: * Returns the configuration element.
085: *
086: * @return the configuration element
087: */
088: public IConfigurationElement getConfigElement() {
089: return desc.getConfigurationElement();
090: }
091:
092: /**
093: * Returns the underlying descriptor.
094: *
095: * @return the descriptor
096: */
097: public ActionSetDescriptor getDesc() {
098: return desc;
099: }
100:
101: /**
102: * Initializes this action set, which is expected to add it actions as required
103: * to the given workbench window and action bars.
104: *
105: * @param window the workbench window
106: * @param bars the action bars
107: */
108: public void init(IWorkbenchWindow window, IActionBars bars) {
109: this .bars = (ActionSetActionBars) bars;
110: }
111: }
|