KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > AttributePanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * AttributePanel.java
22  *
23  * Created on June 9, 2006, 4:03 PM
24  */

25
26 package org.netbeans.modules.xml.wsdl.ui.view;
27
28 import java.awt.BorderLayout JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 import javax.swing.DefaultComboBoxModel JavaDoc;
32 import javax.swing.JComboBox JavaDoc;
33 import javax.swing.JTextField JavaDoc;
34 import javax.swing.event.DocumentEvent JavaDoc;
35 import javax.swing.event.DocumentListener JavaDoc;
36 import javax.xml.namespace.QName JavaDoc;
37
38 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
39 import org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel;
40 import org.openide.util.NbBundle;
41
42 /**
43  *
44  * @author skini
45  */

46 public class AttributePanel extends javax.swing.JPanel JavaDoc {
47     
48     /**
49      *
50      */

51     private static final long serialVersionUID = 1680305470367882467L;
52     /**
53      * Creates new form AttributePanel
54      */

55     public AttributePanel(boolean isNamespaceRequired, Vector JavaDoc namespaces, WSDLComponent component) {
56         this.isNamespaceRequired =isNamespaceRequired;
57         this.mNamespaces = namespaces;
58         this.mComponent = component;
59         initComponents();
60         initCommonMessagePanel();
61     }
62     
63     private void initCommonMessagePanel() {
64         mErrorPanel = new CommonMessagePanel();
65         mCommonMsgPanel.add(mErrorPanel, BorderLayout.CENTER);
66         DocumentListener JavaDoc listener = new AttributeDocumentListener();
67         mAttrNameTextField.getDocument().addDocumentListener(listener);
68         ((JTextField JavaDoc)mAttrNamespaceComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(listener);
69     }
70     
71     /** This method is called from within the constructor to
72      * initialize the form.
73      * WARNING: Do NOT modify this code. The content of this method is
74      * always regenerated by the Form Editor.
75      */

76     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
77
private void initComponents() {
78         mAttrNameLabel = new javax.swing.JLabel JavaDoc();
79         mAttrNamespaceLabel = new javax.swing.JLabel JavaDoc();
80         mAttrNameTextField = new javax.swing.JTextField JavaDoc();
81         mAttrNamespaceComboBox = new javax.swing.JComboBox JavaDoc();
82         mCommonMsgPanel = new javax.swing.JPanel JavaDoc();
83
84         mAttrNameLabel.setLabelFor(mAttrNameTextField);
85         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/wsdl/ui/view/Bundle"); // NOI18N
86
org.openide.awt.Mnemonics.setLocalizedText(mAttrNameLabel, bundle.getString("LBL_AttributePanel_NAME")); // NOI18N
87
mAttrNameLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNameLabel.toolTipText")); // NOI18N
88

89         mAttrNamespaceLabel.setLabelFor(mAttrNamespaceComboBox);
90         org.openide.awt.Mnemonics.setLocalizedText(mAttrNamespaceLabel, bundle.getString("LBL_AttributePanel_NAMESPACE")); // NOI18N
91
mAttrNamespaceLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNamespaceLabel.toolTipText")); // NOI18N
92

93         mAttrNameTextField.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNameTextField.toolTipText")); // NOI18N
94

95         mAttrNamespaceComboBox.setEditable(true);
96         mAttrNamespaceComboBox.setModel(new DefaultComboBoxModel JavaDoc(mNamespaces));
97         mAttrNamespaceComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNamespaceComboBox.toolTipText")); // NOI18N
98

99         mCommonMsgPanel.setLayout(new java.awt.BorderLayout JavaDoc());
100
101         mCommonMsgPanel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mCommonMsgPanel.toolTipText")); // NOI18N
102
mCommonMsgPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mCommonMsgPanel.toolTipText")); // NOI18N
103

104         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
105         this.setLayout(layout);
106         layout.setHorizontalGroup(
107             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
108             .add(layout.createSequentialGroup()
109                 .addContainerGap()
110                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
111                     .add(org.jdesktop.layout.GroupLayout.TRAILING, mCommonMsgPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
112                     .add(layout.createSequentialGroup()
113                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
114                             .add(mAttrNameLabel)
115                             .add(mAttrNamespaceLabel))
116                         .add(16, 16, 16)
117                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
118                             .add(mAttrNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
119                             .add(mAttrNamespaceComboBox, 0, 305, Short.MAX_VALUE))))
120                 .addContainerGap())
121         );
122         layout.setVerticalGroup(
123             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
124             .add(layout.createSequentialGroup()
125                 .addContainerGap()
126                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
127                     .add(mAttrNameLabel)
128                     .add(mAttrNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
129                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
130                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
131                     .add(mAttrNamespaceLabel)
132                     .add(mAttrNamespaceComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
133                 .add(10, 10, 10)
134                 .add(mCommonMsgPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE))
135         );
136     }// </editor-fold>//GEN-END:initComponents
137

138     public String JavaDoc getAttributeNamespace() {
139         JTextField JavaDoc editor = (JTextField JavaDoc) this.mAttrNamespaceComboBox.getEditor().getEditorComponent();
140         return editor.getText();
141     }
142     
143     public String JavaDoc getAttributeNameFromTextField() {
144         return this.mAttrNameTextField.getText();
145     }
146     
147     public JTextField JavaDoc getAttributeNameTextField() {
148         return this.mAttrNameTextField;
149     }
150     
151     public JComboBox JavaDoc getNamespaceComboBox() {
152         return this.mAttrNamespaceComboBox;
153     }
154     
155     public boolean isStateValid() {
156         return mErrorPanel.isStateValid();
157     }
158     
159     private boolean validateAttributeNameAndNamespace() {
160         boolean valid = true;
161         
162         String JavaDoc attrName = getAttributeNameFromTextField();
163         String JavaDoc namespace = getAttributeNamespace();
164         if(attrName == null || attrName.trim().equals("")) {
165             valid = false;
166             
167             mErrorPanel.setErrorMessage(NbBundle.getMessage(getClass(),
168                     "AttributeView_COMMON_MSG_ERROR_ATTRIBUTE_NAME_NOT_VALID", attrName));
169             
170             this.firePropertyChange(STATE_CHANGED,
171                     true, false);
172             
173         } else if(isNamespaceRequired && (namespace == null || namespace.trim().equals(""))) {
174             valid = false;
175             
176             mErrorPanel.setErrorMessage(NbBundle.getMessage(getClass(),
177                     "AttributeView_COMMON_MSG_ERROR_NAMESPACE_IS_NOT_VALID", namespace));
178             
179             this.firePropertyChange(STATE_CHANGED,
180                     true, false);
181             
182         } else {
183             mNamespace = namespace;
184             
185             
186             QName JavaDoc attributeQName = new QName JavaDoc(namespace, attrName);
187             if(mComponent.getAttributeMap().get(attributeQName) != null) {
188                 valid = false;
189                 
190                 mErrorPanel.setErrorMessage(NbBundle.getMessage(getClass(),
191                         "AttributeView_COMMON_MSG_ERROR_ATTRIBUTE_ALREADY_EXIST", attributeQName.toString()));
192                 
193                 this.firePropertyChange(STATE_CHANGED,
194                         true, false);
195                 
196             } else {
197                 mAttributeName = attrName;
198             }
199         }
200         
201         if(valid) {
202             mErrorPanel.setMessage("");
203             this.firePropertyChange(STATE_CHANGED,
204                     false, true);
205         }
206         return valid;
207     }
208     
209     class AttributeDocumentListener implements DocumentListener JavaDoc {
210         
211         
212         
213         public void insertUpdate(DocumentEvent JavaDoc e) {
214             validateAttributeNameAndNamespace();
215         }
216         
217         
218         public void removeUpdate(DocumentEvent JavaDoc e) {
219             validateAttributeNameAndNamespace();
220         }
221         
222         
223         public void changedUpdate(DocumentEvent JavaDoc e) {
224             validateAttributeNameAndNamespace();
225         }
226         
227     }
228     public String JavaDoc getNamespace() {
229         return mNamespace;
230     }
231     
232     public String JavaDoc getAttributeName() {
233         return mAttributeName;
234     }
235     public static String JavaDoc STATE_CHANGED = "STATE_CHANGED";//NOI18N
236
private CommonMessagePanel mErrorPanel;
237     private String JavaDoc mNamespace;
238     private String JavaDoc mAttributeName;
239     private Vector JavaDoc mNamespaces;
240     private boolean isNamespaceRequired = false;
241     private WSDLComponent mComponent;
242     // Variables declaration - do not modify//GEN-BEGIN:variables
243
private javax.swing.JLabel JavaDoc mAttrNameLabel;
244     private javax.swing.JTextField JavaDoc mAttrNameTextField;
245     private javax.swing.JComboBox JavaDoc mAttrNamespaceComboBox;
246     private javax.swing.JLabel JavaDoc mAttrNamespaceLabel;
247     private javax.swing.JPanel JavaDoc mCommonMsgPanel;
248     // End of variables declaration//GEN-END:variables
249

250 }
251
Popular Tags