KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > customizer > J2SEProjectProperties


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seproject.ui.customizer;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.net.MalformedURLException JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.util.Comparator JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.util.TreeMap JavaDoc;
33 import java.util.Vector JavaDoc;
34 import javax.swing.ButtonModel JavaDoc;
35 import javax.swing.ComboBoxModel JavaDoc;
36 import javax.swing.DefaultListModel JavaDoc;
37 import javax.swing.JButton JavaDoc;
38 import javax.swing.JToggleButton JavaDoc;
39 import javax.swing.ListCellRenderer JavaDoc;
40 import javax.swing.table.DefaultTableModel JavaDoc;
41 import javax.swing.text.BadLocationException JavaDoc;
42 import javax.swing.text.Document JavaDoc;
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 /**
68  * @author Petr Hrebejk
69  */

70 public class J2SEProjectProperties {
71     
72     //Hotfix of the issue #70058
73
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
74
private static final Integer JavaDoc BOOLEAN_KIND_TF = new Integer JavaDoc( 0 );
75     private static final Integer JavaDoc BOOLEAN_KIND_YN = new Integer JavaDoc( 1 );
76     private static final Integer JavaDoc BOOLEAN_KIND_ED = new Integer JavaDoc( 2 );
77     private Integer JavaDoc javacDebugBooleanKind;
78     private Integer JavaDoc javadocPreviewBooleanKind;
79     
80     // Special properties of the project
81
public static final String JavaDoc J2SE_PROJECT_NAME = "j2se.project.name"; // NOI18N
82
public static final String JavaDoc JAVA_PLATFORM = "platform.active"; // NOI18N
83

84     // Properties stored in the PROJECT.PROPERTIES
85
public static final String JavaDoc DIST_DIR = "dist.dir"; // NOI18N
86
public static final String JavaDoc DIST_JAR = "dist.jar"; // NOI18N
87
public static final String JavaDoc JAVAC_CLASSPATH = "javac.classpath"; // NOI18N
88
public static final String JavaDoc RUN_CLASSPATH = "run.classpath"; // NOI18N
89
public static final String JavaDoc RUN_JVM_ARGS = "run.jvmargs"; // NOI18N
90
public static final String JavaDoc RUN_WORK_DIR = "work.dir"; // NOI18N
91
public static final String JavaDoc DEBUG_CLASSPATH = "debug.classpath"; // NOI18N
92
public static final String JavaDoc JAR_COMPRESS = "jar.compress"; // NOI18N
93
public static final String JavaDoc MAIN_CLASS = "main.class"; // NOI18N
94
public static final String JavaDoc JAVAC_SOURCE = "javac.source"; // NOI18N
95
public static final String JavaDoc JAVAC_TARGET = "javac.target"; // NOI18N
96
public static final String JavaDoc JAVAC_TEST_CLASSPATH = "javac.test.classpath"; // NOI18N
97
public static final String JavaDoc JAVAC_DEBUG = "javac.debug"; // NOI18N
98
public static final String JavaDoc JAVAC_DEPRECATION = "javac.deprecation"; // NOI18N
99
public static final String JavaDoc JAVAC_COMPILER_ARG = "javac.compilerargs"; //NOI18N
100
public static final String JavaDoc RUN_TEST_CLASSPATH = "run.test.classpath"; // NOI18N
101
public static final String JavaDoc BUILD_DIR = "build.dir"; // NOI18N
102
public static final String JavaDoc BUILD_CLASSES_DIR = "build.classes.dir"; // NOI18N
103
public static final String JavaDoc BUILD_TEST_CLASSES_DIR = "build.test.classes.dir"; // NOI18N
104
public static final String JavaDoc BUILD_TEST_RESULTS_DIR = "build.test.results.dir"; // NOI18N
105
public static final String JavaDoc BUILD_CLASSES_EXCLUDES = "build.classes.excludes"; // NOI18N
106
public static final String JavaDoc DIST_JAVADOC_DIR = "dist.javadoc.dir"; // NOI18N
107
public static final String JavaDoc NO_DEPENDENCIES="no.dependencies"; // NOI18N
108
public static final String JavaDoc DEBUG_TEST_CLASSPATH = "debug.test.classpath"; // NOI18N
109
/** @since org.netbeans.modules.java.j2seproject/1 1.11 */
110     public static final String JavaDoc INCLUDES = "includes"; // NOI18N
111
/** @since org.netbeans.modules.java.j2seproject/1 1.11 */
112     public static final String JavaDoc EXCLUDES = "excludes"; // NOI18N
113

114     public static final String JavaDoc JAVADOC_PRIVATE="javadoc.private"; // NOI18N
115
public static final String JavaDoc JAVADOC_NO_TREE="javadoc.notree"; // NOI18N
116
public static final String JavaDoc JAVADOC_USE="javadoc.use"; // NOI18N
117
public static final String JavaDoc JAVADOC_NO_NAVBAR="javadoc.nonavbar"; // NOI18N
118
public static final String JavaDoc JAVADOC_NO_INDEX="javadoc.noindex"; // NOI18N
119
public static final String JavaDoc JAVADOC_SPLIT_INDEX="javadoc.splitindex"; // NOI18N
120
public static final String JavaDoc JAVADOC_AUTHOR="javadoc.author"; // NOI18N
121
public static final String JavaDoc JAVADOC_VERSION="javadoc.version"; // NOI18N
122
public static final String JavaDoc JAVADOC_WINDOW_TITLE="javadoc.windowtitle"; // NOI18N
123
public static final String JavaDoc JAVADOC_ENCODING="javadoc.encoding"; // NOI18N
124
public static final String JavaDoc JAVADOC_ADDITIONALPARAM="javadoc.additionalparam"; // NOI18N
125

126     public static final String JavaDoc APPLICATION_TITLE ="application.title"; // NOI18N
127
public static final String JavaDoc APPLICATION_VENDOR ="application.vendor"; // NOI18N
128
public static final String JavaDoc APPLICATION_DESC ="application.desc"; // NOI18N
129
public static final String JavaDoc APPLICATION_HOMEPAGE ="application.homepage"; // NOI18N
130
public static final String JavaDoc APPLICATION_SPLASH ="application.splash"; // NOI18N
131

132     // Properties stored in the PRIVATE.PROPERTIES
133
public static final String JavaDoc APPLICATION_ARGS = "application.args"; // NOI18N
134
public static final String JavaDoc JAVADOC_PREVIEW="javadoc.preview"; // NOI18N
135

136     
137     // Well known paths
138
public static final String JavaDoc[] WELL_KNOWN_PATHS = new String JavaDoc[] {
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     // Prefixes and suffixes of classpath
148
public static final String JavaDoc LIBRARY_PREFIX = "${libs."; // NOI18N
149
public static final String JavaDoc LIBRARY_SUFFIX = ".classpath}"; // NOI18N
150
// XXX looks like there is some kind of API missing in ReferenceHelper?
151
public static final String JavaDoc ANT_ARTIFACT_PREFIX = "${reference."; // NOI18N
152

153     ClassPathSupport cs;
154     
155     
156     // SOURCE ROOTS
157
// public static final String SOURCE_ROOTS = "__virtual_source_roots__"; //NOI18N
158
// public static final String TEST_ROOTS = "__virtual_test_roots__"; // NOI18N
159

160     // MODELS FOR VISUAL CONTROLS
161

162     // CustomizerSources
163
DefaultTableModel JavaDoc SOURCE_ROOTS_MODEL;
164     DefaultTableModel JavaDoc TEST_ROOTS_MODEL;
165     ComboBoxModel JavaDoc JAVAC_SOURCE_MODEL;
166      
167     // CustomizerLibraries
168
DefaultListModel JavaDoc JAVAC_CLASSPATH_MODEL;
169     DefaultListModel JavaDoc JAVAC_TEST_CLASSPATH_MODEL;
170     DefaultListModel JavaDoc RUN_CLASSPATH_MODEL;
171     DefaultListModel JavaDoc RUN_TEST_CLASSPATH_MODEL;
172     ComboBoxModel JavaDoc PLATFORM_MODEL;
173     ListCellRenderer JavaDoc CLASS_PATH_LIST_RENDERER;
174     ListCellRenderer JavaDoc PLATFORM_LIST_RENDERER;
175     ListCellRenderer JavaDoc JAVAC_SOURCE_RENDERER;
176     
177     // CustomizerCompile
178
ButtonModel JavaDoc JAVAC_DEPRECATION_MODEL;
179     ButtonModel JavaDoc JAVAC_DEBUG_MODEL;
180     ButtonModel JavaDoc NO_DEPENDENCIES_MODEL;
181     Document JavaDoc JAVAC_COMPILER_ARG_MODEL;
182     
183     // CustomizerCompileTest
184

185     // CustomizerJar
186
Document JavaDoc DIST_JAR_MODEL;
187     Document JavaDoc BUILD_CLASSES_EXCLUDES_MODEL;
188     ButtonModel JavaDoc JAR_COMPRESS_MODEL;
189                 
190     // CustomizerJavadoc
191
ButtonModel JavaDoc JAVADOC_PRIVATE_MODEL;
192     ButtonModel JavaDoc JAVADOC_NO_TREE_MODEL;
193     ButtonModel JavaDoc JAVADOC_USE_MODEL;
194     ButtonModel JavaDoc JAVADOC_NO_NAVBAR_MODEL;
195     ButtonModel JavaDoc JAVADOC_NO_INDEX_MODEL;
196     ButtonModel JavaDoc JAVADOC_SPLIT_INDEX_MODEL;
197     ButtonModel JavaDoc JAVADOC_AUTHOR_MODEL;
198     ButtonModel JavaDoc JAVADOC_VERSION_MODEL;
199     Document JavaDoc JAVADOC_WINDOW_TITLE_MODEL;
200     ButtonModel JavaDoc JAVADOC_PREVIEW_MODEL;
201     Document JavaDoc JAVADOC_ADDITIONALPARAM_MODEL;
202
203     // CustomizerRun
204
Map JavaDoc<String JavaDoc/*|null*/,Map JavaDoc<String JavaDoc,String JavaDoc/*|null*/>/*|null*/> RUN_CONFIGS;
205     String JavaDoc activeConfig;
206     
207     // CustomizerApplication
208
Document JavaDoc APPLICATION_TITLE_DOC;
209     Document JavaDoc APPLICATION_VENDOR_DOC;
210     Document JavaDoc APPLICATION_DESC_DOC;
211     Document JavaDoc APPLICATION_HOMEPAGE_DOC;
212     Document JavaDoc APPLICATION_SPLASH_DOC;
213     
214     // CustomizerRunTest
215

216     // Private fields ----------------------------------------------------------
217
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 JavaDoc<String JavaDoc,String JavaDoc> additionalProperties;
227
228     private String JavaDoc includes, excludes;
229     
230     J2SEProject getProject() {
231         return project;
232     }
233     
234     /** Creates a new instance of J2SEUIProperties and initializes them */
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 JavaDoc<String JavaDoc,String JavaDoc>();
247         
248         init(); // Load known properties
249
}
250
251     /** Initializes the visual models
252      */

253     private void init() {
254         
255         CLASS_PATH_LIST_RENDERER = new J2SEClassPathUi.ClassPathListCellRenderer( evaluator );
256         
257         // CustomizerSources
258
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 = "**"; // NOI18N
263
}
264         excludes = evaluator.getProperty(EXCLUDES);
265         if (excludes == null) {
266             excludes = ""; // NOI18N
267
}
268                 
269         // CustomizerLibraries
270
EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
271         
272         JAVAC_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( JAVAC_CLASSPATH ) ) );
273         JAVAC_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( JAVAC_TEST_CLASSPATH ) ) );
274         RUN_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)projectProperties.get( RUN_CLASSPATH ) ) );
275         RUN_TEST_CLASSPATH_MODEL = ClassPathUiSupport.createListModel( cs.itemsIterator( (String JavaDoc)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         // CustomizerCompile
282
JAVAC_DEPRECATION_MODEL = projectGroup.createToggleButtonModel( evaluator, JAVAC_DEPRECATION );
283                 
284         //Hotfix of the issue #70058
285
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
286
Integer JavaDoc[] kind = new Integer JavaDoc[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         // CustomizerJar
294
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         // CustomizerJavadoc
299
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         //Hotfix of the issue #70058
309
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
310
JAVADOC_PREVIEW_MODEL = createToggleButtonModel ( evaluator, JAVADOC_PREVIEW, kind);
311         javadocPreviewBooleanKind = kind[0];
312         
313         JAVADOC_ADDITIONALPARAM_MODEL = projectGroup.createStringDocument( evaluator, JAVADOC_ADDITIONALPARAM );
314         
315         // CustomizerApplication
316
APPLICATION_TITLE_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_TITLE);
317         String JavaDoc 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 JavaDoc ex) {
322                 // just do not set anything
323
}
324         }
325         APPLICATION_VENDOR_DOC = projectGroup.createStringDocument(evaluator, APPLICATION_VENDOR);
326         String JavaDoc 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 JavaDoc ex) {
331                 // just do not set anything
332
}
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         // CustomizerRun
339
RUN_CONFIGS = readRunConfigs();
340         activeConfig = evaluator.getProperty("config");
341                 
342     }
343     
344     public void save() {
345         try {
346             // Store properties
347
boolean result = ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Boolean JavaDoc>() {
348                 final FileObject projectDir = updateHelper.getAntProjectHelper().getProjectDirectory();
349                 public Boolean JavaDoc run() throws IOException JavaDoc {
350                     if ((genFileHelper.getBuildScriptState(GeneratedFilesHelper.BUILD_IMPL_XML_PATH,
351                         J2SEProject.class.getResource("resources/build-impl.xsl"), //NOI18N
352
findJaxWsFileObject(projectDir))
353                         & GeneratedFilesHelper.FLAG_MODIFIED) == GeneratedFilesHelper.FLAG_MODIFIED) { //NOI18N
354
if (showModifiedMessage (NbBundle.getMessage(J2SEProjectProperties.class,"TXT_ModifiedTitle"))) {
355                             //Delete user modified build-impl.xml
356
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             // and save the project
370
if (result) {
371                 ProjectManager.getDefault().saveProject(project);
372             }
373         }
374         catch (MutexException e) {
375             ErrorManager.getDefault().notify((IOException JavaDoc)e.getException());
376         }
377         catch ( IOException JavaDoc ex ) {
378             ErrorManager.getDefault().notify( ex );
379         }
380     }
381     
382     
383         
384     private void storeProperties() throws IOException JavaDoc {
385         // Store special properties
386

387         // Modify the project dependencies properly
388
resolveProjectDependencies();
389         
390         // Encode all paths (this may change the project properties)
391
String JavaDoc[] javac_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_CLASSPATH_MODEL ) );
392         String JavaDoc[] javac_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( JAVAC_TEST_CLASSPATH_MODEL ) );
393         String JavaDoc[] run_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_CLASSPATH_MODEL ) );
394         String JavaDoc[] run_test_cp = cs.encodeToStrings( ClassPathUiSupport.getIterator( RUN_TEST_CLASSPATH_MODEL ) );
395                 
396         // Store source roots
397
storeRoots( project.getSourceRoots(), SOURCE_ROOTS_MODEL );
398         storeRoots( project.getTestSourceRoots(), TEST_ROOTS_MODEL );
399                 
400         // Store standard properties
401
EditableProperties projectProperties = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
402         EditableProperties privateProperties = updateHelper.getProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH );
403         
404         // Assure inegrity which can't shound not be assured in UI
405
if ( !JAVADOC_NO_INDEX_MODEL.isSelected() ) {
406             JAVADOC_SPLIT_INDEX_MODEL.setSelected( false ); // Can't split non existing index
407
}
408                                 
409         // Standard store of the properties
410
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         //Hotfix of the issue #70058
423
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
424
//Save javac.debug
425
privateProperties.setProperty(JAVAC_DEBUG, encodeBoolean (JAVAC_DEBUG_MODEL.isSelected(), javacDebugBooleanKind));
426                 
427         //Hotfix of the issue #70058
428
//Should use the StoreGroup when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
429
//Save javadoc.preview
430
privateProperties.setProperty(JAVADOC_PREVIEW, encodeBoolean (JAVADOC_PREVIEW_MODEL.isSelected(), javadocPreviewBooleanKind));
431                 
432         // Save all paths
433
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         //Handle platform selection and javac.source javac.target properties
439
PlatformUiSupport.storePlatform (projectProperties, updateHelper,PLATFORM_MODEL.getSelectedItem(), JAVAC_SOURCE_MODEL.getSelectedItem());
440                                 
441         // Handle other special cases
442
if ( NO_DEPENDENCIES_MODEL.isSelected() ) { // NOI18N
443
projectProperties.remove( NO_DEPENDENCIES ); // Remove the property completely if not set
444
}
445
446         projectProperties.putAll(additionalProperties);
447
448         projectProperties.put(INCLUDES, includes);
449         projectProperties.put(EXCLUDES, excludes);
450         
451         // Store the property changes into the project
452
updateHelper.putProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties );
453         updateHelper.putProperties( AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties );
454         
455     }
456     
457     /** Finds out what are new and removed project dependencies and
458      * applyes the info to the project
459      */

