KickJava   Java API By Example, From Geeks To Geeks.

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


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.event.ActionListener JavaDoc;
23 import java.io.File JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.ProjectUtils;
32 import org.netbeans.api.project.SourceGroup;
33 import org.netbeans.api.project.Sources;
34 import org.netbeans.spi.project.support.GenericSources;
35 import org.openide.filesystems.FileObject;
36 import org.openide.filesystems.FileUtil;
37 import org.openide.util.NbBundle;
38 import org.netbeans.modules.web.api.webmodule.WebModule;
39
40 import org.netbeans.modules.web.taglib.TLDDataObject;
41 import org.netbeans.spi.project.ui.templates.support.Templates;
42 import org.netbeans.modules.web.core.Util;
43
44 // XXX I18N
45

46 /**
47  *
48  * @author phrebejk, mkuchtiak
49  */

50 public class TargetChooserPanelGUI extends javax.swing.JPanel JavaDoc implements ActionListener JavaDoc, DocumentListener JavaDoc {
51     private static final String JavaDoc TAG_FILE_FOLDER="WEB-INF/tags"; //NOI18N
52
private static final String JavaDoc TAG_FILE_IN_JAVALIB_FOLDER="META-INF/tags"; //NOI18N
53
private static final String JavaDoc TLD_FOLDER="WEB-INF/tlds"; //NOI18N
54
private static final String JavaDoc TLD_IN_JAVALIB_FOLDER="META-INF"; //NOI18N
55

56     private TargetChooserPanel wizardPanel;
57     private Project project;
58     private String JavaDoc expectedExtension;
59     private final List JavaDoc/*<ChangeListener>*/ listeners = new ArrayList JavaDoc();
60     private SourceGroup[] folders;
61     private FileType fileType;
62     private WebModule wm;
63     // GUI components for JSP/TAG
64
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
65     private javax.swing.JTextArea JavaDoc descriptionArea;
66     private javax.swing.JScrollPane JavaDoc jScrollPane1;
67     private javax.swing.JRadioButton JavaDoc jspSyntaxButton, xmlSyntaxButton;
68     private javax.swing.JCheckBox JavaDoc segmentBox, tldCheckBox;
69     private javax.swing.JButton JavaDoc browseButton1;
70     private javax.swing.JLabel JavaDoc descriptionLabel, optionLabel;
71     private javax.swing.JPanel JavaDoc optionsPanel;
72  
73     private java.util.Set JavaDoc tagValues;
74     private String JavaDoc tagName;
75
76     // GUI components for TLD
77
private javax.swing.JTextField JavaDoc uriTextField,prefixTextField, tldTextField, tagNameTextField;
78     private javax.swing.JLabel JavaDoc uriLabel, prefixLabel;
79     private boolean uriWasTyped,prefixWasTyped;
80     boolean tagFileValid=true;
81     private FileObject tldFo;
82     
83     /** Creates new form TargetChooserGUI */
84     public TargetChooserPanelGUI(final TargetChooserPanel wizardPanel, Project project, SourceGroup[] folders, FileType fileType) {
85         this.wizardPanel = wizardPanel;
86         this.project = project;
87         this.folders=folders;
88         this.fileType=fileType;
89         initComponents();
90         getAccessibleContext().setAccessibleDescription(
91             NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_TargetPanel",fileType.toString()));
92         
93         if (FileType.JSP.equals(fileType) || FileType.TAG.equals(fileType)) {
94             buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
95             jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
96             descriptionArea = new javax.swing.JTextArea JavaDoc();
97             segmentBox = new javax.swing.JCheckBox JavaDoc();
98             descriptionLabel = new javax.swing.JLabel JavaDoc();
99             optionLabel = new javax.swing.JLabel JavaDoc();
100             jspSyntaxButton = new javax.swing.JRadioButton JavaDoc();
101             xmlSyntaxButton = new javax.swing.JRadioButton JavaDoc();
102             optionsPanel = new javax.swing.JPanel JavaDoc();
103
104             optionsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
105
106             java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
107             gridBagConstraints.gridx = 0;
108             gridBagConstraints.gridy = 0;
109             gridBagConstraints.gridwidth = 4;
110             gridBagConstraints.weightx = 2;
111             gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
112             //gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
113
customPanel.add(optionsPanel, gridBagConstraints);
114             
115             segmentBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
116                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
117                     checkBoxChanged(evt);
118                 }
119             });
120
121             optionLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Options"));
122             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123             gridBagConstraints.gridx = 0;
124             gridBagConstraints.gridy = 0;
125             gridBagConstraints.gridheight = 2;
126             gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
127             optionsPanel.add(optionLabel, gridBagConstraints);
128
129             jspSyntaxButton.setSelected(true);
130             if (FileType.JSP.equals(fileType))
131                 jspSyntaxButton.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspStandard_mnem").charAt(0));
132             else
133                 jspSyntaxButton.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_TagStandard_mnem").charAt(0));
134             buttonGroup1.add(jspSyntaxButton);
135             jspSyntaxButton.addItemListener(new java.awt.event.ItemListener JavaDoc() {
136                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
137                     checkBoxChanged(evt);
138                 }
139             });
140
141             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
142             gridBagConstraints.gridx = 1;
143             gridBagConstraints.gridy = 0;
144             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
145             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
146             optionsPanel.add(jspSyntaxButton, gridBagConstraints);
147             
148             xmlSyntaxButton.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspXml_mnem").charAt(0));
149             buttonGroup1.add(xmlSyntaxButton);
150             xmlSyntaxButton.addItemListener(new java.awt.event.ItemListener JavaDoc() {
151                 public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
152                     checkBoxChanged(evt);
153                 }
154             });
155
156             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157             gridBagConstraints.gridx = 2;
158             gridBagConstraints.gridy = 0;
159             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
160             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161             optionsPanel.add(xmlSyntaxButton, gridBagConstraints);
162             
163             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164             gridBagConstraints.gridx = 1;
165             gridBagConstraints.gridy = 1;
166             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
168             segmentBox.setMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_JspSegment_mnem").charAt(0));
169             optionsPanel.add(segmentBox, gridBagConstraints);
170             
171             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
172             gridBagConstraints.gridx = 3;
173             gridBagConstraints.gridy = 0;
174             gridBagConstraints.gridheight = 2;
175             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
176             gridBagConstraints.weightx = 2.0;
177             optionsPanel.add(new javax.swing.JPanel JavaDoc(), gridBagConstraints);
178             
179             descriptionLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_description"));
180             descriptionLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Description_mnem").charAt(0));
181             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
182             gridBagConstraints.gridx = 0;
183             gridBagConstraints.gridy = 1;
184             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
185             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 2, 0);
186             descriptionLabel.setLabelFor(descriptionArea);
187             customPanel.add(descriptionLabel, gridBagConstraints);
188
189             descriptionArea.setEditable(false);
190             descriptionArea.setLineWrap(true);
191             descriptionArea.setRows(2);
192             descriptionArea.setWrapStyleWord(true);
193             descriptionArea.setOpaque(false);
194             descriptionArea.getAccessibleContext().setAccessibleDescription(descriptionLabel.getText());
195             jScrollPane1.setViewportView(descriptionArea);
196             jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
197             
198             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199             gridBagConstraints.gridx = 0;
200             gridBagConstraints.gridy = 2;
201             gridBagConstraints.gridwidth = 4;
202             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203             gridBagConstraints.weightx = 1.0;
204             gridBagConstraints.weighty = 2.0;
205             customPanel.add(jScrollPane1, gridBagConstraints);
206             if (FileType.TAG.equals(fileType)) {
207                 
208                 //remove(fillerPanel);
209
tldCheckBox = new javax.swing.JCheckBox JavaDoc();
210                 tldCheckBox.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_AddToTLD_mnem").charAt(0));
211                 tldCheckBox.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_addTagFileToTLD"));
212                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
213                 gridBagConstraints.gridx = 0;
214                 gridBagConstraints.gridy = 3;
215                 gridBagConstraints.gridwidth = 4;
216                 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
217                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 2, 0);
218                 customPanel.add(tldCheckBox, gridBagConstraints);
219                 tldCheckBox.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("OPT_addToTLD"));
220                 /*
221                 javax.swing.JLabel tldDescriptionLabel = new javax.swing.JLabel();
222                 tldDescriptionLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "HINT_tldFile"));
223                 gridBagConstraints = new java.awt.GridBagConstraints();
224                 gridBagConstraints.gridx = 0;
225                 gridBagConstraints.gridy = 4;
226                 gridBagConstraints.gridwidth = 3;
227                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
228                 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
229                 gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
230                 customPanel.add(tldDescriptionLabel, gridBagConstraints);
231                 */

