KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > wizards > DeployDataPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.wizards;
21
22 import java.awt.Color JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.awt.event.FocusEvent JavaDoc;
26 import java.awt.event.FocusAdapter JavaDoc;
27 import java.awt.event.ItemEvent JavaDoc;
28 import java.awt.event.ItemListener JavaDoc;
29 import java.awt.event.KeyEvent JavaDoc;
30 import java.awt.event.KeyListener JavaDoc;
31
32 import javax.swing.JCheckBox JavaDoc;
33 import javax.swing.JLabel JavaDoc;
34 import javax.swing.JTextField JavaDoc;
35 import javax.swing.KeyStroke JavaDoc;
36 import javax.swing.SwingUtilities JavaDoc;
37
38 import org.openide.util.HelpCtx;
39 import org.openide.util.NbBundle;
40
41 /*
42  * Wizard panel that collects deployment data for Servlets and Filters
43  * @author Ana von Klopp
44  */

45
46 class DeployDataPanel extends BaseWizardPanel implements ItemListener JavaDoc,
47                              KeyListener JavaDoc {
48
49     private TargetEvaluator evaluator = null;
50
51     private ServletData deployData;
52     private FileType fileType;
53     private boolean edited = false;
54
55     private static final boolean debug = false;
56
57     public DeployDataPanel(TargetEvaluator e) {
58         
59     evaluator = e;
60     fileType = evaluator.getFileType();
61     deployData = (ServletData)(evaluator.getDeployData());
62     setName(NbBundle.getMessage(DeployDataPanel.class,
63                     "TITLE_ddpanel_".concat(fileType.toString())));
64     getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class, "ACSD_deployment"));
65     initComponents ();
66     fireChangeEvent();
67     }
68
69     private void initComponents () {
70
71     if(debug) log("::initComponents()"); //NOI18N
72
// Layout description
73
setPreferredSize(new java.awt.Dimension JavaDoc(450, 250));
74     setLayout(new java.awt.GridBagLayout JavaDoc());
75
76     // Entity covers entire row
77
GridBagConstraints JavaDoc fullRowC = new GridBagConstraints JavaDoc();
78     fullRowC.gridx = 0;
79     fullRowC.gridy = GridBagConstraints.RELATIVE;
80     fullRowC.gridwidth = 8;
81     fullRowC.anchor = GridBagConstraints.WEST;
82     fullRowC.fill = GridBagConstraints.HORIZONTAL;
83     fullRowC.insets = new Insets JavaDoc(4, 0, 4, 60);
84
85     // Initial label
86
GridBagConstraints JavaDoc firstC = new GridBagConstraints JavaDoc();
87     firstC.gridx = 0;
88     firstC.gridy = GridBagConstraints.RELATIVE;
89     firstC.gridwidth = 1;
90     firstC.anchor = GridBagConstraints.WEST;
91     firstC.insets = new Insets JavaDoc(4, 20, 4, 0);
92     //firstC.weighty = 0.1;
93

94     // Long textfield
95
GridBagConstraints JavaDoc tfC = new GridBagConstraints JavaDoc();
96     tfC.gridx = GridBagConstraints.RELATIVE;
97     tfC.gridy = 0;
98     tfC.gridwidth = 7;
99     tfC.fill = GridBagConstraints.HORIZONTAL;
100     tfC.insets = new Insets JavaDoc(4, 20, 4, 60);
101
102     // Short textfield
103
GridBagConstraints JavaDoc stfC = new GridBagConstraints JavaDoc();
104     stfC.gridx = GridBagConstraints.RELATIVE;
105     stfC.gridy = 0;
106     //stfC.gridwidth = 7;
107
stfC.gridwidth = 5;
108     stfC.weightx = 1.0;
109     stfC.fill = GridBagConstraints.HORIZONTAL;
110     stfC.insets = new Insets JavaDoc(4, 20, 4, 0);
111
112     // Table panel
113
GridBagConstraints JavaDoc tablePanelC = new GridBagConstraints JavaDoc();
114     tablePanelC.gridx = 0;
115     tablePanelC.gridy = GridBagConstraints.RELATIVE;
116     tablePanelC.gridwidth = 8;
117     tablePanelC.fill = GridBagConstraints.BOTH;
118     tablePanelC.weightx = 1.0;
119     tablePanelC.weighty = 1.0;
120     tablePanelC.insets = new Insets JavaDoc(4, 20, 4, 0);
121
122     // Component Initialization by row
123
// 1. Instruction
124
jLinstruction = new JLabel JavaDoc(NbBundle.getMessage(DeployDataPanel.class, "LBL_dd_".concat(fileType.toString())));
125     this.add(jLinstruction, fullRowC);
126
127     // 2. Checkbox row - add this?
128

129     tfC.gridy++;
130     // PENDING - whether it's selected needs to depend on the
131
// previous panel...
132
jCBservlet = new JCheckBox JavaDoc(NbBundle.getMessage(DeployDataPanel.class, "LBL_addtodd"), true);
133     jCBservlet.setMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_add_mnemonic").charAt (0));
134     jCBservlet.addItemListener(this);
135     jCBservlet.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class, "ACSD_addtodd")); // NOI18N
136

