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.xml.wsdl.ui.view.treeeditor.pastetype;
043:
044: import java.util.Set;
045: import javax.swing.event.DocumentEvent;
046: import javax.swing.event.DocumentListener;
047: import org.netbeans.api.project.Project;
048: import org.openide.DialogDescriptor;
049: import org.openide.filesystems.FileObject;
050: import org.openide.util.NbBundle;
051:
052: /**
053: *
054: * @author skini
055: */
056: public class DnDImportPanel extends javax.swing.JPanel {
057:
058: private DialogDescriptor dd;
059: private Set existingPrefixes;
060: private DocumentListener listener;
061:
062: /** Creates new form DnDImportPanel */
063: public DnDImportPanel() {
064: initComponents();
065:
066: listener = new DocumentListener() {
067:
068: public void insertUpdate(DocumentEvent e) {
069: validatePrefix();
070: }
071:
072: public void removeUpdate(DocumentEvent e) {
073: validatePrefix();
074: }
075:
076: public void changedUpdate(DocumentEvent e) {
077: validatePrefix();
078: }
079:
080: void validatePrefix() {
081: String errorMessage = null;
082: String prefix = prefixTextField.getText();
083: if (prefix == null
084: || prefix.trim().length() == 0
085: || !org.netbeans.modules.xml.xam.dom.Utils
086: .isValidNCName(prefix)) {
087: errorMessage = NbBundle.getMessage(
088: DnDImportPanel.class,
089: "ERRMSG_InvalidPrefix", prefix);
090: }
091:
092: if (existingPrefixes != null
093: && existingPrefixes.contains(prefix)) {
094: errorMessage = NbBundle.getMessage(
095: DnDImportPanel.class,
096: "ERRMSG_PrefixAlreadyExists", prefix);
097: }
098: if (errorMessage != null) {
099: errorWarningMessagePanel
100: .setErrorMessage(errorMessage);
101: } else {
102: errorWarningMessagePanel.setMessage(null);
103: }
104: dd.setValid(errorMessage == null);
105: }
106: };
107: prefixTextField.getDocument().addDocumentListener(listener);
108: }
109:
110: String getPrefix() {
111: return prefixTextField.getText();
112: }
113:
114: void setDialogDescriptor(DialogDescriptor descriptor) {
115: dd = descriptor;
116: }
117:
118: void setFileName(FileObject primaryFile) {
119: fileTextField.setText(primaryFile.getNameExt());
120: }
121:
122: void setNamespace(String impNamespace) {
123: namespaceTextField.setText(impNamespace);
124: }
125:
126: void setPrefix(String prefix) {
127: prefixTextField.getDocument().removeDocumentListener(listener);
128: prefixTextField.setText(prefix);
129: prefixTextField.getDocument().addDocumentListener(listener);
130: }
131:
132: void setPrefixes(Set prefixes) {
133: existingPrefixes = prefixes;
134: }
135:
136: void setProject(Project project) {
137: projectNameTextField.setText(project.getProjectDirectory()
138: .getName());
139: }
140:
141: /** This method is called from within the constructor to
142: * initialize the form.
143: * WARNING: Do NOT modify this code. The content of this method is
144: * always regenerated by the Form Editor.
145: */
146: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
147: private void initComponents() {
148:
149: fileNameLabel = new javax.swing.JLabel();
150: fileTextField = new javax.swing.JTextField();
151: projectNameLabel = new javax.swing.JLabel();
152: projectNameTextField = new javax.swing.JTextField();
153: namespaceLabel = new javax.swing.JLabel();
154: namespaceTextField = new javax.swing.JTextField();
155: prefixLabel = new javax.swing.JLabel();
156: prefixTextField = new javax.swing.JTextField();
157: errorWarningMessagePanel = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel();
158:
159: setName("Form"); // NOI18N
160:
161: fileNameLabel.setLabelFor(fileTextField);
162: org.openide.awt.Mnemonics.setLocalizedText(fileNameLabel,
163: org.openide.util.NbBundle.getMessage(
164: DnDImportPanel.class,
165: "DnDImportPanel.fileNameLabel.text")); // NOI18N
166: fileNameLabel.setToolTipText(org.openide.util.NbBundle
167: .getMessage(DnDImportPanel.class,
168: "DnDImportPanel.fileNameLabel.toolTipText")); // NOI18N
169: fileNameLabel.setName("fileNameLabel"); // NOI18N
170:
171: fileTextField.setEditable(false);
172: fileTextField.setName("fileTextField"); // NOI18N
173:
174: projectNameLabel.setLabelFor(projectNameTextField);
175: org.openide.awt.Mnemonics.setLocalizedText(projectNameLabel,
176: org.openide.util.NbBundle.getMessage(
177: DnDImportPanel.class,
178: "DnDImportPanel.projectNameLabel.text")); // NOI18N
179: projectNameLabel.setToolTipText(org.openide.util.NbBundle
180: .getMessage(DnDImportPanel.class,
181: "DnDImportPanel.projectNameLabel.toolTipText")); // NOI18N
182: projectNameLabel.setName("projectNameLabel"); // NOI18N
183:
184: projectNameTextField.setEditable(false);
185: projectNameTextField.setName("projectNameTextField"); // NOI18N
186:
187: namespaceLabel.setLabelFor(namespaceTextField);
188: org.openide.awt.Mnemonics.setLocalizedText(namespaceLabel,
189: org.openide.util.NbBundle.getMessage(
190: DnDImportPanel.class,
191: "DnDImportPanel.namespaceLabel.text")); // NOI18N
192: namespaceLabel.setToolTipText(org.openide.util.NbBundle
193: .getMessage(DnDImportPanel.class,
194: "DnDImportPanel.namespaceLabel.toolTipText")); // NOI18N
195: namespaceLabel.setName("namespaceLabel"); // NOI18N
196:
197: namespaceTextField.setEditable(false);
198: namespaceTextField.setName("namespaceTextField"); // NOI18N
199:
200: prefixLabel.setLabelFor(prefixTextField);
201: org.openide.awt.Mnemonics.setLocalizedText(prefixLabel,
202: org.openide.util.NbBundle.getMessage(
203: DnDImportPanel.class,
204: "DnDImportPanel.prefixLabel.text")); // NOI18N
205: prefixLabel.setToolTipText(org.openide.util.NbBundle
206: .getMessage(DnDImportPanel.class,
207: "DnDImportPanel.prefixLabel.toolTipText")); // NOI18N
208: prefixLabel.setName("prefixLabel"); // NOI18N
209:
210: prefixTextField.setName("prefixTextField"); // NOI18N
211:
212: errorWarningMessagePanel.setName("errorWarningMessagePanel"); // NOI18N
213:
214: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
215: this );
216: this .setLayout(layout);
217: layout
218: .setHorizontalGroup(layout
219: .createParallelGroup(
220: org.jdesktop.layout.GroupLayout.LEADING)
221: .add(
222: layout
223: .createSequentialGroup()
224: .addContainerGap()
225: .add(
226: layout
227: .createParallelGroup(
228: org.jdesktop.layout.GroupLayout.LEADING)
229: .add(
230: errorWarningMessagePanel,
231: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
232: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
233: Short.MAX_VALUE)
234: .add(
235: layout
236: .createSequentialGroup()
237: .add(
238: layout
239: .createParallelGroup(
240: org.jdesktop.layout.GroupLayout.LEADING,
241: false)
242: .add(
243: projectNameLabel,
244: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
245: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
246: Short.MAX_VALUE)
247: .add(
248: prefixLabel,
249: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
250: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
251: Short.MAX_VALUE)
252: .add(
253: namespaceLabel,
254: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
255: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
256: Short.MAX_VALUE)
257: .add(
258: fileNameLabel,
259: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
260: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
261: Short.MAX_VALUE))
262: .addPreferredGap(
263: org.jdesktop.layout.LayoutStyle.RELATED)
264: .add(
265: layout
266: .createParallelGroup(
267: org.jdesktop.layout.GroupLayout.TRAILING)
268: .add(
269: projectNameTextField,
270: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
271: 240,
272: Short.MAX_VALUE)
273: .add(
274: fileTextField,
275: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
276: 240,
277: Short.MAX_VALUE)
278: .add(
279: org.jdesktop.layout.GroupLayout.LEADING,
280: prefixTextField,
281: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
282: 240,
283: Short.MAX_VALUE)
284: .add(
285: org.jdesktop.layout.GroupLayout.LEADING,
286: namespaceTextField,
287: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
288: 240,
289: Short.MAX_VALUE))))
290: .addContainerGap()));
291: layout
292: .setVerticalGroup(layout
293: .createParallelGroup(
294: org.jdesktop.layout.GroupLayout.LEADING)
295: .add(
296: layout
297: .createSequentialGroup()
298: .addContainerGap()
299: .add(
300: layout
301: .createParallelGroup(
302: org.jdesktop.layout.GroupLayout.BASELINE)
303: .add(
304: fileNameLabel)
305: .add(
306: fileTextField,
307: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
308: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
309: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
310: .addPreferredGap(
311: org.jdesktop.layout.LayoutStyle.RELATED)
312: .add(
313: layout
314: .createParallelGroup(
315: org.jdesktop.layout.GroupLayout.BASELINE)
316: .add(
317: projectNameLabel)
318: .add(
319: projectNameTextField,
320: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
321: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
322: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
323: .addPreferredGap(
324: org.jdesktop.layout.LayoutStyle.RELATED)
325: .add(
326: layout
327: .createParallelGroup(
328: org.jdesktop.layout.GroupLayout.BASELINE)
329: .add(
330: namespaceLabel)
331: .add(
332: namespaceTextField,
333: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
334: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
335: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
336: .addPreferredGap(
337: org.jdesktop.layout.LayoutStyle.RELATED)
338: .add(
339: layout
340: .createParallelGroup(
341: org.jdesktop.layout.GroupLayout.BASELINE)
342: .add(
343: prefixTextField,
344: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
345: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
346: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
347: .add(
348: prefixLabel))
349: .add(18, 18, 18)
350: .add(
351: errorWarningMessagePanel,
352: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
353: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
354: Short.MAX_VALUE)
355: .addContainerGap()));
356:
357: fileTextField
358: .getAccessibleContext()
359: .setAccessibleName(
360: org.openide.util.NbBundle
361: .getMessage(DnDImportPanel.class,
362: "DnDImportPanel.fileTextField.AccessibleContext.accessibleName")); // NOI18N
363: fileTextField
364: .getAccessibleContext()
365: .setAccessibleDescription(
366: org.openide.util.NbBundle
367: .getMessage(DnDImportPanel.class,
368: "DnDImportPanel.fileTextField.AccessibleContext.accessibleDescription")); // NOI18N
369: projectNameTextField
370: .getAccessibleContext()
371: .setAccessibleName(
372: org.openide.util.NbBundle
373: .getMessage(DnDImportPanel.class,
374: "DnDImportPanel.projectNameTextField.AccessibleContext.accessibleName")); // NOI18N
375: projectNameTextField
376: .getAccessibleContext()
377: .setAccessibleDescription(
378: org.openide.util.NbBundle
379: .getMessage(DnDImportPanel.class,
380: "DnDImportPanel.projectNameTextField.AccessibleContext.accessibleDescription")); // NOI18N
381: namespaceTextField
382: .getAccessibleContext()
383: .setAccessibleName(
384: org.openide.util.NbBundle
385: .getMessage(DnDImportPanel.class,
386: "DnDImportPanel.namespaceTextField.AccessibleContext.accessibleName")); // NOI18N
387: namespaceTextField
388: .getAccessibleContext()
389: .setAccessibleDescription(
390: org.openide.util.NbBundle
391: .getMessage(DnDImportPanel.class,
392: "DnDImportPanel.namespaceTextField.AccessibleContext.accessibleDescription")); // NOI18N
393: prefixTextField
394: .getAccessibleContext()
395: .setAccessibleName(
396: org.openide.util.NbBundle
397: .getMessage(DnDImportPanel.class,
398: "DnDImportPanel.prefixTextField.AccessibleContext.accessibleName")); // NOI18N
399: prefixTextField
400: .getAccessibleContext()
401: .setAccessibleDescription(
402: org.openide.util.NbBundle
403: .getMessage(DnDImportPanel.class,
404: "DnDImportPanel.prefixTextField.AccessibleContext.accessibleDescription")); // NOI18N
405: }// </editor-fold>//GEN-END:initComponents
406:
407: // Variables declaration - do not modify//GEN-BEGIN:variables
408: private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel errorWarningMessagePanel;
409: private javax.swing.JLabel fileNameLabel;
410: private javax.swing.JTextField fileTextField;
411: private javax.swing.JLabel namespaceLabel;
412: private javax.swing.JTextField namespaceTextField;
413: private javax.swing.JLabel prefixLabel;
414: private javax.swing.JTextField prefixTextField;
415: private javax.swing.JLabel projectNameLabel;
416: private javax.swing.JTextField projectNameTextField;
417: // End of variables declaration//GEN-END:variables
418: }
|