232                 javax.swing.JLabel JavaDoc tldFileLabel = new javax.swing.JLabel JavaDoc();
233                 tldFileLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TLDName_mnem").charAt(0));
234                 tldFileLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_tldFile"));
235                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
236                 gridBagConstraints.gridx = 0;
237                 gridBagConstraints.gridy = 5;
238                 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
239                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 0);
240                 customPanel.add(tldFileLabel, gridBagConstraints);
241                 
242                 tldTextField = new javax.swing.JTextField JavaDoc();
243                 tldTextField.setEditable(false);
244                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
245                 gridBagConstraints.gridx = 1;
246                 gridBagConstraints.gridy = 5;
247                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248                 gridBagConstraints.weightx = 1.0;
249                 gridBagConstraints.gridwidth = 2;
250                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
251                 customPanel.add(tldTextField, gridBagConstraints);
252                 tldTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TLDFile"));
253                 tldFileLabel.setLabelFor(tldTextField);
254
255                 browseButton1 = new javax.swing.JButton JavaDoc();
256                 browseButton1.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_Browse1_Mnemonic").charAt(0));
257                 browseButton1.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Browse"));
258                 browseButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
259                     public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
260                         browseButton1ActionPerformed(evt);
261                     }
262                 });
263                 browseButton1.setEnabled(false);
264                 
265                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
266                 gridBagConstraints.gridx = 3;
267                 gridBagConstraints.gridy = 5;
268                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
269                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
270                 customPanel.add(browseButton1, gridBagConstraints);
271                 
272                 browseButton1.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("LBL_Browse"));
273                 tldCheckBox.addItemListener(new java.awt.event.ItemListener JavaDoc() {
274                     public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
275                         tagNameTextField.setEditable(tldCheckBox.isSelected());
276                         browseButton1.setEnabled(tldCheckBox.isSelected());
277                         if (tldCheckBox.isSelected()) {
278                             if (tagName==null) {
279                                 String JavaDoc name = documentNameTextField.getText().trim();
280                                 if (name.length()>0) {
281                                     tagNameTextField.setText(name);
282                                     tagName = name;
283                                 }
284                             }
285                         }
286                         wizardPanel.fireChange();
287                     }
288                 });
289                 
290                 javax.swing.JLabel JavaDoc tagNameLabel = new javax.swing.JLabel JavaDoc();
291                 tagNameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_TagName_mnem").charAt(0));
292                 tagNameLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_tagName"));
293                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
294                 gridBagConstraints.gridx = 0;
295                 gridBagConstraints.gridy = 6;
296                 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
297                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
298                 customPanel.add(tagNameLabel, gridBagConstraints);
299                 
300                 tagNameTextField = new javax.swing.JTextField JavaDoc();
301                 //tagNameTextField.setColumns(10);
302
tagNameTextField.setEditable(false);
303                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
304                 gridBagConstraints.gridx = 1;
305                 gridBagConstraints.gridy = 6;
306                 gridBagConstraints.weightx = 1.0;
307                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
308                 gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 0);
309                 customPanel.add(tagNameTextField, gridBagConstraints);
310                 tagNameTextField.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/wizards/Bundle").getString("A11Y_DESC_TagName"));
311                 tagNameLabel.setLabelFor(tagNameTextField);
312                 tagNameTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
313                     public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
314                         tagName = tagNameTextField.getText().trim();
315                         wizardPanel.fireChange();
316                     }
317                 });
318                 
319                 gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
320                 gridBagConstraints.gridx = 2;
321                 gridBagConstraints.gridy = 6;
322                 gridBagConstraints.weightx = 1.0;
323                 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
324                 customPanel.add(new javax.swing.JPanel JavaDoc(), gridBagConstraints);
325             }
326         } else if (FileType.TAGLIBRARY.equals(fileType)) {
327             java.awt.GridBagConstraints JavaDoc gridBagConstraints;
328             uriTextField = new javax.swing.JTextField JavaDoc();
329             uriTextField.setColumns(20);
330             prefixTextField = new javax.swing.JTextField JavaDoc();
331             prefixTextField.setColumns(5);
332             
333             uriLabel = new javax.swing.JLabel JavaDoc(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_URI"));
334             uriLabel.setToolTipText(NbBundle.getMessage(TargetChooserPanelGUI.class, "TTT_URI"));
335             uriLabel.setLabelFor(uriTextField);
336             uriLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_URI_mnem").charAt(0));
337             uriTextField.getAccessibleContext().setAccessibleDescription(
338                 NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_URI"));
339             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
340             gridBagConstraints.gridx = 0;
341             gridBagConstraints.gridy = 0;
342             gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
343             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
344             customPanel.add(uriLabel, gridBagConstraints);
345
346             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
347             gridBagConstraints.gridx = 1;
348             gridBagConstraints.gridy = 0;
349             gridBagConstraints.gridwidth = 2;
350             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
351             gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 6, 0);
352             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
353             gridBagConstraints.weightx = 1.0;
354             customPanel.add(uriTextField, gridBagConstraints);
355
356             prefixLabel = new javax.swing.JLabel JavaDoc(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Prefix"));
357             prefixLabel.setLabelFor(prefixTextField);
358             prefixLabel.setToolTipText(NbBundle.getMessage(TargetChooserPanelGUI.class, "TTT_prefix"));
359             prefixLabel.setDisplayedMnemonic(NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Prefix_mnem").charAt(0));
360             prefixTextField.getAccessibleContext().setAccessibleDescription(
361                 NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Prefix"));
362             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
363             gridBagConstraints.gridx = 0;
364             gridBagConstraints.gridy = 1;
365             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
366             customPanel.add(prefixLabel, gridBagConstraints);
367             
368             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
369             gridBagConstraints.gridx = 1;
370             gridBagConstraints.gridy = 1;
371             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
372             gridBagConstraints.weightx = 1.0;
373             gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
374             gridBagConstraints.weightx = 1.0;
375             gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
376             customPanel.add(prefixTextField, gridBagConstraints);
377             
378             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
379             gridBagConstraints.gridx = 3;
380             gridBagConstraints.gridy = 0;
381             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
382             gridBagConstraints.gridheight = 2;
383             gridBagConstraints.weightx = 2.0;
384             customPanel.add(new javax.swing.JPanel JavaDoc(), gridBagConstraints);
385             
386             gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
387             gridBagConstraints.gridx = 2;
388             gridBagConstraints.gridy = 1;
389             gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
390             gridBagConstraints.weightx = 1.0;
391             customPanel.add(new javax.swing.JPanel JavaDoc(), gridBagConstraints);
392
393             uriTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
394                 public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
395                     uriWasTyped=true;
396                     wizardPanel.fireChange();
397                 }
398             });
399
400             prefixTextField.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
401                 public void keyReleased(java.awt.event.KeyEvent JavaDoc evt) {
402                     prefixWasTyped=true;
403                     wizardPanel.fireChange();
404                 }
405             });
406         }
407           
408         
409         //initValues( project, null, null );
410
browseButton.addActionListener( this );
411         documentNameTextField.getDocument().addDocumentListener( this );
412         folderTextField.getDocument().addDocumentListener( this );
413         
414         setName( NbBundle.getMessage(TargetChooserPanelGUI.class,"TITLE_name_location"));
415         
416         if (fileType.equals(FileType.JSP)) {
417             nameLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_JspName"));
418             jspSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_JspSyntax"));
419             jspSyntaxButton.getAccessibleContext().setAccessibleDescription(
420                 NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_JSP"));
421             xmlSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_XmlSyntax"));
422             xmlSyntaxButton.getAccessibleContext().setAccessibleDescription(
423                 NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_JSP_XML"));
424             segmentBox.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_JspSegment"));
425             segmentBox.getAccessibleContext().setAccessibleDescription(
426                 NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_JSP_segment"));
427             descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP"));
428         } else if (fileType.equals(FileType.TAG)) {
429             nameLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_TagFileName"));
430             jspSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileJsp"));
431             jspSyntaxButton.getAccessibleContext().setAccessibleDescription(
432                 NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_TagFile"));
433             xmlSyntaxButton.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileXml"));
434             xmlSyntaxButton.getAccessibleContext().setAccessibleDescription(
435                 NbBundle.getMessage(TargetChooserPanelGUI.class, "DESC_TagFileXml"));
436             segmentBox.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "OPT_TagFileSegment"));
437             segmentBox.getAccessibleContext().setAccessibleDescription(
438                 NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_TagFile_segment"));
439             descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFile"));
440         } else if (fileType.equals(FileType.TAGLIBRARY)) {
441             nameLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_TldName"));
442         } else if (fileType.equals(FileType.HTML)) {
443             nameLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_HtmlName"));
444             //listener to update fileTextField
445
locationCB.addActionListener(new java.awt.event.ActionListener JavaDoc() {
446                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
447                     changedUpdate(null);
448                 }
449             });
450         } else if (fileType.equals(FileType.XHTML)) {
451             nameLabel.setText(NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_XHtmlName"));
452             //listener to update fileTextField
453
locationCB.addActionListener(new java.awt.event.ActionListener JavaDoc() {
454                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
455                     changedUpdate(null);
456                 }
457             });
458         }
459     }
460
461     WebModule getWebModule() {
462         return wm;
463     }
464     
465     public void initValues( Project p, FileObject template, FileObject preselectedFolder ) {
466         projectTextField.setText(ProjectUtils.getInformation(p).getDisplayName());
467         // set the location field and find web module
468
if (folders!=null && folders.length>0) {
469             locationCB.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(getLocations(folders)));
470             wm = WebModule.getWebModule(folders[0].getRootFolder());
471         } else
472             locationCB.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(
473                 new Object JavaDoc[]{new LocationItem(p.getProjectDirectory())}));
474         
475         // filling the folder field
476
String JavaDoc target=null;
477         FileObject docBase = getLocationRoot();
478         if ( preselectedFolder != null && FileUtil.isParentOf( docBase, preselectedFolder ) ) {
479             target = FileUtil.getRelativePath( docBase, preselectedFolder );
480         }
481         
482         // leave target null for tag files and TLDs outside the web project
483
if (wm==null) {
484             if (FileType.TAG.equals(fileType) && target!=null && !target.startsWith(TAG_FILE_IN_JAVALIB_FOLDER)) {
485                 target=null;
486             }
487             if (FileType.TAGLIBRARY.equals(fileType) && target!=null && !target.startsWith(TLD_IN_JAVALIB_FOLDER)) {
488                 target=null;
489             }
490         }
491
492         // setting target folders for tag files and tlds
493
if (FileType.TAG.equals(fileType)) {
494             if (wm!=null) {
495                 if (target==null || !target.startsWith(TAG_FILE_FOLDER))
496                     folderTextField.setText(TAG_FILE_FOLDER+"/"); // NOI18N
497
else folderTextField.setText( target == null ? "" : target ); // NOI18N
498
} else {
499                  if (target==null || !target.startsWith(TAG_FILE_IN_JAVALIB_FOLDER))
500                      folderTextField.setText(TAG_FILE_IN_JAVALIB_FOLDER+"/"); // NOI18N
501
else folderTextField.setText( target == null ? "" : target ); // NOI18N
502
}
503         } else if (FileType.TAGLIBRARY.equals(fileType) && target==null) {
504             if (wm==null) folderTextField.setText(TLD_IN_JAVALIB_FOLDER+"/"); // NOI18N
505
else folderTextField.setText(TLD_FOLDER+"/"); // NOI18N
506
} else
507             folderTextField.setText( target == null ? "" : target ); // NOI18N
508
String JavaDoc ext = template == null ? "" : template.getExt(); // NOI18N
509
expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N
510
}
511     
512     private Object JavaDoc[] getLocations(SourceGroup[] folders) {
513         Object JavaDoc[] loc = new Object JavaDoc[folders.length];
514         for (int i=0;i<folders.length;i++) loc[i] = new LocationItem(folders[i]);
515         return loc;
516     }
517     
518     private String JavaDoc getRelativeSourcesFolder() {
519         String JavaDoc sourceDir="";
520         if (wm!=null) {
521             FileObject docBase = wm.getDocumentBase();
522             FileObject sourcesBase = ((LocationItem)locationCB.getModel().getSelectedItem()).getFileObject();
523             sourceDir = FileUtil.getRelativePath( docBase, sourcesBase );
524             
525             //just for source roots
526
if (sourceDir == null)
527                 sourceDir = "";
528         }
529         return sourceDir.length()==0?"":sourceDir+"/";
530     }
531     
532     public String JavaDoc getRelativeTargetFolder() {
533         return getRelativeSourcesFolder()+getNormalizedFolder();
534     }
535     
536     public String JavaDoc getNormalizedFolder() {
537         String JavaDoc norm = folderTextField.getText().trim();
538         if (norm.length()==0) return "";
539         norm = norm.replace('\\','/');
540         // removing leading slashes
541
int i=0;
542         while (i<norm.length() && norm.charAt(i)=='/') i++;
543         if (i==norm.length()) return ""; //only slashes
544
norm = norm.substring(i);
545
546         // removing multiple slashes
547
java.util.StringTokenizer JavaDoc tokens = new java.util.StringTokenizer JavaDoc(norm,"/");
548         java.util.List JavaDoc list = new java.util.ArrayList JavaDoc();
549         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(tokens.nextToken());
550         while (tokens.hasMoreTokens()) {
551             String JavaDoc token = tokens.nextToken();
552             if (token.length()>0) buf.append("/"+token);
553         }
554         return buf.toString();
555     }
556     
557     public String JavaDoc getTargetFolder() {
558         return getTargetFile().getPath();
559     }
560     
561     public File JavaDoc getTargetFile() {
562         String JavaDoc text = getRelativeTargetFolder();
563         
564         if ( text.length() == 0 ) {
565             if (wm==null)
566                 return FileUtil.toFile(getLocationRoot());
567             else
568                 return FileUtil.toFile( wm.getDocumentBase());
569         }
570         else {
571             // XXX have to account for FU.tF returning null
572
if (wm==null) {
573                 return new File JavaDoc( FileUtil.toFile(getLocationRoot()), text );
574             } else {
575                 return new File JavaDoc( FileUtil.toFile( wm.getDocumentBase() ), text );
576             }
577         }
578     }
579     public String JavaDoc getTargetName() {
580         
581         String JavaDoc text = documentNameTextField.getText().trim();
582         
583         if ( text.length() == 0 ) {
584             return null;
585         }
586         else {
587             return text;
588         }
589     }
590     /*
591     public void addChangeListener(ChangeListener l) {
592         listeners.add(l);
593     }
594     
595     public void removeChangeListener(ChangeListener l) {
596         listeners.remove(l);
597     }
598     
599     private void fireChange() {
600         ChangeEvent e = new ChangeEvent(this);
601         Iterator it = listeners.iterator();
602         while (it.hasNext()) {
603             ((ChangeListener)it.next()).stateChanged(e);
604         }
605     }
606     */

