KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ide > IDEActionFactory


1 /*******************************************************************************
2  * Copyright (c) 2003, 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.ui.ide;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IncrementalProjectBuilder;
15 import org.eclipse.ui.IWorkbenchWindow;
16 import org.eclipse.ui.actions.ActionFactory;
17 import org.eclipse.ui.actions.GlobalBuildAction;
18 import org.eclipse.ui.actions.NewWizardDropDownAction;
19 import org.eclipse.ui.actions.NewWizardMenu;
20 import org.eclipse.ui.actions.QuickStartAction;
21 import org.eclipse.ui.actions.RetargetAction;
22 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
23 import org.eclipse.ui.internal.ide.TipsAndTricksAction;
24 import org.eclipse.ui.internal.ide.actions.BuildCleanAction;
25 import org.eclipse.ui.internal.ide.actions.OpenWorkspaceAction;
26 import org.eclipse.ui.internal.ide.actions.ProjectPropertyDialogAction;
27 import org.eclipse.ui.internal.ide.actions.RetargetActionWithDefault;
28 import org.eclipse.ui.internal.ide.actions.ToggleAutoBuildAction;
29
30 /**
31  * Access to standard actions provided by the IDE workbench (including
32  * those of the generic workbench).
33  * <p>
34  * The functionality of this class is provided by static fields.
35  * Example usage:
36  * <pre>
37  * MenuManager menu = ...;
38  * ActionFactory.IWorkbenchAction closeProjectAction
39  * = IDEActionFactory.CLOSE_PROJECT.create(window);
40  * menu.add(closeProjectAction);
41  * </pre>
42  * </p>
43  *
44  * @since 3.0
45  */

46 public final class IDEActionFactory {
47
48     /**
49      * Prevents instantiation.
50      */

51     private IDEActionFactory() {
52         // do nothing
53
}
54
55     /**
56      * IDE-specific workbench action: Add task.
57      * This action is a {@link RetargetAction} with
58      * id "addTask". This action maintains its enablement state.
59      */

60     public static final ActionFactory ADD_TASK = new ActionFactory("addTask") { //$NON-NLS-1$
61
/* (non-javadoc) method declared on ActionFactory */
62         public IWorkbenchAction create(IWorkbenchWindow window) {
63             if (window == null) {
64                 throw new IllegalArgumentException JavaDoc();
65             }
66             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.Workbench_addTask);
67             action.setToolTipText(IDEWorkbenchMessages.Workbench_addTaskToolTip);
68             window.getPartService().addPartListener(action);
69             action.setActionDefinitionId("org.eclipse.ui.edit.addTask"); //$NON-NLS-1$
70
return action;
71         }
72     };
73
74     /**
75      * IDE-specific workbench action: Add bookmark.
76      * This action is a {@link RetargetAction} with
77      * id "bookmark". This action maintains its enablement state.
78      */

79     public static final ActionFactory BOOKMARK = new ActionFactory("bookmark") { //$NON-NLS-1$
80
/* (non-javadoc) method declared on ActionFactory */
81         public IWorkbenchAction create(IWorkbenchWindow window) {
82             if (window == null) {
83                 throw new IllegalArgumentException JavaDoc();
84             }
85             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.Workbench_addBookmark);
86             action.setToolTipText(IDEWorkbenchMessages.Workbench_addBookmarkToolTip);
87             window.getPartService().addPartListener(action);
88             action.setActionDefinitionId("org.eclipse.ui.edit.addBookmark"); //$NON-NLS-1$
89
return action;
90         }
91     };
92
93     /**
94      * IDE-specific workbench action: Incremental build.
95      * This action maintains its enablement state.
96      */

97     public static final ActionFactory BUILD = new ActionFactory("build") { //$NON-NLS-1$
98
/* (non-javadoc) method declared on ActionFactory */
99         public IWorkbenchAction create(IWorkbenchWindow window) {
100             if (window == null) {
101                 throw new IllegalArgumentException JavaDoc();
102             }
103             return new GlobalBuildAction(window,
104                     IncrementalProjectBuilder.INCREMENTAL_BUILD);
105         }
106     };
107
108     /**
109      * IDE-specific workbench action: Build clean
110      * This action maintains its enablement state.
111      * @since 3.0
112      */

113     public static final ActionFactory BUILD_CLEAN = new ActionFactory(
114             "buildClean") { //$NON-NLS-1$
115
/* (non-javadoc) method declared on ActionFactory */
116         public IWorkbenchAction create(IWorkbenchWindow window) {
117             if (window == null) {
118                 throw new IllegalArgumentException JavaDoc();
119             }
120             IWorkbenchAction action = new BuildCleanAction(window);
121             action.setId(getId());
122             return action;
123         }
124     };
125
126     /**
127      * IDE-specific workbench action: Build automatically
128      * This action maintains its enablement state.
129      * @since 3.0
130      */

