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.jdt.internal.ui.workingsets;
11:
12: import java.util.ArrayList;
13: import java.util.Iterator;
14: import java.util.List;
15:
16: import org.eclipse.core.runtime.Assert;
17:
18: import org.eclipse.jface.action.Action;
19: import org.eclipse.jface.action.ActionContributionItem;
20: import org.eclipse.jface.action.IContributionItem;
21: import org.eclipse.jface.action.IMenuManager;
22:
23: import org.eclipse.ui.IActionBars;
24: import org.eclipse.ui.IWorkbenchPartSite;
25: import org.eclipse.ui.actions.ActionGroup;
26:
27: public class WorkingSetShowActionGroup extends ActionGroup implements
28: IWorkingSetActionGroup {
29:
30: private List fContributions = new ArrayList();
31: private ConfigureWorkingSetAction fConfigureWorkingSetAction;
32: private WorkingSetModel fWorkingSetModel;
33: private final IWorkbenchPartSite fSite;
34:
35: public WorkingSetShowActionGroup(IWorkbenchPartSite site) {
36: Assert.isNotNull(site);
37: fSite = site;
38: }
39:
40: public void setWorkingSetMode(WorkingSetModel model) {
41: Assert.isNotNull(model);
42: fWorkingSetModel = model;
43: if (fConfigureWorkingSetAction != null)
44: fConfigureWorkingSetAction
45: .setWorkingSetModel(fWorkingSetModel);
46: }
47:
48: /**
49: * {@inheritDoc}
50: */
51: public void fillActionBars(IActionBars actionBars) {
52: super .fillActionBars(actionBars);
53: IMenuManager menuManager = actionBars.getMenuManager();
54: fillViewMenu(menuManager);
55: }
56:
57: public void fillViewMenu(IMenuManager menuManager) {
58: fConfigureWorkingSetAction = new ConfigureWorkingSetAction(
59: fSite);
60: if (fWorkingSetModel != null)
61: fConfigureWorkingSetAction
62: .setWorkingSetModel(fWorkingSetModel);
63: addAction(menuManager, fConfigureWorkingSetAction);
64: }
65:
66: public void cleanViewMenu(IMenuManager menuManager) {
67: for (Iterator iter = fContributions.iterator(); iter.hasNext();) {
68: IContributionItem removed = menuManager
69: .remove((IContributionItem) iter.next());
70: if (removed != null) {
71: removed.dispose();
72: }
73: }
74: fContributions.clear();
75: }
76:
77: private void addAction(IMenuManager menuManager, Action action) {
78: IContributionItem item = new ActionContributionItem(action);
79: menuManager.appendToGroup(ACTION_GROUP, item);
80: fContributions.add(item);
81: }
82: }
|