607         
608     /** This method is called from within the constructor to
609      * initialize the form.
610      * WARNING: Do NOT modify this code. The content of this method is
611      * always regenerated by the Form Editor.
612      */

613     private void initComponents() {//GEN-BEGIN:initComponents
614
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
615
616         nameLabel = new javax.swing.JLabel JavaDoc();
617         documentNameTextField = new javax.swing.JTextField JavaDoc();
618         projectLabel = new javax.swing.JLabel JavaDoc();
619         projectTextField = new javax.swing.JTextField JavaDoc();
620         locationLabel = new javax.swing.JLabel JavaDoc();
621         locationCB = new javax.swing.JComboBox JavaDoc();
622         folderLabel = new javax.swing.JLabel JavaDoc();
623         folderTextField = new javax.swing.JTextField JavaDoc();
624         browseButton = new javax.swing.JButton JavaDoc();
625         pathLabel = new javax.swing.JLabel JavaDoc();
626         fileTextField = new javax.swing.JTextField JavaDoc();
627         targetSeparator = new javax.swing.JSeparator JavaDoc();
628         customPanel = new javax.swing.JPanel JavaDoc();
629         fillerPanel = new javax.swing.JPanel JavaDoc();
630
631         setLayout(new java.awt.GridBagLayout JavaDoc());
632
633         nameLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_FileName_mnem").charAt(0));
634         nameLabel.setLabelFor(documentNameTextField);
635         nameLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_JspName"));
636         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
637         gridBagConstraints.gridx = 0;
638         gridBagConstraints.gridy = 0;
639         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
640         add(nameLabel, gridBagConstraints);
641
642         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
643         gridBagConstraints.gridx = 1;
644         gridBagConstraints.gridy = 0;
645         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
646         gridBagConstraints.weightx = 1.0;
647         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
648         add(documentNameTextField, gridBagConstraints);
649         documentNameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_FileName"));
650
651         projectLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Project_mnem").charAt(0));
652         projectLabel.setLabelFor(projectTextField);
653         projectLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Project"));
654         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
655         gridBagConstraints.gridx = 0;
656         gridBagConstraints.gridy = 1;
657         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
658         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
659         add(projectLabel, gridBagConstraints);
660
661         projectTextField.setEditable(false);
662         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
663         gridBagConstraints.gridx = 1;
664         gridBagConstraints.gridy = 1;
665         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
666         gridBagConstraints.weightx = 1.0;
667         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
668         add(projectTextField, gridBagConstraints);
669         projectTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Project"));
670
671         locationLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Location_mnem").charAt(0));
672         locationLabel.setLabelFor(locationCB);
673         locationLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Location"));
674         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
675         gridBagConstraints.gridx = 0;
676         gridBagConstraints.gridy = 2;
677         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
678         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
679         add(locationLabel, gridBagConstraints);
680
681         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
682         gridBagConstraints.gridx = 1;
683         gridBagConstraints.gridy = 2;
684         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
685         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
686         add(locationCB, gridBagConstraints);
687         locationCB.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Location"));
688
689         folderLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_Folder_mnem").charAt(0));
690         folderLabel.setLabelFor(folderTextField);
691         folderLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Folder"));
692         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
693         gridBagConstraints.gridx = 0;
694         gridBagConstraints.gridy = 3;
695         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
696         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
697         add(folderLabel, gridBagConstraints);
698
699         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
700         gridBagConstraints.gridx = 1;
701         gridBagConstraints.gridy = 3;
702         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
703         gridBagConstraints.weightx = 1.0;
704         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
705         add(folderTextField, gridBagConstraints);
706         folderTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_Folder"));
707
708         browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Browse_Mnemonic").charAt(0));
709         browseButton.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_Browse"));
710         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
711         gridBagConstraints.gridx = 2;
712         gridBagConstraints.gridy = 3;
713         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
714         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
715         add(browseButton, gridBagConstraints);
716         browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "ACSD_Browse"));
717
718         pathLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_CreatedFile_mnem").charAt(0));
719         pathLabel.setLabelFor(fileTextField);
720         pathLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "LBL_CreatedFile"));
721         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
722         gridBagConstraints.gridx = 0;
723         gridBagConstraints.gridy = 4;
724         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
725         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
726         add(pathLabel, gridBagConstraints);
727
728         fileTextField.setEditable(false);
729         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
730         gridBagConstraints.gridx = 1;
731         gridBagConstraints.gridy = 4;
732         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
733         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
734         gridBagConstraints.weightx = 1.0;
735         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 6, 0, 0);
736         add(fileTextField, gridBagConstraints);
737         fileTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "A11Y_DESC_CreatedFile"));
738
739         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
740         gridBagConstraints.gridx = 0;
741         gridBagConstraints.gridy = 5;
742         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
743         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
744         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
745         add(targetSeparator, gridBagConstraints);
746
747         customPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
748
749         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
750         gridBagConstraints.gridx = 0;
751         gridBagConstraints.gridy = 6;
752         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
753         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
754         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
755         add(customPanel, gridBagConstraints);
756
757         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
758         gridBagConstraints.gridx = 0;
759         gridBagConstraints.gridy = 7;
760         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
761         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
762         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
763         gridBagConstraints.weighty = 1.0;
764         add(fillerPanel, gridBagConstraints);
765
766     }//GEN-END:initComponents
767