460     private void resolveProjectDependencies() {
461             
462         // Create a set of old and new artifacts.
463
Set JavaDoc oldArtifacts = new HashSet JavaDoc();
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 JavaDoc newArtifacts = new HashSet JavaDoc();
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         // Create set of removed artifacts and remove them
477
Set JavaDoc removed = new HashSet JavaDoc( oldArtifacts );
478         removed.removeAll( newArtifacts );
479         Set JavaDoc added = new HashSet JavaDoc(newArtifacts);
480         added.removeAll(oldArtifacts);
481         
482         // 1. first remove all project references. The method will modify
483
// project property files, so it must be done separately
484
for( Iterator JavaDoc 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         // 2. now read project.properties and modify rest
493
EditableProperties ep = updateHelper.getProperties( AntProjectHelper.PROJECT_PROPERTIES_PATH );
494         boolean changed = false;
495         
496         for( Iterator JavaDoc it = removed.iterator(); it.hasNext(); ) {
497             ClassPathSupport.Item item = (ClassPathSupport.Item)it.next();
498             if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY) {
499                 // remove helper property pointing to library jar if there is any
500
String JavaDoc prop = item.getReference();
501                 prop = ClassPathSupport.getAntPropertyName(prop);
502                 ep.remove(prop);
503                 changed = true;
504             }
505         }
506         for( Iterator JavaDoc it = added.iterator(); it.hasNext(); ) {
507             ClassPathSupport.Item item = (ClassPathSupport.Item)it.next();
508             if (item.getType() == ClassPathSupport.Item.TYPE_LIBRARY && !item.isBroken()) {
509                 // add property to project.properties pointing to relativized
510
// library jar(s) if possible
511
String JavaDoc 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 JavaDoc tableModel ) throws MalformedURLException JavaDoc {
522         Vector JavaDoc data = tableModel.getDataVector();
523         URL JavaDoc[] rootURLs = new URL JavaDoc[data.size()];
524         String JavaDoc []rootLabels = new String JavaDoc[data.size()];
525         for (int i=0; i<data.size();i++) {
526             File JavaDoc f = (File JavaDoc) ((Vector JavaDoc)data.elementAt(i)).elementAt(0);
527             rootURLs[i] = J2SEProjectUtil.getRootURL(f,null);
528             rootLabels[i] = (String JavaDoc) ((Vector JavaDoc)data.elementAt(i)).elementAt(1);
529         }
530         roots.putRoots(rootURLs,rootLabels);
531     }
532     
533     /* This is used by CustomizerWSServiceHost */
534     public void putAdditionalProperty(String JavaDoc propertyName, String JavaDoc propertyValue) {
535         additionalProperties.put(propertyName, propertyValue);
536     }
537     
538     private static boolean showModifiedMessage (String JavaDoc title) {
539         String JavaDoc message = NbBundle.getMessage(J2SEProjectProperties.class,"TXT_Regenerate");
540         JButton JavaDoc regenerateButton = new JButton JavaDoc (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 JavaDoc[] {regenerateButton, NotifyDescriptor.CANCEL_OPTION});
547         return DialogDisplayer.getDefault().notify(d) == regenerateButton;
548     }
549     
550     //Hotfix of the issue #70058
551
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
552
private static String JavaDoc encodeBoolean (boolean value, Integer JavaDoc kind) {
553         if ( kind == BOOLEAN_KIND_ED ) {
554             return value ? "on" : "off"; // NOI18N
555
}
556         else if ( kind == BOOLEAN_KIND_YN ) { // NOI18N
557
return value ? "yes" : "no";
558         }
559         else {
560             return value ? "true" : "false"; // NOI18N
561
}
562     }
563     
564     //Hotfix of the issue #70058
565
//Should be removed when the StoreGroup SPI will be extended to allow false default value in ToggleButtonModel
566
private static JToggleButton.ToggleButtonModel JavaDoc createToggleButtonModel (final PropertyEvaluator evaluator, final String JavaDoc propName, Integer JavaDoc[] kind) {
567         assert evaluator != null && propName != null && kind != null && kind.length == 1;
568         String JavaDoc value = evaluator.getProperty( propName );
569         boolean isSelected = false;
570         if (value == null) {
571             isSelected = true;
572         }
573         else {
574            String JavaDoc lowercaseValue = value.toLowerCase();
575            if ( lowercaseValue.equals( "yes" ) || lowercaseValue.equals( "no" ) ) { // NOI18N
576
kind[0] = BOOLEAN_KIND_YN;
577            }
578            else if ( lowercaseValue.equals( "on" ) || lowercaseValue.equals( "off" ) ) { // NOI18N
579
kind[0] = BOOLEAN_KIND_ED;
580            }
581            else {
582                kind[0] = BOOLEAN_KIND_TF;
583            }
584
585            if ( lowercaseValue.equals( "true") || // NOI18N
586
lowercaseValue.equals( "yes") || // NOI18N
587
lowercaseValue.equals( "on") ) { // NOI18N
588
isSelected = true;
589            }
590         }
591         JToggleButton.ToggleButtonModel JavaDoc bm = new JToggleButton.ToggleButtonModel JavaDoc();
592         bm.setSelected(isSelected );
593         return bm;
594     }
595     
596     /**
597      * A mess.
598      */

599     Map JavaDoc<String JavaDoc/*|null*/,Map JavaDoc<String JavaDoc,String JavaDoc>> readRunConfigs() {
600         Map JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> m = new TreeMap JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>>(new Comparator JavaDoc<String JavaDoc>() {
601             public int compare(String JavaDoc s1, String JavaDoc s2) {
602                 return s1 != null ? (s2 != null ? s1.compareTo(s2) : 1) : (s2 != null ? -1 : 0);
603             }
604         });
605         Map JavaDoc<String JavaDoc,String JavaDoc> def = new TreeMap JavaDoc<String JavaDoc,String JavaDoc>();
606         for (String JavaDoc prop : new String JavaDoc[] {MAIN_CLASS, APPLICATION_ARGS, RUN_JVM_ARGS, RUN_WORK_DIR}) {
607             String JavaDoc 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 JavaDoc<String JavaDoc,String JavaDoc>(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 JavaDoc<String JavaDoc,String JavaDoc> c = m.get(kid.getName());
632                 if (c == null) {
633                     continue;
634                 }
635                 c.putAll(new HashMap JavaDoc<String JavaDoc,String JavaDoc>(updateHelper.getProperties(FileUtil.getRelativePath(project.getProjectDirectory(), kid))));
636             }
637         }
638         //System.err.println("readRunConfigs: " + m);
639
return m;
640     }
641
642     /**
643      * A royal mess.
644      */

645     void storeRunConfigs(Map JavaDoc<String JavaDoc/*|null*/,Map JavaDoc<String JavaDoc,String JavaDoc/*|null*/>/*|null*/> configs,
646             EditableProperties projectProperties, EditableProperties privateProperties) throws IOException JavaDoc {
647         //System.err.println("storeRunConfigs: " + configs);
648
Map JavaDoc<String JavaDoc,String JavaDoc> def = configs.get(null);
649         for (String JavaDoc prop : new String JavaDoc[] {MAIN_CLASS, APPLICATION_ARGS, RUN_JVM_ARGS, RUN_WORK_DIR}) {
650             String JavaDoc 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 JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> entry : configs.entrySet()) {
662             String JavaDoc config = entry.getKey();
663             if (config == null) {
664                 continue;
665             }
666             String JavaDoc sharedPath = "nbproject/configs/" + config + ".properties"; // NOI18N
667
String JavaDoc privatePath = "nbproject/private/configs/" + config + ".properties"; // NOI18N
668
Map JavaDoc<String JavaDoc,String JavaDoc> c = entry.getValue();
669             if (c == null) {
670                 updateHelper.putProperties(sharedPath, null);
671                 updateHelper.putProperties(privatePath, null);
672                 continue;
673             }
674             for (Map.Entry JavaDoc<String JavaDoc,String JavaDoc> entry2 : c.entrySet()) {
675                 String JavaDoc prop = entry2.getKey();
676                 String JavaDoc v = entry2.getValue();
677                 String JavaDoc 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             // Make sure the definition file is always created, even if it is empty.
690
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 JavaDoc<File JavaDoc> roots = new HashSet JavaDoc<File JavaDoc>();
700         for (DefaultTableModel JavaDoc model : new DefaultTableModel JavaDoc[] {SOURCE_ROOTS_MODEL, TEST_ROOTS_MODEL}) {
701             for (Object JavaDoc row : model.getDataVector()) {
702                 roots.add((File JavaDoc) ((Vector JavaDoc) row).elementAt(0));
703             }
704         }
705         v.setRoots(roots.toArray(new File JavaDoc[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