1 19 20 package org.netbeans.modules.ant.freeform.ui; 21 22 import java.awt.Frame ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.util.ArrayList ; 26 import java.util.Arrays ; 27 import java.util.Collections ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.StringTokenizer ; 31 import java.util.regex.Matcher ; 32 import java.util.regex.Pattern ; 33 import javax.swing.ComboBoxModel ; 34 import javax.swing.DefaultCellEditor ; 35 import javax.swing.JComboBox ; 36 import javax.swing.JDialog ; 37 import javax.swing.JLabel ; 38 import javax.swing.JPanel ; 39 import javax.swing.WindowConstants ; 40 import javax.swing.table.AbstractTableModel ; 41 import org.netbeans.modules.ant.freeform.FreeformProjectGenerator; 42 import org.netbeans.modules.ant.freeform.Util; 43 import org.netbeans.modules.ant.freeform.spi.ProjectConstants; 44 import org.netbeans.modules.ant.freeform.spi.TargetDescriptor; 45 import org.netbeans.spi.project.support.ant.AntProjectHelper; 46 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 47 import org.openide.awt.Mnemonics; 48 import org.openide.filesystems.FileObject; 49 import org.openide.util.HelpCtx; 50 import org.openide.util.NbBundle; 51 52 55 public class TargetMappingPanel extends JPanel implements ActionListener , HelpCtx.Provider { 56 57 public static final String BUILD_ACTION = "build"; public static final String CLEAN_ACTION = "clean"; public static final String REBUILD_ACTION = "rebuild"; public static final String JAVADOC_ACTION = "javadoc"; public static final String RUN_ACTION = "run"; public static final String TEST_ACTION = "test"; 64 private static final List <String > DEFAULT_BUILD_TARGETS = Arrays.asList("build", "compile", "jar", "dist", "all", ".*jar.*"); private static final List <String > DEFAULT_CLEAN_TARGETS = Arrays.asList("clean", ".*clean.*"); private static final List <String > DEFAULT_JAVADOC_TARGETS = Arrays.asList("javadoc", "javadocs", "docs", "doc", ".*javadoc.*", ".*doc.*"); private static final List <String > DEFAULT_RUN_TARGETS = Arrays.asList("run", "start", ".*run.*", ".*start.*"); private static final List <String > DEFAULT_TEST_TARGETS = Arrays.asList("test", ".*test.*"); 71 private List <String > targetNames; 72 private List <FreeformProjectGenerator.TargetMapping> targetMappings; 73 private List <FreeformProjectGenerator.CustomTarget> custTargets; 74 private CustomTargetsModel customTargetsModel; 75 private String antScript; 76 77 private List <JComboBox > combos = new ArrayList <JComboBox >(); 78 private List <TargetDescriptor> targetDescs = new ArrayList <TargetDescriptor>(); 79 80 81 private boolean dirtyRegular; 82 83 84 private boolean dirtyCustom; 85 86 private AntProjectHelper helper; 87 88 public TargetMappingPanel(boolean advancedPart) { 89 this(new ArrayList <TargetDescriptor>(), advancedPart); 90 } 91 92 public TargetMappingPanel(List <TargetDescriptor> extraTargets, boolean advancedPart) { 93 initComponents(); 94 targetMappings = new ArrayList <FreeformProjectGenerator.TargetMapping>(); 95 96 custTargets = new ArrayList <FreeformProjectGenerator.CustomTarget>(); 97 customTargetsModel = new CustomTargetsModel(); 98 customTargets.setModel(customTargetsModel); 99 customTargets.getTableHeader().setReorderingAllowed(false); 100 101 addTargets(extraTargets); 102 showAdvancedPart(advancedPart); 103 } 104 105 public TargetMappingPanel(List <TargetDescriptor> extraTargets, PropertyEvaluator evaluator, AntProjectHelper helper) { 106 this(extraTargets, true); 107 this.helper = helper; 108 FileObject as = FreeformProjectGenerator.getAntScript(helper, evaluator); 109 List <String > l = null; 110 if (as != null) { 112 l = Util.getAntScriptTargetNames(as); 113 } 114 if (l != null) { 115 setTargetNames(l, false); 116 initAntTargetEditor(l); 117 } 118 antScript = defaultAntScript(evaluator); 119 initMappings(FreeformProjectGenerator.getTargetMappings(helper), antScript); 120 121 custTargets = FreeformProjectGenerator.getCustomContextMenuActions(helper); 122 customTargetsModel.fireTableDataChanged(); 123 124 updateButtons(); 125 } 126 127 133 static String defaultAntScript(PropertyEvaluator evaluator) { 134 String antScript = evaluator.getProperty(ProjectConstants.PROP_ANT_SCRIPT); 135 if (antScript == null) { 136 return null; 138 } else { 139 return "${" + ProjectConstants.PROP_ANT_SCRIPT + "}"; } 142 } 143 144 145 private void addTargets(List <TargetDescriptor> extraTargets) { 146 combos.add(buildCombo); 147 targetDescs.add(new TargetDescriptor(BUILD_ACTION, DEFAULT_BUILD_TARGETS, null, null)); 148 combos.add(cleanCombo); 149 targetDescs.add(new TargetDescriptor(CLEAN_ACTION, DEFAULT_CLEAN_TARGETS, null, null)); 150 combos.add(javadocCombo); 151 targetDescs.add(new TargetDescriptor(JAVADOC_ACTION, DEFAULT_JAVADOC_TARGETS, null, null)); 152 combos.add(runCombo); 153 targetDescs.add(new TargetDescriptor(RUN_ACTION, DEFAULT_RUN_TARGETS, null, null)); 154 combos.add(testCombo); 155 targetDescs.add(new TargetDescriptor(TEST_ACTION, DEFAULT_TEST_TARGETS, null, null)); 156 int y = 5; 157 for (TargetDescriptor desc : extraTargets) { 158 targetDescs.add(desc); 159 160 JComboBox combo = new JComboBox (); 161 combo.setEditable(true); 162 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 163 gridBagConstraints.gridx = 1; 164 gridBagConstraints.gridy = y; 165 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 166 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 167 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 168 targetsPanel.add(combo, gridBagConstraints); 169 170 JLabel label = new JLabel (); 171 label.setLabelFor(combo); 172 Mnemonics.setLocalizedText(label, desc.getIDEActionLabel()); 173 gridBagConstraints = new java.awt.GridBagConstraints (); 174 gridBagConstraints.gridx = 0; 175 gridBagConstraints.gridy = y; 176 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 177 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 178 targetsPanel.add(label, gridBagConstraints); 179 label.getAccessibleContext().setAccessibleDescription(desc.getAccessibleLabel()); 180 181 combos.add(combo); 182 y++; 183 } 184 } 185 186 public HelpCtx getHelpCtx() { 187 return new HelpCtx( TargetMappingPanel.class ); 188 } 189 190 private void showAdvancedPart(boolean show) { 191 additionalTargetsLabel.setVisible(show); 192 jScrollPane1.setVisible(show); 193 customTargets.setVisible(show); 194 add.setVisible(show); 195 remove.setVisible(show); 196 remainder.setVisible(show); 198 specialRemainder.setVisible(!show); 199 } 200 201 private void initAntTargetEditor(List <String > targets) { 202 JComboBox combo = new JComboBox (); 203 combo.setEditable(true); 204 for (String target : targets) { 205 combo.addItem(target); 206 } 207 customTargets.setDefaultEditor(JComboBox .class, new DefaultCellEditor (combo)); 208 } 209 210 private FreeformProjectGenerator.CustomTarget getItem(int index) { 211 return custTargets.get(index); 212 } 213 214 public void setTargetNames(List <String > list, boolean selectDefaults) { 215 targetNames = list; 216 targetNames.add(0, ""); updateCombos(selectDefaults); 218 } 219 220 public void setScript(String script) { 221 this.antScript = script; 222 for (FreeformProjectGenerator.TargetMapping tm : targetMappings) { 223 tm.script = script; 224 } 225 } 226 227 private void updateCombos(boolean selectDefaults) { 228 Iterator <TargetDescriptor> descriptors = targetDescs.iterator(); 230 for (JComboBox combo : combos) { 231 TargetDescriptor desc = descriptors.next(); 232 combo.removeAllItems(); 233 for (String name : targetNames) { 234 combo.addItem(name); 235 } 236 if (selectDefaults) { 237 selectItem(combo, desc.getDefaultTargets(), false); } 239 } 240 } 241 242 246 private void selectItem(JComboBox combo, List <String > items, boolean add) { 247 ComboBoxModel model = combo.getModel(); 248 for (String item : items) { 249 Pattern pattern = Pattern.compile(item); 250 for (int i=0; i<model.getSize(); i++) { 251 String target = (String )model.getElementAt(i); 252 Matcher matcher = pattern.matcher(target); 253 if (matcher.matches()) { 254 model.setSelectedItem(target); 255 return; 256 } 257 } 258 } 259 if (add) { 260 assert items.size() == 1 : "There should be only one item in this case"; combo.addItem(items.get(0)); 262 model.setSelectedItem(items.get(0)); 263 } else { 264 model.setSelectedItem(""); } 266 } 267 268 private void initMappings(List <FreeformProjectGenerator.TargetMapping> list, String antScript) { 269 for (FreeformProjectGenerator.TargetMapping tm : list) { 270 Iterator <JComboBox > combosIt = combos.iterator(); 271 for (TargetDescriptor desc : targetDescs) { 272 JComboBox combo = combosIt.next(); 273 if (tm.name.equals(desc.getIDEActionName())) { 274 selectItem(combo, Collections.singletonList(getListAsString(tm.targets)), true); 275 checkAntScript(combo, antScript, tm.script); 276 } 277 } 278 } 279 targetMappings = list; 280 } 281 282 private void checkAntScript(JComboBox combo, String antScript, String targetScript) { 283 if ((antScript == null && targetScript == null) || 284 (antScript != null && antScript.equals(targetScript))) { 285 combo.setEnabled(true); 286 } else { 287 combo.setEnabled(false); 288 } 289 } 290 291 private static String getListAsString(List <String > list) { 292 assert list != null; 293 StringBuffer sb = new StringBuffer (); 294 Iterator <String > it = list.iterator(); 295 while (it.hasNext()) { 296 sb.append(it.next()); 297 if (it.hasNext()) { 298 sb.append(" "); } 300 } 301 return sb.toString(); 302 } 303 304 static List <String > getStringAsList(String str) { 305 List <String > l = new ArrayList <String >(2); 306 StringTokenizer tok = new StringTokenizer (str, " "); while (tok.hasMoreTokens()) { 308 String target = tok.nextToken().trim(); 309 if (target.length() == 0) { 310 continue; 311 } 312 l.add(target); 313 } 314 return l; 315 } 316 317 private void storeTarget(String key, JComboBox combo) { 318 if (combo.getModel().getSelectedItem() == null || ((String )combo.getModel().getSelectedItem()).length() == 0) { 319 removeTargetMapping(key); 320 return; 321 } 322 FreeformProjectGenerator.TargetMapping tm = getTargetMapping(key); 323 String value = (String )combo.getModel().getSelectedItem(); 324 List <String > l = getStringAsList(value); 325 if (!l.equals(tm.targets)) { 326 dirtyRegular = true; 327 } 328 tm.targets = l; 329 return; 330 } 331 332 private FreeformProjectGenerator.TargetMapping getTargetMapping(String key) { 333 for (FreeformProjectGenerator.TargetMapping tm : targetMappings) { 334 if (tm.name.equals(key)) { 335 return tm; 336 } 337 } 338 FreeformProjectGenerator.TargetMapping tm = new FreeformProjectGenerator.TargetMapping(); 339 tm.name = key; 340 tm.script = antScript; 341 targetMappings.add(tm); 342 dirtyRegular = true; 343 return tm; 344 } 345 346 private void removeTargetMapping(String key) { 347 Iterator <FreeformProjectGenerator.TargetMapping> it = targetMappings.iterator(); 348 while (it.hasNext()) { 349 if (it.next().name.equals(key)) { 350 it.remove(); 351 dirtyRegular = true; 352 return; 353 } 354 } 355 } 356 357 public List <FreeformProjectGenerator.TargetMapping> getMapping() { 358 Iterator <JComboBox > combosIt = combos.iterator(); 359 for (TargetDescriptor desc : targetDescs) { 360 JComboBox combo = combosIt.next(); 361 storeTarget(desc.getIDEActionName(), combo); 362 } 363 if (cleanCombo.getModel().getSelectedItem() != null && 365 ((String )cleanCombo.getModel().getSelectedItem()).length() > 0 && 366 buildCombo.getModel().getSelectedItem() != null && 367 ((String )buildCombo.getModel().getSelectedItem()).length() > 0) { 368 FreeformProjectGenerator.TargetMapping tm = getTargetMapping(REBUILD_ACTION); 369 String val = (String )cleanCombo.getModel().getSelectedItem() + " " + (String )buildCombo.getModel().getSelectedItem(); tm.targets = getStringAsList(val); 371 } else { 372 removeTargetMapping(REBUILD_ACTION); 373 } 374 return targetMappings; 375 } 376 377 382 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 384 385 mainLabel = new javax.swing.JLabel (); 386 additionalTargetsLabel = new javax.swing.JLabel (); 387 jScrollPane1 = new javax.swing.JScrollPane (); 388 customTargets = new javax.swing.JTable (); 389 add = new javax.swing.JButton (); 390 remove = new javax.swing.JButton (); 391 remainder = new javax.swing.JPanel (); 392 targetsPanel = new javax.swing.JPanel (); 393 buildLabel = new javax.swing.JLabel (); 394 cleanLabel = new javax.swing.JLabel (); 395 runLabel = new javax.swing.JLabel (); 396 javadocLabel = new javax.swing.JLabel (); 397 testLabel = new javax.swing.JLabel (); 398 buildCombo = new javax.swing.JComboBox (); 399 cleanCombo = new javax.swing.JComboBox (); 400 javadocCombo = new javax.swing.JComboBox (); 401 runCombo = new javax.swing.JComboBox (); 402 testCombo = new javax.swing.JComboBox (); 403 specialRemainder = new javax.swing.JPanel (); 404 405 setLayout(new java.awt.GridBagLayout ()); 406 407 setPreferredSize(new java.awt.Dimension (300, 280)); 408 mainLabel.setLabelFor(this); 409 org.openide.awt.Mnemonics.setLocalizedText(mainLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel1")); 410 gridBagConstraints = new java.awt.GridBagConstraints (); 411 gridBagConstraints.gridx = 0; 412 gridBagConstraints.gridy = 0; 413 gridBagConstraints.gridwidth = 2; 414 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 415 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 416 add(mainLabel, gridBagConstraints); 417 mainLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel1")); 418 419 additionalTargetsLabel.setLabelFor(customTargets); 420 org.openide.awt.Mnemonics.setLocalizedText(additionalTargetsLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel10")); 421 gridBagConstraints = new java.awt.GridBagConstraints (); 422 gridBagConstraints.gridx = 0; 423 gridBagConstraints.gridy = 3; 424 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 425 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 426 add(additionalTargetsLabel, gridBagConstraints); 427 additionalTargetsLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel10")); 428 429 jScrollPane1.setViewportView(customTargets); 430 431 gridBagConstraints = new java.awt.GridBagConstraints (); 432 gridBagConstraints.gridx = 0; 433 gridBagConstraints.gridy = 4; 434 gridBagConstraints.gridheight = 2; 435 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 436 gridBagConstraints.weightx = 1.0; 437 gridBagConstraints.weighty = 1.0; 438 add(jScrollPane1, gridBagConstraints); 439 440 org.openide.awt.Mnemonics.setLocalizedText(add, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "BTN_TargetMappingPanel_add")); 441 add.addActionListener(this); 442 443 gridBagConstraints = new java.awt.GridBagConstraints (); 444 gridBagConstraints.gridx = 1; 445 gridBagConstraints.gridy = 4; 446 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 447 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 448 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 449 add(add, gridBagConstraints); 450 add.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_add")); 451 452 org.openide.awt.Mnemonics.setLocalizedText(remove, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "BTN_TargetMappingPanel_remove")); 453 remove.addActionListener(this); 454 455 gridBagConstraints = new java.awt.GridBagConstraints (); 456 gridBagConstraints.gridx = 1; 457 gridBagConstraints.gridy = 5; 458 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 459 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 460 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 0); 461 add(remove, gridBagConstraints); 462 remove.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_remove")); 463 464 gridBagConstraints = new java.awt.GridBagConstraints (); 465 gridBagConstraints.gridx = 0; 466 gridBagConstraints.gridy = 6; 467 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 468 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 469 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 470 add(remainder, gridBagConstraints); 471 472 targetsPanel.setLayout(new java.awt.GridBagLayout ()); 473 474 buildLabel.setLabelFor(buildCombo); 475 org.openide.awt.Mnemonics.setLocalizedText(buildLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel2")); 476 gridBagConstraints = new java.awt.GridBagConstraints (); 477 gridBagConstraints.gridx = 0; 478 gridBagConstraints.gridy = 0; 479 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 480 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 481 targetsPanel.add(buildLabel, gridBagConstraints); 482 buildLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel2")); 483 484 cleanLabel.setLabelFor(cleanCombo); 485 org.openide.awt.Mnemonics.setLocalizedText(cleanLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel4")); 486 gridBagConstraints = new java.awt.GridBagConstraints (); 487 gridBagConstraints.gridx = 0; 488 gridBagConstraints.gridy = 1; 489 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 490 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 491 targetsPanel.add(cleanLabel, gridBagConstraints); 492 cleanLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel4")); 493 494 runLabel.setLabelFor(runCombo); 495 org.openide.awt.Mnemonics.setLocalizedText(runLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel5")); 496 gridBagConstraints = new java.awt.GridBagConstraints (); 497 gridBagConstraints.gridx = 0; 498 gridBagConstraints.gridy = 3; 499 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 500 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 501 targetsPanel.add(runLabel, gridBagConstraints); 502 runLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel5")); 503 504 javadocLabel.setLabelFor(javadocCombo); 505 org.openide.awt.Mnemonics.setLocalizedText(javadocLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel6")); 506 gridBagConstraints = new java.awt.GridBagConstraints (); 507 gridBagConstraints.gridx = 0; 508 gridBagConstraints.gridy = 2; 509 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 510 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 511 targetsPanel.add(javadocLabel, gridBagConstraints); 512 javadocLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel6")); 513 514 testLabel.setLabelFor(testCombo); 515 org.openide.awt.Mnemonics.setLocalizedText(testLabel, org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_jLabel7")); 516 gridBagConstraints = new java.awt.GridBagConstraints (); 517 gridBagConstraints.gridx = 0; 518 gridBagConstraints.gridy = 4; 519 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 520 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 521 targetsPanel.add(testLabel, gridBagConstraints); 522 testLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(TargetMappingPanel.class, "ACSD_TargetMappingPanel_jLabel7")); 523 524 buildCombo.setEditable(true); 525 gridBagConstraints = new java.awt.GridBagConstraints (); 526 gridBagConstraints.gridx = 1; 527 gridBagConstraints.gridy = 0; 528 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 529 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 530 gridBagConstraints.weightx = 1.0; 531 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 532 targetsPanel.add(buildCombo, gridBagConstraints); 533 534 cleanCombo.setEditable(true); 535 gridBagConstraints = new java.awt.GridBagConstraints (); 536 gridBagConstraints.gridx = 1; 537 gridBagConstraints.gridy = 1; 538 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 539 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 540 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 541 targetsPanel.add(cleanCombo, gridBagConstraints); 542 543 javadocCombo.setEditable(true); 544 gridBagConstraints = new java.awt.GridBagConstraints (); 545 gridBagConstraints.gridx = 1; 546 gridBagConstraints.gridy = 2; 547 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 548 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 549 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 550 targetsPanel.add(javadocCombo, gridBagConstraints); 551 552 runCombo.setEditable(true); 553 gridBagConstraints = new java.awt.GridBagConstraints (); 554 gridBagConstraints.gridx = 1; 555 gridBagConstraints.gridy = 3; 556 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 557 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 558 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 559 targetsPanel.add(runCombo, gridBagConstraints); 560 561 testCombo.setEditable(true); 562 gridBagConstraints = new java.awt.GridBagConstraints (); 563 gridBagConstraints.gridx = 1; 564 gridBagConstraints.gridy = 4; 565 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 566 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 567 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 0); 568 targetsPanel.add(testCombo, gridBagConstraints); 569 570 gridBagConstraints = new java.awt.GridBagConstraints (); 571 gridBagConstraints.gridx = 0; 572 gridBagConstraints.gridy = 1; 573 gridBagConstraints.gridwidth = 2; 574 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 575 add(targetsPanel, gridBagConstraints); 576 577 gridBagConstraints = new java.awt.GridBagConstraints (); 578 gridBagConstraints.gridx = 0; 579 gridBagConstraints.gridy = 6; 580 gridBagConstraints.gridwidth = 2; 581 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 582 gridBagConstraints.weightx = 1.0; 583 gridBagConstraints.weighty = 1.0; 584 add(specialRemainder, gridBagConstraints); 585 586 } 587 588 590 public void actionPerformed(java.awt.event.ActionEvent evt) { 591 if (evt.getSource() == add) { 592 TargetMappingPanel.this.addActionPerformed(evt); 593 } 594 else if (evt.getSource() == remove) { 595 TargetMappingPanel.this.removeActionPerformed(evt); 596 } 597 } 599 private void removeActionPerformed(java.awt.event.ActionEvent evt) { int index = customTargets.getSelectedRow(); 601 if (index == -1) { 602 return; 603 } 604 custTargets.remove(index); 605 customTargetsModel.fireTableDataChanged(); 606 dirtyCustom = true; 607 updateButtons(); 608 } 610 private void addActionPerformed(java.awt.event.ActionEvent evt) { FreeformProjectGenerator.CustomTarget ct = new FreeformProjectGenerator.CustomTarget(); 612 ct.targets = new ArrayList <String >(); 613 ct.script = antScript; 614 custTargets.add(ct); 615 customTargetsModel.fireTableDataChanged(); 616 dirtyCustom = true; 617 updateButtons(); 618 } 620 private void updateButtons() { 621 remove.setEnabled(custTargets.size() > 0); 622 } 623 624 625 ActionListener getCustomizerOkListener() { 626 return new ActionListener () { 627 public void actionPerformed(ActionEvent arg0) { 628 List <FreeformProjectGenerator.TargetMapping> mapping = getMapping(); 629 if (dirtyRegular) { 630 FreeformProjectGenerator.putTargetMappings(helper, mapping); 631 FreeformProjectGenerator.putContextMenuAction(helper, mapping); 632 } 633 634 if (dirtyCustom) { 635 List <FreeformProjectGenerator.CustomTarget> l = new ArrayList <FreeformProjectGenerator.CustomTarget>(custTargets); 636 Iterator <FreeformProjectGenerator.CustomTarget> it = l.iterator(); 637 while (it.hasNext()) { 638 FreeformProjectGenerator.CustomTarget ct = it.next(); 639 if (ct.targets == null || ct.targets.size() == 0) { 641 it.remove(); 642 continue; 643 } 644 if (ct.label == null || ct.label.length() == 0) { 645 ct.label = ct.targets.get(0); 646 } 647 } 648 FreeformProjectGenerator.putCustomContextMenuActions(helper, l); 649 } 650 } 651 }; 652 } 653 654 655 private javax.swing.JButton add; 657 private javax.swing.JLabel additionalTargetsLabel; 658 private javax.swing.JComboBox buildCombo; 659 private javax.swing.JLabel buildLabel; 660 private javax.swing.JComboBox cleanCombo; 661 private javax.swing.JLabel cleanLabel; 662 private javax.swing.JTable customTargets; 663 private javax.swing.JScrollPane jScrollPane1; 664 private javax.swing.JComboBox javadocCombo; 665 private javax.swing.JLabel javadocLabel; 666 private javax.swing.JLabel mainLabel; 667 private javax.swing.JPanel remainder; 668 private javax.swing.JButton remove; 669 private javax.swing.JComboBox runCombo; 670 private javax.swing.JLabel runLabel; 671 private javax.swing.JPanel specialRemainder; 672 private javax.swing.JPanel targetsPanel; 673 private javax.swing.JComboBox testCombo; 674 private javax.swing.JLabel testLabel; 675 677 private class CustomTargetsModel extends AbstractTableModel { 678 679 public CustomTargetsModel() { 680 } 681 682 public int getColumnCount() { 683 return 2; 684 } 685 686 public String getColumnName(int column) { 687 switch (column) { 688 case 0: return NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_Target"); 689 default: return NbBundle.getMessage(TargetMappingPanel.class, "LBL_TargetMappingPanel_Label"); 690 } 691 } 692 693 public int getRowCount() { 694 return custTargets.size(); 695 } 696 697 public boolean isCellEditable(int row, int column) { 698 if (column == 0) { 699 FreeformProjectGenerator.CustomTarget ct = getItem(row); 700 if (ct.targets != null && ct.targets.size() > 1) { 701 return false; 702 } 703 if ((antScript == null && ct.script == null) || 704 (antScript != null && antScript.equals(ct.script))) { 705 return true; 706 } else { 707 return false; 708 } 709 } 710 return true; 711 } 712 713 public Class <?> getColumnClass(int column) { 714 switch (column) { 715 case 0: return JComboBox .class; 716 default: return String .class; 717 } 718 } 719 720 public Object getValueAt(int rowIndex, int columnIndex) { 721 if (columnIndex == 0) { 722 if ((getItem(rowIndex) == null) || (getItem(rowIndex).targets == null)) { 723 return ""; } else { 725 return TargetMappingPanel.getListAsString(getItem(rowIndex).targets); 726 } 727 } else { 728 return getItem(rowIndex).label; 729 } 730 } 731 732 public void setValueAt(Object val, int rowIndex, int columnIndex) { 733 if (rowIndex >= custTargets.size ()) { 734 return ; 735 } 736 FreeformProjectGenerator.CustomTarget ct = getItem(rowIndex); 737 String v = (String ) val; 738 if (columnIndex == 0) { 739 if (v.length() > 0) { 740 ct.targets = Collections.singletonList(v); 741 } else { 742 ct.targets = null; 743 } 744 } else { 745 ct.label = v; 746 } 747 dirtyCustom = true; 748 } 749 750 } 751 752 public static void main(String [] ignore) { 754 boolean[] adv = {false, true}; 755 for (int j = 0; j < adv.length; j++) { 756 JDialog dlg = new JDialog ((Frame ) null, "advancedMode=" + adv[j], false); dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 758 TargetMappingPanel panel = new TargetMappingPanel(adv[j]); 759 panel.setTargetNames(new ArrayList <String >(Arrays.asList("build", "clean", "test")), true); dlg.getContentPane().add(panel); 761 dlg.pack(); 762 dlg.setSize(700, 500); 763 dlg.setVisible(true); 764 } 765 } 766 767 } 768 | Popular Tags |