131     public static final ActionFactory BUILD_AUTOMATICALLY = new ActionFactory(
132             "buildAutomatically") { //$NON-NLS-1$
133
/* (non-javadoc) method declared on ActionFactory */
134         public IWorkbenchAction create(IWorkbenchWindow window) {
135             if (window == null) {
136                 throw new IllegalArgumentException JavaDoc();
137             }
138             IWorkbenchAction action = new ToggleAutoBuildAction(window);
139             action.setId(getId());
140             action.setActionDefinitionId("org.eclipse.ui.project.buildAutomatically"); //$NON-NLS-1$
141
return action;
142         }
143     };
144
145     /**
146      * IDE-specific workbench action: Incremental build.
147      * This action is a {@link RetargetAction} with
148      * id "buildProject". This action maintains its enablement state.
149      */

150     public static final ActionFactory BUILD_PROJECT = new ActionFactory(
151             "buildProject") { //$NON-NLS-1$
152
/* (non-javadoc) method declared on ActionFactory */
153         public IWorkbenchAction create(IWorkbenchWindow window) {
154             if (window == null) {
155                 throw new IllegalArgumentException JavaDoc();
156             }
157             RetargetAction action = new RetargetActionWithDefault(getId(),
158                     IDEWorkbenchMessages.Workbench_buildProject);
159             action.setToolTipText(IDEWorkbenchMessages.Workbench_buildProjectToolTip);
160             window.getPartService().addPartListener(action);
161             action.setActionDefinitionId("org.eclipse.ui.project.buildProject"); //$NON-NLS-1$
162
return action;
163         }
164     };
165
166     /**
167      * IDE-specific workbench action: Close project.
168      * This action is a {@link RetargetAction} with
169      * id "closeProject". This action maintains its enablement state.
170      */

171     public static final ActionFactory CLOSE_PROJECT = new ActionFactory(
172             "closeProject") { //$NON-NLS-1$
173
/* (non-javadoc) method declared on ActionFactory */
174         public IWorkbenchAction create(IWorkbenchWindow window) {
175             if (window == null) {
176                 throw new IllegalArgumentException JavaDoc();
177             }
178             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.CloseResourceAction_text);
179             action.setToolTipText(IDEWorkbenchMessages.CloseResourceAction_text);
180             window.getPartService().addPartListener(action);
181             action.setActionDefinitionId("org.eclipse.ui.project.closeProject"); //$NON-NLS-1$
182
return action;
183         }
184     };
185
186     /**
187      * IDE-specific workbench action: Close unrelated projects.
188      * <p>
189      * This action closes all projects that are unrelated to the selected projects. A
190      * project is unrelated if it is not directly or transitively referenced by one
191      * of the selected projects, and does not directly or transitively reference
192      * one of the selected projects.
193      * </p>
194      * This action is a {@link RetargetAction} with
195      * id "closeUnrelatedProjects". This action maintains its enablement state.
196      * @see IProject#getReferencedProjects()
197      * @see IProject#getReferencingProjects()
198      * @see IProject#close(org.eclipse.core.runtime.IProgressMonitor)
199      * @since 3.2
200      */

201     public static final ActionFactory CLOSE_UNRELATED_PROJECTS = new ActionFactory(
202             "closeUnrelatedProjects") { //$NON-NLS-1$
203
/* (non-javadoc) method declared on ActionFactory */
204         public IWorkbenchAction create(IWorkbenchWindow window) {
205             if (window == null) {
206                 throw new IllegalArgumentException JavaDoc();
207             }
208             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.CloseUnrelatedProjectsAction_text);
209             action.setToolTipText(IDEWorkbenchMessages.CloseUnrelatedProjectsAction_toolTip);
210             window.getPartService().addPartListener(action);
211             action.setActionDefinitionId("org.eclipse.ui.project.closeUnrelatedProjects"); //$NON-NLS-1$
212
return action;
213         }
214     };
215
216     /**
217      * IDE-specific workbench action: Opens the "new" wizard drop down, including
218      * resource-specific items for Project... and Example...
219      * This action maintains its enablement state.
220      */

221     public static final ActionFactory NEW_WIZARD_DROP_DOWN = new ActionFactory(
222             "newWizardDropDown") { //$NON-NLS-1$
223
/* (non-javadoc) method declared on ActionFactory */
224         public IWorkbenchAction create(IWorkbenchWindow window) {
225             if (window == null) {
226                 throw new IllegalArgumentException JavaDoc();
227             }
228             // @issue we are creating a NEW action just to pass to NewWizardDropDownAction
229
IWorkbenchAction innerAction = ActionFactory.NEW.create(window);
230             NewWizardMenu newWizardMenu = new NewWizardMenu(window);
231             IWorkbenchAction action = new NewWizardDropDownAction(window,
232                     innerAction, newWizardMenu);
233             action.setId(getId());
234             return action;
235         }
236     };
237
238     /**
239      * IDE-specific workbench action: Open project.
240      * This action is a {@link RetargetAction} with
241      * id "openProject". This action maintains its enablement state.
242      */

