001: package org.enhydra.kelp.ant.deployer;
002:
003: import java.awt.*;
004: import javax.swing.*;
005: import org.enhydra.tool.swing.layout.*;
006: import org.enhydra.kelp.ant.node.AntProject;
007: import org.enhydra.kelp.common.node.OtterProject;
008: import java.util.ResourceBundle;
009: import java.awt.event.*;
010: import javax.swing.JFileChooser;
011: import java.io.File;
012:
013: /**
014: * <p>Title: </p>
015: * <p>Description: </p>
016: * <p>Copyright: Copyright (c) 2003</p>
017: * <p>Company: </p>
018: * @author unascribed
019: * @version 1.0
020: */
021:
022: public class AntDeployGeneralPanel extends JPanel {
023:
024: static ResourceBundle res = ResourceBundle
025: .getBundle("org.enhydra.kelp.common.Res");
026:
027: private XYLayout xYLayout1 = new XYLayout();
028: JLabel jLabelDescr = new JLabel();
029: JLabel jLabelType = new JLabel();
030: JTextField jTextType = new JTextField();
031: JLabel jLabelRoot = new JLabel();
032: JTextField jTextDestination = new JTextField();
033: JButton jButtonBrowse = new JButton();
034: JCheckBox jCheckInvokeMake = new JCheckBox();
035: AntProject project = null;
036: private JCheckBox jCheckBoxMakeWAR = new JCheckBox();
037: private JCheckBox jCheckBoxEnhydraLib = new JCheckBox();
038:
039: public AntDeployGeneralPanel() {
040: try {
041: jbInit();
042: } catch (Exception ex) {
043: ex.printStackTrace();
044: }
045: }
046:
047: public void setProject(OtterProject otterProject) {
048: if (otterProject instanceof AntProject) {
049: project = (AntProject) otterProject;
050: initOptions();
051: } else
052: System.err.println("DEBUG project must be AntProject");//FIXME throw Exception
053: }
054:
055: private void initOptions() {
056: if (project.isWebType()) {
057: jTextType.setText(res.getString("Web_Application"));
058: jCheckBoxMakeWAR.setVisible(false); //by default WAR is created for Web app
059: } else {
060: jTextType.setText(res.getString("Enhydra_Super_Servlet"));
061: jCheckBoxMakeWAR.setVisible(true);
062:
063: if (project.getProperty(AntProject.DEPLOY_WAR_ENABLED)
064: .equalsIgnoreCase("true")) {
065: jCheckBoxMakeWAR.setSelected(true);
066: jCheckBoxEnhydraLib.setVisible(true);
067: } else {
068: jCheckBoxMakeWAR.setSelected(false);
069: jCheckBoxEnhydraLib.setVisible(false);
070: }
071: }
072: if (project.getProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS)
073: .equalsIgnoreCase("true")) {
074: jCheckBoxEnhydraLib.setSelected(true);
075: } else {
076: jCheckBoxEnhydraLib.setSelected(false);
077: }
078: jTextDestination.setText(project
079: .getProperty(AntProject.OUTPUT_DIR));
080: if (project.getProperty(AntProject.DEPLOY_INVOKE)
081: .equalsIgnoreCase("true"))
082: jCheckInvokeMake.setSelected(true);
083: else
084: jCheckInvokeMake.setSelected(false);
085:
086: }
087:
088: public OtterProject getProject() {
089: return (OtterProject) project;
090: }
091:
092: void jbInit() throws Exception {
093: jLabelDescr.setFont(new java.awt.Font("Dialog", 1, 12));
094: jLabelDescr
095: .setText(res.getString("General_deployment_options"));
096: this .setLayout(xYLayout1);
097: jLabelType.setText(res.getString("Deploy_type"));
098: jTextType.setBackground(SystemColor.control);
099: jTextType.setEditable(false);
100: jLabelRoot.setText(res
101: .getString("Deploy_destination_directory"));
102: jButtonBrowse.setText(res.getString("Browse"));
103: jButtonBrowse
104: .addActionListener(new java.awt.event.ActionListener() {
105: public void actionPerformed(ActionEvent e) {
106: jButtonBrowse_actionPerformed(e);
107: }
108: });
109: jCheckInvokeMake.setText(res.getString("Deploy_during_make"));
110: jCheckInvokeMake
111: .addActionListener(new java.awt.event.ActionListener() {
112: public void actionPerformed(ActionEvent e) {
113: jCheckInvokeMake_actionPerformed(e);
114: }
115: });
116:
117: jTextDestination
118: .addFocusListener(new java.awt.event.FocusAdapter() {
119: public void focusLost(FocusEvent e) {
120: jTextDestination_focusLost(e);
121: }
122: });
123:
124: jCheckBoxMakeWAR.setText("Make WAR (Web Archive)");
125: jCheckBoxMakeWAR
126: .addActionListener(new java.awt.event.ActionListener() {
127: public void actionPerformed(ActionEvent e) {
128: jCheckBoxMakeWAR_actionPerformed(e);
129: }
130: });
131:
132: xYLayout1.setWidth(460);
133: xYLayout1.setHeight(372);
134: jCheckBoxEnhydraLib.setText("Include Enhydra library into WAR");
135: jCheckBoxEnhydraLib
136: .addActionListener(new java.awt.event.ActionListener() {
137: public void actionPerformed(ActionEvent e) {
138: jCheckBoxEnhydraLib_actionPerformed(e);
139: }
140: });
141: this .add(jLabelDescr, new XYConstraints(13, 13, 178, 18));
142: this .add(jCheckInvokeMake, new XYConstraints(13, 55, 258, 20));
143: this .add(jLabelType, new XYConstraints(13, 88, 74, 18));
144: this .add(jTextType, new XYConstraints(13, 112, 368, 22));
145: this .add(jLabelRoot, new XYConstraints(13, 159, 170, 26));
146: this .add(jTextDestination, new XYConstraints(13, 189, 267, 22));
147: this .add(jButtonBrowse, new XYConstraints(291, 187, 90, 25));
148: this .add(jCheckBoxMakeWAR, new XYConstraints(13, 245, 328, 24));
149: this .add(jCheckBoxEnhydraLib, new XYConstraints(13, 277, 368,
150: 32));
151: }
152:
153: public void jTextDestination_focusLost(FocusEvent fe) {
154: project.setProperty(AntProject.OUTPUT_DIR, jTextDestination
155: .getText());
156: }
157:
158: void jButtonBrowse_actionPerformed(ActionEvent e) {
159: browseForDir();
160: }
161:
162: private void browseForDir() {
163: JFileChooser chooser;
164: String fileDir = new String();
165: File file = null;
166: chooser = new JFileChooser();
167: chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
168: file = new File(project.getProperty(AntProject.OUTPUT_DIR));
169: if (!file.isAbsolute()) {
170: file = new File(project.getWorkingPath(), file.getPath());
171: }
172: chooser.setCurrentDirectory(file);
173: chooser.setDialogTitle(res
174: .getString("chooser_DeployRoot_DialogTitle"));
175: chooser.setApproveButtonText(res.getString("OK"));
176: int v = chooser.showOpenDialog(this );
177:
178: this .requestFocus();
179: jButtonBrowse.requestFocus();
180: if (v == JFileChooser.APPROVE_OPTION) {
181: if (!(chooser.getCurrentDirectory() == null)) {
182: fileDir = chooser.getSelectedFile().toString();
183: jTextDestination.setText(fileDir);
184: project.setProperty(AntProject.OUTPUT_DIR, fileDir);
185: }
186: }
187: chooser.removeAll();
188: chooser = null;
189: }
190:
191: void jCheckInvokeMake_actionPerformed(ActionEvent e) {
192: if (jCheckInvokeMake.isSelected()) {
193: project.setProperty(AntProject.DEPLOY_INVOKE, "true");
194: } else {
195: project.setProperty(AntProject.DEPLOY_INVOKE, "false");
196: }
197: }
198:
199: void jCheckBoxMakeWAR_actionPerformed(ActionEvent e) {
200: if (jCheckBoxMakeWAR.isSelected()) {
201: project.setProperty(AntProject.DEPLOY_WAR_ENABLED, "true");
202: jCheckBoxEnhydraLib.setVisible(true);
203: } else {
204: project.setProperty(AntProject.DEPLOY_WAR_ENABLED, "false");
205: jCheckBoxEnhydraLib.setVisible(false);
206: }
207: }
208:
209: void jCheckBoxEnhydraLib_actionPerformed(ActionEvent e) {
210: if (jCheckBoxEnhydraLib.isSelected()) {
211: project.setProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS,
212: "true");
213: } else {
214: project.setProperty(AntProject.DEPLOY_WAR_ENHYDRA_LIBS,
215: "false");
216: }
217: }
218: }
|