1 19 20 package org.netbeans.modules.j2ee.common.method.impl; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.Collections ; 26 import java.util.List ; 27 import java.util.Set ; 28 import javax.lang.model.element.Modifier; 29 import javax.swing.event.DocumentEvent ; 30 import javax.swing.event.DocumentListener ; 31 import org.netbeans.modules.j2ee.common.method.MethodModel; 32 33 37 public final class MethodCustomizerPanel extends javax.swing.JPanel { 38 39 public static final String NAME = "name"; 40 public static final String RETURN_TYPE = "returnType"; 41 public static final String INTERFACES = "interfaces"; 42 43 private final MethodModel methodModel; 45 private final ParametersPanel parametersPanel; 46 private final boolean hasInterfaces; 47 48 private MethodCustomizerPanel( 49 MethodModel methodModel, 50 boolean hasLocal, 51 boolean hasRemote, 52 boolean selectLocal, 53 boolean selectRemote, 54 boolean hasReturnType, 55 String ejbql, 56 boolean hasFinderCardinality, 57 boolean hasExceptions, 58 boolean hasInterfaces) { 59 initComponents(); 60 61 this.methodModel = methodModel; 62 this.hasInterfaces = hasInterfaces; 63 64 nameTextField.setText(methodModel.getName()); 65 returnTypeTextField.setText(methodModel.getReturnType()); 66 67 localCheckBox.setEnabled(hasLocal); 68 remoteCheckBox.setEnabled(hasRemote); 69 localCheckBox.setSelected(selectLocal); 70 remoteCheckBox.setSelected(selectRemote); 71 72 if (!hasReturnType) { 73 disableReturnType(); 74 } 75 if (ejbql == null) { 76 ejbqlPanel.setVisible(false); 77 } else { 78 ejbqlTextArea.setText(ejbql); 79 } 80 cardinalityPanel.setVisible(hasFinderCardinality); 81 exceptionsPanel.setVisible(hasExceptions); 82 interfacesPanel.setVisible(hasInterfaces); 83 84 parametersPanel = new ParametersPanel(methodModel.getParameters()); 85 parametersContainerPanel.add(parametersPanel); 86 87 nameTextField.getDocument().addDocumentListener(new SimpleListener(NAME)); 89 returnTypeTextField.getDocument().addDocumentListener(new SimpleListener(RETURN_TYPE)); 90 SimpleListener interfacesListener = new SimpleListener(INTERFACES); 91 localCheckBox.addActionListener(interfacesListener); 92 remoteCheckBox.addActionListener(interfacesListener); 93 } 94 95 public static MethodCustomizerPanel create(MethodModel methodModel, boolean hasLocal, boolean hasRemote, boolean selectLocal, boolean selectRemote, 96 boolean hasReturnType, String ejbql, boolean hasFinderCardinality, boolean hasExceptions, boolean hasInterfaces) { 97 return new MethodCustomizerPanel(methodModel, hasLocal, hasRemote, selectLocal, selectRemote, 98 hasReturnType, ejbql, hasFinderCardinality, hasExceptions, hasInterfaces); 99 } 100 101 @Override 102 public void addPropertyChangeListener(PropertyChangeListener listener) { 103 super.addPropertyChangeListener(listener); 104 firePropertyChange(NAME, null, null); 106 firePropertyChange(RETURN_TYPE, null, null); 107 firePropertyChange(INTERFACES, null, null); 108 } 109 110 115 private void initComponents() { 117 118 finderCardinalityButtonGroup = new javax.swing.ButtonGroup (); 119 exceptionAndParameterPane = new javax.swing.JTabbedPane (); 120 parametersContainerPanel = new javax.swing.JPanel (); 121 exceptionsPanel = new javax.swing.JPanel (); 122 errorTextField = new javax.swing.JTextField (); 123 returnTypeLabel = new javax.swing.JLabel (); 124 returnTypeTextField = new javax.swing.JTextField (); 125 nameTextField = new javax.swing.JTextField (); 126 jLabel1 = new javax.swing.JLabel (); 127 methodLabel = new javax.swing.JLabel (); 128 methodSeparator = new javax.swing.JSeparator (); 129 interfacesPanel = new javax.swing.JPanel (); 130 interfaceLabel = new javax.swing.JLabel (); 131 remoteCheckBox = new javax.swing.JCheckBox (); 132 localCheckBox = new javax.swing.JCheckBox (); 133 cardinalityPanel = new javax.swing.JPanel (); 134 cardinalityLabel = new javax.swing.JLabel (); 135 oneRadioButton = new javax.swing.JRadioButton (); 136 manyRadioButton = new javax.swing.JRadioButton (); 137 ejbqlPanel = new javax.swing.JPanel (); 138 ejbqlLabel = new javax.swing.JLabel (); 139 ejbqlScrollPane = new javax.swing.JScrollPane (); 140 ejbqlTextArea = new javax.swing.JTextArea (); 141 142 parametersContainerPanel.setLayout(new java.awt.BorderLayout ()); 143 exceptionAndParameterPane.addTab(org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.parametersContainerPanel.TabConstraints.tabTitle"), parametersContainerPanel); 145 org.jdesktop.layout.GroupLayout exceptionsPanelLayout = new org.jdesktop.layout.GroupLayout(exceptionsPanel); 146 exceptionsPanel.setLayout(exceptionsPanelLayout); 147 exceptionsPanelLayout.setHorizontalGroup( 148 exceptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 149 .add(0, 412, Short.MAX_VALUE) 150 ); 151 exceptionsPanelLayout.setVerticalGroup( 152 exceptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 153 .add(0, 122, Short.MAX_VALUE) 154 ); 155 156 exceptionAndParameterPane.addTab(org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.exceptionsPanel.TabConstraints.tabTitle"), exceptionsPanel); 158 errorTextField.setEditable(false); 159 errorTextField.setText(org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.errorTextField.text")); errorTextField.setBorder(null); 161 162 returnTypeLabel.setLabelFor(returnTypeTextField); 163 org.openide.awt.Mnemonics.setLocalizedText(returnTypeLabel, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.returnTypeLabel.text")); 165 returnTypeTextField.setText(org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.returnTypeTextField.text")); 167 nameTextField.setText(org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.nameTextField.text")); 169 jLabel1.setLabelFor(nameTextField); 170 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.jLabel1.text")); 172 org.openide.awt.Mnemonics.setLocalizedText(methodLabel, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.methodLabel.text")); 174 org.openide.awt.Mnemonics.setLocalizedText(interfaceLabel, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.interfaceLabel.text")); 176 org.openide.awt.Mnemonics.setLocalizedText(remoteCheckBox, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.remoteCheckBox.text")); remoteCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 178 remoteCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 179 180 org.openide.awt.Mnemonics.setLocalizedText(localCheckBox, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.localCheckBox.text")); localCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 182 localCheckBox.setMargin(new java.awt.Insets (0, 0, 0, 0)); 183 184 org.jdesktop.layout.GroupLayout interfacesPanelLayout = new org.jdesktop.layout.GroupLayout(interfacesPanel); 185 interfacesPanel.setLayout(interfacesPanelLayout); 186 interfacesPanelLayout.setHorizontalGroup( 187 interfacesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 188 .add(interfacesPanelLayout.createSequentialGroup() 189 .add(interfaceLabel) 190 .add(24, 24, 24) 191 .add(remoteCheckBox) 192 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 193 .add(localCheckBox) 194 .addContainerGap(174, Short.MAX_VALUE)) 195 ); 196 interfacesPanelLayout.setVerticalGroup( 197 interfacesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 198 .add(interfacesPanelLayout.createSequentialGroup() 199 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 200 .add(interfacesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 201 .add(interfaceLabel) 202 .add(remoteCheckBox) 203 .add(localCheckBox))) 204 ); 205 206 org.openide.awt.Mnemonics.setLocalizedText(cardinalityLabel, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.cardinalityLabel.text")); 208 finderCardinalityButtonGroup.add(oneRadioButton); 209 org.openide.awt.Mnemonics.setLocalizedText(oneRadioButton, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.oneRadioButton.text")); oneRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 211 oneRadioButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 212 213 finderCardinalityButtonGroup.add(manyRadioButton); 214 org.openide.awt.Mnemonics.setLocalizedText(manyRadioButton, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.manyRadioButton.text")); manyRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 216 manyRadioButton.setMargin(new java.awt.Insets (0, 0, 0, 0)); 217 218 org.jdesktop.layout.GroupLayout cardinalityPanelLayout = new org.jdesktop.layout.GroupLayout(cardinalityPanel); 219 cardinalityPanel.setLayout(cardinalityPanelLayout); 220 cardinalityPanelLayout.setHorizontalGroup( 221 cardinalityPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 222 .add(cardinalityPanelLayout.createSequentialGroup() 223 .add(cardinalityLabel) 224 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 225 .add(oneRadioButton) 226 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 227 .add(manyRadioButton) 228 .addContainerGap(194, Short.MAX_VALUE)) 229 ); 230 cardinalityPanelLayout.setVerticalGroup( 231 cardinalityPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 232 .add(cardinalityPanelLayout.createSequentialGroup() 233 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 234 .add(cardinalityPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 235 .add(cardinalityLabel) 236 .add(oneRadioButton) 237 .add(manyRadioButton))) 238 ); 239 240 org.openide.awt.Mnemonics.setLocalizedText(ejbqlLabel, org.openide.util.NbBundle.getMessage(MethodCustomizerPanel.class, "MethodCustomizerPanel.ejbqlLabel.text")); 242 ejbqlScrollPane.setBorder(null); 243 244 ejbqlTextArea.setColumns(20); 245 ejbqlTextArea.setRows(5); 246 ejbqlTextArea.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 247 ejbqlScrollPane.setViewportView(ejbqlTextArea); 248 249 org.jdesktop.layout.GroupLayout ejbqlPanelLayout = new org.jdesktop.layout.GroupLayout(ejbqlPanel); 250 ejbqlPanel.setLayout(ejbqlPanelLayout); 251 ejbqlPanelLayout.setHorizontalGroup( 252 ejbqlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 253 .add(ejbqlPanelLayout.createSequentialGroup() 254 .add(ejbqlLabel) 255 .addContainerGap(377, Short.MAX_VALUE)) 256 .add(ejbqlScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE) 257 ); 258 ejbqlPanelLayout.setVerticalGroup( 259 ejbqlPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 260 .add(ejbqlPanelLayout.createSequentialGroup() 261 .addContainerGap() 262 .add(ejbqlLabel) 263 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 264 .add(ejbqlScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)) 265 ); 266 267 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 268 this.setLayout(layout); 269 layout.setHorizontalGroup( 270 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 271 .add(layout.createSequentialGroup() 272 .addContainerGap() 273 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 274 .add(org.jdesktop.layout.GroupLayout.TRAILING, exceptionAndParameterPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE) 275 .add(layout.createSequentialGroup() 276 .add(methodLabel) 277 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 278 .add(methodSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)) 279 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 280 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 281 .add(jLabel1) 282 .add(returnTypeLabel)) 283 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 284 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 285 .add(nameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE) 286 .add(returnTypeTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE))) 287 .add(ejbqlPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 288 .add(cardinalityPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 289 .add(interfacesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 290 .add(errorTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)) 291 .addContainerGap()) 292 ); 293 layout.setVerticalGroup( 294 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 295 .add(layout.createSequentialGroup() 296 .addContainerGap() 297 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) 298 .add(methodLabel) 299 .add(methodSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 300 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 301 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 302 .add(nameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 303 .add(jLabel1)) 304 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 305 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 306 .add(returnTypeLabel) 307 .add(returnTypeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 308 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 309 .add(exceptionAndParameterPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE) 310 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 311 .add(interfacesPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 312 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 313 .add(cardinalityPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 314 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 315 .add(ejbqlPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 316 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 317 .add(errorTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 318 ); 319 } 321 322 private javax.swing.JLabel cardinalityLabel; 324 private javax.swing.JPanel cardinalityPanel; 325 private javax.swing.JLabel ejbqlLabel; 326 private javax.swing.JPanel ejbqlPanel; 327 private javax.swing.JScrollPane ejbqlScrollPane; 328 private javax.swing.JTextArea ejbqlTextArea; 329 private javax.swing.JTextField errorTextField; 330 private javax.swing.JTabbedPane exceptionAndParameterPane; 331 private javax.swing.JPanel exceptionsPanel; 332 private javax.swing.ButtonGroup finderCardinalityButtonGroup; 333 private javax.swing.JLabel interfaceLabel; 334 private javax.swing.JPanel interfacesPanel; 335 private javax.swing.JLabel jLabel1; 336 private javax.swing.JCheckBox localCheckBox; 337 private javax.swing.JRadioButton manyRadioButton; 338 private javax.swing.JLabel methodLabel; 339 private javax.swing.JSeparator methodSeparator; 340 private javax.swing.JTextField nameTextField; 341 private javax.swing.JRadioButton oneRadioButton; 342 private javax.swing.JPanel parametersContainerPanel; 343 private javax.swing.JCheckBox remoteCheckBox; 344 private javax.swing.JLabel returnTypeLabel; 345 private javax.swing.JTextField returnTypeTextField; 346 348 public void setError(String message) { 349 errorTextField.setText(message); 350 } 351 352 public String getMethodName() { 353 return nameTextField.getText().trim(); 354 } 355 356 public String getReturnType() { 357 return returnTypeTextField.getText().trim(); 358 } 359 360 public List <MethodModel.Variable> getParameters() { 361 return parametersPanel.getParameters(); 362 } 363 364 public List <String > getExceptions() { 365 return Collections.<String >emptyList(); 366 } 367 368 public Set <Modifier> getModifiers() { 369 return methodModel.getModifiers(); 371 } 372 373 public String getMethodBody() { 374 return methodModel.getBody(); 376 } 377 378 public boolean supportsInterfacesChecking() { 379 return hasInterfaces; 380 } 381 382 public boolean hasLocal() { 383 return localCheckBox.isEnabled() & localCheckBox.isSelected(); 384 } 385 386 public boolean hasRemote() { 387 return remoteCheckBox.isEnabled() && remoteCheckBox.isSelected(); 388 } 389 390 private void disableReturnType() { 391 returnTypeLabel.setVisible(false); 392 returnTypeTextField.setVisible(false); 393 } 394 395 402 private class SimpleListener implements DocumentListener , ActionListener { 403 404 private final String propertyName; 405 406 public SimpleListener(String propertyName) { 407 this.propertyName = propertyName; 408 } 409 410 public void insertUpdate(DocumentEvent documentEvent) { fire(); } 411 412 public void removeUpdate(DocumentEvent documentEvent) { fire(); } 413 414 public void changedUpdate(DocumentEvent documentEvent) {} 415 416 public void actionPerformed(ActionEvent actionEvent) { fire(); } 417 418 private void fire() { 419 firePropertyChange(propertyName, null, null); 420 } 421 422 } 423 424 } 425 | Popular Tags |