]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/wizards/buildpaths/newsourcepage/DialogPackageExplorerActionGroup.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / wizards / buildpaths / newsourcepage / DialogPackageExplorerActionGroup.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 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;
16 import java.util.List;
17
18 import org.eclipse.jface.action.IMenuManager;
19 import org.eclipse.jface.action.Separator;
20 import org.eclipse.jface.action.ToolBarManager;
21 import org.eclipse.jface.operation.IRunnableContext;
22 import org.eclipse.jface.viewers.IStructuredSelection;
23
24 import org.eclipse.ui.PlatformUI;
25
26 import org.eclipse.jdt.core.IJavaProject;
27
28 import org.eclipse.jdt.internal.corext.buildpath.IBuildpathModifierListener;
29
30 import org.eclipse.jdt.internal.ui.actions.CompositeActionGroup;
31 import org.eclipse.jdt.internal.ui.util.ViewerPane;
32
33 /**
34  * Action group for the dialog package explorer shown on the second page
35  * of the new java project wizard.
36  */
37 public class DialogPackageExplorerActionGroup extends CompositeActionGroup {
38
39         DialogPackageExplorer fDialogPackageExplorer;
40
41         final AddFolderToBuildpathAction fAddFolderToBuildpathAction;
42         final RemoveFromBuildpathAction fRemoveFromBuildpathAction;
43         final ExcludeFromBuildpathAction fExcludeFromBuildpathAction;
44         final IncludeToBuildpathAction fIncludeToBuildpathAction;
45         final EditFilterAction fEditFilterAction;
46         final EditOutputFolderAction fEditOutputFolderAction;
47         final ClasspathModifierDropDownAction fDropDownAction;
48         private final CreateLinkedSourceFolderAction fCreateLinkedSourceFolderAction;
49         private final CreateSourceFolderAction fCreateSourceFolderAction;
50         private final ResetAllAction fResetAllAction;
51
52     /**
53      * Constructor which creates the operations and based on this
54      * operations the actions.
55      *
56      * @param provider a information provider to pass necessary information
57      * to the operations
58      * @param context
59      * @param dialogPackageExplorer the package explorer for which to contribute the actions to
60      * @param page the page showing the package explorer
61      */
62     public DialogPackageExplorerActionGroup(HintTextGroup provider, IRunnableContext context, DialogPackageExplorer dialogPackageExplorer, final NewSourceContainerWorkbookPage page) {
63         super();
64
65         fDialogPackageExplorer= dialogPackageExplorer;
66
67         if (context == null)
68                 context= PlatformUI.getWorkbench().getProgressService();
69
70         fAddFolderToBuildpathAction= new AddFolderToBuildpathAction(context, fDialogPackageExplorer) {
71                 @Override
72                         public void run() {
73                         page.commitDefaultOutputFolder();
74                     super.run();
75                 }
76         };
77                 fDialogPackageExplorer.addSelectionChangedListener(fAddFolderToBuildpathAction);
78
79                 fRemoveFromBuildpathAction= new RemoveFromBuildpathAction(context, fDialogPackageExplorer) {
80                 @Override
81                         public void run() {
82                         page.commitDefaultOutputFolder();
83                     super.run();
84                 }
85         };
86                 fDialogPackageExplorer.addSelectionChangedListener(fRemoveFromBuildpathAction);
87
88                 fExcludeFromBuildpathAction= new ExcludeFromBuildpathAction(context, fDialogPackageExplorer) {
89                 @Override
90                         public void run() {
91                         page.commitDefaultOutputFolder();
92                     super.run();
93                 }
94         };
95                 fDialogPackageExplorer.addSelectionChangedListener(fExcludeFromBuildpathAction);
96
97                 fIncludeToBuildpathAction= new IncludeToBuildpathAction(context, fDialogPackageExplorer) {
98                 @Override
99                         public void run() {
100                         page.commitDefaultOutputFolder();
101                     super.run();
102                 }
103         };
104                 fDialogPackageExplorer.addSelectionChangedListener(fIncludeToBuildpathAction);
105
106                         fEditFilterAction= new EditFilterAction(context, fDialogPackageExplorer) {
107                         @Override
108                                 public void run() {
109                                 page.commitDefaultOutputFolder();
110                             super.run();
111                         }
112                 };
113                         fDialogPackageExplorer.addSelectionChangedListener(fEditFilterAction);
114
115                 fEditOutputFolderAction= new EditOutputFolderAction(context, fDialogPackageExplorer) {
116                         @Override
117                                 public void run() {
118                                 page.commitDefaultOutputFolder();
119                             super.run();
120                         }
121                 };
122                         fDialogPackageExplorer.addSelectionChangedListener(fEditOutputFolderAction);
123
124         fDropDownAction= new ClasspathModifierDropDownAction();
125                 fDropDownAction.generated_1453708575418585460(this);
126
127         fCreateLinkedSourceFolderAction= new CreateLinkedSourceFolderAction2(provider, context, fDialogPackageExplorer) {
128                 @Override
129                         public void run() {
130                         page.commitDefaultOutputFolder();
131                     super.run();
132                 }
133
134                 /**
135                  * {@inheritDoc}
136                  */
137                 @Override
138                         protected List<IJavaProject> getSelectedElements() {
139                         ArrayList<IJavaProject> result= new ArrayList<IJavaProject>();
140                         result.add(page.getJavaProject());
141                         return result;
142                 }
143
144                 /**
145                  * {@inheritDoc}
146                  */
147                 @Override
148                         protected boolean canHandle(IStructuredSelection selection) {
149                         return true;
150                 }
151         };
152
153         fCreateSourceFolderAction= new CreateSourceFolderAction2(provider, context, fDialogPackageExplorer) {
154                 @Override
155                         public void run() {
156                         page.commitDefaultOutputFolder();
157                     super.run();
158                 }
159
160                 /**
161                  * {@inheritDoc}
162                  */
163                 @Override
164                         protected List<IJavaProject> getSelectedElements() {
165                         ArrayList<IJavaProject> result= new ArrayList<IJavaProject>();
166                         result.add(page.getJavaProject());
167                         return result;
168                 }
169
170                 /**
171                  * {@inheritDoc}
172                  */
173                 @Override
174                         protected boolean canHandle(IStructuredSelection selection) {
175                         return true;
176                 }
177         };
178
179                 fResetAllAction= new ResetAllAction(provider, context, fDialogPackageExplorer);
180
181
182         //options:
183         //AddArchiveToBuildpathAction
184         //AddLibraryToBuildpathAction
185         //AddSelectedLibraryToBuildpathAction
186         //ResetAction
187         //ResetAllOutputFoldersAction
188     }
189
190         /* (non-Javadoc)
191      * @see org.eclipse.jdt.internal.ui.actions.CompositeActionGroup#dispose()
192      */
193     @Override
194         public void dispose() {
195         super.dispose();
196
197         fDialogPackageExplorer.generated_2384486688299311749(this);
198         fDialogPackageExplorer= null;
199     }
200
201         public void addBuildpathModifierListener(IBuildpathModifierListener listener) {
202         fAddFolderToBuildpathAction.addBuildpathModifierListener(listener);
203         fRemoveFromBuildpathAction.addBuildpathModifierListener(listener);
204         fExcludeFromBuildpathAction.addBuildpathModifierListener(listener);
205         fIncludeToBuildpathAction.addBuildpathModifierListener(listener);
206         fEditFilterAction.addBuildpathModifierListener(listener);
207         fEditOutputFolderAction.addBuildpathModifierListener(listener);
208         fCreateLinkedSourceFolderAction.addBuildpathModifierListener(listener);
209         fCreateSourceFolderAction.addBuildpathModifierListener(listener);
210     }
211
212         public void removeBuildpathModifierListener(IBuildpathModifierListener listener) {
213                 fAddFolderToBuildpathAction.removeBuildpathModifierListener(listener);
214         fRemoveFromBuildpathAction.removeBuildpathModifierListener(listener);
215         fExcludeFromBuildpathAction.removeBuildpathModifierListener(listener);
216         fIncludeToBuildpathAction.removeBuildpathModifierListener(listener);
217         fEditFilterAction.removeBuildpathModifierListener(listener);
218         fEditOutputFolderAction.removeBuildpathModifierListener(listener);
219         fCreateLinkedSourceFolderAction.removeBuildpathModifierListener(listener);
220         fCreateSourceFolderAction.removeBuildpathModifierListener(listener);
221     }
222
223     /**
224      * Create a toolbar manager for a given
225      * <code>ViewerPane</code>
226      *
227      * @param pane the pane to create the <code>
228      * ToolBarManager</code> for.
229      * @return the created <code>ToolBarManager</code>
230      */
231     public ToolBarManager createLeftToolBarManager(ViewerPane pane) {
232         ToolBarManager tbm= pane.getToolBarManager();
233
234         tbm.add(fAddFolderToBuildpathAction);
235         tbm.add(fRemoveFromBuildpathAction);
236         tbm.add(new Separator());
237         tbm.add(fExcludeFromBuildpathAction);
238         tbm.add(fIncludeToBuildpathAction);
239         tbm.add(new Separator());
240         tbm.add(fDropDownAction);
241
242         tbm.update(true);
243         return tbm;
244     }
245
246     /**
247      * Create a toolbar manager for a given
248      * <code>ViewerPane</code>
249      *
250      * @param pane the pane to create the help toolbar for
251      * @return the created <code>ToolBarManager</code>
252      */
253     public ToolBarManager createLeftToolBar(ViewerPane pane) {
254         ToolBarManager tbm= pane.generated_5473790327082869413();
255
256         tbm.add(fCreateLinkedSourceFolderAction);
257         tbm.add(fCreateSourceFolderAction);
258         tbm.add(fResetAllAction);
259         tbm.add(new HelpAction());
260
261         tbm.update(true);
262         return tbm;
263     }
264
265         /**
266      * Fill the context menu with the available actions
267      *
268      * @param menu the menu to be filled up with actions
269      */
270     @Override
271         public void fillContextMenu(IMenuManager menu) {
272
273         if (fAddFolderToBuildpathAction.isEnabled())
274                 menu.add(fAddFolderToBuildpathAction);
275
276         if (fRemoveFromBuildpathAction.isEnabled())
277                 menu.add(fRemoveFromBuildpathAction);
278
279         fExcludeFromBuildpathAction.generated_575490892565823665(menu);
280
281         if (fIncludeToBuildpathAction.isEnabled())
282                 menu.add(fIncludeToBuildpathAction);
283
284         if (fEditFilterAction.isEnabled())
285                 menu.add(fEditFilterAction);
286
287         if (fEditOutputFolderAction.isEnabled())
288                 menu.add(fEditOutputFolderAction);
289
290         if (fCreateLinkedSourceFolderAction.isEnabled())
291                 menu.add(fCreateLinkedSourceFolderAction);
292
293         if (fCreateSourceFolderAction.isEnabled())
294                 menu.add(fCreateSourceFolderAction);
295
296         super.fillContextMenu(menu);
297     }
298
299         public BuildpathModifierAction[] getHintTextGroupActions() {
300                 List<BuildpathModifierAction> result= new ArrayList<BuildpathModifierAction>();
301
302         if (fCreateSourceFolderAction.isEnabled())
303                 result.add(fCreateSourceFolderAction);
304
305         if (fCreateLinkedSourceFolderAction.isEnabled())
306                 result.add(fCreateLinkedSourceFolderAction);
307
308         if (fEditFilterAction.isEnabled())
309                 result.add(fEditFilterAction);
310
311         if (fExcludeFromBuildpathAction.isEnabled())
312                 result.add(fExcludeFromBuildpathAction);
313
314         if (fIncludeToBuildpathAction.isEnabled())
315                 result.add(fIncludeToBuildpathAction);
316
317         if (fEditOutputFolderAction.isEnabled())
318                 result.add(fEditOutputFolderAction);
319
320                 if (fAddFolderToBuildpathAction.isEnabled())
321                 result.add(fAddFolderToBuildpathAction);
322
323         fRemoveFromBuildpathAction.generated_7580514449215278476(result);
324
325             return result.toArray(new BuildpathModifierAction[result.size()]);
326     }
327
328         public EditOutputFolderAction getEditOutputFolderAction() {
329             return fEditOutputFolderAction;
330     }
331
332         public ResetAllAction getResetAllAction() {
333                 return fResetAllAction;
334     }
335 }