KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > workingsets > WorkingSetShowActionGroup


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.jdt.internal.ui.workingsets;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.core.runtime.Assert;
18
19 import org.eclipse.jface.action.Action;
20 import org.eclipse.jface.action.ActionContributionItem;
21 import org.eclipse.jface.action.IContributionItem;
22 import org.eclipse.jface.action.IMenuManager;
23
24 import org.eclipse.ui.IActionBars;
25 import org.eclipse.ui.IWorkbenchPartSite;
26 import org.eclipse.ui.actions.ActionGroup;
27
28 public class WorkingSetShowActionGroup extends ActionGroup implements IWorkingSetActionGroup {
29     
30     private List JavaDoc fContributions= new ArrayList JavaDoc();
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.setWorkingSetModel(fWorkingSetModel);
45     }
46     
47     /**
48      * {@inheritDoc}
49      */

50     public void fillActionBars(IActionBars actionBars) {
51         super.fillActionBars(actionBars);
52         IMenuManager menuManager= actionBars.getMenuManager();
53         fillViewMenu(menuManager);
54     }
55     
56     public void fillViewMenu(IMenuManager menuManager) {
57         fConfigureWorkingSetAction= new ConfigureWorkingSetAction(fSite);
58         if (fWorkingSetModel != null)
59             fConfigureWorkingSetAction.setWorkingSetModel(fWorkingSetModel);
60         addAction(menuManager, fConfigureWorkingSetAction);
61     }
62     
63     public void cleanViewMenu(IMenuManager menuManager) {
64         for (Iterator JavaDoc iter= fContributions.iterator(); iter.hasNext();) {
65             IContributionItem removed= menuManager.remove((IContributionItem) iter.next());
66             if (removed != null) {
67                 removed.dispose();
68             }
69         }
70         fContributions.clear();
71     }
72
73     private void addAction(IMenuManager menuManager, Action action) {
74         IContributionItem item= new ActionContributionItem(action);
75         menuManager.appendToGroup(ACTION_GROUP, item);
76         fContributions.add(item);
77     }
78 }
79
Popular Tags