KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > SuiteProperties


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.apisupport.project.ui.customizer;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.SortedSet JavaDoc;
28 import java.util.StringTokenizer JavaDoc;
29 import java.util.TreeSet JavaDoc;
30 import org.netbeans.api.java.platform.JavaPlatform;
31 import org.netbeans.api.project.Project;
32 import org.netbeans.modules.apisupport.project.NbModuleProject;
33 import org.netbeans.modules.apisupport.project.suite.SuiteProject;
34 import org.netbeans.modules.apisupport.project.ui.customizer.CustomizerComponentFactory.SuiteSubModulesListModel;
35 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
36 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
37 import org.netbeans.spi.project.support.ant.AntProjectHelper;
38 import org.netbeans.spi.project.support.ant.EditableProperties;
39 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
40
41 /**
42  * Provides convenient access to a lot of Suite Module's properties.
43  *
44  * @author Martin Krauskopf
45  */

46 public final class SuiteProperties extends ModuleProperties {
47     
48     public static final String JavaDoc DISABLED_MODULES_PROPERTY = "disabled.modules"; // NOI18N
49
public static final String JavaDoc ENABLED_CLUSTERS_PROPERTY = "enabled.clusters"; // NOI18N
50
public static final String JavaDoc DISABLED_CLUSTERS_PROPERTY = "disabled.clusters"; // NOI18N
51

52     public static final String JavaDoc NB_PLATFORM_PROPERTY = "nbPlatform"; // NOI18N
53
public static final String JavaDoc JAVA_PLATFORM_PROPERTY = "nbjdk.active"; // NOI18N
54

55     private NbPlatform activePlatform;
56     private JavaPlatform activeJavaPlatform;
57     
58     /** Project the current properties represents. */
59     private SuiteProject project;
60     
61     /** Represent original set of sub-modules. */
62     private Set JavaDoc<NbModuleProject> origSubModules;
63     
64     /** Represent currently set set of sub-modules. */
65     private Set JavaDoc<NbModuleProject> subModules;
66     
67     // models
68
private SuiteSubModulesListModel moduleListModel;
69     
70     /** disabled modules */
71     private String JavaDoc[] disabledModules;
72     /** enabled clusters */
73     private String JavaDoc[] enabledClusters;
74     /** boolean variable to remember whether there were some changes */
75     private boolean changedDisabledModules, changedEnabledClusters;
76     
77     /** keeps all information related to branding*/
78     private final BasicBrandingModel brandingModel;
79     
80     /**
81      * Creates a new instance of SuiteProperties
82      */

83     public SuiteProperties(SuiteProject project, AntProjectHelper helper,
84             PropertyEvaluator evaluator, Set JavaDoc<NbModuleProject> subModules) {
85         super(helper, evaluator);
86         this.project = project;
87         refresh(subModules);
88         this.disabledModules = getArrayProperty(evaluator, DISABLED_MODULES_PROPERTY);
89         this.enabledClusters = getArrayProperty(evaluator, ENABLED_CLUSTERS_PROPERTY);
90         if (enabledClusters.length == 0) {
91             // Compatibility.
92
SortedSet JavaDoc<String JavaDoc> clusters = new TreeSet JavaDoc();
93             ModuleEntry[] modules = activePlatform.getModules();
94             for (int i = 0; i < modules.length; i++) {
95                 clusters.add(modules[i].getClusterDirectory().getName());
96             }
97             clusters.removeAll(Arrays.asList(getArrayProperty(evaluator, DISABLED_CLUSTERS_PROPERTY)));
98             enabledClusters = (String JavaDoc[]) clusters.toArray(new String JavaDoc[clusters.size()]);
99         }
100         brandingModel = new BasicBrandingModel(this);
101     }
102     
103     void refresh(Set JavaDoc<NbModuleProject> subModules) {
104         reloadProperties();
105         this.origSubModules = Collections.unmodifiableSet(subModules);
106         this.subModules = subModules;
107         this.moduleListModel = null;
108         activePlatform = project.getPlatform(true);
109         activeJavaPlatform = ModuleProperties.findJavaPlatformByID(getEvaluator().getProperty("nbjdk.active")); // NOI18N
110
firePropertiesRefreshed();
111     }
112     
113     public SuiteProject getProject() {
114         return project;
115     }
116     
117     Map JavaDoc<String JavaDoc, String JavaDoc> getDefaultValues() {
118         return Collections.EMPTY_MAP; // no default value (yet)
119
}
120     
121     public NbPlatform getActivePlatform() {
122         return activePlatform;
123     }
124     
125     void setActivePlatform(NbPlatform newPlaf) {
126         NbPlatform oldPlaf = this.activePlatform;
127         this.activePlatform = newPlaf;
128         firePropertyChange(NB_PLATFORM_PROPERTY, oldPlaf, newPlaf);
129     }
130     
131     JavaPlatform getActiveJavaPlatform() {
132         return activeJavaPlatform;
133     }
134     
135     void setActiveJavaPlatform(JavaPlatform nue) {
136         JavaPlatform old = activeJavaPlatform;
137         if (nue != old) {
138             activeJavaPlatform = nue;
139             firePropertyChange(JAVA_PLATFORM_PROPERTY, old, nue);
140         }
141     }
142     
143     String JavaDoc[] getEnabledClusters() {
144         return enabledClusters;
145     }
146     
147     String JavaDoc[] getDisabledModules() {
148         return disabledModules;
149     }
150     
151     void setEnabledClusters(String JavaDoc[] value) {
152         if (Arrays.asList(enabledClusters).equals(Arrays.asList(value))) {
153             return;
154         }
155         this.enabledClusters = value;
156         this.changedEnabledClusters = true;
157     }
158     
159     void setDisabledModules(String JavaDoc[] value) {
160         if (Arrays.asList(disabledModules).equals(Arrays.asList(value))) {
161             return;
162         }
163         this.disabledModules = value;
164         this.changedDisabledModules = true;
165     }
166     
167     public static String JavaDoc[] getArrayProperty(PropertyEvaluator evaluator, String JavaDoc p) {
168         String JavaDoc s = evaluator.getProperty(p);
169         String JavaDoc[] arr = null;
170         if (s != null) {
171             StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(s, ","); // NOI18N
172
arr = new String JavaDoc[tok.countTokens()];
173             for (int i = 0; i < arr.length; i++) {
174                 arr[i] = tok.nextToken().trim();
175             }
176         }
177         return arr == null ? new String JavaDoc[0] : arr;
178     }
179     
180     public void storeProperties() throws IOException JavaDoc {
181         ModuleProperties.storePlatform(getHelper(), getActivePlatform());
182         ModuleProperties.storeJavaPlatform(getHelper(), getEvaluator(), getActiveJavaPlatform(), false);
183         getBrandingModel().store();
184         
185         // store submodules if they've changed
186
SuiteSubModulesListModel model = getModulesListModel();
187         if (model.isChanged()) {
188             SuiteUtils.replaceSubModules(this);
189         }
190         
191         if (changedDisabledModules || changedEnabledClusters) {
192             EditableProperties ep = getHelper().getProperties("nbproject/platform.properties"); // NOI18N
193
if (changedDisabledModules) {
194                 String JavaDoc[] separated = (String JavaDoc[]) disabledModules.clone();
195                 for (int i = 0; i < disabledModules.length - 1; i++) {
196                     separated[i] = disabledModules[i] + ',';
197                 }
198                 ep.setProperty(DISABLED_MODULES_PROPERTY, separated);
199                 // Do not want it left in project.properties if it was there before (from 5.0):
200
setProperty(DISABLED_MODULES_PROPERTY, (String JavaDoc) null);
201             }
202             if (changedEnabledClusters) {
203                 String JavaDoc[] separated = (String JavaDoc[]) enabledClusters.clone();
204                 for (int i = 0; i < enabledClusters.length - 1; i++) {
205                     separated[i] = enabledClusters[i] + ',';
206                 }
207                 ep.setProperty(ENABLED_CLUSTERS_PROPERTY, separated);
208                 setProperty(ENABLED_CLUSTERS_PROPERTY, (String JavaDoc) null);
209                 // Compatibility.
210
SortedSet JavaDoc<String JavaDoc> disabledClusters = new TreeSet JavaDoc();
211                 ModuleEntry[] modules = activePlatform.getModules();
212                 for (int i = 0; i < modules.length; i++) {
213                     disabledClusters.add(modules[i].getClusterDirectory().getName());
214                 }
215                 disabledClusters.removeAll(Arrays.asList(enabledClusters));
216                 separated = (String JavaDoc[]) disabledClusters.toArray(new String JavaDoc[disabledClusters.size()]);
217                 for (int i = 0; i < separated.length - 1; i++) {
218                     separated[i] = separated[i] + ',';
219                 }
220                 ep.setProperty(DISABLED_CLUSTERS_PROPERTY, separated);
221                 ep.setComment(DISABLED_CLUSTERS_PROPERTY, new String JavaDoc[] {"# Deprecated since 5.0u1; for compatibility with 5.0:"}, false); // NOI18N
222
}
223             getHelper().putProperties("nbproject/platform.properties", ep); // NOI18N
224
}
225         
226         super.storeProperties();
227     }
228     
229     Set JavaDoc<NbModuleProject> getSubModules() {
230         return getModulesListModel().getSubModules();
231     }
232     
233     Set JavaDoc<NbModuleProject> getOrigSubModules() {
234         return origSubModules;
235     }
236     
237     /**
238      * Returns list model of module's dependencies regarding the currently
239      * selected platform.
240      */

241     SuiteSubModulesListModel getModulesListModel() {
242         if (moduleListModel == null) {
243             moduleListModel = new SuiteSubModulesListModel(subModules);
244         }
245         return moduleListModel;
246     }
247     
248     public BasicBrandingModel getBrandingModel() {
249         return brandingModel;
250     }
251     
252 }
253
254
Popular Tags