1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.io.IOException ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.SortedSet ; 28 import java.util.StringTokenizer ; 29 import java.util.TreeSet ; 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 46 public final class SuiteProperties extends ModuleProperties { 47 48 public static final String DISABLED_MODULES_PROPERTY = "disabled.modules"; public static final String ENABLED_CLUSTERS_PROPERTY = "enabled.clusters"; public static final String DISABLED_CLUSTERS_PROPERTY = "disabled.clusters"; 52 public static final String NB_PLATFORM_PROPERTY = "nbPlatform"; public static final String JAVA_PLATFORM_PROPERTY = "nbjdk.active"; 55 private NbPlatform activePlatform; 56 private JavaPlatform activeJavaPlatform; 57 58 59 private SuiteProject project; 60 61 62 private Set <NbModuleProject> origSubModules; 63 64 65 private Set <NbModuleProject> subModules; 66 67 private SuiteSubModulesListModel moduleListModel; 69 70 71 private String [] disabledModules; 72 73 private String [] enabledClusters; 74 75 private boolean changedDisabledModules, changedEnabledClusters; 76 77 78 private final BasicBrandingModel brandingModel; 79 80 83 public SuiteProperties(SuiteProject project, AntProjectHelper helper, 84 PropertyEvaluator evaluator, Set <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 SortedSet <String > clusters = new TreeSet (); 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 []) clusters.toArray(new String [clusters.size()]); 99 } 100 brandingModel = new BasicBrandingModel(this); 101 } 102 103 void refresh(Set <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")); firePropertiesRefreshed(); 111 } 112 113 public SuiteProject getProject() { 114 return project; 115 } 116 117 Map <String , String > getDefaultValues() { 118 return Collections.EMPTY_MAP; } 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 [] getEnabledClusters() { 144 return enabledClusters; 145 } 146 147 String [] getDisabledModules() { 148 return disabledModules; 149 } 150 151 void setEnabledClusters(String [] 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 [] 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 [] getArrayProperty(PropertyEvaluator evaluator, String p) { 168 String s = evaluator.getProperty(p); 169 String [] arr = null; 170 if (s != null) { 171 StringTokenizer tok = new StringTokenizer (s, ","); arr = new String [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 [0] : arr; 178 } 179 180 public void storeProperties() throws IOException { 181 ModuleProperties.storePlatform(getHelper(), getActivePlatform()); 182 ModuleProperties.storeJavaPlatform(getHelper(), getEvaluator(), getActiveJavaPlatform(), false); 183 getBrandingModel().store(); 184 185 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"); if (changedDisabledModules) { 194 String [] separated = (String []) 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 setProperty(DISABLED_MODULES_PROPERTY, (String ) null); 201 } 202 if (changedEnabledClusters) { 203 String [] separated = (String []) 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 ) null); 209 SortedSet <String > disabledClusters = new TreeSet (); 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 []) disabledClusters.toArray(new String [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 [] {"# Deprecated since 5.0u1; for compatibility with 5.0:"}, false); } 223 getHelper().putProperties("nbproject/platform.properties", ep); } 225 226 super.storeProperties(); 227 } 228 229 Set <NbModuleProject> getSubModules() { 230 return getModulesListModel().getSubModules(); 231 } 232 233 Set <NbModuleProject> getOrigSubModules() { 234 return origSubModules; 235 } 236 237 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 |