KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 org.eclipse.jface.action.IMenuManager;
14 import org.eclipse.jface.action.Separator;
15 import org.eclipse.jface.viewers.ISelection;
16 import org.eclipse.jface.viewers.ISelectionChangedListener;
17 import org.eclipse.jface.viewers.ISelectionProvider;
18 import org.eclipse.jface.viewers.SelectionChangedEvent;
19
20 import org.eclipse.ui.IViewPart;
21 import org.eclipse.ui.IViewSite;
22 import org.eclipse.ui.actions.ActionGroup;
23
24 import org.eclipse.jdt.ui.IContextMenuConstants;
25
26 public class WorkingSetActionGroup extends ActionGroup {
27
28     private static final String JavaDoc GROUP_WORKINGSETS= "group.workingSets"; //$NON-NLS-1$
29

30     private IViewSite fSite;
31     private ISelectionChangedListener fLazyInitializer= new ISelectionChangedListener() {
32         public void selectionChanged(SelectionChangedEvent event) {
33             ISelectionProvider selectionProvider= fSite.getSelectionProvider();
34             selectionProvider.removeSelectionChangedListener(fLazyInitializer);
35             ISelection selection= event.getSelection();
36             
37             fRemoveAction= new RemoveWorkingSetElementAction(fSite);
38             fRemoveAction.update(selection);
39             selectionProvider.addSelectionChangedListener(fRemoveAction);
40             
41             fEditAction= new OpenPropertiesWorkingSetAction(fSite);
42             fEditAction.update(selection);
43             selectionProvider.addSelectionChangedListener(fEditAction);
44             
45             fCloseAction= OpenCloseWorkingSetAction.createCloseAction(fSite);
46             fCloseAction.update(selection);
47             selectionProvider.addSelectionChangedListener(fCloseAction);
48             
49             fOpenAction= OpenCloseWorkingSetAction.createOpenAction(fSite);
50             fOpenAction.update(selection);
51             selectionProvider.addSelectionChangedListener(fOpenAction);
52         }
53     };
54     
55     private RemoveWorkingSetElementAction fRemoveAction;
56     private OpenPropertiesWorkingSetAction fEditAction;
57     private OpenCloseWorkingSetAction fCloseAction;
58     private OpenCloseWorkingSetAction fOpenAction;
59     
60     public WorkingSetActionGroup(IViewPart part) {
61         fSite= part.getViewSite();
62         fSite.getSelectionProvider().addSelectionChangedListener(fLazyInitializer);
63     }
64     
65     public void dispose() {
66         ISelectionProvider selectionProvider= fSite.getSelectionProvider();
67         
68         if (fRemoveAction != null)
69             selectionProvider.removeSelectionChangedListener(fRemoveAction);
70         if (fEditAction != null)
71             selectionProvider.removeSelectionChangedListener(fEditAction);
72         if (fCloseAction != null) {
73             selectionProvider.removeSelectionChangedListener(fCloseAction);
74             fCloseAction.dispose();
75         }
76         if (fOpenAction != null) {
77             selectionProvider.removeSelectionChangedListener(fOpenAction);
78             fOpenAction.dispose();
79         }
80     }
81     
82     public void fillContextMenu(IMenuManager menu) {
83         super.fillContextMenu(menu);
84         menu.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, new Separator(GROUP_WORKINGSETS));
85         if (fRemoveAction != null && fRemoveAction.isEnabled())
86             menu.appendToGroup(GROUP_WORKINGSETS, fRemoveAction);
87         if (fCloseAction != null && fCloseAction.isEnabled())
88             menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fCloseAction);
89         if (fOpenAction != null && fOpenAction.isEnabled())
90             menu.appendToGroup(IContextMenuConstants.GROUP_BUILD, fOpenAction);
91         if (fEditAction != null && fEditAction.isEnabled())
92             menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fEditAction);
93     }
94 }
95
Popular Tags