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.web.wizards;
043:
044: import java.awt.Color;
045: import java.awt.GridBagConstraints;
046: import java.awt.Insets;
047: import java.awt.event.FocusEvent;
048: import java.awt.event.FocusAdapter;
049: import java.awt.event.ItemEvent;
050: import java.awt.event.ItemListener;
051: import java.awt.event.KeyEvent;
052:
053: import javax.swing.JCheckBox;
054: import javax.swing.JLabel;
055: import javax.swing.JTextField;
056: import javax.swing.KeyStroke;
057:
058: import javax.swing.event.DocumentEvent;
059: import javax.swing.event.DocumentListener;
060: import org.openide.util.HelpCtx;
061: import org.openide.util.Mutex;
062: import org.openide.util.NbBundle;
063:
064: /*
065: * Wizard panel that collects deployment data for Servlets and Filters
066: * @author Ana von Klopp
067: */
068:
069: class DeployDataPanel extends BaseWizardPanel implements ItemListener {
070:
071: private TargetEvaluator evaluator = null;
072:
073: private ServletData deployData;
074: private FileType fileType;
075: private boolean edited = false;
076:
077: private static final boolean debug = false;
078:
079: public DeployDataPanel(TargetEvaluator e) {
080:
081: evaluator = e;
082: fileType = evaluator.getFileType();
083: deployData = (ServletData) (evaluator.getDeployData());
084: setName(NbBundle.getMessage(DeployDataPanel.class,
085: "TITLE_ddpanel_".concat(fileType.toString())));
086: getAccessibleContext().setAccessibleDescription(
087: NbBundle.getMessage(DeployDataPanel.class,
088: "ACSD_deployment"));
089: initComponents();
090: fireChangeEvent();
091: }
092:
093: private void initComponents() {
094:
095: if (debug)
096: log("::initComponents()"); //NOI18N
097: // Layout description
098: setPreferredSize(new java.awt.Dimension(450, 250));
099: setLayout(new java.awt.GridBagLayout());
100:
101: // Entity covers entire row
102: GridBagConstraints fullRowC = new GridBagConstraints();
103: fullRowC.gridx = 0;
104: fullRowC.gridy = GridBagConstraints.RELATIVE;
105: fullRowC.gridwidth = 8;
106: fullRowC.anchor = GridBagConstraints.WEST;
107: fullRowC.fill = GridBagConstraints.HORIZONTAL;
108: fullRowC.insets = new Insets(4, 0, 4, 60);
109:
110: // Initial label
111: GridBagConstraints firstC = new GridBagConstraints();
112: firstC.gridx = 0;
113: firstC.gridy = GridBagConstraints.RELATIVE;
114: firstC.gridwidth = 1;
115: firstC.anchor = GridBagConstraints.WEST;
116: firstC.insets = new Insets(4, 20, 4, 0);
117: //firstC.weighty = 0.1;
118:
119: // Long textfield
120: GridBagConstraints tfC = new GridBagConstraints();
121: tfC.gridx = GridBagConstraints.RELATIVE;
122: tfC.gridy = 0;
123: tfC.gridwidth = 7;
124: tfC.fill = GridBagConstraints.HORIZONTAL;
125: tfC.insets = new Insets(4, 20, 4, 60);
126:
127: // Short textfield
128: GridBagConstraints stfC = new GridBagConstraints();
129: stfC.gridx = GridBagConstraints.RELATIVE;
130: stfC.gridy = 0;
131: //stfC.gridwidth = 7;
132: stfC.gridwidth = 5;
133: stfC.weightx = 1.0;
134: stfC.fill = GridBagConstraints.HORIZONTAL;
135: stfC.insets = new Insets(4, 20, 4, 0);
136:
137: // Table panel
138: GridBagConstraints tablePanelC = new GridBagConstraints();
139: tablePanelC.gridx = 0;
140: tablePanelC.gridy = GridBagConstraints.RELATIVE;
141: tablePanelC.gridwidth = 8;
142: tablePanelC.fill = GridBagConstraints.BOTH;
143: tablePanelC.weightx = 1.0;
144: tablePanelC.weighty = 1.0;
145: tablePanelC.insets = new Insets(4, 20, 4, 0);
146:
147: // Component Initialization by row
148: // 1. Instruction
149: jLinstruction = new JLabel(NbBundle.getMessage(
150: DeployDataPanel.class, "LBL_dd_".concat(fileType
151: .toString())));
152: this .add(jLinstruction, fullRowC);
153:
154: // 2. Checkbox row - add this?
155:
156: tfC.gridy++;
157: // PENDING - whether it's selected needs to depend on the
158: // previous panel...
159: jCBservlet = new JCheckBox(NbBundle.getMessage(
160: DeployDataPanel.class, "LBL_addtodd"), true);
161: jCBservlet.setMnemonic(NbBundle.getMessage(
162: DeployDataPanel.class, "LBL_add_mnemonic").charAt(0));
163: jCBservlet.addItemListener(this );
164: jCBservlet.getAccessibleContext().setAccessibleDescription(
165: NbBundle.getMessage(DeployDataPanel.class,
166: "ACSD_addtodd")); // NOI18N
167:
168: this .add(jCBservlet, fullRowC);
169:
170: // 3. Classname
171: tfC.gridy++;
172: jTFclassname = new JTextField(25);
173: jTFclassname.setEnabled(false);
174: jTFclassname.setBackground(this .getBackground());
175: jLclassname = new JLabel(NbBundle.getMessage(
176: DeployDataPanel.class, "LBL_ClassName"));
177: jLclassname.setLabelFor(jTFclassname);
178: jLclassname.setDisplayedMnemonic(NbBundle.getMessage(
179: DeployDataPanel.class, "LBL_Class_Mnemonic").charAt(0));
180: jTFclassname.getAccessibleContext().setAccessibleDescription(
181: NbBundle.getMessage(DeployDataPanel.class,
182: "ACSD_ClassName"));
183:
184: this .add(jLclassname, firstC);
185: this .add(jTFclassname, tfC);
186:
187: // 4. Servlet or filter name
188: tfC.gridy++;
189: jTFname = new JTextField(25);
190: jTFname.getAccessibleContext().setAccessibleDescription(
191: NbBundle.getMessage(DeployDataPanel.class, "ACSD_name_"
192: .concat(fileType.toString())));
193: jTFname.getDocument().addDocumentListener(
194: new DocumentListener() {
195:
196: public void insertUpdate(DocumentEvent e) {
197: changedUpdate(e);
198: }
199:
200: public void removeUpdate(DocumentEvent e) {
201: changedUpdate(e);
202: }
203:
204: public void changedUpdate(DocumentEvent e) {
205: Mutex.EVENT.readAccess(new Runnable() {
206: public void run() {
207: // PENDING - this is way too heavy weight,
208: // just append until we get the focus lost.
209: deployData.setName(jTFname.getText()
210: .trim());
211: if (fileType == FileType.FILTER) {
212: mappingPanel.setData();
213: }
214: fireChangeEvent();
215: }
216: });
217: }
218: });
219: jTFname.unregisterKeyboardAction(KeyStroke.getKeyStroke(
220: KeyEvent.VK_ENTER, 0));
221: jTFname.addFocusListener(new FocusAdapter() {
222: public void focusGained(FocusEvent evt) {
223: if (debug)
224: log("\tjTFname got focus"); //NOI18N
225: jTFname.selectAll();
226: }
227: });
228:
229: jLname = new JLabel(NbBundle.getMessage(DeployDataPanel.class,
230: "LBL_name_".concat(fileType.toString())));
231: jLname.setLabelFor(jTFname);
232: jLname.setDisplayedMnemonic(NbBundle
233: .getMessage(
234: DeployDataPanel.class,
235: "LBL_name_".concat(fileType.toString()).concat(
236: "_mnem")).charAt(0));
237:
238: this .add(jLname, firstC);
239: this .add(jTFname, tfC);
240:
241: // 5. URL Mappings (servlet only)
242: if (fileType == FileType.SERVLET) {
243: tfC.gridy++;
244: jTFmapping = new JTextField(25);
245: jTFmapping.getAccessibleContext().setAccessibleDescription(
246: NbBundle.getMessage(DeployDataPanel.class,
247: "ACSD_url_mapping"));
248: jTFmapping.getDocument().addDocumentListener(
249: new DocumentListener() {
250:
251: public void insertUpdate(DocumentEvent e) {
252: changedUpdate(e);
253: }
254:
255: public void removeUpdate(DocumentEvent e) {
256: changedUpdate(e);
257: }
258:
259: public void changedUpdate(DocumentEvent e) {
260: Mutex.EVENT.readAccess(new Runnable() {
261: public void run() {
262: // PENDING - this is way too heavy weight,
263: // just append until we get the focus lost.
264: deployData
265: .parseUrlMappingString(jTFmapping
266: .getText().trim());
267: fireChangeEvent();
268: }
269: });
270: }
271: });
272: jTFmapping.unregisterKeyboardAction(KeyStroke.getKeyStroke(
273: KeyEvent.VK_ENTER, 0));
274: jTFmapping.addFocusListener(new FocusAdapter() {
275: public void focusGained(FocusEvent evt) {
276: if (debug)
277: log("\tjTFmapping got focus"); //NOI18N
278: jTFmapping.selectAll();
279: }
280:
281: public void focusLost(FocusEvent evt) {
282: if (debug)
283: log("\tjTFmapping lost focus"); //NOI18N
284: deployData.parseUrlMappingString(jTFmapping
285: .getText().trim());
286: fireChangeEvent();
287: }
288: });
289:
290: jLmapping = new JLabel(NbBundle.getMessage(
291: DeployDataPanel.class, "LBL_url_mapping"));
292: jLmapping.setLabelFor(jTFmapping);
293: jLmapping.setDisplayedMnemonic(NbBundle.getMessage(
294: DeployDataPanel.class, "LBL_mapping_mnemonic")
295: .charAt(0));
296:
297: this .add(jLmapping, firstC);
298: this .add(jTFmapping, tfC);
299: }
300:
301: // 7. Init parameter
302: if (fileType == FileType.SERVLET) {
303: paramPanel = new InitParamPanel(deployData, this );
304: this .add(paramPanel, tablePanelC);
305: } else if (fileType == FileType.FILTER) {
306: mappingPanel = new MappingPanel(deployData, this );
307: this .add(mappingPanel, tablePanelC);
308: }
309: // Add vertical filler at the bottom
310: GridBagConstraints fillerC = new GridBagConstraints();
311: fillerC.gridx = 0;
312: fillerC.gridy = GridBagConstraints.RELATIVE;
313: fillerC.weighty = 1.0;
314: fillerC.fill = GridBagConstraints.BOTH;
315: this .add(new javax.swing.JPanel(), fillerC);
316: }
317:
318: void setData() {
319: if (debug)
320: log("::setData()"); //NOi18N
321:
322: deployData.setClassName(evaluator.getClassName());
323: jTFclassname.setText(deployData.getClassName());
324:
325: if (!edited) {
326: if (debug)
327: log("\tUser has not edited dd data yet"); //NOi18N
328:
329: deployData.setName(evaluator.getFileName());
330: if (fileType == FileType.SERVLET) {
331: if (debug)
332: log("\tData type is servlet"); //NOi18N
333: deployData.parseUrlMappingString("/"
334: + ServletData.getRFC2396URI(evaluator
335: .getFileName())); // NOI18N
336: }
337: }
338:
339: jTFname.setText(deployData.getName());
340:
341: if (fileType == FileType.SERVLET)
342: jTFmapping.setText(deployData.getUrlMappingsAsString());
343: else if (fileType == FileType.FILTER)
344: mappingPanel.setData();
345: }
346:
347: public void itemStateChanged(java.awt.event.ItemEvent itemEvent) {
348: if (itemEvent.getSource() == jCBservlet) {
349: boolean enabled = (itemEvent.getStateChange() == ItemEvent.SELECTED);
350: enableInput(enabled);
351: deployData.setMakeEntry(enabled);
352: deployData.setAddToDD(enabled);
353: if (fileType == FileType.SERVLET) {
354: paramPanel.setEnabled();
355: }
356: }
357: fireChangeEvent();
358: }
359:
360: private void enableInput(boolean enable) {
361:
362: if (debug)
363: log("::enableInput()");
364:
365: jTFname.setEnabled(enable);
366: jLinstruction.setEnabled(enable);
367: jLclassname.setEnabled(enable);
368: jLname.setEnabled(enable);
369: if (fileType == FileType.SERVLET) {
370: jTFmapping.setEnabled(enable);
371: jLmapping.setEnabled(enable);
372: paramPanel.setEnabled(enable);
373: } else if (fileType == FileType.FILTER) {
374: mappingPanel.setEnabled(enable);
375: }
376:
377: if (enable) {
378: jTFclassname.setDisabledTextColor(Color.black);
379: jTFclassname.repaint();
380: jTFname.setBackground(Color.white);
381: if (fileType == FileType.SERVLET)
382: jTFmapping.setBackground(Color.white);
383: } else {
384: jTFclassname.setDisabledTextColor(jTFname
385: .getDisabledTextColor());
386: jTFclassname.repaint();
387: jTFname.setBackground(this .getBackground());
388: if (fileType == FileType.SERVLET)
389: jTFmapping.setBackground(this .getBackground());
390: }
391: }
392:
393: public void log(String s) {
394: System.out.println("DeployDataPanel" + s); //NOI18N
395: }
396:
397: public HelpCtx getHelp() {
398: return new HelpCtx(this .getClass().getName() + "."
399: + evaluator.getFileType().toString()); //NOI18N
400: }
401:
402: // Variables declaration
403: private JCheckBox jCBservlet;
404: private JTextField jTFclassname;
405: private JTextField jTFname;
406: private JTextField jTFmapping;
407: private JLabel jLinstruction;
408: private JLabel jLclassname;
409: private JLabel jLname;
410: private JLabel jLmapping;
411: private InitParamPanel paramPanel;
412: private MappingPanel mappingPanel;
413:
414: private static final long serialVersionUID = -2704206901170711687L;
415:
416: }
|