001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: /*
021: * Sun Public License Notice
022: *
023: * The contents of this file are subject to the Sun Public License
024: * Version 1.0 (the "License"). You may not use this file except in
025: * compliance with the License. A copy of the License is available at
026: * http://www.sun.com/
027: *
028: * The Original Code is NetBeans. The Initial Developer of the Original
029: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
030: * Microsystems, Inc. All Rights Reserved.
031: */
032:
033: package org.netbeans.modules.sql.project;
034:
035: import org.netbeans.modules.compapp.projects.base.IcanproConstants;
036: import org.netbeans.modules.compapp.projects.base.ui.NoSelectedServerWarning;
037: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
038: import java.awt.Dialog;
039: import java.io.IOException;
040: import java.util.HashMap;
041: import java.util.Map;
042: import java.util.Properties;
043: import org.apache.tools.ant.module.api.support.ActionUtils;
044: import org.netbeans.spi.project.ActionProvider;
045: import org.netbeans.spi.project.support.ant.AntProjectHelper;
046: import org.netbeans.spi.project.support.ant.ReferenceHelper;
047: import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
048: import org.openide.DialogDescriptor;
049: import org.openide.DialogDisplayer;
050: import org.openide.ErrorManager;
051: import org.openide.filesystems.FileObject;
052: import org.openide.util.Lookup;
053: import org.openide.util.NbBundle;
054:
055: /** Action provider of the Web project. This is the place where to do
056: * strange things to Web actions. E.g. compile-single.
057: */
058: class SQLproActionProvider implements ActionProvider {
059:
060: // Definition of commands
061:
062: // Commands available from Web project
063: private static final String[] supportedActions = { COMMAND_BUILD,
064: COMMAND_CLEAN, COMMAND_REBUILD, COMMAND_COMPILE_SINGLE,
065: COMMAND_DELETE, COMMAND_COPY, COMMAND_MOVE, COMMAND_RENAME, };
066:
067: // Project
068: SQLproProject project;
069:
070: // Ant project helper of the project
071: private AntProjectHelper antProjectHelper;
072: private ReferenceHelper refHelper;
073:
074: /** Map from commands to ant targets */
075: Map/*<String,String[]>*/commands;
076:
077: public SQLproActionProvider(SQLproProject project,
078: AntProjectHelper antProjectHelper, ReferenceHelper refHelper) {
079: commands = new HashMap();
080: commands.put(COMMAND_BUILD, new String[] { "dist" }); // NOI18N
081: commands.put(COMMAND_CLEAN, new String[] { "clean" }); // NOI18N
082: commands.put(COMMAND_REBUILD, new String[] { "clean", "dist" }); // NOI18N
083:
084: this .antProjectHelper = antProjectHelper;
085: this .project = project;
086: this .refHelper = refHelper;
087: }
088:
089: private FileObject findBuildXml() {
090: return project.getProjectDirectory().getFileObject(
091: project.getBuildXmlName());
092: }
093:
094: public String[] getSupportedActions() {
095: return supportedActions;
096: }
097:
098: String[] getTargetNames(String command, Lookup context, Properties p)
099: throws IllegalArgumentException {
100: String[] targetNames = (String[]) commands.get(command);
101: return targetNames;
102: }
103:
104: public void invokeAction(String command, Lookup context)
105: throws IllegalArgumentException {
106:
107: if (COMMAND_COPY.equals(command)) {
108: DefaultProjectOperations
109: .performDefaultCopyOperation(project);
110: return;
111: }
112:
113: if (COMMAND_MOVE.equals(command)) {
114: DefaultProjectOperations
115: .performDefaultMoveOperation(project);
116: return;
117: }
118:
119: if (COMMAND_RENAME.equals(command)) {
120: DefaultProjectOperations.performDefaultRenameOperation(
121: project, null);
122: return;
123: }
124:
125: if (COMMAND_DELETE.equals(command)) {
126: DefaultProjectOperations
127: .performDefaultDeleteOperation(project);
128: return;
129: }
130:
131: Properties p = null;
132: String[] targetNames = (String[]) commands.get(command);
133: //EXECUTION PART
134: if (command.equals(IcanproConstants.COMMAND_DEPLOY)
135: || command.equals(IcanproConstants.COMMAND_REDEPLOY)) {
136: if (!isSelectedServer()) {
137: return;
138: }
139: } else {
140: p = null;
141: if (targetNames == null) {
142: throw new IllegalArgumentException(command);
143: }
144: }
145:
146: try {
147: ActionUtils.runTarget(findBuildXml(), targetNames, p);
148: } catch (IOException e) {
149: ErrorManager.getDefault().notify(e);
150: }
151: }
152:
153: public boolean isActionEnabled(String command, Lookup context) {
154:
155: if (findBuildXml() == null) {
156: return false;
157: }
158: return true;
159:
160: }
161:
162: // Private methods -----------------------------------------------------
163:
164: private boolean isDebugged() {
165: return false;
166: }
167:
168: private boolean isSelectedServer() {
169: String instance = antProjectHelper
170: .getStandardPropertyEvaluator().getProperty(
171: IcanproProjectProperties.J2EE_SERVER_INSTANCE);
172: boolean selected;
173: if (instance != null) {
174: selected = true;
175: } else {
176: // no selected server => warning
177: String server = antProjectHelper
178: .getStandardPropertyEvaluator().getProperty(
179: IcanproProjectProperties.J2EE_SERVER_TYPE);
180: NoSelectedServerWarning panel = new NoSelectedServerWarning(
181: server);
182:
183: Object[] options = new Object[] {
184: DialogDescriptor.OK_OPTION,
185: DialogDescriptor.CANCEL_OPTION };
186: DialogDescriptor desc = new DialogDescriptor(
187: panel,
188: NbBundle.getMessage(NoSelectedServerWarning.class,
189: "CTL_NoSelectedServerWarning_Title"), // NOI18N
190: true, options, options[0],
191: DialogDescriptor.DEFAULT_ALIGN, null, null);
192: Dialog dlg = DialogDisplayer.getDefault()
193: .createDialog(desc);
194: dlg.setVisible(true);
195: if (desc.getValue() != options[0]) {
196: selected = false;
197: } else {
198: instance = panel.getSelectedInstance();
199: selected = instance != null;
200: if (selected) {
201: IcanproProjectProperties wpp = new IcanproProjectProperties(
202: project, antProjectHelper, refHelper);
203: wpp
204: .put(
205: IcanproProjectProperties.J2EE_SERVER_INSTANCE,
206: instance);
207: wpp.store();
208: }
209: }
210: dlg.dispose();
211: }
212: return selected;
213: }
214:
215: }
|