001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.project.ui.actions;
043:
044: import javax.swing.Action;
045: import javax.swing.Icon;
046: import javax.swing.ImageIcon;
047: import org.netbeans.modules.project.uiapi.ActionsFactory;
048: import org.netbeans.spi.project.ActionProvider;
049: import org.netbeans.spi.project.ui.support.ProjectActionPerformer;
050: import org.openide.actions.DeleteAction;
051: import org.openide.util.NbBundle;
052: import org.openide.util.Utilities;
053: import org.openide.util.actions.SystemAction;
054:
055: /** Factory for all kinds of actions used in projectui and
056: *projectuiapi.
057: */
058: public class Actions implements ActionsFactory {
059:
060: //private static final Actions INSTANCE = new Actions();
061:
062: public Actions() {
063: }
064:
065: // Implementation of ActionFactory -----------------------------------------
066:
067: private static Action SET_AS_MAIN_PROJECT;
068: private static Action CUSTOMIZE_PROJECT;
069: private static Action OPEN_SUBPROJECTS;
070: private static Action CLOSE_PROJECT;
071: private static Action NEW_FILE;
072: private static Action COPY_PROJECT;
073: private static Action MOVE_PROJECT;
074: private static Action RENAME_PROJECT;
075:
076: public synchronized Action setAsMainProjectAction() {
077: if (SET_AS_MAIN_PROJECT == null) {
078: SET_AS_MAIN_PROJECT = new SetMainProject();
079: }
080: return SET_AS_MAIN_PROJECT;
081: }
082:
083: public synchronized Action customizeProjectAction() {
084: if (CUSTOMIZE_PROJECT == null) {
085: CUSTOMIZE_PROJECT = new CustomizeProject();
086: }
087: return CUSTOMIZE_PROJECT;
088: }
089:
090: public synchronized Action openSubprojectsAction() {
091: if (OPEN_SUBPROJECTS == null) {
092: OPEN_SUBPROJECTS = new OpenSubprojects();
093: }
094: return OPEN_SUBPROJECTS;
095: }
096:
097: public synchronized Action closeProjectAction() {
098: if (CLOSE_PROJECT == null) {
099: CLOSE_PROJECT = new CloseProject();
100: }
101: return CLOSE_PROJECT;
102: }
103:
104: public synchronized Action newFileAction() {
105: if (NEW_FILE == null) {
106: NEW_FILE = new NewFile.WithSubMenu();
107: }
108: return NEW_FILE;
109: }
110:
111: public Action deleteProjectAction() {
112: return deleteProject();
113: }
114:
115: public Action copyProjectAction() {
116: return copyProject();
117: }
118:
119: public Action moveProjectAction() {
120: return moveProject();
121: }
122:
123: public Action renameProjectAction() {
124: return renameProject();
125: }
126:
127: public synchronized Action newProjectAction() {
128: return new NewProject();
129: }
130:
131: public Action projectCommandAction(String command,
132: String namePattern, Icon icon) {
133: return new ProjectAction(command, namePattern, icon, null);
134: }
135:
136: public Action projectSensitiveAction(
137: ProjectActionPerformer performer, String namePattern,
138: Icon icon) {
139: return new ProjectAction(performer, namePattern, icon, null);
140: }
141:
142: public Action mainProjectCommandAction(String command, String name,
143: Icon icon) {
144: return new MainProjectAction(command, name, icon);
145: }
146:
147: public Action mainProjectSensitiveAction(
148: ProjectActionPerformer performer, String name, Icon icon) {
149: return new MainProjectAction(performer, name, icon);
150: }
151:
152: public Action fileCommandAction(String command, String name,
153: Icon icon) {
154: return new FileCommandAction(command, name, icon, null);
155: }
156:
157: // Project specific actions ------------------------------------------------
158:
159: public static Action javadocProject() {
160: return new ProjectAction("javadoc", // XXX Define standard
161: NbBundle.getMessage(Actions.class,
162: "LBL_JavadocProjectAction_Name"), // NOI18N
163: null, null);
164: }
165:
166: public static Action testProject() {
167: Action a = new ProjectAction(
168: "test", // XXX Define standard
169: NbBundle.getMessage(Actions.class,
170: "LBL_TestProjectAction_Name"), // NOI18N
171: new ImageIcon(
172: Utilities
173: .loadImage("org/netbeans/modules/project/ui/resources/testProject.png")), //NOI18N
174: null);
175: a
176: .putValue("iconBase",
177: "org/netbeans/modules/project/ui/resources/testProject.png"); //NOI18N
178: a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
179: return a;
180: }
181:
182: public static Action buildProject() {
183: Action a = new ProjectAction(
184: ActionProvider.COMMAND_BUILD,
185: NbBundle.getMessage(Actions.class,
186: "LBL_BuildProjectAction_Name"), // NO18N
187: new ImageIcon(
188: Utilities
189: .loadImage("org/netbeans/modules/project/ui/resources/buildCurrentProject.gif")), //NOI18N
190: null);
191: a
192: .putValue("iconBase",
193: "org/netbeans/modules/project/ui/resources/buildCurrentProject.gif"); //NOI18N
194: return a;
195: }
196:
197: public static Action cleanProject() {
198: Action a = new ProjectAction(
199: ActionProvider.COMMAND_CLEAN,
200: NbBundle.getMessage(Actions.class,
201: "LBL_CleanProjectAction_Name"), // NO18N
202: new ImageIcon(
203: Utilities
204: .loadImage("org/netbeans/modules/project/ui/resources/cleanCurrentProject.gif")), //NOI18N
205: null);
206: a
207: .putValue("iconBase",
208: "org/netbeans/modules/project/ui/resources/cleanCurrentProject.gif"); //NOI18N
209: return a;
210: }
211:
212: public static Action rebuildProject() {
213: Action a = new ProjectAction(
214: ActionProvider.COMMAND_REBUILD,
215: NbBundle.getMessage(Actions.class,
216: "LBL_RebuildProjectAction_Name"), // NOI18N
217: new ImageIcon(
218: Utilities
219: .loadImage("org/netbeans/modules/project/ui/resources/rebuildCurrentProject.gif")), //NOI18N
220: null);
221: a
222: .putValue("iconBase",
223: "org/netbeans/modules/project/ui/resources/rebuildCurrentProject.gif"); //NOI18N
224: return a;
225: }
226:
227: public static Action runProject() {
228: Action a = new ProjectAction(
229: ActionProvider.COMMAND_RUN,
230: NbBundle.getMessage(Actions.class,
231: "LBL_RunProjectAction_Name"), // NO18N
232: new ImageIcon(
233: Utilities
234: .loadImage("org/netbeans/modules/project/ui/resources/runCurrentProject.gif")), //NOI18N
235: null);
236: a
237: .putValue("iconBase",
238: "org/netbeans/modules/project/ui/resources/runCurrentProject.gif"); //NOI18N
239: return a;
240: }
241:
242: public static synchronized Action deleteProject() {
243: Action a = new ProjectAction(ActionProvider.COMMAND_DELETE,
244: NbBundle.getMessage(Actions.class,
245: "LBL_DeleteProjectAction_Name"), null, null);
246:
247: a.putValue(Action.ACCELERATOR_KEY, DeleteAction.get(
248: DeleteAction.class).getValue(Action.ACCELERATOR_KEY));
249:
250: return a;
251: }
252:
253: public static synchronized Action copyProject() {
254: if (COPY_PROJECT == null) {
255: Action a = new ProjectAction(ActionProvider.COMMAND_COPY,
256: NbBundle.getMessage(Actions.class,
257: "LBL_CopyProjectAction_Name"), null, //NOI18N
258: null);
259: COPY_PROJECT = a;
260: }
261:
262: return COPY_PROJECT;
263: }
264:
265: public static synchronized Action moveProject() {
266: if (MOVE_PROJECT == null) {
267: Action a = new ProjectAction(ActionProvider.COMMAND_MOVE,
268: NbBundle.getMessage(Actions.class,
269: "LBL_MoveProjectAction_Name"), null, //NOI18N
270: null);
271: MOVE_PROJECT = a;
272: }
273:
274: return MOVE_PROJECT;
275: }
276:
277: public static synchronized Action renameProject() {
278: if (RENAME_PROJECT == null) {
279: Action a = new ProjectAction(ActionProvider.COMMAND_RENAME,
280: NbBundle.getMessage(Actions.class,
281: "LBL_RenameProjectAction_Name"), null, //NOI18N
282: null);
283: RENAME_PROJECT = a;
284: }
285:
286: return RENAME_PROJECT;
287: }
288:
289: // 1-off actions -----------------------------------------------------------
290:
291: public static Action compileSingle() {
292: Action a = new FileCommandAction(
293: "compile.single", // XXX Define standard
294: NbBundle.getMessage(Actions.class,
295: "LBL_CompileSingleAction_Name"),// NOI18N
296: new ImageIcon(
297: Utilities
298: .loadImage("org/netbeans/modules/project/ui/resources/compileSingle.png")), //NOI18N
299: null); //NOI18N
300: a
301: .putValue("iconBase",
302: "org/netbeans/modules/project/ui/resources/compileSingle.png"); //NOI18N
303: a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
304: return a;
305: }
306:
307: public static Action runSingle() {
308: Action a = new FileCommandAction(
309: "run.single", // XXX Define standard
310: NbBundle.getMessage(Actions.class,
311: "LBL_RunSingleAction_Name"), // NOI18N
312: new ImageIcon(
313: Utilities
314: .loadImage("org/netbeans/modules/project/ui/resources/runSingle.png")), //NOI18N
315: null);
316: a
317: .putValue("iconBase",
318: "org/netbeans/modules/project/ui/resources/runSingle.png"); //NOI18N
319: a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
320: return a;
321: }
322:
323: public static Action testSingle() {
324: Action a = new FileCommandAction(
325: "test.single", // XXX Define standard
326: NbBundle.getMessage(Actions.class,
327: "LBL_TestSingleAction_Name"),// NOI18N
328: new ImageIcon(
329: Utilities
330: .loadImage("org/netbeans/modules/project/ui/resources/testSingle.png")), //NOI18N
331: null); //NOI18N
332: a
333: .putValue("iconBase",
334: "org/netbeans/modules/project/ui/resources/testSingle.png"); //NOI18N
335: a.putValue("noIconInMenu", Boolean.TRUE); //NOI18N
336: return a;
337: }
338:
339: // Main Project actions ----------------------------------------------------
340:
341: public static Action buildMainProject() {
342: Action a = new MainProjectAction(
343: ActionProvider.COMMAND_BUILD,
344: NbBundle.getMessage(Actions.class,
345: "LBL_BuildMainProjectAction_Name"),
346: new ImageIcon(
347: Utilities
348: .loadImage("org/netbeans/modules/project/ui/resources/buildProject.png"))); //NOI18N
349: a
350: .putValue("iconBase",
351: "org/netbeans/modules/project/ui/resources/buildProject.png"); //NOI18N
352: return a;
353: }
354:
355: public static Action cleanMainProject() {
356: Action a = new MainProjectAction(
357: ActionProvider.COMMAND_CLEAN,
358: NbBundle.getMessage(Actions.class,
359: "LBL_CleanMainProjectAction_Name"),
360: new ImageIcon(
361: Utilities
362: .loadImage("org/netbeans/modules/project/ui/resources/cleanProject.gif"))); //NOI18N
363: a
364: .putValue("iconBase",
365: "org/netbeans/modules/project/ui/resources/cleanProject.gif"); //NOI18N
366: return a;
367: }
368:
369: public static Action rebuildMainProject() {
370: Action a = new MainProjectAction(
371: ActionProvider.COMMAND_REBUILD,
372: NbBundle.getMessage(Actions.class,
373: "LBL_RebuildMainProjectAction_Name"), // NOI18N
374: new ImageIcon(
375: Utilities
376: .loadImage("org/netbeans/modules/project/ui/resources/rebuildProject.png"))); //NOI18N
377: a
378: .putValue("iconBase",
379: "org/netbeans/modules/project/ui/resources/rebuildProject.png"); //NOI18N
380: return a;
381: }
382:
383: public static Action runMainProject() {
384: Action a = new MainProjectAction(
385: ActionProvider.COMMAND_RUN,
386: NbBundle.getMessage(Actions.class,
387: "LBL_RunMainProjectAction_Name"), // NO18N
388: new ImageIcon(
389: Utilities
390: .loadImage("org/netbeans/modules/project/ui/resources/runProject.png"))); //NOI18N
391: a
392: .putValue("iconBase",
393: "org/netbeans/modules/project/ui/resources/runProject.png"); //NOI18N
394: return a;
395: }
396:
397: public Action setProjectConfigurationAction() {
398: return SystemAction.get(ActiveConfigAction.class);
399: }
400:
401: }
|