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