KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > buildpaths > newsourcepage > DialogPackageExplorerActionGroup


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  * Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
11  *******************************************************************************/

12
13 package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.ToolBar;
20
21 import org.eclipse.jface.action.IMenuManager;
22 import org.eclipse.jface.action.Separator;
23 import org.eclipse.jface.action.ToolBarManager;
24 import org.eclipse.jface.operation.IRunnableContext;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26
27 import org.eclipse.ui.PlatformUI;
28
29 import org.eclipse.jdt.internal.corext.buildpath.IBuildpathModifierListener;
30
31 import org.eclipse.jdt.internal.ui.actions.CompositeActionGroup;
32 import org.eclipse.jdt.internal.ui.util.ViewerPane;
33
34 /**
35  * Action group for the dialog package explorer shown on the second page
36  * of the new java project wizard.
37  */

38 public class DialogPackageExplorerActionGroup extends CompositeActionGroup {
39     
40     private DialogPackageExplorer fDialogPackageExplorer;
41     
42     private final AddFolderToBuildpathAction fAddFolderToBuildpathAction;
43     private final RemoveFromBuildpathAction fRemoveFromBuildpathAction;
44     private final ExcludeFromBuildpathAction fExcludeFromBuildpathAction;
45     private final IncludeToBuildpathAction fIncludeToBuildpathAction;
46     private final EditFilterAction fEditFilterAction;
47     private final EditOutputFolderAction fEditOutputFolderAction;
48     private final ClasspathModifierDropDownAction fDropDownAction;
49     private final CreateLinkedSourceFolderAction fCreateLinkedSourceFolderAction;
50     private final CreateSourceFolderAction fCreateSourceFolderAction;
51     private final ResetAllAction fResetAllAction;
52     
53     /**
54      * Constructor which creates the operations and based on this
55      * operations the actions.
56      *
57      * @param provider a information provider to pass necessary information
58      * to the operations
59      * @param context
60      * @param dialogPackageExplorer the package explorer for which to contribute the actions to
61      * @param page the page showing the package explorer
62      */

63     public DialogPackageExplorerActionGroup(HintTextGroup provider, IRunnableContext context, DialogPackageExplorer dialogPackageExplorer, final NewSourceContainerWorkbookPage page) {
64         super();
65         
66         fDialogPackageExplorer= dialogPackageExplorer;
67         
68         if (context == null)
69             context= PlatformUI.getWorkbench().getProgressService();
70         
71         fAddFolderToBuildpathAction= new AddFolderToBuildpathAction(context, fDialogPackageExplorer) {
72             public void run() {
73                 page.commitDefaultOutputFolder();
74                 super.run();
75             }
76         };
77         fDialogPackageExplorer.addSelectionChangedListener(fAddFolderToBuildpathAction);
78         
79         fRemoveFromBuildpathAction= new RemoveFromBuildpathAction(context, fDialogPackageExplorer) {
80             public void run() {
81                 page.commitDefaultOutputFolder();
82                 super.run();
83             }
84         };
85         fDialogPackageExplorer.addSelectionChangedListener(fRemoveFromBuildpathAction);
86         
87         fExcludeFromBuildpathAction= new ExcludeFromBuildpathAction(context, fDialogPackageExplorer) {
88             public void run() {
89                 page.commitDefaultOutputFolder();
90                 super.run();
91             }
92         };
93         fDialogPackageExplorer.addSelectionChangedListener(fExcludeFromBuildpathAction);
94         
95         fIncludeToBuildpathAction= new IncludeToBuildpathAction(context, fDialogPackageExplorer) {
96             public void run() {
97                 page.commitDefaultOutputFolder();
98                 super.run();
99             }
100         };
101         fDialogPackageExplorer.addSelectionChangedListener(fIncludeToBuildpathAction);
102         
103             fEditFilterAction= new EditFilterAction(context, fDialogPackageExplorer) {
104                 public void run() {
105                     page.commitDefaultOutputFolder();
106                     super.run();
107                 }
108             };
109             fDialogPackageExplorer.addSelectionChangedListener(fEditFilterAction);
110     
111             fEditOutputFolderAction= new EditOutputFolderAction(context, fDialogPackageExplorer) {
112                 public void run() {
113                     page.commitDefaultOutputFolder();
114                     super.run();
115                 }
116             };
117             fDialogPackageExplorer.addSelectionChangedListener(fEditOutputFolderAction);
118         
119         fDropDownAction= new ClasspathModifierDropDownAction();
120         fDropDownAction.addAction(fEditFilterAction);
121         fDropDownAction.addAction(fEditOutputFolderAction);
122         fDialogPackageExplorer.addPostSelectionChangedListener(fDropDownAction);
123         
124         fCreateLinkedSourceFolderAction= new CreateLinkedSourceFolderAction2(provider, context, fDialogPackageExplorer) {
125             public void run() {
126                 page.commitDefaultOutputFolder();
127                 super.run();
128             }
129             
130             /**
131              * {@inheritDoc}
132              */

133             protected List JavaDoc getSelectedElements() {
134                 ArrayList JavaDoc result= new ArrayList JavaDoc();
135                 result.add(page.getJavaProject());
136                 return result;
137             }
138
139             /**
140              * {@inheritDoc}
141              */

142             protected boolean canHandle(IStructuredSelection selection) {
143                 return true;
144             }
145         };
146         
147         fCreateSourceFolderAction= new CreateSourceFolderAction2(provider, context, fDialogPackageExplorer) {
148             public void run() {
149                 page.commitDefaultOutputFolder();
150                 super.run();
151             }
152             
153             /**
154              * {@inheritDoc}
155              */

156             protected List JavaDoc getSelectedElements() {
157                 ArrayList JavaDoc result= new ArrayList JavaDoc();
158                 result.add(page.getJavaProject());
159                 return result;
160             }
161
162             /**
163              * {@inheritDoc}
164              */

165             protected boolean canHandle(IStructuredSelection selection) {
166                 return true;
167             }
168         };
169         
170         fResetAllAction= new ResetAllAction(provider, context, fDialogPackageExplorer);
171
172         
173         //options:
174
//AddArchiveToBuildpathAction
175
//AddLibraryToBuildpathAction
176
//AddSelectedLibraryToBuildpathAction
177
//ResetAction
178
//ResetAllOutputFoldersAction
179
}
180     
181     /* (non-Javadoc)
182      * @see org.eclipse.jdt.internal.ui.actions.CompositeActionGroup#dispose()
183      */

184     public void dispose() {
185         super.dispose();
186         
187         fDialogPackageExplorer.removeSelectionChangedListener(fAddFolderToBuildpathAction);
188         fDialogPackageExplorer.removeSelectionChangedListener(fRemoveFromBuildpathAction);
189         fDialogPackageExplorer.removeSelectionChangedListener(fExcludeFromBuildpathAction);
190         fDialogPackageExplorer.removeSelectionChangedListener(fIncludeToBuildpathAction);
191         fDialogPackageExplorer.removeSelectionChangedListener(fEditFilterAction);
192         fDialogPackageExplorer.removeSelectionChangedListener(fEditOutputFolderAction);
193         fDialogPackageExplorer.removePostSelectionChangedListener(fDropDownAction);
194         fDialogPackageExplorer= null;
195     }
196     
197     public void addBuildpathModifierListener(IBuildpathModifierListener listener) {
198         fAddFolderToBuildpathAction.addBuildpathModifierListener(listener);
199         fRemoveFromBuildpathAction.addBuildpathModifierListener(listener);
200         fExcludeFromBuildpathAction.addBuildpathModifierListener(listener);
201         fIncludeToBuildpathAction.addBuildpathModifierListener(listener);
202         fEditFilterAction.addBuildpathModifierListener(listener);
203         fEditOutputFolderAction.addBuildpathModifierListener(listener);
204         fCreateLinkedSourceFolderAction.addBuildpathModifierListener(listener);
205         fCreateSourceFolderAction.addBuildpathModifierListener(listener);
206     }
207     
208     public void removeBuildpathModifierListener(IBuildpathModifierListener listener) {
209         fAddFolderToBuildpathAction.removeBuildpathModifierListener(listener);
210         fRemoveFromBuildpathAction.removeBuildpathModifierListener(listener);
211         fExcludeFromBuildpathAction.removeBuildpathModifierListener(listener);
212         fIncludeToBuildpathAction.removeBuildpathModifierListener(listener);
213         fEditFilterAction.removeBuildpathModifierListener(listener);
214         fEditOutputFolderAction.removeBuildpathModifierListener(listener);
215         fCreateLinkedSourceFolderAction.removeBuildpathModifierListener(listener);
216         fCreateSourceFolderAction.removeBuildpathModifierListener(listener);
217     }
218         
219     /**
220      * Create a toolbar manager for a given
221      * <code>ViewerPane</code>
222      *
223      * @param pane the pane to create the <code>
224      * ToolBarManager</code> for.
225      * @return the created <code>ToolBarManager</code>
226      */

227     public ToolBarManager createLeftToolBarManager(ViewerPane pane) {
228         ToolBarManager tbm= pane.getToolBarManager();
229         
230         tbm.add(fAddFolderToBuildpathAction);
231         tbm.add(fRemoveFromBuildpathAction);
232         tbm.add(new Separator());
233         tbm.add(fExcludeFromBuildpathAction);
234         tbm.add(fIncludeToBuildpathAction);
235         tbm.add(new Separator());
236         tbm.add(fDropDownAction);
237         
238         tbm.update(true);
239         return tbm;
240     }
241     
242     /**
243      * Create a toolbar manager for a given
244      * <code>ViewerPane</code>
245      *
246      * @param pane the pane to create the help toolbar for
247      * @return the created <code>ToolBarManager</code>
248      */

249     public ToolBarManager createLeftToolBar(ViewerPane pane) {
250         ToolBar tb= new ToolBar(pane, SWT.FLAT);
251         pane.setTopRight(tb);
252         ToolBarManager tbm= new ToolBarManager(tb);
253         
254         tbm.add(fCreateLinkedSourceFolderAction);
255         tbm.add(fCreateSourceFolderAction);
256         tbm.add(fResetAllAction);
257         tbm.add(new HelpAction());
258         
259         tbm.update(true);
260         return tbm;
261     }
262         
263     /**
264      * Fill the context menu with the available actions
265      *
266      * @param menu the menu to be filled up with actions
267      */

268     public void fillContextMenu(IMenuManager menu) {
269         
270         if (fAddFolderToBuildpathAction.isEnabled())
271             menu.add(fAddFolderToBuildpathAction);
272         
273         if (fRemoveFromBuildpathAction.isEnabled())
274             menu.add(fRemoveFromBuildpathAction);
275         
276         if (fExcludeFromBuildpathAction.isEnabled())
277             menu.add(fExcludeFromBuildpathAction);
278             
279         if (fIncludeToBuildpathAction.isEnabled())
280             menu.add(fIncludeToBuildpathAction);
281         
282         if (fEditFilterAction.isEnabled())
283             menu.add(fEditFilterAction);
284         
285         if (fEditOutputFolderAction.isEnabled())
286             menu.add(fEditOutputFolderAction);
287         
288         if (fCreateLinkedSourceFolderAction.isEnabled())
289             menu.add(fCreateLinkedSourceFolderAction);
290         
291         if (fCreateSourceFolderAction.isEnabled())
292             menu.add(fCreateSourceFolderAction);
293         
294         super.fillContextMenu(menu);
295     }
296     
297     public BuildpathModifierAction[] getHintTextGroupActions() {
298         List JavaDoc result= new ArrayList JavaDoc();
299         
300         if (fCreateSourceFolderAction.isEnabled())
301             result.add(fCreateSourceFolderAction);
302         
303         if (fCreateLinkedSourceFolderAction.isEnabled())
304             result.add(fCreateLinkedSourceFolderAction);
305         
306         if (fEditFilterAction.isEnabled())
307             result.add(fEditFilterAction);
308         
309         if (fExcludeFromBuildpathAction.isEnabled())
310             result.add(fExcludeFromBuildpathAction);
311             
312         if (fIncludeToBuildpathAction.isEnabled())
313             result.add(fIncludeToBuildpathAction);
314         
315         if (fEditOutputFolderAction.isEnabled())
316             result.add(fEditOutputFolderAction);
317         
318         if (fAddFolderToBuildpathAction.isEnabled())
319             result.add(fAddFolderToBuildpathAction);
320         
321         if (fRemoveFromBuildpathAction.isEnabled())
322             result.add(fRemoveFromBuildpathAction);
323     
324         return (BuildpathModifierAction[])result.toArray(new BuildpathModifierAction[result.size()]);
325     }
326
327     public EditOutputFolderAction getEditOutputFolderAction() {
328         return fEditOutputFolderAction;
329     }
330
331     public ResetAllAction getResetAllAction() {
332         return fResetAllAction;
333     }
334 }
335
Popular Tags