001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.compapp.test.ui.wizards;
043:
044: import javax.swing.JPanel;
045: import javax.swing.JTextField;
046: import javax.swing.event.DocumentEvent;
047: import javax.swing.event.DocumentListener;
048: import org.openide.WizardDescriptor;
049: import org.openide.util.NbBundle;
050:
051: public class NewTestcaseNameVisualPanel extends JPanel implements
052: DocumentListener {
053:
054: private NewTestcaseNameWizardPanel panel;
055:
056: /** Creates new form NewTestcaseNameVisualPanel */
057: public NewTestcaseNameVisualPanel(NewTestcaseNameWizardPanel panel) {
058: initComponents();
059: this .panel = panel;
060: // Register listener on the textFields to make the automatic updates
061: mNameTf.getDocument().addDocumentListener(this );
062: }
063:
064: /** This method is called from within the constructor to
065: * initialize the form.
066: * WARNING: Do NOT modify this code. The content of this method is
067: * always regenerated by the Form Editor.
068: */
069: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
070: private void initComponents() {
071:
072: mNameLbl = new javax.swing.JLabel();
073: mNameTf = new javax.swing.JTextField();
074:
075: mNameLbl.setLabelFor(mNameTf);
076: org.openide.awt.Mnemonics.setLocalizedText(mNameLbl,
077: org.openide.util.NbBundle.getMessage(
078: NewTestcaseNameVisualPanel.class,
079: "LBL_Testcase_Name")); // NOI18N
080:
081: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
082: this );
083: this .setLayout(layout);
084: layout
085: .setHorizontalGroup(layout
086: .createParallelGroup(
087: org.jdesktop.layout.GroupLayout.LEADING)
088: .add(
089: layout
090: .createSequentialGroup()
091: .add(mNameLbl)
092: .addPreferredGap(
093: org.jdesktop.layout.LayoutStyle.RELATED)
094: .add(
095: mNameTf,
096: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
097: 304, Short.MAX_VALUE)
098: .addContainerGap()));
099: layout
100: .setVerticalGroup(layout
101: .createParallelGroup(
102: org.jdesktop.layout.GroupLayout.LEADING)
103: .add(
104: layout
105: .createSequentialGroup()
106: .add(
107: layout
108: .createParallelGroup(
109: org.jdesktop.layout.GroupLayout.BASELINE)
110: .add(mNameLbl)
111: .add(
112: mNameTf,
113: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
114: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
115: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
116: .addContainerGap(281,
117: Short.MAX_VALUE)));
118:
119: mNameLbl.getAccessibleContext().setAccessibleDescription(
120: org.openide.util.NbBundle.getMessage(
121: NewTestcaseNameVisualPanel.class,
122: "ACS_TEST_CASE_NAME_LABEL")); // NOI18N
123:
124: getAccessibleContext().setAccessibleDescription(
125: org.openide.util.NbBundle.getMessage(
126: NewTestcaseNameVisualPanel.class,
127: "ACS_NewTestcaseNameVisualPanel_A11YDesc")); // NOI18N
128: }// </editor-fold>//GEN-END:initComponents
129:
130: // Variables declaration - do not modify//GEN-BEGIN:variables
131: private javax.swing.JLabel mNameLbl;
132: private javax.swing.JTextField mNameTf;
133:
134: // End of variables declaration//GEN-END:variables
135:
136: public JTextField getTestcaseNameTf() {
137: return mNameTf;
138: }
139:
140: public String getTestcaseName() {
141: return mNameTf.getText();
142: }
143:
144: public String getName() {
145: return NbBundle.getMessage(NewTestcaseNameVisualPanel.class,
146: "LBL_Enter_the_testcase_name"); //NOI18N
147: }
148:
149: // Implementation of DocumentListener --------------------------------------
150: public void changedUpdate(DocumentEvent e) {
151: updateTexts(e);
152: }
153:
154: public void insertUpdate(DocumentEvent e) {
155: updateTexts(e);
156: }
157:
158: public void removeUpdate(DocumentEvent e) {
159: updateTexts(e);
160: }
161:
162: // End if implementation of DocumentListener -------------------------------
163:
164: boolean valid(WizardDescriptor wizardDescriptor) {
165: if (mNameTf.getText().length() == 0) {
166: wizardDescriptor.putProperty("WizardPanel_errorMessage",
167: NbBundle.getMessage(
168: NewTestcaseNameVisualPanel.class,
169: "LBL_Testcase_name_cannot_be_empty")); //NOI18N
170: return false; // Display name not specified
171: }
172:
173: // 2. no existing testcase under Test node has name: mComponent.getTestcaseName()
174: if (panel.mTestDir.getFileObject(mNameTf.getText()) != null) {
175: wizardDescriptor
176: .putProperty(
177: "WizardPanel_errorMessage",
178: NbBundle
179: .getMessage(
180: NewTestcaseNameVisualPanel.class,
181: "LBL_Name_is_already_used_by_another_testcase")); //NOI18N
182: return false;
183: }
184:
185: wizardDescriptor.putProperty("WizardPanel_errorMessage", ""); //NOI18N
186: return true;
187: }
188:
189: /** Handles changes in the project name and project directory
190: */
191: private void updateTexts(DocumentEvent e) {
192: panel.fireChangeEvent(); // Notify that the panel changed
193: }
194: }
|