1 19 20 25 26 package org.netbeans.modules.xml.wsdl.ui.view; 27 28 import java.awt.BorderLayout ; 29 import java.util.Vector ; 30 31 import javax.swing.DefaultComboBoxModel ; 32 import javax.swing.JComboBox ; 33 import javax.swing.JTextField ; 34 import javax.swing.event.DocumentEvent ; 35 import javax.swing.event.DocumentListener ; 36 import javax.xml.namespace.QName ; 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 46 public class AttributePanel extends javax.swing.JPanel { 47 48 51 private static final long serialVersionUID = 1680305470367882467L; 52 55 public AttributePanel(boolean isNamespaceRequired, Vector 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 listener = new AttributeDocumentListener(); 67 mAttrNameTextField.getDocument().addDocumentListener(listener); 68 ((JTextField )mAttrNamespaceComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(listener); 69 } 70 71 76 private void initComponents() { 78 mAttrNameLabel = new javax.swing.JLabel (); 79 mAttrNamespaceLabel = new javax.swing.JLabel (); 80 mAttrNameTextField = new javax.swing.JTextField (); 81 mAttrNamespaceComboBox = new javax.swing.JComboBox (); 82 mCommonMsgPanel = new javax.swing.JPanel (); 83 84 mAttrNameLabel.setLabelFor(mAttrNameTextField); 85 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/wsdl/ui/view/Bundle"); org.openide.awt.Mnemonics.setLocalizedText(mAttrNameLabel, bundle.getString("LBL_AttributePanel_NAME")); mAttrNameLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNameLabel.toolTipText")); 89 mAttrNamespaceLabel.setLabelFor(mAttrNamespaceComboBox); 90 org.openide.awt.Mnemonics.setLocalizedText(mAttrNamespaceLabel, bundle.getString("LBL_AttributePanel_NAMESPACE")); mAttrNamespaceLabel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNamespaceLabel.toolTipText")); 93 mAttrNameTextField.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNameTextField.toolTipText")); 95 mAttrNamespaceComboBox.setEditable(true); 96 mAttrNamespaceComboBox.setModel(new DefaultComboBoxModel (mNamespaces)); 97 mAttrNamespaceComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mAttrNamespaceComboBox.toolTipText")); 99 mCommonMsgPanel.setLayout(new java.awt.BorderLayout ()); 100 101 mCommonMsgPanel.setToolTipText(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mCommonMsgPanel.toolTipText")); mCommonMsgPanel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(AttributePanel.class, "AttributePanel.mCommonMsgPanel.toolTipText")); 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 } 138 public String getAttributeNamespace() { 139 JTextField editor = (JTextField ) this.mAttrNamespaceComboBox.getEditor().getEditorComponent(); 140 return editor.getText(); 141 } 142 143 public String getAttributeNameFromTextField() { 144 return this.mAttrNameTextField.getText(); 145 } 146 147 public JTextField getAttributeNameTextField() { 148 return this.mAttrNameTextField; 149 } 150 151 public JComboBox 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 attrName = getAttributeNameFromTextField(); 163 String 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 attributeQName = new QName (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 { 210 211 212 213 public void insertUpdate(DocumentEvent e) { 214 validateAttributeNameAndNamespace(); 215 } 216 217 218 public void removeUpdate(DocumentEvent e) { 219 validateAttributeNameAndNamespace(); 220 } 221 222 223 public void changedUpdate(DocumentEvent e) { 224 validateAttributeNameAndNamespace(); 225 } 226 227 } 228 public String getNamespace() { 229 return mNamespace; 230 } 231 232 public String getAttributeName() { 233 return mAttributeName; 234 } 235 public static String STATE_CHANGED = "STATE_CHANGED"; private CommonMessagePanel mErrorPanel; 237 private String mNamespace; 238 private String mAttributeName; 239 private Vector mNamespaces; 240 private boolean isNamespaceRequired = false; 241 private WSDLComponent mComponent; 242 private javax.swing.JLabel mAttrNameLabel; 244 private javax.swing.JTextField mAttrNameTextField; 245 private javax.swing.JComboBox mAttrNamespaceComboBox; 246 private javax.swing.JLabel mAttrNamespaceLabel; 247 private javax.swing.JPanel mCommonMsgPanel; 248 250 } 251 | Popular Tags |