0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common
0008: * Development and Distribution License("CDDL") (collectively, the
0009: * "License"). You may not use this file except in compliance with the
0010: * License. You can obtain a copy of the License at
0011: * http://www.netbeans.org/cddl-gplv2.html
0012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013: * specific language governing permissions and limitations under the
0014: * License. When distributing the software, include this License Header
0015: * Notice in each file and include the License file at
0016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
0017: * particular file as subject to the "Classpath" exception as provided
0018: * by Sun in the GPL Version 2 section of the License file that
0019: * accompanied this code. If applicable, add the following below the
0020: * License Header, with the fields enclosed by brackets [] replaced by
0021: * your own identifying information:
0022: * "Portions Copyrighted [year] [name of copyright owner]"
0023: *
0024: * Contributor(s):
0025: *
0026: * The Original Software is NetBeans. The Initial Developer of the Original
0027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
0028: * Microsystems, Inc. All Rights Reserved.
0029: *
0030: * If you wish your version of this file to be governed by only the CDDL
0031: * or only the GPL Version 2, indicate your decision by adding
0032: * "[Contributor] elects to include this software in this distribution
0033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034: * single choice of license, a recipient has the option to distribute
0035: * your version of this file under either the CDDL, the GPL Version 2 or
0036: * to extend the choice of license to its licensees as provided above.
0037: * However, if you add GPL Version 2 code and therefore, elected the GPL
0038: * Version 2 license, then the option applies only if the new code is
0039: * made subject to such option by the copyright holder.
0040: */
0041:
0042: package org.netbeans.modules.web.wizards;
0043:
0044: import java.awt.event.ActionListener;
0045: import java.io.File;
0046: import java.util.ArrayList;
0047: import java.util.Iterator;
0048: import java.util.List;
0049: import javax.swing.event.ChangeEvent;
0050: import javax.swing.event.ChangeListener;
0051: import javax.swing.event.DocumentListener;
0052: import org.netbeans.api.project.Project;
0053: import org.netbeans.api.project.ProjectUtils;
0054: import org.netbeans.api.project.SourceGroup;
0055: import org.netbeans.api.project.Sources;
0056: import org.netbeans.spi.project.support.GenericSources;
0057: import org.openide.filesystems.FileObject;
0058: import org.openide.filesystems.FileUtil;
0059: import org.openide.util.NbBundle;
0060: import org.netbeans.modules.web.api.webmodule.WebModule;
0061:
0062: import org.netbeans.modules.web.taglib.TLDDataObject;
0063: import org.netbeans.spi.project.ui.templates.support.Templates;
0064: import org.netbeans.modules.web.core.Util;
0065:
0066: // XXX I18N
0067:
0068: /**
0069: *
0070: * @author phrebejk, mkuchtiak
0071: */
0072: public class TargetChooserPanelGUI extends javax.swing.JPanel implements
0073: ActionListener, DocumentListener {
0074: private static final String TAG_FILE_FOLDER = "WEB-INF/tags"; //NOI18N
0075: private static final String TAG_FILE_IN_JAVALIB_FOLDER = "META-INF/tags"; //NOI18N
0076: private static final String TLD_FOLDER = "WEB-INF/tlds"; //NOI18N
0077: private static final String TLD_IN_JAVALIB_FOLDER = "META-INF"; //NOI18N
0078:
0079: private TargetChooserPanel wizardPanel;
0080: private Project project;
0081: private String expectedExtension;
0082: private final List/*<ChangeListener>*/listeners = new ArrayList();
0083: private SourceGroup[] folders;
0084: private FileType fileType;
0085: private WebModule wm;
0086: // GUI components for JSP/TAG
0087: private javax.swing.ButtonGroup buttonGroup1;
0088: private javax.swing.JTextArea descriptionArea;
0089: private javax.swing.JScrollPane jScrollPane1;
0090: private javax.swing.JRadioButton jspSyntaxButton, xmlSyntaxButton;
0091: private javax.swing.JCheckBox segmentBox, tldCheckBox;
0092: private javax.swing.JButton browseButton1;
0093: private javax.swing.JLabel descriptionLabel, optionLabel;
0094: private javax.swing.JPanel optionsPanel;
0095:
0096: private java.util.Set tagValues;
0097: private String tagName;
0098:
0099: // GUI components for TLD
0100: private javax.swing.JTextField uriTextField, prefixTextField,
0101: tldTextField, tagNameTextField;
0102: private javax.swing.JLabel uriLabel, prefixLabel;
0103: private boolean uriWasTyped, prefixWasTyped;
0104: boolean tagFileValid = true;
0105: private FileObject tldFo;
0106:
0107: /** Creates new form TargetChooserGUI */
0108: public TargetChooserPanelGUI(final TargetChooserPanel wizardPanel,
0109: Project project, SourceGroup[] folders, FileType fileType) {
0110: this .wizardPanel = wizardPanel;
0111: this .project = project;
0112: this .folders = folders;
0113: this .fileType = fileType;
0114: initComponents();
0115: getAccessibleContext().setAccessibleDescription(
0116: NbBundle.getMessage(TargetChooserPanelGUI.class,
0117: "A11Y_DESC_TargetPanel", fileType.toString()));
0118:
0119: if (FileType.JSP.equals(fileType)
0120: || FileType.TAG.equals(fileType)) {
0121: buttonGroup1 = new javax.swing.ButtonGroup();
0122: jScrollPane1 = new javax.swing.JScrollPane();
0123: descriptionArea = new javax.swing.JTextArea();
0124: segmentBox = new javax.swing.JCheckBox();
0125: descriptionLabel = new javax.swing.JLabel();
0126: optionLabel = new javax.swing.JLabel();
0127: jspSyntaxButton = new javax.swing.JRadioButton();
0128: xmlSyntaxButton = new javax.swing.JRadioButton();
0129: optionsPanel = new javax.swing.JPanel();
0130:
0131: optionsPanel.setLayout(new java.awt.GridBagLayout());
0132:
0133: java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
0134: gridBagConstraints.gridx = 0;
0135: gridBagConstraints.gridy = 0;
0136: gridBagConstraints.gridwidth = 4;
0137: gridBagConstraints.weightx = 2;
0138: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0139: //gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0140: customPanel.add(optionsPanel, gridBagConstraints);
0141:
0142: segmentBox
0143: .addItemListener(new java.awt.event.ItemListener() {
0144: public void itemStateChanged(
0145: java.awt.event.ItemEvent evt) {
0146: checkBoxChanged(evt);
0147: }
0148: });
0149:
0150: optionLabel.setText(org.openide.util.NbBundle.getMessage(
0151: TargetChooserPanelGUI.class, "LBL_Options"));
0152: gridBagConstraints = new java.awt.GridBagConstraints();
0153: gridBagConstraints.gridx = 0;
0154: gridBagConstraints.gridy = 0;
0155: gridBagConstraints.gridheight = 2;
0156: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0157: optionsPanel.add(optionLabel, gridBagConstraints);
0158:
0159: jspSyntaxButton.setSelected(true);
0160: if (FileType.JSP.equals(fileType))
0161: jspSyntaxButton.setMnemonic(NbBundle.getMessage(
0162: TargetChooserPanelGUI.class,
0163: "A11Y_JspStandard_mnem").charAt(0));
0164: else
0165: jspSyntaxButton.setMnemonic(NbBundle.getMessage(
0166: TargetChooserPanelGUI.class,
0167: "A11Y_TagStandard_mnem").charAt(0));
0168: buttonGroup1.add(jspSyntaxButton);
0169: jspSyntaxButton
0170: .addItemListener(new java.awt.event.ItemListener() {
0171: public void itemStateChanged(
0172: java.awt.event.ItemEvent evt) {
0173: checkBoxChanged(evt);
0174: }
0175: });
0176:
0177: gridBagConstraints = new java.awt.GridBagConstraints();
0178: gridBagConstraints.gridx = 1;
0179: gridBagConstraints.gridy = 0;
0180: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0181: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0182: optionsPanel.add(jspSyntaxButton, gridBagConstraints);
0183:
0184: xmlSyntaxButton.setMnemonic(NbBundle.getMessage(
0185: TargetChooserPanelGUI.class, "A11Y_JspXml_mnem")
0186: .charAt(0));
0187: buttonGroup1.add(xmlSyntaxButton);
0188: xmlSyntaxButton
0189: .addItemListener(new java.awt.event.ItemListener() {
0190: public void itemStateChanged(
0191: java.awt.event.ItemEvent evt) {
0192: checkBoxChanged(evt);
0193: }
0194: });
0195:
0196: gridBagConstraints = new java.awt.GridBagConstraints();
0197: gridBagConstraints.gridx = 2;
0198: gridBagConstraints.gridy = 0;
0199: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0200: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0201: optionsPanel.add(xmlSyntaxButton, gridBagConstraints);
0202:
0203: gridBagConstraints = new java.awt.GridBagConstraints();
0204: gridBagConstraints.gridx = 1;
0205: gridBagConstraints.gridy = 1;
0206: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0207: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0208: segmentBox.setMnemonic(NbBundle
0209: .getMessage(TargetChooserPanelGUI.class,
0210: "A11Y_JspSegment_mnem").charAt(0));
0211: optionsPanel.add(segmentBox, gridBagConstraints);
0212:
0213: gridBagConstraints = new java.awt.GridBagConstraints();
0214: gridBagConstraints.gridx = 3;
0215: gridBagConstraints.gridy = 0;
0216: gridBagConstraints.gridheight = 2;
0217: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0218: gridBagConstraints.weightx = 2.0;
0219: optionsPanel.add(new javax.swing.JPanel(),
0220: gridBagConstraints);
0221:
0222: descriptionLabel.setText(NbBundle.getMessage(
0223: TargetChooserPanelGUI.class, "LBL_description"));
0224: descriptionLabel.setDisplayedMnemonic(NbBundle.getMessage(
0225: TargetChooserPanelGUI.class,
0226: "A11Y_Description_mnem").charAt(0));
0227: gridBagConstraints = new java.awt.GridBagConstraints();
0228: gridBagConstraints.gridx = 0;
0229: gridBagConstraints.gridy = 1;
0230: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0231: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
0232: descriptionLabel.setLabelFor(descriptionArea);
0233: customPanel.add(descriptionLabel, gridBagConstraints);
0234:
0235: descriptionArea.setEditable(false);
0236: descriptionArea.setLineWrap(true);
0237: descriptionArea.setRows(2);
0238: descriptionArea.setWrapStyleWord(true);
0239: descriptionArea.setOpaque(false);
0240: descriptionArea.getAccessibleContext()
0241: .setAccessibleDescription(
0242: descriptionLabel.getText());
0243: jScrollPane1.setViewportView(descriptionArea);
0244: jScrollPane1
0245: .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
0246:
0247: gridBagConstraints = new java.awt.GridBagConstraints();
0248: gridBagConstraints.gridx = 0;
0249: gridBagConstraints.gridy = 2;
0250: gridBagConstraints.gridwidth = 4;
0251: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0252: gridBagConstraints.weightx = 1.0;
0253: gridBagConstraints.weighty = 2.0;
0254: customPanel.add(jScrollPane1, gridBagConstraints);
0255: if (FileType.TAG.equals(fileType)) {
0256:
0257: //remove(fillerPanel);
0258: tldCheckBox = new javax.swing.JCheckBox();
0259: tldCheckBox
0260: .setMnemonic(java.util.ResourceBundle
0261: .getBundle(
0262: "org/netbeans/modules/web/wizards/Bundle")
0263: .getString("A11Y_AddToTLD_mnem")
0264: .charAt(0));
0265: tldCheckBox.setText(org.openide.util.NbBundle
0266: .getMessage(TargetChooserPanelGUI.class,
0267: "OPT_addTagFileToTLD"));
0268: gridBagConstraints = new java.awt.GridBagConstraints();
0269: gridBagConstraints.gridx = 0;
0270: gridBagConstraints.gridy = 3;
0271: gridBagConstraints.gridwidth = 4;
0272: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0273: gridBagConstraints.insets = new java.awt.Insets(6, 0,
0274: 2, 0);
0275: customPanel.add(tldCheckBox, gridBagConstraints);
0276: tldCheckBox
0277: .getAccessibleContext()
0278: .setAccessibleDescription(
0279: java.util.ResourceBundle
0280: .getBundle(
0281: "org/netbeans/modules/web/wizards/Bundle")
0282: .getString("OPT_addToTLD"));
0283: /*
0284: javax.swing.JLabel tldDescriptionLabel = new javax.swing.JLabel();
0285: tldDescriptionLabel.setText(org.openide.util.NbBundle.getMessage(TargetChooserPanelGUI.class, "HINT_tldFile"));
0286: gridBagConstraints = new java.awt.GridBagConstraints();
0287: gridBagConstraints.gridx = 0;
0288: gridBagConstraints.gridy = 4;
0289: gridBagConstraints.gridwidth = 3;
0290: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0291: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0292: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 0);
0293: customPanel.add(tldDescriptionLabel, gridBagConstraints);
0294: */
0295: javax.swing.JLabel tldFileLabel = new javax.swing.JLabel();
0296: tldFileLabel
0297: .setDisplayedMnemonic(java.util.ResourceBundle
0298: .getBundle(
0299: "org/netbeans/modules/web/wizards/Bundle")
0300: .getString("A11Y_TLDName_mnem").charAt(
0301: 0));
0302: tldFileLabel.setText(org.openide.util.NbBundle
0303: .getMessage(TargetChooserPanelGUI.class,
0304: "LBL_tldFile"));
0305: gridBagConstraints = new java.awt.GridBagConstraints();
0306: gridBagConstraints.gridx = 0;
0307: gridBagConstraints.gridy = 5;
0308: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0309: gridBagConstraints.insets = new java.awt.Insets(0, 0,
0310: 0, 0);
0311: customPanel.add(tldFileLabel, gridBagConstraints);
0312:
0313: tldTextField = new javax.swing.JTextField();
0314: tldTextField.setEditable(false);
0315: gridBagConstraints = new java.awt.GridBagConstraints();
0316: gridBagConstraints.gridx = 1;
0317: gridBagConstraints.gridy = 5;
0318: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0319: gridBagConstraints.weightx = 1.0;
0320: gridBagConstraints.gridwidth = 2;
0321: gridBagConstraints.insets = new java.awt.Insets(0, 12,
0322: 0, 0);
0323: customPanel.add(tldTextField, gridBagConstraints);
0324: tldTextField
0325: .getAccessibleContext()
0326: .setAccessibleDescription(
0327: java.util.ResourceBundle
0328: .getBundle(
0329: "org/netbeans/modules/web/wizards/Bundle")
0330: .getString("A11Y_DESC_TLDFile"));
0331: tldFileLabel.setLabelFor(tldTextField);
0332:
0333: browseButton1 = new javax.swing.JButton();
0334: browseButton1
0335: .setMnemonic(java.util.ResourceBundle
0336: .getBundle(
0337: "org/netbeans/modules/web/wizards/Bundle")
0338: .getString("LBL_Browse1_Mnemonic")
0339: .charAt(0));
0340: browseButton1.setText(org.openide.util.NbBundle
0341: .getMessage(TargetChooserPanelGUI.class,
0342: "LBL_Browse"));
0343: browseButton1
0344: .addActionListener(new java.awt.event.ActionListener() {
0345: public void actionPerformed(
0346: java.awt.event.ActionEvent evt) {
0347: browseButton1ActionPerformed(evt);
0348: }
0349: });
0350: browseButton1.setEnabled(false);
0351:
0352: gridBagConstraints = new java.awt.GridBagConstraints();
0353: gridBagConstraints.gridx = 3;
0354: gridBagConstraints.gridy = 5;
0355: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0356: gridBagConstraints.insets = new java.awt.Insets(0, 6,
0357: 0, 0);
0358: customPanel.add(browseButton1, gridBagConstraints);
0359:
0360: browseButton1
0361: .getAccessibleContext()
0362: .setAccessibleDescription(
0363: java.util.ResourceBundle
0364: .getBundle(
0365: "org/netbeans/modules/web/wizards/Bundle")
0366: .getString("LBL_Browse"));
0367: tldCheckBox
0368: .addItemListener(new java.awt.event.ItemListener() {
0369: public void itemStateChanged(
0370: java.awt.event.ItemEvent evt) {
0371: tagNameTextField
0372: .setEditable(tldCheckBox
0373: .isSelected());
0374: browseButton1.setEnabled(tldCheckBox
0375: .isSelected());
0376: if (tldCheckBox.isSelected()) {
0377: if (tagName == null) {
0378: String name = documentNameTextField
0379: .getText().trim();
0380: if (name.length() > 0) {
0381: tagNameTextField
0382: .setText(name);
0383: tagName = name;
0384: }
0385: }
0386: }
0387: wizardPanel.fireChange();
0388: }
0389: });
0390:
0391: javax.swing.JLabel tagNameLabel = new javax.swing.JLabel();
0392: tagNameLabel
0393: .setDisplayedMnemonic(java.util.ResourceBundle
0394: .getBundle(
0395: "org/netbeans/modules/web/wizards/Bundle")
0396: .getString("A11Y_TagName_mnem").charAt(
0397: 0));
0398: tagNameLabel.setText(org.openide.util.NbBundle
0399: .getMessage(TargetChooserPanelGUI.class,
0400: "LBL_tagName"));
0401: gridBagConstraints = new java.awt.GridBagConstraints();
0402: gridBagConstraints.gridx = 0;
0403: gridBagConstraints.gridy = 6;
0404: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0405: gridBagConstraints.insets = new java.awt.Insets(6, 0,
0406: 0, 0);
0407: customPanel.add(tagNameLabel, gridBagConstraints);
0408:
0409: tagNameTextField = new javax.swing.JTextField();
0410: //tagNameTextField.setColumns(10);
0411: tagNameTextField.setEditable(false);
0412: gridBagConstraints = new java.awt.GridBagConstraints();
0413: gridBagConstraints.gridx = 1;
0414: gridBagConstraints.gridy = 6;
0415: gridBagConstraints.weightx = 1.0;
0416: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0417: gridBagConstraints.insets = new java.awt.Insets(6, 12,
0418: 0, 0);
0419: customPanel.add(tagNameTextField, gridBagConstraints);
0420: tagNameTextField
0421: .getAccessibleContext()
0422: .setAccessibleDescription(
0423: java.util.ResourceBundle
0424: .getBundle(
0425: "org/netbeans/modules/web/wizards/Bundle")
0426: .getString("A11Y_DESC_TagName"));
0427: tagNameLabel.setLabelFor(tagNameTextField);
0428: tagNameTextField
0429: .addKeyListener(new java.awt.event.KeyAdapter() {
0430: public void keyReleased(
0431: java.awt.event.KeyEvent evt) {
0432: tagName = tagNameTextField.getText()
0433: .trim();
0434: wizardPanel.fireChange();
0435: }
0436: });
0437:
0438: gridBagConstraints = new java.awt.GridBagConstraints();
0439: gridBagConstraints.gridx = 2;
0440: gridBagConstraints.gridy = 6;
0441: gridBagConstraints.weightx = 1.0;
0442: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0443: customPanel.add(new javax.swing.JPanel(),
0444: gridBagConstraints);
0445: }
0446: } else if (FileType.TAGLIBRARY.equals(fileType)) {
0447: java.awt.GridBagConstraints gridBagConstraints;
0448: uriTextField = new javax.swing.JTextField();
0449: uriTextField.setColumns(20);
0450: prefixTextField = new javax.swing.JTextField();
0451: prefixTextField.setColumns(5);
0452:
0453: uriLabel = new javax.swing.JLabel(NbBundle.getMessage(
0454: TargetChooserPanelGUI.class, "LBL_URI"));
0455: uriLabel.setToolTipText(NbBundle.getMessage(
0456: TargetChooserPanelGUI.class, "TTT_URI"));
0457: uriLabel.setLabelFor(uriTextField);
0458: uriLabel.setDisplayedMnemonic(NbBundle.getMessage(
0459: TargetChooserPanelGUI.class, "A11Y_URI_mnem")
0460: .charAt(0));
0461: uriTextField.getAccessibleContext()
0462: .setAccessibleDescription(
0463: NbBundle.getMessage(
0464: TargetChooserPanelGUI.class,
0465: "A11Y_DESC_URI"));
0466: gridBagConstraints = new java.awt.GridBagConstraints();
0467: gridBagConstraints.gridx = 0;
0468: gridBagConstraints.gridy = 0;
0469: gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
0470: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0471: customPanel.add(uriLabel, gridBagConstraints);
0472:
0473: gridBagConstraints = new java.awt.GridBagConstraints();
0474: gridBagConstraints.gridx = 1;
0475: gridBagConstraints.gridy = 0;
0476: gridBagConstraints.gridwidth = 2;
0477: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0478: gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 0);
0479: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0480: gridBagConstraints.weightx = 1.0;
0481: customPanel.add(uriTextField, gridBagConstraints);
0482:
0483: prefixLabel = new javax.swing.JLabel(NbBundle.getMessage(
0484: TargetChooserPanelGUI.class, "LBL_Prefix"));
0485: prefixLabel.setLabelFor(prefixTextField);
0486: prefixLabel.setToolTipText(NbBundle.getMessage(
0487: TargetChooserPanelGUI.class, "TTT_prefix"));
0488: prefixLabel.setDisplayedMnemonic(NbBundle.getMessage(
0489: TargetChooserPanelGUI.class, "A11Y_Prefix_mnem")
0490: .charAt(0));
0491: prefixTextField.getAccessibleContext()
0492: .setAccessibleDescription(
0493: NbBundle.getMessage(
0494: TargetChooserPanelGUI.class,
0495: "A11Y_DESC_Prefix"));
0496: gridBagConstraints = new java.awt.GridBagConstraints();
0497: gridBagConstraints.gridx = 0;
0498: gridBagConstraints.gridy = 1;
0499: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0500: customPanel.add(prefixLabel, gridBagConstraints);
0501:
0502: gridBagConstraints = new java.awt.GridBagConstraints();
0503: gridBagConstraints.gridx = 1;
0504: gridBagConstraints.gridy = 1;
0505: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0506: gridBagConstraints.weightx = 1.0;
0507: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0508: gridBagConstraints.weightx = 1.0;
0509: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0510: customPanel.add(prefixTextField, gridBagConstraints);
0511:
0512: gridBagConstraints = new java.awt.GridBagConstraints();
0513: gridBagConstraints.gridx = 3;
0514: gridBagConstraints.gridy = 0;
0515: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0516: gridBagConstraints.gridheight = 2;
0517: gridBagConstraints.weightx = 2.0;
0518: customPanel.add(new javax.swing.JPanel(),
0519: gridBagConstraints);
0520:
0521: gridBagConstraints = new java.awt.GridBagConstraints();
0522: gridBagConstraints.gridx = 2;
0523: gridBagConstraints.gridy = 1;
0524: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0525: gridBagConstraints.weightx = 1.0;
0526: customPanel.add(new javax.swing.JPanel(),
0527: gridBagConstraints);
0528:
0529: uriTextField
0530: .addKeyListener(new java.awt.event.KeyAdapter() {
0531: public void keyReleased(
0532: java.awt.event.KeyEvent evt) {
0533: uriWasTyped = true;
0534: wizardPanel.fireChange();
0535: }
0536: });
0537:
0538: prefixTextField
0539: .addKeyListener(new java.awt.event.KeyAdapter() {
0540: public void keyReleased(
0541: java.awt.event.KeyEvent evt) {
0542: prefixWasTyped = true;
0543: wizardPanel.fireChange();
0544: }
0545: });
0546: }
0547:
0548: //initValues( project, null, null );
0549: browseButton.addActionListener(this );
0550: documentNameTextField.getDocument().addDocumentListener(this );
0551: folderTextField.getDocument().addDocumentListener(this );
0552:
0553: setName(NbBundle.getMessage(TargetChooserPanelGUI.class,
0554: "TITLE_name_location"));
0555:
0556: if (fileType.equals(FileType.JSP)) {
0557: nameLabel.setText(NbBundle.getMessage(
0558: TargetChooserPanelGUI.class, "LBL_JspName"));
0559: jspSyntaxButton.setText(NbBundle.getMessage(
0560: TargetChooserPanelGUI.class, "OPT_JspSyntax"));
0561: jspSyntaxButton.getAccessibleContext()
0562: .setAccessibleDescription(
0563: NbBundle.getMessage(
0564: TargetChooserPanelGUI.class,
0565: "DESC_JSP"));
0566: xmlSyntaxButton.setText(NbBundle.getMessage(
0567: TargetChooserPanelGUI.class, "OPT_XmlSyntax"));
0568: xmlSyntaxButton.getAccessibleContext()
0569: .setAccessibleDescription(
0570: NbBundle.getMessage(
0571: TargetChooserPanelGUI.class,
0572: "DESC_JSP_XML"));
0573: segmentBox.setText(NbBundle.getMessage(
0574: TargetChooserPanelGUI.class, "OPT_JspSegment"));
0575: segmentBox.getAccessibleContext().setAccessibleDescription(
0576: NbBundle.getMessage(TargetChooserPanelGUI.class,
0577: "A11Y_DESC_JSP_segment"));
0578: descriptionArea.setText(NbBundle.getMessage(
0579: TargetChooserPanelGUI.class, "DESC_JSP"));
0580: } else if (fileType.equals(FileType.TAG)) {
0581: nameLabel.setText(NbBundle.getMessage(
0582: TargetChooserPanelGUI.class, "LBL_TagFileName"));
0583: jspSyntaxButton.setText(NbBundle.getMessage(
0584: TargetChooserPanelGUI.class, "OPT_TagFileJsp"));
0585: jspSyntaxButton.getAccessibleContext()
0586: .setAccessibleDescription(
0587: NbBundle.getMessage(
0588: TargetChooserPanelGUI.class,
0589: "DESC_TagFile"));
0590: xmlSyntaxButton.setText(NbBundle.getMessage(
0591: TargetChooserPanelGUI.class, "OPT_TagFileXml"));
0592: xmlSyntaxButton.getAccessibleContext()
0593: .setAccessibleDescription(
0594: NbBundle.getMessage(
0595: TargetChooserPanelGUI.class,
0596: "DESC_TagFileXml"));
0597: segmentBox.setText(NbBundle.getMessage(
0598: TargetChooserPanelGUI.class, "OPT_TagFileSegment"));
0599: segmentBox.getAccessibleContext().setAccessibleDescription(
0600: NbBundle.getMessage(TargetChooserPanelGUI.class,
0601: "A11Y_DESC_TagFile_segment"));
0602: descriptionArea.setText(NbBundle.getMessage(
0603: TargetChooserPanelGUI.class, "DESC_TagFile"));
0604: } else if (fileType.equals(FileType.TAGLIBRARY)) {
0605: nameLabel.setText(NbBundle.getMessage(
0606: TargetChooserPanelGUI.class, "LBL_TldName"));
0607: } else if (fileType.equals(FileType.HTML)) {
0608: nameLabel.setText(NbBundle.getMessage(
0609: TargetChooserPanelGUI.class, "LBL_HtmlName"));
0610: //listener to update fileTextField
0611: locationCB
0612: .addActionListener(new java.awt.event.ActionListener() {
0613: public void actionPerformed(
0614: java.awt.event.ActionEvent evt) {
0615: changedUpdate(null);
0616: }
0617: });
0618: } else if (fileType.equals(FileType.CSS)) {
0619: nameLabel.setText(NbBundle.getMessage(
0620: TargetChooserPanelGUI.class, "LBL_CssName"));
0621: //listener to update fileTextField
0622: locationCB
0623: .addActionListener(new java.awt.event.ActionListener() {
0624: public void actionPerformed(
0625: java.awt.event.ActionEvent evt) {
0626: changedUpdate(null);
0627: }
0628: });
0629: } else if (fileType.equals(FileType.XHTML)) {
0630: nameLabel.setText(NbBundle.getMessage(
0631: TargetChooserPanelGUI.class, "LBL_XHtmlName"));
0632: //listener to update fileTextField
0633: locationCB
0634: .addActionListener(new java.awt.event.ActionListener() {
0635: public void actionPerformed(
0636: java.awt.event.ActionEvent evt) {
0637: changedUpdate(null);
0638: }
0639: });
0640: }
0641: }
0642:
0643: WebModule getWebModule() {
0644: return wm;
0645: }
0646:
0647: public void initValues(Project p, FileObject template,
0648: FileObject preselectedFolder) {
0649: projectTextField.setText(ProjectUtils.getInformation(p)
0650: .getDisplayName());
0651: // set the location field and find web module
0652: if (folders != null && folders.length > 0) {
0653: locationCB.setModel(new javax.swing.DefaultComboBoxModel(
0654: getLocations(folders)));
0655: wm = WebModule.getWebModule(folders[0].getRootFolder());
0656: } else
0657: locationCB.setModel(new javax.swing.DefaultComboBoxModel(
0658: new Object[] { new LocationItem(p
0659: .getProjectDirectory()) }));
0660:
0661: // filling the folder field
0662: String target = null;
0663: FileObject docBase = getLocationRoot();
0664: if (preselectedFolder != null
0665: && FileUtil.isParentOf(docBase, preselectedFolder)) {
0666: target = FileUtil.getRelativePath(docBase,
0667: preselectedFolder);
0668: }
0669:
0670: // leave target null for tag files and TLDs outside the web project
0671: if (wm == null) {
0672: if (FileType.TAG.equals(fileType) && target != null
0673: && !target.startsWith(TAG_FILE_IN_JAVALIB_FOLDER)) {
0674: target = null;
0675: }
0676: if (FileType.TAGLIBRARY.equals(fileType) && target != null
0677: && !target.startsWith(TLD_IN_JAVALIB_FOLDER)) {
0678: target = null;
0679: }
0680: }
0681:
0682: // setting target folders for tag files and tlds
0683: if (FileType.TAG.equals(fileType)) {
0684: if (wm != null) {
0685: if (target == null
0686: || !target.startsWith(TAG_FILE_FOLDER))
0687: folderTextField.setText(TAG_FILE_FOLDER + "/"); // NOI18N
0688: else
0689: folderTextField.setText(target == null ? ""
0690: : target); // NOI18N
0691: } else {
0692: if (target == null
0693: || !target
0694: .startsWith(TAG_FILE_IN_JAVALIB_FOLDER))
0695: folderTextField.setText(TAG_FILE_IN_JAVALIB_FOLDER
0696: + "/"); // NOI18N
0697: else
0698: folderTextField.setText(target == null ? ""
0699: : target); // NOI18N
0700: }
0701: } else if (FileType.TAGLIBRARY.equals(fileType)
0702: && target == null) {
0703: if (wm == null)
0704: folderTextField.setText(TLD_IN_JAVALIB_FOLDER + "/"); // NOI18N
0705: else
0706: folderTextField.setText(TLD_FOLDER + "/"); // NOI18N
0707: } else
0708: folderTextField.setText(target == null ? "" : target); // NOI18N
0709: String ext = template == null ? "" : template.getExt(); // NOI18N
0710: expectedExtension = ext.length() == 0 ? "" : "." + ext; // NOI18N
0711: }
0712:
0713: private Object[] getLocations(SourceGroup[] folders) {
0714: Object[] loc = new Object[folders.length];
0715: for (int i = 0; i < folders.length; i++)
0716: loc[i] = new LocationItem(folders[i]);
0717: return loc;
0718: }
0719:
0720: private String getRelativeSourcesFolder() {
0721: String sourceDir = "";
0722: if (wm != null) {
0723: FileObject docBase = wm.getDocumentBase();
0724: FileObject sourcesBase = ((LocationItem) locationCB
0725: .getModel().getSelectedItem()).getFileObject();
0726: sourceDir = FileUtil.getRelativePath(docBase, sourcesBase);
0727:
0728: //just for source roots
0729: if (sourceDir == null)
0730: sourceDir = "";
0731: }
0732: return sourceDir.length() == 0 ? "" : sourceDir + "/";
0733: }
0734:
0735: public String getRelativeTargetFolder() {
0736: return getRelativeSourcesFolder() + getNormalizedFolder();
0737: }
0738:
0739: public String getNormalizedFolder() {
0740: String norm = folderTextField.getText().trim();
0741: if (norm.length() == 0)
0742: return "";
0743: norm = norm.replace('\\', '/');
0744: // removing leading slashes
0745: int i = 0;
0746: while (i < norm.length() && norm.charAt(i) == '/')
0747: i++;
0748: if (i == norm.length())
0749: return ""; //only slashes
0750: norm = norm.substring(i);
0751:
0752: // removing multiple slashes
0753: java.util.StringTokenizer tokens = new java.util.StringTokenizer(
0754: norm, "/");
0755: java.util.List list = new java.util.ArrayList();
0756: StringBuffer buf = new StringBuffer(tokens.nextToken());
0757: while (tokens.hasMoreTokens()) {
0758: String token = tokens.nextToken();
0759: if (token.length() > 0)
0760: buf.append("/" + token);
0761: }
0762: return buf.toString();
0763: }
0764:
0765: public String getTargetFolder() {
0766: return getTargetFile().getPath();
0767: }
0768:
0769: public File getTargetFile() {
0770: String text = getRelativeTargetFolder();
0771:
0772: if (text.length() == 0) {
0773: if (wm == null)
0774: return FileUtil.toFile(getLocationRoot());
0775: else
0776: return FileUtil.toFile(wm.getDocumentBase());
0777: } else {
0778: // XXX have to account for FU.tF returning null
0779: if (wm == null) {
0780: return new File(FileUtil.toFile(getLocationRoot()),
0781: text);
0782: } else {
0783: return new File(FileUtil.toFile(wm.getDocumentBase()),
0784: text);
0785: }
0786: }
0787: }
0788:
0789: public String getTargetName() {
0790:
0791: String text = documentNameTextField.getText().trim();
0792:
0793: if (text.length() == 0) {
0794: return null;
0795: } else {
0796: return text;
0797: }
0798: }
0799:
0800: /*
0801: public void addChangeListener(ChangeListener l) {
0802: listeners.add(l);
0803: }
0804:
0805: public void removeChangeListener(ChangeListener l) {
0806: listeners.remove(l);
0807: }
0808:
0809: private void fireChange() {
0810: ChangeEvent e = new ChangeEvent(this);
0811: Iterator it = listeners.iterator();
0812: while (it.hasNext()) {
0813: ((ChangeListener)it.next()).stateChanged(e);
0814: }
0815: }
0816: */
0817:
0818: /** This method is called from within the constructor to
0819: * initialize the form.
0820: * WARNING: Do NOT modify this code. The content of this method is
0821: * always regenerated by the Form Editor.
0822: */
0823: private void initComponents() {//GEN-BEGIN:initComponents
0824: java.awt.GridBagConstraints gridBagConstraints;
0825:
0826: nameLabel = new javax.swing.JLabel();
0827: documentNameTextField = new javax.swing.JTextField();
0828: projectLabel = new javax.swing.JLabel();
0829: projectTextField = new javax.swing.JTextField();
0830: locationLabel = new javax.swing.JLabel();
0831: locationCB = new javax.swing.JComboBox();
0832: folderLabel = new javax.swing.JLabel();
0833: folderTextField = new javax.swing.JTextField();
0834: browseButton = new javax.swing.JButton();
0835: pathLabel = new javax.swing.JLabel();
0836: fileTextField = new javax.swing.JTextField();
0837: targetSeparator = new javax.swing.JSeparator();
0838: customPanel = new javax.swing.JPanel();
0839: fillerPanel = new javax.swing.JPanel();
0840:
0841: setLayout(new java.awt.GridBagLayout());
0842:
0843: nameLabel.setDisplayedMnemonic(org.openide.util.NbBundle
0844: .getMessage(TargetChooserPanelGUI.class,
0845: "A11Y_FileName_mnem").charAt(0));
0846: nameLabel.setLabelFor(documentNameTextField);
0847: nameLabel.setText(org.openide.util.NbBundle.getMessage(
0848: TargetChooserPanelGUI.class, "LBL_JspName"));
0849: gridBagConstraints = new java.awt.GridBagConstraints();
0850: gridBagConstraints.gridx = 0;
0851: gridBagConstraints.gridy = 0;
0852: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0853: add(nameLabel, gridBagConstraints);
0854:
0855: gridBagConstraints = new java.awt.GridBagConstraints();
0856: gridBagConstraints.gridx = 1;
0857: gridBagConstraints.gridy = 0;
0858: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0859: gridBagConstraints.weightx = 1.0;
0860: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
0861: add(documentNameTextField, gridBagConstraints);
0862: documentNameTextField.getAccessibleContext()
0863: .setAccessibleDescription(
0864: org.openide.util.NbBundle.getMessage(
0865: TargetChooserPanelGUI.class,
0866: "A11Y_DESC_FileName"));
0867:
0868: projectLabel.setDisplayedMnemonic(org.openide.util.NbBundle
0869: .getMessage(TargetChooserPanelGUI.class,
0870: "A11Y_Project_mnem").charAt(0));
0871: projectLabel.setLabelFor(projectTextField);
0872: projectLabel.setText(org.openide.util.NbBundle.getMessage(
0873: TargetChooserPanelGUI.class, "LBL_Project"));
0874: gridBagConstraints = new java.awt.GridBagConstraints();
0875: gridBagConstraints.gridx = 0;
0876: gridBagConstraints.gridy = 1;
0877: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0878: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
0879: add(projectLabel, gridBagConstraints);
0880:
0881: projectTextField.setEditable(false);
0882: gridBagConstraints = new java.awt.GridBagConstraints();
0883: gridBagConstraints.gridx = 1;
0884: gridBagConstraints.gridy = 1;
0885: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0886: gridBagConstraints.weightx = 1.0;
0887: gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
0888: add(projectTextField, gridBagConstraints);
0889: projectTextField.getAccessibleContext()
0890: .setAccessibleDescription(
0891: org.openide.util.NbBundle.getMessage(
0892: TargetChooserPanelGUI.class,
0893: "A11Y_DESC_Project"));
0894:
0895: locationLabel.setDisplayedMnemonic(org.openide.util.NbBundle
0896: .getMessage(TargetChooserPanelGUI.class,
0897: "A11Y_Location_mnem").charAt(0));
0898: locationLabel.setLabelFor(locationCB);
0899: locationLabel.setText(org.openide.util.NbBundle.getMessage(
0900: TargetChooserPanelGUI.class, "LBL_Location"));
0901: gridBagConstraints = new java.awt.GridBagConstraints();
0902: gridBagConstraints.gridx = 0;
0903: gridBagConstraints.gridy = 2;
0904: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0905: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0906: add(locationLabel, gridBagConstraints);
0907:
0908: gridBagConstraints = new java.awt.GridBagConstraints();
0909: gridBagConstraints.gridx = 1;
0910: gridBagConstraints.gridy = 2;
0911: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0912: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
0913: add(locationCB, gridBagConstraints);
0914: locationCB.getAccessibleContext().setAccessibleDescription(
0915: org.openide.util.NbBundle.getMessage(
0916: TargetChooserPanelGUI.class,
0917: "A11Y_DESC_Location"));
0918:
0919: folderLabel.setDisplayedMnemonic(org.openide.util.NbBundle
0920: .getMessage(TargetChooserPanelGUI.class,
0921: "A11Y_Folder_mnem").charAt(0));
0922: folderLabel.setLabelFor(folderTextField);
0923: folderLabel.setText(org.openide.util.NbBundle.getMessage(
0924: TargetChooserPanelGUI.class, "LBL_Folder"));
0925: gridBagConstraints = new java.awt.GridBagConstraints();
0926: gridBagConstraints.gridx = 0;
0927: gridBagConstraints.gridy = 3;
0928: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0929: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0930: add(folderLabel, gridBagConstraints);
0931:
0932: gridBagConstraints = new java.awt.GridBagConstraints();
0933: gridBagConstraints.gridx = 1;
0934: gridBagConstraints.gridy = 3;
0935: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0936: gridBagConstraints.weightx = 1.0;
0937: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
0938: add(folderTextField, gridBagConstraints);
0939: folderTextField.getAccessibleContext()
0940: .setAccessibleDescription(
0941: org.openide.util.NbBundle.getMessage(
0942: TargetChooserPanelGUI.class,
0943: "A11Y_DESC_Folder"));
0944:
0945: browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(
0946: TargetChooserPanelGUI.class, "LBL_Browse_Mnemonic")
0947: .charAt(0));
0948: browseButton.setText(org.openide.util.NbBundle.getMessage(
0949: TargetChooserPanelGUI.class, "LBL_Browse"));
0950: gridBagConstraints = new java.awt.GridBagConstraints();
0951: gridBagConstraints.gridx = 2;
0952: gridBagConstraints.gridy = 3;
0953: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0954: gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
0955: add(browseButton, gridBagConstraints);
0956: browseButton.getAccessibleContext().setAccessibleDescription(
0957: org.openide.util.NbBundle.getMessage(
0958: TargetChooserPanelGUI.class, "ACSD_Browse"));
0959:
0960: pathLabel.setDisplayedMnemonic(org.openide.util.NbBundle
0961: .getMessage(TargetChooserPanelGUI.class,
0962: "A11Y_CreatedFile_mnem").charAt(0));
0963: pathLabel.setLabelFor(fileTextField);
0964: pathLabel.setText(org.openide.util.NbBundle.getMessage(
0965: TargetChooserPanelGUI.class, "LBL_CreatedFile"));
0966: gridBagConstraints = new java.awt.GridBagConstraints();
0967: gridBagConstraints.gridx = 0;
0968: gridBagConstraints.gridy = 4;
0969: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0970: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
0971: add(pathLabel, gridBagConstraints);
0972:
0973: fileTextField.setEditable(false);
0974: gridBagConstraints = new java.awt.GridBagConstraints();
0975: gridBagConstraints.gridx = 1;
0976: gridBagConstraints.gridy = 4;
0977: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0978: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0979: gridBagConstraints.weightx = 1.0;
0980: gridBagConstraints.insets = new java.awt.Insets(12, 6, 0, 0);
0981: add(fileTextField, gridBagConstraints);
0982: fileTextField.getAccessibleContext().setAccessibleDescription(
0983: org.openide.util.NbBundle.getMessage(
0984: TargetChooserPanelGUI.class,
0985: "A11Y_DESC_CreatedFile"));
0986:
0987: gridBagConstraints = new java.awt.GridBagConstraints();
0988: gridBagConstraints.gridx = 0;
0989: gridBagConstraints.gridy = 5;
0990: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0991: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0992: gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
0993: add(targetSeparator, gridBagConstraints);
0994:
0995: customPanel.setLayout(new java.awt.GridBagLayout());
0996:
0997: gridBagConstraints = new java.awt.GridBagConstraints();
0998: gridBagConstraints.gridx = 0;
0999: gridBagConstraints.gridy = 6;
1000: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
1001: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
1002: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
1003: add(customPanel, gridBagConstraints);
1004:
1005: gridBagConstraints = new java.awt.GridBagConstraints();
1006: gridBagConstraints.gridx = 0;
1007: gridBagConstraints.gridy = 7;
1008: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
1009: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
1010: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
1011: gridBagConstraints.weighty = 1.0;
1012: add(fillerPanel, gridBagConstraints);
1013:
1014: }//GEN-END:initComponents
1015:
1016: // Variables declaration - do not modify//GEN-BEGIN:variables
1017: private javax.swing.JButton browseButton;
1018: private javax.swing.JPanel customPanel;
1019: private javax.swing.JTextField documentNameTextField;
1020: private javax.swing.JTextField fileTextField;
1021: private javax.swing.JPanel fillerPanel;
1022: private javax.swing.JLabel folderLabel;
1023: private javax.swing.JTextField folderTextField;
1024: private javax.swing.JComboBox locationCB;
1025: private javax.swing.JLabel locationLabel;
1026: private javax.swing.JLabel nameLabel;
1027: private javax.swing.JLabel pathLabel;
1028: private javax.swing.JLabel projectLabel;
1029: private javax.swing.JTextField projectTextField;
1030: private javax.swing.JSeparator targetSeparator;
1031:
1032: // End of variables declaration//GEN-END:variables
1033:
1034: // ActionListener implementation -------------------------------------------
1035:
1036: public void actionPerformed(java.awt.event.ActionEvent e) {
1037: if (browseButton == e.getSource()) {
1038: FileObject fo = null;
1039: // Show the browse dialog
1040: if (folders != null)
1041: fo = BrowseFolders.showDialog(folders,
1042: org.openide.loaders.DataFolder.class,
1043: folderTextField.getText().replace(
1044: File.separatorChar, '/'));
1045: else {
1046: Sources sources = ProjectUtils.getSources(project);
1047: fo = BrowseFolders.showDialog(sources
1048: .getSourceGroups(Sources.TYPE_GENERIC),
1049: org.openide.loaders.DataFolder.class,
1050: folderTextField.getText().replace(
1051: File.separatorChar, '/'));
1052: }
1053:
1054: if (fo != null && fo.isFolder()) {
1055: FileObject root = ((LocationItem) locationCB
1056: .getSelectedItem()).getFileObject();
1057: folderTextField.setText(FileUtil.getRelativePath(root,
1058: fo));
1059: }
1060:
1061: }
1062: }
1063:
1064: // DocumentListener implementation -----------------------------------------
1065:
1066: public void changedUpdate(javax.swing.event.DocumentEvent e) {
1067:
1068: File rootDirFile = FileUtil.toFile(((LocationItem) locationCB
1069: .getSelectedItem()).getFileObject());
1070: if (rootDirFile != null) {
1071: String documentName = documentNameTextField.getText()
1072: .trim();
1073: if (documentName.length() == 0) {
1074: fileTextField.setText(""); // NOI18N
1075: } else {
1076: File newFile = new File(new File(rootDirFile,
1077: folderTextField.getText().replace('/',
1078: File.separatorChar)), documentName
1079: + expectedExtension
1080: + (isSegment() ? "f" : (isXml() ? "x" : ""))); //NOI18N
1081: fileTextField.setText(newFile.getAbsolutePath());
1082: }
1083: } else {
1084: // Not on disk.
1085: fileTextField.setText(""); // NOI18N
1086: }
1087: if (FileType.TAGLIBRARY.equals(fileType)) {
1088: if (!uriWasTyped) {
1089: String norm = getNormalizedFolder();
1090: //Default value for uri
1091: if (wm == null) {
1092: String pack = getPackageNameInMetaInf();
1093: uriTextField.setText((pack.length() > 0 ? pack
1094: + "." : "")
1095: + documentNameTextField.getText());
1096: } else
1097: uriTextField.setText((norm.length() == 0 ? "" : "/"
1098: + getNormalizedFolder())
1099: + //NOI18N
1100: "/"
1101: + documentNameTextField.getText().trim()); //NOI18N
1102: }
1103: //Default value for prefix
1104: if (!prefixWasTyped)
1105: prefixTextField.setText(documentNameTextField.getText()
1106: .trim().toLowerCase());
1107: }
1108: wizardPanel.fireChange();
1109: }
1110:
1111: private String getPackageNameInMetaInf() {
1112: String pack = getRelativeTargetFolder();
1113: if (pack.startsWith("META-INF")) {//NOI18N
1114: pack = pack.substring(8);
1115: if (pack.length() == 0)
1116: return "";
1117: if (pack.startsWith("/"))
1118: pack = pack.substring(1);//NOI18N
1119: }
1120: if (pack.length() == 0)
1121: return "";//NOI18N
1122: pack = pack.replace('/', '.');
1123: return pack;
1124: }
1125:
1126: /** specific for JSP/TAG wizards
1127: */
1128: private void checkBoxChanged(java.awt.event.ItemEvent evt) {
1129: // TODO add your handling code here:
1130: if (fileType.equals(FileType.JSP)) {
1131: if (isSegment()) {
1132: if (isXml()) {
1133: descriptionArea.setText(NbBundle.getMessage(
1134: TargetChooserPanelGUI.class,
1135: "DESC_segment_XML"));
1136: } else {
1137: descriptionArea.setText(NbBundle
1138: .getMessage(TargetChooserPanelGUI.class,
1139: "DESC_segment"));
1140: }
1141: String createdFile = fileTextField.getText();
1142: if (createdFile.endsWith("jspx")) //NOI18N
1143: fileTextField.setText(createdFile.substring(0,
1144: createdFile.length() - 1)
1145: + "f"); //NOI18N
1146: else if (createdFile.endsWith("jsp")) //NOI18N
1147: fileTextField.setText(createdFile + "f"); //NOI18N
1148: } else {
1149: String createdFile = fileTextField.getText();
1150: if (isXml()) {
1151: descriptionArea.setText(NbBundle
1152: .getMessage(TargetChooserPanelGUI.class,
1153: "DESC_JSP_XML"));
1154: if (createdFile.endsWith("jspf")) { //NOI18N
1155: fileTextField.setText(createdFile.substring(0,
1156: createdFile.length() - 1)
1157: + "x"); //NOI18N
1158: } else if (createdFile.endsWith("jsp")) { //NOI18N
1159: fileTextField.setText(createdFile + "x"); //NOI18N
1160: }
1161: } else {
1162: descriptionArea.setText(NbBundle.getMessage(
1163: TargetChooserPanelGUI.class, "DESC_JSP"));
1164: if (createdFile.endsWith("jspf")
1165: || createdFile.endsWith("jspx")) { //NOI18N
1166: fileTextField.setText(createdFile.substring(0,
1167: createdFile.length() - 1)); //NOI18N
1168: }
1169: }
1170: }
1171: } else if (fileType.equals(FileType.TAG)) {
1172: if (isSegment()) {
1173: if (isXml()) {
1174: descriptionArea.setText(NbBundle.getMessage(
1175: TargetChooserPanelGUI.class,
1176: "DESC_TagFileSegmentXml"));
1177: } else {
1178: descriptionArea.setText(NbBundle.getMessage(
1179: TargetChooserPanelGUI.class,
1180: "DESC_TagFileSegment"));
1181: }
1182: String createdFile = fileTextField.getText();
1183: if (createdFile.endsWith("tagx")) //NOI18N
1184: fileTextField.setText(createdFile.substring(0,
1185: createdFile.length() - 1)
1186: + "f"); //NOI18N
1187: else if (createdFile.endsWith("tag")) //NOI18N
1188: fileTextField.setText(createdFile + "f"); //NOI18N
1189: } else {
1190: String createdFile = fileTextField.getText();
1191: if (isXml()) {
1192: descriptionArea.setText(NbBundle.getMessage(
1193: TargetChooserPanelGUI.class,
1194: "DESC_TagFileXml"));
1195: if (createdFile.endsWith("tagf")) { //NOI18N
1196: fileTextField.setText(createdFile.substring(0,
1197: createdFile.length() - 1)
1198: + "x"); //NOI18N
1199: } else if (createdFile.endsWith("tag")) { //NOI18N
1200: fileTextField.setText(createdFile + "x"); //NOI18N
1201: }
1202: } else {
1203: descriptionArea.setText(NbBundle
1204: .getMessage(TargetChooserPanelGUI.class,
1205: "DESC_TagFile"));
1206: if (createdFile.endsWith("tagf")
1207: || createdFile.endsWith("tagx")) { //NOI18N
1208: fileTextField.setText(createdFile.substring(0,
1209: createdFile.length() - 1)); //NOI18N
1210: }
1211: }
1212: }
1213: }
1214: wizardPanel.fireChange();
1215: }
1216:
1217: public void insertUpdate(javax.swing.event.DocumentEvent e) {
1218: changedUpdate(e);
1219: }
1220:
1221: public void removeUpdate(javax.swing.event.DocumentEvent e) {
1222: changedUpdate(e);
1223: }
1224:
1225: boolean isXml() {
1226: if (xmlSyntaxButton == null)
1227: return false;
1228: else
1229: return xmlSyntaxButton.isSelected();
1230: }
1231:
1232: boolean isSegment() {
1233: if (segmentBox == null)
1234: return false;
1235: else
1236: return segmentBox.isSelected();
1237: }
1238:
1239: String getUri() {
1240: if (uriTextField == null)
1241: return "";
1242: else
1243: return uriTextField.getText();
1244: }
1245:
1246: String getPrefix() {
1247: if (prefixTextField == null)
1248: return "";
1249: else
1250: return prefixTextField.getText();
1251: }
1252:
1253: String getErrorMessage() {
1254: if (FileType.JSP.equals(fileType)) {
1255: if (isSegment()
1256: && !getNormalizedFolder()
1257: .startsWith("WEB-INF/jspf")) //NOI18N
1258: return NbBundle.getMessage(TargetChooserPanelGUI.class,
1259: "NOTE_segment");
1260: } else if (FileType.TAG.equals(fileType)) {
1261: tagFileValid = true;
1262: if (wm != null) {
1263: if (!getNormalizedFolder().startsWith(TAG_FILE_FOLDER)) {
1264: tagFileValid = false;
1265: return NbBundle.getMessage(
1266: TargetChooserPanelGUI.class, "MSG_TagFile");
1267: }
1268: } else {
1269: if (!getNormalizedFolder().startsWith(
1270: TAG_FILE_IN_JAVALIB_FOLDER)) {
1271: tagFileValid = false;
1272: return NbBundle.getMessage(
1273: TargetChooserPanelGUI.class,
1274: "MSG_TagFileInJavalib");
1275: }
1276: }
1277: } else if (FileType.TAGLIBRARY.equals(fileType)) {
1278: if (wm == null) {
1279: if (!getNormalizedFolder().startsWith(
1280: TLD_IN_JAVALIB_FOLDER))
1281: return NbBundle.getMessage(
1282: TargetChooserPanelGUI.class,
1283: "NOTE_TLDInJavalib");
1284: } else if (!getNormalizedFolder().startsWith("WEB-INF")) //NOI18N
1285: return NbBundle.getMessage(TargetChooserPanelGUI.class,
1286: "NOTE_TLDInWeb");
1287: if (getUri().length() == 0) //NOI18N
1288: return NbBundle.getMessage(TargetChooserPanelGUI.class,
1289: "MSG_missingUri");
1290: if (getPrefix().length() == 0) //NOI18N
1291: return NbBundle.getMessage(TargetChooserPanelGUI.class,
1292: "MSG_missingPrefix");
1293: }
1294: return null;
1295: }
1296:
1297: boolean isPanelValid() {
1298: if (FileType.TAGLIBRARY.equals(fileType)
1299: && (getUri().length() == 0 || getPrefix().length() == 0))
1300: return false;
1301: if (FileType.TAG.equals(fileType) && !tagFileValid)
1302: return false;
1303: return true;
1304: }
1305:
1306: FileObject getLocationRoot() {
1307: return ((LocationItem) locationCB.getModel().getSelectedItem())
1308: .getFileObject();
1309: }
1310:
1311: public static class LocationItem {
1312: FileObject fo;
1313: SourceGroup group;
1314:
1315: public LocationItem(FileObject fo) {
1316: this .fo = fo;
1317: }
1318:
1319: public LocationItem(SourceGroup group) {
1320: this .fo = group.getRootFolder();
1321: this .group = group;
1322: }
1323:
1324: public FileObject getFileObject() {
1325: return fo;
1326: }
1327:
1328: public String toString() {
1329: return (group == null ? fo.getName() : group
1330: .getDisplayName());
1331: }
1332: }
1333:
1334: private void browseButton1ActionPerformed(
1335: java.awt.event.ActionEvent evt) {
1336: // TODO add your handling code here:
1337: org.openide.filesystems.FileObject fo = null;
1338: // Show the browse dialog
1339: if (folders != null)
1340: fo = BrowseFolders.showDialog(folders, TLDDataObject.class,
1341: folderTextField.getText().replace(
1342: File.separatorChar, '/'));
1343: else {
1344: Sources sources = ProjectUtils.getSources(project);
1345: fo = BrowseFolders.showDialog(sources
1346: .getSourceGroups(Sources.TYPE_GENERIC),
1347: org.openide.loaders.DataFolder.class,
1348: folderTextField.getText().replace(
1349: File.separatorChar, '/'));
1350: }
1351:
1352: if (fo != null) {
1353: tldFo = fo;
1354: FileObject targetFolder = Templates
1355: .getTargetFolder(wizardPanel.getTemplateWizard());
1356: WebModule wm = (targetFolder == null ? null : WebModule
1357: .getWebModule(targetFolder));
1358: tldTextField.setText(FileUtil.getRelativePath(
1359: (wm == null ? project.getProjectDirectory() : wm
1360: .getDocumentBase()), fo));
1361: try {
1362: java.io.InputStream is = tldFo.getInputStream();
1363: // get existing tag names for testing duplicity
1364: tagValues = Util.getTagValues(is, new String[] { "tag",
1365: "tag-file" }, "name"); //NOI18N
1366: is.close();
1367: } catch (java.io.IOException ex) {
1368: } catch (org.xml.sax.SAXException ex) {
1369: }
1370: wizardPanel.fireChange();
1371: }
1372: }
1373:
1374: boolean isTldCheckBoxSelected() {
1375: return tldCheckBox.isSelected();
1376: }
1377:
1378: String getTagName() {
1379: return tagName;
1380: }
1381:
1382: FileObject getTldFileObject() {
1383: return tldFo;
1384: }
1385:
1386: static boolean isTagNameEmpty(String name) {
1387: if (name == null) {
1388: return true;
1389: }
1390: return "".equals(name); // NOI18N
1391: }
1392:
1393: static boolean isValidTagName(String name) {
1394: if (name == null)
1395: return false;
1396: return org.apache.xerces.util.XMLChar.isValidNCName(name);
1397: }
1398:
1399: boolean tagNameExists(String name) {
1400: if (tagValues != null && tagValues.contains(name))
1401: return true;
1402: else
1403: return false;
1404: }
1405:
1406: public String getCreatedFilePath() {
1407: return fileTextField.getText();
1408: }
1409:
1410: }
|