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: package org.netbeans.modules.etl.project;
020:
021: import java.awt.Dialog;
022: import java.io.IOException;
023: import java.util.HashMap;
024: import java.util.Map;
025: import java.util.Properties;
026: import org.apache.tools.ant.module.api.support.ActionUtils;
027: import org.netbeans.spi.project.ActionProvider;
028: import org.netbeans.spi.project.support.ant.AntProjectHelper;
029: import org.openide.filesystems.FileObject;
030: import org.openide.util.NbBundle;
031: import org.openide.util.Lookup;
032: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
033: import org.netbeans.spi.project.support.ant.ReferenceHelper;
034: import org.openide.*;
035:
036: import org.netbeans.modules.compapp.projects.base.ui.NoSelectedServerWarning;
037: import org.netbeans.modules.compapp.projects.base.IcanproConstants;
038: import org.netbeans.spi.project.ui.support.DefaultProjectOperations;
039:
040: /** Action provider of the Web project. This is the place where to do
041: * strange things to Web actions. E.g. compile-single.
042: */
043: class EtlproActionProvider implements ActionProvider {
044:
045: // Definition of commands
046:
047: // Commands available from Web project
048: private static final String[] supportedActions = { COMMAND_BUILD,
049: COMMAND_CLEAN, COMMAND_REBUILD, COMMAND_COMPILE_SINGLE,
050: EtlproProject.COMMAND_GENWSDL,
051: EtlproProject.COMMAND_SCHEMA,
052: EtlproProject.COMMAND_BULK_LOADER, COMMAND_DELETE,
053: COMMAND_COPY, COMMAND_MOVE, COMMAND_RENAME, };
054:
055: // Project
056: EtlproProject project;
057: // Ant project helper of the project
058: private AntProjectHelper antProjectHelper;
059: private ReferenceHelper refHelper;
060: /** Map from commands to ant targets */
061: Map/*<String,String[]>*/commands;
062:
063: public EtlproActionProvider(EtlproProject project,
064: AntProjectHelper antProjectHelper, ReferenceHelper refHelper) {
065: commands = new HashMap();
066: commands.put(COMMAND_BUILD, new String[] { "dist" }); // NOI18N
067: commands.put(COMMAND_CLEAN, new String[] { "clean" }); // NOI18N
068: commands.put(COMMAND_REBUILD, new String[] { "clean", "dist" }); // NOI18N
069: commands.put(EtlproProject.COMMAND_GENWSDL,
070: new String[] { "gen-wsdl" }); // NOI18N
071: commands.put(EtlproProject.COMMAND_SCHEMA,
072: new String[] { "gen-schema" }); // NOI18N
073: commands.put(EtlproProject.COMMAND_BULK_LOADER,
074: new String[] { "etl_bulkloader" }); // NOI18N
075: //commands.put(IcanproConstants.COMMAND_REDEPLOY, new String[] {"run"}); // NOI18N
076: //commands.put(IcanproConstants.COMMAND_DEPLOY, new String[] {"run"}); // NOI18N
077:
078: this .antProjectHelper = antProjectHelper;
079: this .project = project;
080: this .refHelper = refHelper;
081: }
082:
083: private FileObject findBuildXml() {
084: return project.getProjectDirectory().getFileObject(
085: project.getBuildXmlName());
086: }
087:
088: public String[] getSupportedActions() {
089: return supportedActions;
090: }
091:
092: public void invokeAction(String command, Lookup context)
093: throws IllegalArgumentException {
094: Properties p = null;
095: String[] targetNames = (String[]) commands.get(command);
096:
097: if (COMMAND_COPY.equals(command)) {
098: DefaultProjectOperations
099: .performDefaultCopyOperation(project);
100: return;
101: }
102:
103: if (COMMAND_MOVE.equals(command)) {
104: DefaultProjectOperations
105: .performDefaultMoveOperation(project);
106: return;
107: }
108:
109: if (COMMAND_RENAME.equals(command)) {
110: DefaultProjectOperations.performDefaultRenameOperation(
111: project, null);
112: return;
113: }
114: if (COMMAND_DELETE.equals(command)) {
115: try {
116: project.getAntProjectHelper().resolveFileObject("data")
117: .delete();
118: DefaultProjectOperations
119: .performDefaultDeleteOperation(project);
120: return;
121: } catch (IOException ex) {
122: }
123: }
124: //EXECUTION PART
125: if (command.equals(IcanproConstants.COMMAND_DEPLOY)
126: || command.equals(IcanproConstants.COMMAND_REDEPLOY)) {
127: if (!isSelectedServer()) {
128: return;
129: }
130: } /*else {
131: p = null;
132: if (targetNames == null) {
133: throw new IllegalArgumentException(command);
134: }
135: }*/
136:
137: try {
138: ActionUtils.runTarget(findBuildXml(), targetNames, p);
139: } catch (IOException e) {
140: ErrorManager.getDefault().notify(e);
141: }
142: }
143:
144: public boolean isActionEnabled(String command, Lookup context) {
145: return findBuildXml() != null;
146: }
147:
148: // Private methods -----------------------------------------------------
149: private boolean isDebugged() {
150: return false;
151: }
152:
153: String[] getTargetNames(String command, Lookup context, Properties p)
154: throws IllegalArgumentException {
155: String[] targetNames = (String[]) commands.get(command);
156: return targetNames;
157: }
158:
159: private boolean isSelectedServer() {
160: String instance = antProjectHelper
161: .getStandardPropertyEvaluator().getProperty(
162: IcanproProjectProperties.J2EE_SERVER_INSTANCE);
163: boolean selected;
164: if (instance != null) {
165: selected = true;
166: } else {
167: // no selected server => warning
168: String server = antProjectHelper
169: .getStandardPropertyEvaluator().getProperty(
170: IcanproProjectProperties.J2EE_SERVER_TYPE);
171: NoSelectedServerWarning panel = new NoSelectedServerWarning(
172: server);
173:
174: Object[] options = new Object[] {
175: DialogDescriptor.OK_OPTION,
176: DialogDescriptor.CANCEL_OPTION };
177: DialogDescriptor desc = new DialogDescriptor(
178: panel,
179: NbBundle.getMessage(NoSelectedServerWarning.class,
180: "CTL_NoSelectedServerWarning_Title"), // NOI18N
181: true, options, options[0],
182: DialogDescriptor.DEFAULT_ALIGN, null, null);
183: Dialog dlg = DialogDisplayer.getDefault()
184: .createDialog(desc);
185: dlg
186: .getAccessibleContext()
187: .setAccessibleDescription(
188: "This dialog displays warning if no server is selected");
189: dlg.setVisible(true);
190: if (desc.getValue() != options[0]) {
191: selected = false;
192: } else {
193: instance = panel.getSelectedInstance();
194: selected = instance != null;
195: if (selected) {
196: IcanproProjectProperties wpp = new IcanproProjectProperties(
197: project, antProjectHelper, refHelper);
198: wpp
199: .put(
200: IcanproProjectProperties.J2EE_SERVER_INSTANCE,
201: instance);
202: wpp.store();
203: }
204: }
205: dlg.dispose();
206: }
207: return selected;
208: }
209: }
|