768     
769     
770     // Variables declaration - do not modify//GEN-BEGIN:variables
771
private javax.swing.JButton JavaDoc browseButton;
772     private javax.swing.JPanel JavaDoc customPanel;
773     private javax.swing.JTextField JavaDoc documentNameTextField;
774     private javax.swing.JTextField JavaDoc fileTextField;
775     private javax.swing.JPanel JavaDoc fillerPanel;
776     private javax.swing.JLabel JavaDoc folderLabel;
777     private javax.swing.JTextField JavaDoc folderTextField;
778     private javax.swing.JComboBox JavaDoc locationCB;
779     private javax.swing.JLabel JavaDoc locationLabel;
780     private javax.swing.JLabel JavaDoc nameLabel;
781     private javax.swing.JLabel JavaDoc pathLabel;
782     private javax.swing.JLabel JavaDoc projectLabel;
783     private javax.swing.JTextField JavaDoc projectTextField;
784     private javax.swing.JSeparator JavaDoc targetSeparator;
785     // End of variables declaration//GEN-END:variables
786

787     // ActionListener implementation -------------------------------------------
788

789     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
790         if ( browseButton == e.getSource() ) {
791             FileObject fo=null;
792             // Show the browse dialog
793
if (folders!=null) fo = BrowseFolders.showDialog(folders,
794                     org.openide.loaders.DataFolder.class,
795                     folderTextField.getText().replace( File.separatorChar, '/' ) );
796             else {
797                 Sources sources = ProjectUtils.getSources(project);
798                 fo = BrowseFolders.showDialog( sources.getSourceGroups( Sources.TYPE_GENERIC ),
799                         org.openide.loaders.DataFolder.class,
800                         folderTextField.getText().replace( File.separatorChar, '/' ) );
801             }
802             
803             if ( fo != null && fo.isFolder() ) {
804                 FileObject root = ((LocationItem)locationCB.getSelectedItem()).getFileObject();
805                 folderTextField.setText( FileUtil.getRelativePath( root, fo ) );
806             }
807                         
808         }
809     }
810     
811     // DocumentListener implementation -----------------------------------------
812

