1 19 20 package org.netbeans.modules.j2ee.ddloaders.web.multiview; 21 22 import java.util.ArrayList ; 23 import java.util.StringTokenizer ; 24 import javax.swing.JTextField ; 25 26 34 public class WebResourceCollectionPanel extends javax.swing.JPanel { 35 private static String GET = "GET"; private static String POST = "POST"; private static String HEAD = "HEAD"; private static String PUT = "PUT"; private static String OPTIONS = "OPTIONS"; private static String TRACE = "TRACE"; private static String DELETE = "DELETE"; private static String [] allMethods = {GET, POST, HEAD, PUT, OPTIONS, TRACE, 43 DELETE}; 44 45 46 public WebResourceCollectionPanel() { 47 initComponents(); 48 } 49 50 public String getResourceName() { 51 return resourceNameTF.getText(); 52 } 53 54 public void setResourceName(String name) { 55 resourceNameTF.setText(name); 56 } 57 58 public String [] getUrlPatterns() { 59 StringTokenizer tokenizer = new StringTokenizer (urlPatternsTF.getText(), 60 ","); 62 ArrayList list = new ArrayList (); 63 while (tokenizer.hasMoreTokens()) { 64 String pattern = tokenizer.nextToken().trim(); 65 if (pattern.length() > 0) 66 list.add(pattern); 67 } 68 69 String [] result = new String [list.size()]; 70 71 return (String []) list.toArray(result); 72 } 73 74 public void setUrlPatterns(String [] patterns) { 75 urlPatternsTF.setText(WebResourceCollectionTableModel.getCommaSeparatedString(patterns)); 76 } 77 78 public String getDescription() { 79 return descriptionTF.getText(); 80 } 81 82 public void setDescription(String description) { 83 descriptionTF.setText(description); 84 } 85 86 public void setHttpMethods(String [] methods) { 87 boolean allSelected = true; 88 89 for (int i = 0; i < allMethods.length; i++) { 90 boolean found = false; 91 String method = allMethods[i]; 92 93 for (int j = 0; j < methods.length; j++) { 94 if (method.equals(methods[j])) { 95 found = true; 96 break; 97 } 98 } 99 100 if (!found) { 101 allSelected = false; 102 break; 103 } 104 } 105 106 if (allSelected) { 107 allHttpMethodsRB.setSelected(true); 108 } else { 109 subsetHttpMethodsRB.setSelected(true); 110 for (int i =0; i < methods.length; i++) { 111 String method = methods[i]; 112 113 if (method.equals(GET)) { 114 getCB.setSelected(true); 115 } else if (method.equals(PUT)) { 116 putCB.setSelected(true); 117 } else if (method.equals(HEAD)) { 118 headCB.setSelected(true); 119 } else if (method.equals(POST)) { 120 postCB.setSelected(true); 121 } else if (method.equals(TRACE)) { 122 traceCB.setSelected(true); 123 } else if (method.equals(DELETE)) { 124 deleteCB.setSelected(true); 125 } else if (method.equals(OPTIONS)) { 126 optionsCB.setSelected(true); 127 } 128 } 129 } 130 131 updateVisualState(); 132 } 133 134 public String [] getSelectedHttpMethods() { 135 if (allHttpMethodsRB.isSelected()) { 136 return allMethods; 137 } else if (subsetHttpMethodsRB.isSelected()) { 138 ArrayList list = new ArrayList (); 139 140 if (getCB.isSelected()) { 141 list.add(GET); 142 } 143 144 if (putCB.isSelected()) { 145 list.add(PUT); 146 } 147 148 if (headCB.isSelected()) { 149 list.add(HEAD); 150 } 151 152 if (postCB.isSelected()) { 153 list.add(POST); 154 } 155 156 if (optionsCB.isSelected()) { 157 list.add(OPTIONS); 158 } 159 160 if (traceCB.isSelected()) { 161 list.add(TRACE); 162 } 163 164 if (deleteCB.isSelected()) { 165 list.add(DELETE); 166 } 167 168 String [] results = new String [list.size()]; 169 return (String []) list.toArray(results); 170 } 171 172 return new String [] {}; 173 } 174 175 private void updateVisualState() { 176 if (subsetHttpMethodsRB.isSelected()) { 177 getCB.setEnabled(true); 178 putCB.setEnabled(true); 179 headCB.setEnabled(true); 180 postCB.setEnabled(true); 181 optionsCB.setEnabled(true); 182 traceCB.setEnabled(true); 183 deleteCB.setEnabled(true); 184 } else { 185 getCB.setEnabled(false); 186 putCB.setEnabled(false); 187 headCB.setEnabled(false); 188 postCB.setEnabled(false); 189 optionsCB.setEnabled(false); 190 traceCB.setEnabled(false); 191 deleteCB.setEnabled(false); 192 } 193 } 194 195 public JTextField getResourceNameTF() { 196 return resourceNameTF; 197 } 198 199 public JTextField getDescriptionTF() { 200 return descriptionTF; 201 } 202 203 public JTextField getUrlPatternsTF() { 204 return urlPatternsTF; 205 } 206 207 212 private void initComponents() { 214 buttonGroup1 = new javax.swing.ButtonGroup (); 215 resourceNameLabel = new javax.swing.JLabel (); 216 resourceNameTF = new javax.swing.JTextField (); 217 descriptionLabel = new javax.swing.JLabel (); 218 descriptionTF = new javax.swing.JTextField (); 219 urlPatternsLabel = new javax.swing.JLabel (); 220 urlPatternsTF = new javax.swing.JTextField (); 221 httpMethodLabel = new javax.swing.JLabel (); 222 getCB = new javax.swing.JCheckBox (); 223 postCB = new javax.swing.JCheckBox (); 224 headCB = new javax.swing.JCheckBox (); 225 putCB = new javax.swing.JCheckBox (); 226 optionsCB = new javax.swing.JCheckBox (); 227 traceCB = new javax.swing.JCheckBox (); 228 deleteCB = new javax.swing.JCheckBox (); 229 jLabel5 = new javax.swing.JLabel (); 230 allHttpMethodsRB = new javax.swing.JRadioButton (); 231 subsetHttpMethodsRB = new javax.swing.JRadioButton (); 232 233 resourceNameLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_resourceName_mnem").charAt(0)); 234 resourceNameLabel.setLabelFor(resourceNameTF); 235 resourceNameLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionName")); 236 237 descriptionLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_description_mnem").charAt(0)); 238 descriptionLabel.setLabelFor(descriptionTF); 239 descriptionLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionDescription")); 240 241 urlPatternsLabel.setDisplayedMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_urlPatterns_mnem2").charAt(0)); 242 urlPatternsLabel.setLabelFor(urlPatternsTF); 243 urlPatternsLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionUrlPatterns")); 244 245 httpMethodLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_WebResourceCollectionHttpMethods")); 246 247 getCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_get_mnem").charAt(0)); 248 getCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_GET")); 249 getCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 250 getCB.setEnabled(false); 251 getCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 252 253 postCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_post_mnem").charAt(0)); 254 postCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_POST")); 255 postCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 256 postCB.setEnabled(false); 257 postCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 258 259 headCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_head_mnem").charAt(0)); 260 headCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_HEAD")); 261 headCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 262 headCB.setEnabled(false); 263 headCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 264 265 putCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_put_mnem").charAt(0)); 266 putCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_PUT")); 267 putCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 268 putCB.setEnabled(false); 269 putCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 270 271 optionsCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_options_mnem").charAt(0)); 272 optionsCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_OPTIONS")); 273 optionsCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 274 optionsCB.setEnabled(false); 275 optionsCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 276 277 traceCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_trace_mnem").charAt(0)); 278 traceCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_TRACE")); 279 traceCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 280 traceCB.setEnabled(false); 281 traceCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 282 283 deleteCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_delete_mnem").charAt(0)); 284 deleteCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_DELETE")); 285 deleteCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 286 deleteCB.setEnabled(false); 287 deleteCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 288 289 jLabel5.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("HINT_urlPatterns")); 290 291 buttonGroup1.add(allHttpMethodsRB); 292 allHttpMethodsRB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_allHttpMethods_mnem").charAt(0)); 293 allHttpMethodsRB.setSelected(true); 294 allHttpMethodsRB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_AllHttpMethods")); 295 allHttpMethodsRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 296 allHttpMethodsRB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 297 allHttpMethodsRB.addActionListener(new java.awt.event.ActionListener () { 298 public void actionPerformed(java.awt.event.ActionEvent evt) { 299 allHttpMethodsRBActionPerformed(evt); 300 } 301 }); 302 303 buttonGroup1.add(subsetHttpMethodsRB); 304 subsetHttpMethodsRB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_subsetHttpMethods_mnem").charAt(0)); 305 subsetHttpMethodsRB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/j2ee/ddloaders/web/multiview/Bundle").getString("LBL_SubsetOfHttpMethods")); 306 subsetHttpMethodsRB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 307 subsetHttpMethodsRB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 308 subsetHttpMethodsRB.addActionListener(new java.awt.event.ActionListener () { 309 public void actionPerformed(java.awt.event.ActionEvent evt) { 310 subsetHttpMethodsRBActionPerformed(evt); 311 } 312 }); 313 314 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 315 this.setLayout(layout); 316 layout.setHorizontalGroup( 317 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 318 .add(layout.createSequentialGroup() 319 .addContainerGap() 320 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 321 .add(resourceNameLabel) 322 .add(descriptionLabel) 323 .add(urlPatternsLabel) 324 .add(httpMethodLabel)) 325 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 326 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 327 .add(urlPatternsTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE) 328 .add(descriptionTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE) 329 .add(resourceNameTF, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE) 330 .add(layout.createSequentialGroup() 331 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 332 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 333 .add(jLabel5) 334 .add(allHttpMethodsRB) 335 .add(subsetHttpMethodsRB))) 336 .add(layout.createSequentialGroup() 337 .add(25, 25, 25) 338 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 339 .add(optionsCB) 340 .add(getCB) 341 .add(headCB) 342 .add(deleteCB)) 343 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 344 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 345 .add(postCB) 346 .add(traceCB) 347 .add(putCB)) 348 .add(163, 163, 163))) 349 .addContainerGap()) 350 ); 351 layout.setVerticalGroup( 352 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 353 .add(layout.createSequentialGroup() 354 .addContainerGap() 355 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 356 .add(resourceNameLabel) 357 .add(resourceNameTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 358 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 359 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 360 .add(descriptionLabel) 361 .add(descriptionTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 362 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 363 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 364 .add(urlPatternsLabel) 365 .add(urlPatternsTF, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 366 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 367 .add(jLabel5) 368 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 369 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 370 .add(httpMethodLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 371 .add(allHttpMethodsRB)) 372 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 373 .add(subsetHttpMethodsRB) 374 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 375 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 376 .add(getCB) 377 .add(postCB)) 378 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 379 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 380 .add(headCB) 381 .add(putCB, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) 382 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 383 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 384 .add(optionsCB) 385 .add(traceCB)) 386 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 387 .add(deleteCB) 388 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 389 ); 390 } 392 private void subsetHttpMethodsRBActionPerformed(java.awt.event.ActionEvent evt) { updateVisualState(); 395 } 397 private void allHttpMethodsRBActionPerformed(java.awt.event.ActionEvent evt) { updateVisualState(); 400 } 402 403 private javax.swing.JRadioButton allHttpMethodsRB; 405 private javax.swing.ButtonGroup buttonGroup1; 406 private javax.swing.JCheckBox deleteCB; 407 private javax.swing.JLabel descriptionLabel; 408 private javax.swing.JTextField descriptionTF; 409 private javax.swing.JCheckBox getCB; 410 private javax.swing.JCheckBox headCB; 411 private javax.swing.JLabel httpMethodLabel; 412 private javax.swing.JLabel jLabel5; 413 private javax.swing.JCheckBox optionsCB; 414 private javax.swing.JCheckBox postCB; 415 private javax.swing.JCheckBox putCB; 416 private javax.swing.JLabel resourceNameLabel; 417 private javax.swing.JTextField resourceNameTF; 418 private javax.swing.JRadioButton subsetHttpMethodsRB; 419 private javax.swing.JCheckBox traceCB; 420 private javax.swing.JLabel urlPatternsLabel; 421 private javax.swing.JTextField urlPatternsTF; 422 424 } 425 | Popular Tags |