1 19 20 package org.netbeans.modules.java.j2seproject.ui.customizer; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Comparator ; 27 import java.util.HashMap ; 28 import java.util.HashSet ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.Set ; 32 import java.util.TreeMap ; 33 import java.util.Vector ; 34 import javax.swing.ButtonModel ; 35 import javax.swing.ComboBoxModel ; 36 import javax.swing.DefaultListModel ; 37 import javax.swing.JButton ; 38 import javax.swing.JToggleButton ; 39 import javax.swing.ListCellRenderer ; 40 import javax.swing.table.DefaultTableModel ; 41 import javax.swing.text.BadLocationException ; 42 import javax.swing.text.Document ; 43 import org.netbeans.api.project.ProjectManager; 44 import org.netbeans.api.project.ProjectUtils; 45 import org.netbeans.modules.java.j2seproject.J2SEProject; 46 import org.netbeans.modules.java.j2seproject.J2SEProjectUtil; 47 import org.netbeans.modules.java.j2seproject.SourceRoots; 48 import org.netbeans.modules.java.j2seproject.UpdateHelper; 49 import org.netbeans.modules.java.j2seproject.classpath.ClassPathSupport; 50 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 51 import org.netbeans.spi.java.project.support.ui.IncludeExcludeVisualizer; 52 import org.netbeans.spi.project.support.ant.AntProjectHelper; 53 import org.netbeans.spi.project.support.ant.EditableProperties; 54 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 55 import org.netbeans.spi.project.support.ant.ReferenceHelper; 56 import org.netbeans.spi.project.support.ant.ui.StoreGroup; 57 import org.openide.DialogDisplayer; 58 import org.openide.ErrorManager; 59 import org.openide.NotifyDescriptor; 60 import org.openide.filesystems.FileObject; 61 import org.openide.filesystems.FileUtil; 62 import org.openide.util.Mutex; 63 import org.openide.util.MutexException; 64 import org.openide.util.NbBundle; 65 import org.openide.util.Utilities; 66 67 70 public class J2SEProjectProperties { 71 72 private static final Integer BOOLEAN_KIND_TF = new Integer ( 0 ); 75 private static final Integer BOOLEAN_KIND_YN = new Integer ( 1 ); 76 private static final Integer BOOLEAN_KIND_ED = new Integer ( 2 ); 77 private Integer javacDebugBooleanKind; 78 private Integer javadocPreviewBooleanKind; 79 80 public static final String J2SE_PROJECT_NAME = "j2se.project.name"; public static final String JAVA_PLATFORM = "platform.active"; 84 public static final String DIST_DIR = "dist.dir"; public static final String DIST_JAR = "dist.jar"; public static final String JAVAC_CLASSPATH = "javac.classpath"; public static final String RUN_CLASSPATH = "run.classpath"; public static final String RUN_JVM_ARGS = "run.jvmargs"; public static final String RUN_WORK_DIR = "work.dir"; public static final String DEBUG_CLASSPATH = "debug.classpath"; public static final String JAR_COMPRESS = "jar.compress"; public static final String MAIN_CLASS = "main.class"; public static final String JAVAC_SOURCE = "javac.source"; public static final String JAVAC_TARGET = "javac.target"; public static final String JAVAC_TEST_CLASSPATH = "javac.test.classpath"; public static final String JAVAC_DEBUG = "javac.debug"; public static final String JAVAC_DEPRECATION = "javac.deprecation"; public static final String JAVAC_COMPILER_ARG = "javac.compilerargs"; public static final String RUN_TEST_CLASSPATH = "run.test.classpath"; public static final String BUILD_DIR = "build.dir"; public static final String BUILD_CLASSES_DIR = "build.classes.dir"; public static final String BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; public static final String BUILD_TEST_RESULTS_DIR = "build.test.results.dir"; public static final String BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; public static final String DIST_JAVADOC_DIR = "dist.javadoc.dir"; public static final String NO_DEPENDENCIES="no.dependencies"; public static final String DEBUG_TEST_CLASSPATH = "debug.test.classpath"; 110 public static final String INCLUDES = "includes"; 112 public static final String EXCLUDES = "excludes"; 114 public static final String JAVADOC_PRIVATE="javadoc.private"; public static final String JAVADOC_NO_TREE="javadoc.notree"; public static final String JAVADOC_USE="javadoc.use"; public static final String JAVADOC_NO_NAVBAR="javadoc.nonavbar"; public static final String JAVADOC_NO_INDEX="javadoc.noindex"; public static final String JAVADOC_SPLIT_INDEX="javadoc.splitindex"; public static final String JAVADOC_AUTHOR="javadoc.author"; public static final String JAVADOC_VERSION="javadoc.version"; public static final String JAVADOC_WINDOW_TITLE="javadoc.windowtitle"; public static final String JAVADOC_ENCODING="javadoc.encoding"; public static final String JAVADOC_ADDITIONALPARAM="javadoc.additionalparam"; 126 public static final String APPLICATION_TITLE ="application.title"; public static final String APPLICATION_VENDOR ="application.vendor"; public static final String APPLICATION_DESC ="application.desc"; public static final String APPLICATION_HOMEPAGE ="application.homepage"; public static final String APPLICATION_SPLASH ="application.splash"; 132 public static final String APPLICATION_ARGS = "application.args"; public static final String JAVADOC_PREVIEW="javadoc.preview"; 136 137 public static final String [] WELL_KNOWN_PATHS = new String [] { 139 "${" + JAVAC_CLASSPATH + "}", 140 "${" + JAVAC_TEST_CLASSPATH + "}", 141 "${" + RUN_CLASSPATH + "}", 142 "${" + RUN_TEST_CLASSPATH + "}", 143 "${" + BUILD_CLASSES_DIR + "}", 144 "${" + BUILD_TEST_CLASSES_DIR + "}", 145 }; 146 147 public static final String LIBRARY_PREFIX = "${libs."; public static final String LIBRARY_SUFFIX = ".classpath}"; public static final String ANT_ARTIFACT_PREFIX = "${reference."; 153 ClassPathSupport cs; 154 155 156 160 162 DefaultTableModel SOURCE_ROOTS_MODEL; 164 DefaultTableModel TEST_ROOTS_MODEL; 165 ComboBoxModel JAVAC_SOURCE_MODEL; 166 167 DefaultListModel JAVAC_CLASSPATH_MODEL; 169 DefaultListModel JAVAC_TEST_CLASSPATH_MODEL; 170 DefaultListModel RUN_CLASSPATH_MODEL; 171 DefaultListModel RUN_TEST_CLASSPATH_MODEL; 172 ComboBoxModel PLATFORM_MODEL; 173 ListCellRenderer CLASS_PATH_LIST_RENDERER; 174 ListCellRenderer PLATFORM_LIST_RENDERER; 175 ListCellRenderer JAVAC_SOURCE_RENDERER; 176 177 ButtonModel JAVAC_DEPRECATION_MODEL; 179 ButtonModel JAVAC_DEBUG_MODEL; 180 ButtonModel NO_DEPENDENCIES_MODEL; 181 Document JAVAC_COMPILER_ARG_MODEL; 182 183 185 Document DIST_JAR_MODEL; 187 Document BUILD_CLASSES_EXCLUDES_MODEL; 188 ButtonModel JAR_COMPRESS_MODEL; 189 190 ButtonModel JAVADOC_PRIVATE_MODEL; 192 ButtonModel JAVADOC_NO_TREE_MODEL; 193 ButtonModel JAVADOC_USE_MODEL; 194 ButtonModel JAVADOC_NO_NAVBAR_MODEL; 195 ButtonModel JAVADOC_NO_INDEX_MODEL; 196 ButtonModel JAVADOC_SPLIT_INDEX_MODEL; 197 ButtonModel JAVADOC_AUTHOR_MODEL; 198 ButtonModel JAVADOC_VERSION_MODEL; 199 Document JAVADOC_WINDOW_TITLE_MODEL; 200 ButtonModel JAVADOC_PREVIEW_MODEL; 201 Document JAVADOC_ADDITIONALPARAM_MODEL; 202 203 Map <String ,Map <String ,String >> RUN_CONFIGS; 205 String activeConfig; 206 207 Document APPLICATION_TITLE_DOC; 209 Document APPLICATION_VENDOR_DOC; 210 Document APPLICATION_DESC_DOC; 211 Document APPLICATION_HOMEPAGE_DOC; 212 Document APPLICATION_SPLASH_DOC; 213 214 216 private J2SEProject project; 218 private UpdateHelper updateHelper; 219 private PropertyEvaluator evaluator; 220 private ReferenceHelper refHelper; 221 private GeneratedFilesHelper genFileHelper; 222 223 private StoreGroup privateGroup; 224 private StoreGroup projectGroup; 225 226 private Map <String ,String > additionalProperties; 227 228 private String includes, excludes; 229 230 J2SEProject getProject() { 231 return project; 232 } 233 234 235 public J2SEProjectProperties( J2SEProject project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper ) { 236 this.project = project; 237 this.updateHelper = updateHelper; 238 this.evaluator = evaluator; 239 this.refHelper = refHelper; 240 this.genFileHelper = genFileHelper; 241 this.cs = new ClassPathSupport( evaluator, refHelper, updateHelper.getAntProjectHelper(), WELL_KNOWN_PATHS, LIBRARY_PREFIX, LIBRARY_SUFFIX, ANT_ARTIFACT_PREFIX ); 242 243 privateGroup = new StoreGroup(); 244 projectGroup = new StoreGroup(); 245 246 additionalProperties = new HashMap <String ,String >(); 247 248 init(); } 250 251 253 private void init() { 254 255 CLASS_PATH_LIST_RENDERER = new J2SEClassPathUi.ClassPathListCellRenderer( evaluator ); 256 257 SOURCE_ROOTS_MODEL = J2SESourceRootsUi.createModel( project.getSourceRoots() ); 259 TEST_ROOTS_MODEL = J2SESourceRootsUi.createModel( project.getTestSourceRoots() ); 260 includes = evaluator.getProperty(INCLUDES); 261 if (includes == null) { 262 includes = "**"; } 264 excludes = evaluator.getProperty(EXCLUDES); 265 if (excludes == null) { 266 excludes = ""; } 268 269 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 271 272 JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_CLASSPATH ) ) ); 273 JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( JAVAC_TEST_CLASSPATH ) ) ); 274 RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_CLASSPATH ) ) ); 275 RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String )projectProperties.get( RUN_TEST_CLASSPATH ) ) ); 276 PLATFORM_MODEL = PlatformUiSupport.createPlatformComboBoxModel (evaluator.getProperty(JAVA_PLATFORM)); 277 PLATFORM_LIST_RENDERER = PlatformUiSupport.createPlatformListCellRenderer(); 278 JAVAC_SOURCE_MODEL = PlatformUiSupport.createSourceLevelComboBoxModel (PLATFORM_MODEL, evaluator.getProperty(JAVAC_SOURCE)); 279 JAVAC_SOURCE_RENDERER = PlatformUiSupport.createSourceLevelListCellRenderer (); 280 281 JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION ); 283 284 Integer [] kind = new Integer [1]; 287 JAVAC_DEBUG_MODEL = createToggleButtonModel( evaluator, JAVAC_DEBUG, kind); 288 javacDebugBooleanKind = kind[0]; 289 290 NO_DEPENDENCIES_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, NO_DEPENDENCIES ); 291 JAVAC_COMPILER_ARG_MODEL = projectGroup.createStringDocument( evaluator, JAVAC_COMPILER_ARG ); 292 293 DIST_JAR_MODEL = projectGroup.createStringDocument( evaluator, DIST_JAR ); 295 BUILD_CLASSES_EXCLUDES_MODEL = projectGroup.createStringDocument( evaluator, BUILD_CLASSES_EXCLUDES ); 296 JAR_COMPRESS_MODEL = projectGroup.createToggleButtonModel( evaluator, JAR_COMPRESS ); 297 298 JAVADOC_PRIVATE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_PRIVATE ); 300 JAVADOC_NO_TREE_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_TREE ); 301 JAVADOC_USE_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_USE ); 302 JAVADOC_NO_NAVBAR_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_NAVBAR ); 303 JAVADOC_NO_INDEX_MODEL = projectGroup.createInverseToggleButtonModel( evaluator, JAVADOC_NO_INDEX ); 304 JAVADOC_SPLIT_INDEX_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_SPLIT_INDEX ); 305 JAVADOC_AUTHOR_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_AUTHOR ); 306 JAVADOC_VERSION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVADOC_VERSION ); 307 JAVADOC_WINDOW_TITLE_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_WINDOW_TITLE ); 308 JAVADOC_PREVIEW_MODEL = createToggleButtonModel ( evaluator, JAVADOC_PREVIEW, kind); 311 javadocPreviewBooleanKind = kind[0]; 312 313 JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM ); 314 315 APPLICATION_TITLE_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_TITLE); 317 String title = evaluator.getProperty("application.title"); 318 if (title == null) { 319 try { 320 APPLICATION_TITLE_DOC.insertString(0, ProjectUtils.getInformation(project).getDisplayName(), null); 321 } catch (BadLocationException ex) { 322 } 324 } 325 APPLICATION_VENDOR_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_VENDOR); 326 String vendor = evaluator.getProperty("application.vendor"); 327 if (vendor == null) { 328 try { 329 APPLICATION_VENDOR_DOC.insertString(0, System.getProperty("user.name", "User Name"), null); 330 } catch (BadLocationException ex) { 331 } 333 } 334 APPLICATION_DESC_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_DESC); 335 APPLICATION_HOMEPAGE_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_HOMEPAGE); 336 APPLICATION_SPLASH_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_SPLASH); 337 338 RUN_CONFIGS = readRunConfigs(); 340 activeConfig = evaluator.getProperty("config"); 341 342 } 343 344 public void save() { 345 try { 346 boolean result = ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Boolean >() { 348 final FileObject projectDir = updateHelper.getAntProjectHelper().getProjectDirectory(); 349 public Boolean run() throws IOException { 350 if ((genFileHelper.getBuildScriptState(GeneratedFilesHelper.BUILD_IMPL_XML_PATH, 351 J2SEProject.class.getResource("resources/build-impl.xsl"), findJaxWsFileObject(projectDir)) 353 & GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) { if (showModifiedMessage (NbBundle.getMessage(J2SEProjectProperties.class,"TXT_ModifiedTitle"))) { 355 FileObject fo = projectDir.getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH); 357 if (fo != null) { 358 fo.delete(); 359 } 360 } 361 else { 362 return false; 363 } 364 } 365 storeProperties(); 366 return true; 367 } 368 }); 369 if (result) { 371 ProjectManager.getDefault().saveProject(project); 372 } 373 } 374 catch (MutexException e) { 375 ErrorManager.getDefault().notify((IOException )e.getException()); 376 } 377 catch ( IOException ex ) { 378 ErrorManager.getDefault().notify( ex ); 379 } 380 } 381 382 383 384 private void storeProperties() throws IOException { 385 387 resolveProjectDependencies(); 389 390 String [] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL ) ); 392 String [] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ) ); 393 String [] run_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_CLASSPATH_MODEL ) ); 394 String [] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ) ); 395 396 storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL ); 398 storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL ); 399 400 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 402 EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH ); 403 404 if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) { 406 JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); } 408 409 projectGroup.store( projectProperties ); 411 privateGroup.store( privateProperties ); 412 413 storeRunConfigs(RUN_CONFIGS, projectProperties, privateProperties); 414 EditableProperties ep = updateHelper.getProperties("nbproject/private/config.properties"); 415 if (activeConfig == null) { 416 ep.remove("config"); 417 } else { 418 ep.setProperty("config", activeConfig); 419 } 420 updateHelper.putProperties("nbproject/private/config.properties", ep); 421 422 privateProperties.setProperty(JAVAC_DEBUG, encodeBoolean (JAVAC_DEBUG_MODEL.isSelected(), javacDebugBooleanKind)); 426 427 privateProperties.setProperty(JAVADOC_PREVIEW, encodeBoolean (JAVADOC_PREVIEW_MODEL.isSelected(), javadocPreviewBooleanKind)); 431 432 projectProperties.setProperty( JAVAC_CLASSPATH, javac_cp ); 434 projectProperties.setProperty( JAVAC_TEST_CLASSPATH, javac_test_cp ); 435 projectProperties.setProperty( RUN_CLASSPATH, run_cp ); 436 projectProperties.setProperty( RUN_TEST_CLASSPATH, run_test_cp ); 437 438 PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem()); 440 441 if ( NO_DEPENDENCIES_MODEL.isSelected() ) { projectProperties.remove( NO_DEPENDENCIES ); } 445 446 projectProperties.putAll(additionalProperties); 447 448 projectProperties.put(INCLUDES, includes); 449 projectProperties.put(EXCLUDES, excludes); 450 451 updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties ); 453 updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties ); 454 455 } 456 457 460 private void resolveProjectDependencies() { 461 462 Set oldArtifacts = new HashSet (); 464 EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 465 oldArtifacts.addAll( cs.itemsList( projectProperties.get( JAVAC_CLASSPATH ) ) ); 466 oldArtifacts.addAll( cs.itemsList( projectProperties.get( JAVAC_TEST_CLASSPATH ) ) ); 467 oldArtifacts.addAll( cs.itemsList( projectProperties.get( RUN_CLASSPATH ) ) ); 468 oldArtifacts.addAll( cs.itemsList( projectProperties.get( RUN_TEST_CLASSPATH ) ) ); 469 470 Set newArtifacts = new HashSet (); 471 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_CLASSPATH_MODEL ) ); 472 newArtifacts.addAll( ClassPathUiSupport.getList( JAVAC_TEST_CLASSPATH_MODEL ) ); 473 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_CLASSPATH_MODEL ) ); 474 newArtifacts.addAll( ClassPathUiSupport.getList( RUN_TEST_CLASSPATH_MODEL ) ); 475 476 Set removed = new HashSet ( oldArtifacts ); 478 removed.removeAll( newArtifacts ); 479 Set added = new HashSet (newArtifacts); 480 added.removeAll(oldArtifacts); 481 482 for( Iterator it = removed.iterator(); it.hasNext(); ) { 485 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 486 if ( item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT || 487 item.getType() == ClassPathSupport.Item.TYPE_JAR ) { 488 refHelper.destroyReference(item.getReference()); 489 } 490 } 491 492 EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH ); 494 boolean changed = false; 495 496 for( Iterator it = removed.iterator(); it.hasNext(); ) { 497 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 498 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) { 499 String prop = item.getReference(); 501 prop = ClassPathSupport.getAntPropertyName(prop); 502 ep.remove(prop); 503 changed = true; 504 } 505 } 506 for( Iterator it = added.iterator(); it.hasNext(); ) { 507 ClassPathSupport.Item item = (ClassPathSupport.Item)it.next(); 508 if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY && !item.isBroken()) { 509 String prop = cs.getLibraryReference( item ); 512 prop = ClassPathSupport.getAntPropertyName(prop); 513 changed |= ClassPathSupport.relativizeLibraryClassPath(ep,updateHelper.getAntProjectHelper(),prop); 514 } 515 } 516 if (changed) { 517 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 518 } 519 } 520 521 private void storeRoots( SourceRoots roots, DefaultTableModel tableModel ) throws MalformedURLException { 522 Vector data = tableModel.getDataVector(); 523 URL [] rootURLs = new URL [data.size()]; 524 String []rootLabels = new String [data.size()]; 525 for (int i=0; i<data.size();i++) { 526 File f = (File ) ((Vector )data.elementAt(i)).elementAt(0); 527 rootURLs[i] = J2SEProjectUtil.getRootURL(f,null); 528 rootLabels[i] = (String ) ((Vector )data.elementAt(i)).elementAt(1); 529 } 530 roots.putRoots(rootURLs,rootLabels); 531 } 532 533 534 public void putAdditionalProperty(String propertyName, String propertyValue) { 535 additionalProperties.put(propertyName, propertyValue); 536 } 537 538 private static boolean showModifiedMessage (String title) { 539 String message = NbBundle.getMessage(J2SEProjectProperties.class,"TXT_Regenerate"); 540 JButton regenerateButton = new JButton (NbBundle.getMessage(J2SEProjectProperties.class,"CTL_RegenerateButton")); 541 regenerateButton.setDefaultCapable(true); 542 regenerateButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(J2SEProjectProperties.class,"AD_RegenerateButton")); 543 NotifyDescriptor d = new NotifyDescriptor.Message (message, NotifyDescriptor.WARNING_MESSAGE); 544 d.setTitle(title); 545 d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION); 546 d.setOptions(new Object [] {regenerateButton, NotifyDescriptor.CANCEL_OPTION}); 547 return DialogDisplayer.getDefault().notify(d) == regenerateButton; 548 } 549 550 private static String encodeBoolean (boolean value, Integer kind) { 553 if ( kind == BOOLEAN_KIND_ED ) { 554 return value ? "on" : "off"; } 556 else if ( kind == BOOLEAN_KIND_YN ) { return value ? "yes" : "no"; 558 } 559 else { 560 return value ? "true" : "false"; } 562 } 563 564 private static JToggleButton.ToggleButtonModel createToggleButtonModel (final PropertyEvaluator evaluator, final String propName, Integer [] kind) { 567 assert evaluator != null && propName != null && kind != null && kind.length == 1; 568 String value = evaluator.getProperty( propName ); 569 boolean isSelected = false; 570 if (value == null) { 571 isSelected = true; 572 } 573 else { 574 String lowercaseValue = value.toLowerCase(); 575 if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { kind[0] = BOOLEAN_KIND_YN; 577 } 578 else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { kind[0] = BOOLEAN_KIND_ED; 580 } 581 else { 582 kind[0] = BOOLEAN_KIND_TF; 583 } 584 585 if ( lowercaseValue.equals( "true") || lowercaseValue.equals( "yes") || lowercaseValue.equals( "on") ) { isSelected = true; 589 } 590 } 591 JToggleButton.ToggleButtonModel bm = new JToggleButton.ToggleButtonModel (); 592 bm.setSelected(isSelected ); 593 return bm; 594 } 595 596 599 Map <String ,Map <String ,String >> readRunConfigs() { 600 Map <String ,Map <String ,String >> m = new TreeMap <String ,Map <String ,String >>(new Comparator <String >() { 601 public int compare(String s1, String s2) { 602 return s1 != null ? (s2 != null ? s1.compareTo(s2) : 1) : (s2 != null ? -1 : 0); 603 } 604 }); 605 Map <String ,String > def = new TreeMap <String ,String >(); 606 for (String prop : new String [] {MAIN_CLASS, APPLICATION_ARGS, RUN_JVM_ARGS, RUN_WORK_DIR}) { 607 String v = updateHelper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH).getProperty(prop); 608 if (v == null) { 609 v = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH).getProperty(prop); 610 } 611 if (v != null) { 612 def.put(prop, v); 613 } 614 } 615 m.put(null, def); 616 FileObject configs = project.getProjectDirectory().getFileObject("nbproject/configs"); 617 if (configs != null) { 618 for (FileObject kid : configs.getChildren()) { 619 if (!kid.hasExt("properties")) { 620 continue; 621 } 622 m.put(kid.getName(), new TreeMap <String ,String >(updateHelper.getProperties(FileUtil.getRelativePath(project.getProjectDirectory(), kid)))); 623 } 624 } 625 configs = project.getProjectDirectory().getFileObject("nbproject/private/configs"); 626 if (configs != null) { 627 for (FileObject kid : configs.getChildren()) { 628 if (!kid.hasExt("properties")) { 629 continue; 630 } 631 Map <String ,String > c = m.get(kid.getName()); 632 if (c == null) { 633 continue; 634 } 635 c.putAll(new HashMap <String ,String >(updateHelper.getProperties(FileUtil.getRelativePath(project.getProjectDirectory(), kid)))); 636 } 637 } 638 return m; 640 } 641 642 645 void storeRunConfigs(Map <String ,Map <String ,String >> configs, 646 EditableProperties projectProperties, EditableProperties privateProperties) throws IOException { 647 Map <String ,String > def = configs.get(null); 649 for (String prop : new String [] {MAIN_CLASS, APPLICATION_ARGS, RUN_JVM_ARGS, RUN_WORK_DIR}) { 650 String v = def.get(prop); 651 EditableProperties ep = (prop.equals(APPLICATION_ARGS) || prop.equals(RUN_WORK_DIR)) ? 652 privateProperties : projectProperties; 653 if (!Utilities.compareObjects(v, ep.getProperty(prop))) { 654 if (v != null && v.length() > 0) { 655 ep.setProperty(prop, v); 656 } else { 657 ep.remove(prop); 658 } 659 } 660 } 661 for (Map.Entry <String ,Map <String ,String >> entry : configs.entrySet()) { 662 String config = entry.getKey(); 663 if (config == null) { 664 continue; 665 } 666 String sharedPath = "nbproject/configs/" + config + ".properties"; String privatePath = "nbproject/private/configs/" + config + ".properties"; Map <String ,String > c = entry.getValue(); 669 if (c == null) { 670 updateHelper.putProperties(sharedPath, null); 671 updateHelper.putProperties(privatePath, null); 672 continue; 673 } 674 for (Map.Entry <String ,String > entry2 : c.entrySet()) { 675 String prop = entry2.getKey(); 676 String v = entry2.getValue(); 677 String path = (prop.equals(APPLICATION_ARGS) || prop.equals(RUN_WORK_DIR)) ? 678 privatePath : sharedPath; 679 EditableProperties ep = updateHelper.getProperties(path); 680 if (!Utilities.compareObjects(v, ep.getProperty(prop))) { 681 if (v != null && (v.length() > 0 || (def.get(prop) != null && def.get(prop).length() > 0))) { 682 ep.setProperty(prop, v); 683 } else { 684 ep.remove(prop); 685 } 686 updateHelper.putProperties(path, ep); 687 } 688 } 689 updateHelper.putProperties(sharedPath, updateHelper.getProperties(sharedPath)); 691 } 692 } 693 694 private FileObject findJaxWsFileObject(FileObject projectDir) { 695 return projectDir.getFileObject(GeneratedFilesHelper.JAX_WS_XML_PATH); 696 } 697 698 void loadIncludesExcludes(IncludeExcludeVisualizer v) { 699 Set <File > roots = new HashSet <File >(); 700 for (DefaultTableModel model : new DefaultTableModel [] {SOURCE_ROOTS_MODEL, TEST_ROOTS_MODEL}) { 701 for (Object row : model.getDataVector()) { 702 roots.add((File ) ((Vector ) row).elementAt(0)); 703 } 704 } 705 v.setRoots(roots.toArray(new File [roots.size()])); 706 v.setIncludePattern(includes); 707 v.setExcludePattern(excludes); 708 } 709 710 void storeIncludesExcludes(IncludeExcludeVisualizer v) { 711 includes = v.getIncludePattern(); 712 excludes = v.getExcludePattern(); 713 } 714 715 } 716 | Popular Tags |