813     public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
814
815         File JavaDoc rootDirFile = FileUtil.toFile(((LocationItem)locationCB.getSelectedItem()).getFileObject());
816         if (rootDirFile != null) {
817             String JavaDoc documentName = documentNameTextField.getText().trim();
818             if (documentName.length() == 0) {
819                 fileTextField.setText(""); // NOI18N
820
} else {
821                 File JavaDoc newFile = new File JavaDoc(new File JavaDoc(rootDirFile, folderTextField.getText().replace('/', File.separatorChar)),
822                                         documentName + expectedExtension+(isSegment()?"f":(isXml()?"x":""))); //NOI18N
823
fileTextField.setText(newFile.getAbsolutePath());
824             }
825         } else {
826             // Not on disk.
827
fileTextField.setText(""); // NOI18N
828
}
829         if (FileType.TAGLIBRARY.equals(fileType)) {
830             if (!uriWasTyped) {
831                 String JavaDoc norm=getNormalizedFolder();
832                 //Default value for uri
833
if (wm==null) {
834                     String JavaDoc pack = getPackageNameInMetaInf();
835                     uriTextField.setText((pack.length()>0?pack+".":"")+documentNameTextField.getText());
836                 }
837                 else uriTextField.setText((norm.length()==0?"":"/"+getNormalizedFolder())+ //NOI18N
838
"/"+documentNameTextField.getText().trim()); //NOI18N
839
}
840             //Default value for prefix
841
if (!prefixWasTyped)
842                  prefixTextField.setText(documentNameTextField.getText().trim().toLowerCase());
843         }
844         wizardPanel.fireChange();
845     }
846     
847     private String JavaDoc getPackageNameInMetaInf() {
848         String JavaDoc pack = getRelativeTargetFolder();
849         if (pack.startsWith("META-INF")) {//NOI18N
850
pack = pack.substring(8);
851             if (pack.length()==0) return "";
852             if (pack.startsWith("/")) pack=pack.substring(1);//NOI18N
853
}
854         if (pack.length()==0) return "";//NOI18N
855
pack = pack.replace('/', '.');
856         return pack;
857     }
858     
859     
860     /** specific for JSP/TAG wizards
861      */