137     this.add(jCBservlet, fullRowC);
138
139     // 3. Classname
140
tfC.gridy++;
141     jTFclassname = new JTextField JavaDoc(25);
142     jTFclassname.setEnabled(false);
143     jTFclassname.setBackground(this.getBackground());
144     jLclassname = new JLabel JavaDoc(NbBundle.getMessage(DeployDataPanel.class, "LBL_ClassName"));
145     jLclassname.setLabelFor(jTFclassname);
146     jLclassname.setDisplayedMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_Class_Mnemonic").charAt(0));
147     jTFclassname.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_ClassName"));
148         
149     this.add(jLclassname, firstC);
150     this.add(jTFclassname, tfC);
151
152     // 4. Servlet or filter name
153
tfC.gridy++;
154     jTFname = new JTextField JavaDoc(25);
155     jTFname.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_name_".concat(fileType.toString())));
156     jTFname.addKeyListener (this);
157     jTFname.unregisterKeyboardAction
158         (KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
159     jTFname.addFocusListener(new FocusAdapter JavaDoc() {
160         public void focusGained(FocusEvent JavaDoc evt) {
161             if(debug) log("\tjTFname got focus"); //NOI18N
162
jTFname.selectAll();
163         }
164         });
165         
166     jLname = new JLabel JavaDoc(NbBundle.getMessage(DeployDataPanel.class, "LBL_name_".concat(fileType.toString())));
167     jLname.setLabelFor(jTFname);
168     jLname.setDisplayedMnemonic(NbBundle.getMessage(DeployDataPanel.class, "LBL_name_".concat(fileType.toString()).concat("_mnem")).charAt(0));
169
170     this.add(jLname, firstC);
171     this.add(jTFname, tfC);
172
173     // 5. URL Mappings (servlet only)
174
if(fileType == FileType.SERVLET) {
175         tfC.gridy++;
176         jTFmapping = new JTextField JavaDoc(25);
177         jTFmapping.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DeployDataPanel.class,"ACSD_url_mapping"));
178         jTFmapping.addKeyListener (this);
179         jTFmapping.unregisterKeyboardAction
180         (KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
181         jTFmapping.addFocusListener(new FocusAdapter JavaDoc() {
182             public void focusGained(FocusEvent JavaDoc evt) {
183             if(debug) log("\tjTFmapping got focus"); //NOI18N
184
jTFmapping.selectAll();
185             }
186             public void focusLost(FocusEvent JavaDoc evt) {
187             if(debug) log("\tjTFmapping lost focus"); //NOI18N
188
deployData.parseUrlMappingString(jTFmapping.getText().trim());
189             fireChangeEvent();
190             }
191         });
192         
193         jLmapping = new JLabel JavaDoc(NbBundle.getMessage(DeployDataPanel.class, "LBL_url_mapping"));
194         jLmapping.setLabelFor (jTFmapping);
195         jLmapping.setDisplayedMnemonic(NbBundle.getMessage (DeployDataPanel.class, "LBL_mapping_mnemonic").charAt (0));
196
197         this.add(jLmapping, firstC);
198         this.add(jTFmapping, tfC);
199     }
200
201     // 7. Init parameter
202
if(fileType == FileType.SERVLET) {
203         paramPanel = new InitParamPanel(deployData, this);
204         this.add(paramPanel, tablePanelC);
205     }
206     else if(fileType == FileType.FILTER) {
207         mappingPanel = new MappingPanel(deployData, this);
208         this.add(mappingPanel, tablePanelC);
209     }
210     // Add vertical filler at the bottom
211
GridBagConstraints JavaDoc fillerC = new GridBagConstraints JavaDoc();
212     fillerC.gridx = 0;
213     fillerC.gridy = GridBagConstraints.RELATIVE;
214     fillerC.weighty = 1.0;
215         fillerC.fill = GridBagConstraints.BOTH;
216     this.add(new javax.swing.JPanel JavaDoc (), fillerC);
217     }
218
219     void setData() {
220     if(debug) log("::setData()"); //NOi18N
221

222     deployData.setClassName(evaluator.getClassName());
223     jTFclassname.setText(deployData.getClassName());
224         
225     if(!edited) {
226         if(debug) log("\tUser has not edited dd data yet"); //NOi18N
227

228         deployData.setName(evaluator.getFileName());
229         if(fileType == FileType.SERVLET) {
230         if(debug) log("\tData type is servlet"); //NOi18N
231
deployData.parseUrlMappingString("/" + //NOI18N
232
evaluator.getFileName());
233         }
234     }
235
236     jTFname.setText(deployData.getName());
237
238     if(fileType == FileType.SERVLET)
239         jTFmapping.setText(deployData.getUrlMappingsAsString());
240     else if(fileType == FileType.FILTER)
241         mappingPanel.setData();
242     }
243
244     public void itemStateChanged (java.awt.event.ItemEvent JavaDoc itemEvent) {
245     if(itemEvent.getSource() == jCBservlet) {
246         boolean enabled =
247         (itemEvent.getStateChange() == ItemEvent.SELECTED);
248         enableInput(enabled);
249         deployData.setMakeEntry(enabled);
250             deployData.setAddToDD(enabled);
251             if(fileType == FileType.SERVLET) {
252                 paramPanel.setEnabled();
253             }
254     }
255     fireChangeEvent ();
256     }
257
258     private void enableInput(boolean enable) {
259
260     if(debug) log("::enableInput()");
261
262     jTFname.setEnabled(enable);
263     jLinstruction.setEnabled(enable);
264     jLclassname.setEnabled(enable);
265     jLname.setEnabled(enable);
266     if(fileType == FileType.SERVLET) {
267         jTFmapping.setEnabled(enable);
268         jLmapping.setEnabled(enable);
269         paramPanel.setEnabled(enable);
270     }
271     else if (fileType == FileType.FILTER) {
272         mappingPanel.setEnabled(enable);
273     }
274
275     if(enable) {
276         jTFclassname.setDisabledTextColor(Color.black);
277         jTFclassname.repaint();
278         jTFname.setBackground(Color.white);
279         if(fileType == FileType.SERVLET)
280         jTFmapping.setBackground(Color.white);
281     }
282     else {
283         jTFclassname.setDisabledTextColor
284         (jTFname.getDisabledTextColor());
285         jTFclassname.repaint();
286         jTFname.setBackground(this.getBackground());
287         if(fileType == FileType.SERVLET)
288         jTFmapping.setBackground(this.getBackground());
289     }
290     }
291
292     public void keyPressed (java.awt.event.KeyEvent JavaDoc keyEvent) {
293     }
294         
295     public void keyReleased (java.awt.event.KeyEvent JavaDoc keyEvent) {
296     edited = true;
297     if(keyEvent.getSource() == jTFname) {
298         SwingUtilities.invokeLater(new Runnable JavaDoc() {
299             public void run() {
300             // PENDING - this is way too heavy weight,
301
// just append until we get the focus lost.
302
deployData.setName(jTFname.getText().trim());
303             if(fileType == FileType.FILTER)
304                 mappingPanel.setData();
305             fireChangeEvent();
306             }
307         });
308         return;
309     }
310     else if(keyEvent.getSource() == jTFmapping) {
311         SwingUtilities.invokeLater(new Runnable JavaDoc() {
312             public void run() {
313             // PENDING - this is way too heavy weight,
314
// just append until we get the focus lost.
315
deployData.parseUrlMappingString(jTFmapping.getText().trim());
316             fireChangeEvent();
317             }
318         });
319         return;
320     }
321     fireChangeEvent();
322     }
323         
324     public void keyTyped (java.awt.event.KeyEvent JavaDoc keyEvent) {
325     }
326     
327
328     public void log(String JavaDoc s) {
329     System.out.println("DeployDataPanel" + s); //NOI18N
330
}
331
332
333     public HelpCtx getHelp() {
334         return new HelpCtx(this.getClass().getName()+"."+evaluator.getFileType().toString()); //NOI18N
335
}
336
337     // Variables declaration
338
private JCheckBox JavaDoc jCBservlet;
339     private JTextField JavaDoc jTFclassname;
340     private JTextField JavaDoc jTFname;
341     private JTextField JavaDoc jTFmapping;
342     private JLabel JavaDoc jLinstruction;
343     private JLabel JavaDoc jLclassname;
344     private JLabel JavaDoc jLname;
345     private JLabel JavaDoc jLmapping;
346     private InitParamPanel paramPanel;
347     private MappingPanel mappingPanel;
348     
349     private static final long serialVersionUID = -2704206901170711687L;
350     
351 }
352
Popular Tags