243     public static final ActionFactory OPEN_PROJECT = new ActionFactory(
244             "openProject") { //$NON-NLS-1$
245
/* (non-javadoc) method declared on ActionFactory */
246         public IWorkbenchAction create(IWorkbenchWindow window) {
247             if (window == null) {
248                 throw new IllegalArgumentException JavaDoc();
249             }
250             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.OpenResourceAction_text);
251             action.setToolTipText(IDEWorkbenchMessages.OpenResourceAction_toolTip);
252             window.getPartService().addPartListener(action);
253             action.setActionDefinitionId("org.eclipse.ui.project.openProject"); //$NON-NLS-1$
254
return action;
255         }
256     };
257
258     /**
259      * IDE-specific workbench action: Open workspace.
260      * This action maintains its enablement state.
261      */

262     public static final ActionFactory OPEN_WORKSPACE = new ActionFactory(
263             "openWorkspace") { //$NON-NLS-1$
264
/* (non-javadoc) method declared on ActionFactory */
265         public IWorkbenchAction create(IWorkbenchWindow window) {
266             if (window == null) {
267                 throw new IllegalArgumentException JavaDoc();
268             }
269             IWorkbenchAction action = new OpenWorkspaceAction(window);
270             action.setId(getId());
271             return action;
272         }
273     };
274
275     /**
276      * IDE-specific workbench action: Open project properties.
277      * This action maintains its enablement state.
278      */

279     public static final ActionFactory OPEN_PROJECT_PROPERTIES = new ActionFactory(
280             "projectProperties") { //$NON-NLS-1$
281
/* (non-javadoc) method declared on ActionFactory */
282         public IWorkbenchAction create(IWorkbenchWindow window) {
283             if (window == null) {
284                 throw new IllegalArgumentException JavaDoc();
285             }
286             IWorkbenchAction action = new ProjectPropertyDialogAction(window);
287             action.setId(getId());
288             return action;
289         }
290     };
291
292     /**
293      * IDE-specific workbench action: Quick start.
294      * This action maintains its enablement state.
295      *
296      * @deprecated the IDE now uses the new intro mechanism
297      */

298     public static final ActionFactory QUICK_START = new ActionFactory(
299             "quickStart") { //$NON-NLS-1$
300
/* (non-javadoc) method declared on ActionFactory */
301         public IWorkbenchAction create(IWorkbenchWindow window) {
302             if (window == null) {
303                 throw new IllegalArgumentException JavaDoc();
304             }
305             IWorkbenchAction action = new QuickStartAction(window);
306             action.setId(getId());
307             return action;
308         }
309     };
310
311     /**
312      * IDE-specific workbench action: Full build.
313      * This action maintains its enablement state.
314      *
315      * @deprecated as of 3.0, this action no longer appears in the UI (was deprecated in 3.1)
316      */

317     public static final ActionFactory REBUILD_ALL = new ActionFactory(
318             "rebuildAll") { //$NON-NLS-1$
319
/* (non-javadoc) method declared on ActionFactory */
320         public IWorkbenchAction create(IWorkbenchWindow window) {
321             if (window == null) {
322                 throw new IllegalArgumentException JavaDoc();
323             }
324             IWorkbenchAction action = new GlobalBuildAction(window,
325                     IncrementalProjectBuilder.FULL_BUILD);
326             action.setId(getId());
327             return action;
328         }
329     };
330
331     /**
332      * IDE-specific workbench action: Rebuild project.
333      * This action is a {@link RetargetAction} with
334      * id "rebuildProject". This action maintains its enablement state.
335      *
336      * @deprecated as of 3.0, this action no longer appears in the UI (was deprecated in 3.1)
337      */

338     public static final ActionFactory REBUILD_PROJECT = new ActionFactory(
339             "rebuildProject") { //$NON-NLS-1$
340
/* (non-javadoc) method declared on ActionFactory */
341         public IWorkbenchAction create(IWorkbenchWindow window) {
342             if (window == null) {
343                 throw new IllegalArgumentException JavaDoc();
344             }
345             RetargetAction action = new RetargetAction(getId(), IDEWorkbenchMessages.Workbench_rebuildProject);
346             action.setToolTipText(IDEWorkbenchMessages.Workbench_rebuildProjectToolTip);
347             window.getPartService().addPartListener(action);
348             action
349                     .setActionDefinitionId("org.eclipse.ui.project.rebuildProject"); //$NON-NLS-1$
350
return action;
351         }
352     };
353
354     /**
355      * IDE-specific workbench action: Tips and tricks.
356      * This action maintains its enablement state.
357      */

358     public static final ActionFactory TIPS_AND_TRICKS = new ActionFactory(
359             "tipsAndTricks") { //$NON-NLS-1$
360
/* (non-javadoc) method declared on ActionFactory */
361         public IWorkbenchAction create(IWorkbenchWindow window) {
362             if (window == null) {
363                 throw new IllegalArgumentException JavaDoc();
364             }
365             IWorkbenchAction action = new TipsAndTricksAction(window);
366             action.setId(getId());
367             return action;
368         }
369     };
370
371 }
372
Popular Tags