862     private void checkBoxChanged(java.awt.event.ItemEvent JavaDoc evt) {
863         // TODO add your handling code here:
864
if (fileType.equals(FileType.JSP)) {
865             if (isSegment()) {
866                 if (isXml()) {
867                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_segment_XML"));
868                 } else {
869                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_segment"));
870                 }
871                 String JavaDoc createdFile = fileTextField.getText();
872                 if (createdFile.endsWith("jspx")) //NOI18N
873
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"f"); //NOI18N
874
else if (createdFile.endsWith("jsp")) //NOI18N
875
fileTextField.setText(createdFile+"f"); //NOI18N
876
} else {
877                 String JavaDoc createdFile = fileTextField.getText();
878                 if (isXml()) {
879                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP_XML"));
880                     if (createdFile.endsWith("jspf")) { //NOI18N
881
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"x"); //NOI18N
882
} else if (createdFile.endsWith("jsp")) { //NOI18N
883
fileTextField.setText(createdFile+"x"); //NOI18N
884
}
885                 } else {
886                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_JSP"));
887                     if (createdFile.endsWith("jspf") || createdFile.endsWith("jspx")) { //NOI18N
888
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)); //NOI18N
889
}
890                 }
891             }
892         } else if (fileType.equals(FileType.TAG)){
893             if (isSegment()) {
894                 if (isXml()) {
895                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileSegmentXml"));
896                 } else {
897                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileSegment"));
898                 }
899                 String JavaDoc createdFile = fileTextField.getText();
900                 if (createdFile.endsWith("tagx")) //NOI18N
901
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"f"); //NOI18N
902
else if (createdFile.endsWith("tag")) //NOI18N
903
fileTextField.setText(createdFile+"f"); //NOI18N
904
} else {
905                 String JavaDoc createdFile = fileTextField.getText();
906                 if (isXml()) {
907                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFileXml"));
908                     if (createdFile.endsWith("tagf")) { //NOI18N
909
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)+"x"); //NOI18N
910
} else if (createdFile.endsWith("tag")) { //NOI18N
911
fileTextField.setText(createdFile+"x"); //NOI18N
912
}
913                 } else {
914                     descriptionArea.setText(NbBundle.getMessage(TargetChooserPanelGUI.class,"DESC_TagFile"));
915                     if (createdFile.endsWith("tagf") || createdFile.endsWith("tagx")) { //NOI18N
916
fileTextField.setText(createdFile.substring(0,createdFile.length()-1)); //NOI18N
917
}
918                 }
919             }
920         }
921         wizardPanel.fireChange();
922     }
923     
924     public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
925         changedUpdate( e );
926     }
927     
928     public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
929         changedUpdate( e );
930     }
931     
932     boolean isXml() {
933         if (xmlSyntaxButton==null) return false;
934         else return xmlSyntaxButton.isSelected();
935     }
936     
937     boolean isSegment() {
938         if (segmentBox==null) return false;
939         else return segmentBox.isSelected();
940     }
941
942     String JavaDoc getUri() {
943         if (uriTextField==null) return "";
944         else return uriTextField.getText();
945     }
946     String JavaDoc getPrefix() {
947         if (prefixTextField==null) return "";
948         else return prefixTextField.getText();
949     }
950     
951     String JavaDoc getErrorMessage() {
952         if (FileType.JSP.equals(fileType)) {
953             if (isSegment() && !getNormalizedFolder().startsWith("WEB-INF/jspf")) //NOI18N
954
return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_segment");
955         } else if (FileType.TAG.equals(fileType)) {
956             tagFileValid=true;
957             if (wm!=null) {
958                 if (!getNormalizedFolder().startsWith(TAG_FILE_FOLDER)) {
959                     tagFileValid=false;
960                     return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_TagFile");
961                 }
962             } else {
963                 if (!getNormalizedFolder().startsWith(TAG_FILE_IN_JAVALIB_FOLDER)) {
964                     tagFileValid=false;
965                     return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_TagFileInJavalib");
966                 }
967             }
968         } else if (FileType.TAGLIBRARY.equals(fileType)) {
969             if (wm==null) {
970                 if (!getNormalizedFolder().startsWith(TLD_IN_JAVALIB_FOLDER))
971                     return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_TLDInJavalib");
972             } else
973                 if (!getNormalizedFolder().startsWith("WEB-INF")) //NOI18N
974
return NbBundle.getMessage(TargetChooserPanelGUI.class,"NOTE_TLDInWeb");
975             if (getUri().length()==0) //NOI18N
976
return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_missingUri");
977             if (getPrefix().length()==0) //NOI18N
978
return NbBundle.getMessage(TargetChooserPanelGUI.class,"MSG_missingPrefix");
979         }
980         return null;
981     }
982     
983     boolean isPanelValid() {
984         if (FileType.TAGLIBRARY.equals(fileType) &&
985             (getUri().length()==0 || getPrefix().length()==0))
986             return false;
987         if (FileType.TAG.equals(fileType) && !tagFileValid)
988             return false;
989         return true;
990     }
991     
992     FileObject getLocationRoot() {
993         return ((LocationItem)locationCB.getModel().getSelectedItem()).getFileObject();
994     }
995     
996     public static class LocationItem {
997         FileObject fo;
998         SourceGroup group;
999         public LocationItem(FileObject fo) {
1000            this.fo=fo;
1001        }
1002        public LocationItem(SourceGroup group) {
1003            this.fo=group.getRootFolder();
1004            this.group=group;
1005        }
1006        public FileObject getFileObject() {
1007            return fo;
1008        }
1009        
1010        public String JavaDoc toString() {
1011            return (group==null?fo.getName():group.getDisplayName());
1012        }
1013    }
1014    
1015    private void browseButton1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1016        // TODO add your handling code here:
1017
org.openide.filesystems.FileObject fo=null;
1018        // Show the browse dialog
1019
if (folders!=null) fo = BrowseFolders.showDialog(folders, TLDDataObject.class,
1020                folderTextField.getText().replace( File.separatorChar, '/' ) );
1021        else {
1022            Sources sources = ProjectUtils.getSources(project);
1023            fo = BrowseFolders.showDialog( sources.getSourceGroups( Sources.TYPE_GENERIC ),
1024                                           org.openide.loaders.DataFolder.class,
1025                    folderTextField.getText().replace( File.separatorChar, '/' ) );
1026        }
1027
1028        if ( fo != null) {
1029            tldFo=fo;
1030            FileObject targetFolder=Templates.getTargetFolder(wizardPanel.getTemplateWizard());
1031            WebModule wm = (targetFolder==null?null:WebModule.getWebModule(targetFolder));
1032            tldTextField.setText( FileUtil.getRelativePath( (wm==null?project.getProjectDirectory():wm.getDocumentBase()), fo ) );
1033            try {
1034                java.io.InputStream JavaDoc is = tldFo.getInputStream();
1035                // get existing tag names for testing duplicity
1036
tagValues = Util.getTagValues(is, new String JavaDoc[]{"tag","tag-file"},"name"); //NOI18N
1037
is.close();
1038            } catch (java.io.IOException JavaDoc ex) {}
1039              catch (org.xml.sax.SAXException JavaDoc ex ){}
1040            wizardPanel.fireChange();
1041        }
1042    }
1043 
1044    boolean isTldCheckBoxSelected() {
1045        return tldCheckBox.isSelected();
1046    }
1047    
1048    String JavaDoc getTagName() {
1049        return tagName;
1050    }
1051    
1052    FileObject getTldFileObject() {
1053        return tldFo;
1054    }
1055    
1056    boolean isValidTagName(String JavaDoc name) {
1057        if (name==null) return false;
1058        return org.apache.xerces.util.XMLChar.isValidNCName(name);
1059    }
1060    
1061    boolean tagNameExists(String JavaDoc name) {
1062        if (tagValues!=null && tagValues.contains(name)) return true;
1063        else return false;
1064    }
1065    
1066    public String JavaDoc getCreatedFilePath() {
1067        return fileTextField.getText();
1068    }
1069
1070}
1071
Popular Tags