1 11 package org.eclipse.pde.internal.core.product; 12 13 import java.io.PrintWriter ; 14 import java.util.ArrayList ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.TreeMap ; 18 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.internal.core.iproduct.IAboutInfo; 21 import org.eclipse.pde.internal.core.iproduct.IArgumentsInfo; 22 import org.eclipse.pde.internal.core.iproduct.IConfigurationFileInfo; 23 import org.eclipse.pde.internal.core.iproduct.IIntroInfo; 24 import org.eclipse.pde.internal.core.iproduct.IJREInfo; 25 import org.eclipse.pde.internal.core.iproduct.ILauncherInfo; 26 import org.eclipse.pde.internal.core.iproduct.IProduct; 27 import org.eclipse.pde.internal.core.iproduct.IProductFeature; 28 import org.eclipse.pde.internal.core.iproduct.IProductModel; 29 import org.eclipse.pde.internal.core.iproduct.IProductModelFactory; 30 import org.eclipse.pde.internal.core.iproduct.IProductPlugin; 31 import org.eclipse.pde.internal.core.iproduct.ISplashInfo; 32 import org.eclipse.pde.internal.core.iproduct.IWindowImages; 33 import org.w3c.dom.Element ; 34 import org.w3c.dom.Node ; 35 import org.w3c.dom.NodeList ; 36 37 38 public class Product extends ProductObject implements IProduct { 39 40 private static final long serialVersionUID = 1L; 41 private String fId; 42 private String fName; 43 private String fApplication; 44 private IAboutInfo fAboutInfo; 45 46 private TreeMap fPlugins = new TreeMap (); 47 private List fFeatures = new ArrayList (); 48 private IConfigurationFileInfo fConfigIniInfo; 49 private IJREInfo fJVMInfo; 50 private boolean fUseFeatures; 51 private IWindowImages fWindowImages; 52 private ISplashInfo fSplashInfo; 53 private ILauncherInfo fLauncherInfo; 54 private IArgumentsInfo fLauncherArgs; 55 private IIntroInfo fIntroInfo; 56 57 public Product(IProductModel model) { 58 super(model); 59 } 60 61 64 public String getId() { 65 return fId; 66 } 67 68 71 public String getName() { 72 return fName; 73 } 74 75 78 public String getApplication() { 79 return fApplication; 80 } 81 82 85 public String getDefiningPluginId() { 86 if (fId == null) 87 return null; 88 int dot = fId.lastIndexOf('.'); 89 return (dot != -1) ? fId.substring(0, dot) : null; 90 } 91 92 95 public void setId(String id) { 96 String old = fId; 97 fId = id; 98 if (isEditable()) 99 firePropertyChanged(P_ID, old, fId); 100 } 101 102 105 public void setName(String name) { 106 String old = fName; 107 fName = name; 108 if (isEditable()) 109 firePropertyChanged(P_NAME, old, fName); 110 } 111 112 115 public void setAboutInfo(IAboutInfo info) { 116 fAboutInfo = info; 117 } 118 119 122 public void setApplication(String application) { 123 String old = fApplication; 124 fApplication = application; 125 if (isEditable()) 126 firePropertyChanged(P_APPLICATION, old, fApplication); 127 } 128 129 132 public void write(String indent, PrintWriter writer) { 133 writer.print(indent + "<product"); if (fName != null && fName.length() > 0) 135 writer.print(" " + P_NAME + "=\"" + getWritableString(fName) + "\""); if (fId != null && fId.length() > 0) 137 writer.print(" " + P_ID + "=\"" + fId + "\""); if (fApplication != null && fApplication.length() > 0) 139 writer.print(" " + P_APPLICATION + "=\"" + fApplication + "\""); writer.print(" " + P_USEFEATURES + "=\"" + Boolean.toString(fUseFeatures) + "\""); writer.println(">"); 143 if (fAboutInfo != null) { 144 writer.println(); 145 fAboutInfo.write(indent + " ", writer); } 147 148 if (fConfigIniInfo != null) { 149 writer.println(); 150 fConfigIniInfo.write(indent + " ", writer); } 152 153 if (fLauncherArgs != null) { 154 writer.println(); 155 fLauncherArgs.write(indent + " ", writer); } 157 158 if (fWindowImages != null) { 159 writer.println(); 160 fWindowImages.write(indent + " ", writer); } 162 163 if (fSplashInfo != null) { 164 writer.println(); 165 fSplashInfo.write(indent + " ", writer); } 167 168 if (fLauncherInfo != null) { 169 writer.println(); 170 fLauncherInfo.write(indent + " ", writer); } 172 173 if (fIntroInfo != null) { 174 writer.println(); 175 fIntroInfo.write(indent + " ", writer); } 177 178 if (fJVMInfo != null) { 179 writer.println(); 180 fJVMInfo.write(indent + " ", writer); } 182 183 writer.println(); 184 writer.println(indent + " <plugins>"); Iterator iter = fPlugins.values().iterator(); 186 while (iter.hasNext()) { 187 IProductPlugin plugin = (IProductPlugin)iter.next(); 188 plugin.write(indent + " ", writer); } 190 writer.println(indent + " </plugins>"); 192 if (fFeatures.size() > 0) { 193 writer.println(); 194 writer.println(indent + " <features>"); iter = fFeatures.iterator(); 196 while (iter.hasNext()) { 197 IProductFeature feature = (IProductFeature)iter.next(); 198 feature.write(indent + " ", writer); } 200 writer.println(indent + " </features>"); } 202 203 writer.println(); 204 writer.println("</product>"); } 206 207 210 public IAboutInfo getAboutInfo() { 211 return fAboutInfo; 212 } 213 214 217 public void reset() { 218 fApplication = null; 219 fId = null; 220 fName = null; 221 fUseFeatures = false; 222 fAboutInfo = null; 223 fPlugins.clear(); 224 fFeatures.clear(); 225 fConfigIniInfo = null; 226 fWindowImages = null; 227 fSplashInfo = null; 228 fLauncherInfo = null; 229 fLauncherArgs = null; 230 fIntroInfo = null; 231 fJVMInfo = null; 232 } 233 234 237 public void parse(Node node) { 238 if (node.getNodeType() == Node.ELEMENT_NODE 239 && node.getNodeName().equals("product")) { Element element = (Element )node; 241 fApplication = element.getAttribute(P_APPLICATION); 242 fId = element.getAttribute(P_ID); 243 fName = element.getAttribute(P_NAME); 244 fUseFeatures = "true".equals(element.getAttribute(P_USEFEATURES)); NodeList children = node.getChildNodes(); 246 IProductModelFactory factory = getModel().getFactory(); 247 for (int i = 0; i < children.getLength(); i++) { 248 Node child = children.item(i); 249 if (child.getNodeType() == Node.ELEMENT_NODE) { 250 String name = child.getNodeName(); 251 if (name.equals("aboutInfo")) { fAboutInfo = factory.createAboutInfo(); 253 fAboutInfo.parse(child); 254 } else if (name.equals("plugins")) { parsePlugins(child.getChildNodes()); 256 } else if (name.equals("features")) { parseFeatures(child.getChildNodes()); 258 } else if (name.equals("configIni")) { fConfigIniInfo = factory.createConfigFileInfo(); 260 fConfigIniInfo.parse(child); 261 } else if (name.equals("windowImages")) { fWindowImages = factory.createWindowImages(); 263 fWindowImages.parse(child); 264 } else if (name.equals("splash")) { fSplashInfo = factory.createSplashInfo(); 266 fSplashInfo.parse(child); 267 } else if (name.equals("launcher")) { fLauncherInfo = factory.createLauncherInfo(); 269 fLauncherInfo.parse(child); 270 } else if (name.equals("launcherArgs")) { fLauncherArgs = factory.createLauncherArguments(); 272 fLauncherArgs.parse(child); 273 } else if (name.equals("intro")) { fIntroInfo = factory.createIntroInfo(); 275 fIntroInfo.parse(child); 276 } else if (name.equals("vm")) { fJVMInfo = factory.createJVMInfo(); 278 fJVMInfo.parse(child); 279 } 280 } 281 } 282 } 283 } 284 285 private void parsePlugins(NodeList children) { 286 for (int i = 0; i < children.getLength(); i++) { 287 Node child = children.item(i); 288 if (child.getNodeType() == Node.ELEMENT_NODE) { 289 if (child.getNodeName().equals("plugin")) { IProductPlugin plugin = getModel().getFactory().createPlugin(); 291 plugin.parse(child); 292 fPlugins.put(plugin.getId(), plugin); 293 } 294 } 295 } 296 } 297 298 private void parseFeatures(NodeList children) { 299 for (int i = 0; i < children.getLength(); i++) { 300 Node child = children.item(i); 301 if (child.getNodeType() == Node.ELEMENT_NODE) { 302 if (child.getNodeName().equals("feature")) { IProductFeature feature = getModel().getFactory().createFeature(); 304 feature.parse(child); 305 fFeatures.add(feature); 306 } 307 } 308 } 309 } 310 311 314 public void addPlugins(IProductPlugin[] plugins) { 315 boolean modified = false; 316 for (int i = 0; i < plugins.length; i++) { 317 if (plugins[i] == null) 318 continue; 319 String id = plugins[i].getId(); 320 if (id == null || fPlugins.containsKey(id)) { 321 plugins[i] = null; 322 continue; 323 } 324 325 plugins[i].setModel(getModel()); 326 fPlugins.put(id, plugins[i]); 327 modified = true; 328 } 329 if (modified && isEditable()) 330 fireStructureChanged(plugins, IModelChangedEvent.INSERT); 331 } 332 333 336 public void removePlugins(IProductPlugin[] plugins) { 337 boolean modified = false; 338 for (int i = 0; i < plugins.length; i++) { 339 if (fPlugins.remove(plugins[i].getId()) != null) 340 modified = true; 341 } 342 if (modified && isEditable()) 343 fireStructureChanged(plugins, IModelChangedEvent.REMOVE); 344 } 345 346 349 public IProductPlugin[] getPlugins() { 350 return (IProductPlugin[])fPlugins.values().toArray(new IProductPlugin[fPlugins.size()]); 351 } 352 353 356 public IConfigurationFileInfo getConfigurationFileInfo() { 357 return fConfigIniInfo; 358 } 359 360 363 public void setConfigurationFileInfo(IConfigurationFileInfo info) { 364 fConfigIniInfo = info; 365 } 366 367 public boolean useFeatures() { 368 return fUseFeatures; 369 } 370 371 public void setUseFeatures(boolean use) { 372 boolean old = fUseFeatures; 373 fUseFeatures = use; 374 if (isEditable()) 375 firePropertyChanged(P_USEFEATURES, Boolean.toString(old), Boolean.toString(fUseFeatures)); 376 } 377 378 public boolean containsPlugin(String id) { 379 return fPlugins.containsKey(id); 380 } 381 382 public boolean containsFeature(String id) { 383 IProductFeature[] features = getFeatures(); 384 for(int i = 0; i < features.length; i++) { 385 if(features[i].getId().equals(id)) 386 return true; 387 } 388 return false; 389 } 390 391 public IWindowImages getWindowImages() { 392 return fWindowImages; 393 } 394 395 public void setWindowImages(IWindowImages images) { 396 fWindowImages = images; 397 } 398 399 public ISplashInfo getSplashInfo() { 400 return fSplashInfo; 401 } 402 403 public void setSplashInfo(ISplashInfo info) { 404 fSplashInfo = info; 405 } 406 407 public ILauncherInfo getLauncherInfo() { 408 return fLauncherInfo; 409 } 410 411 public void setLauncherInfo(ILauncherInfo info) { 412 fLauncherInfo = info; 413 } 414 415 public void addFeatures(IProductFeature[] features) { 416 boolean modified = false; 417 for (int i = 0; i < features.length; i++) { 418 if (features[i] == null) 419 continue; 420 String id = features[i].getId(); 421 if (fFeatures.contains((id))) { 422 features[i] = null; 423 continue; 424 } 425 426 features[i].setModel(getModel()); 427 fFeatures.add(features[i]); 428 modified = true; 429 } 430 431 if (modified && isEditable()) 432 fireStructureChanged(features, IModelChangedEvent.INSERT); 433 } 434 435 public void removeFeatures(IProductFeature[] features) { 436 boolean modified = false; 437 for (int i = 0; i < features.length; i++) { 438 if(features[i].getId() != null) { 439 fFeatures.remove(features[i]); 440 modified = true; 441 } 442 } 443 if (modified && isEditable()) 444 fireStructureChanged(features, IModelChangedEvent.REMOVE); 445 } 446 447 public IProductFeature[] getFeatures() { 448 return (IProductFeature[])fFeatures.toArray(new IProductFeature[fFeatures.size()]); 449 } 450 451 public IArgumentsInfo getLauncherArguments() { 452 return fLauncherArgs; 453 } 454 455 public void setLauncherArguments(IArgumentsInfo info) { 456 fLauncherArgs = info; 457 } 458 459 public IIntroInfo getIntroInfo() { 460 return fIntroInfo; 461 } 462 463 public void setIntroInfo(IIntroInfo introInfo) { 464 fIntroInfo = introInfo; 465 } 466 467 public IJREInfo getJREInfo() { 468 return fJVMInfo; 469 } 470 471 public void setJREInfo(IJREInfo info) { 472 fJVMInfo = info; 473 } 474 475 public void swap(IProductFeature feature1, IProductFeature feature2) { 476 int index1 = fFeatures.indexOf(feature1); 477 int index2 = fFeatures.indexOf(feature2); 478 if (index1 == -1 || index2 == -1) 479 return; 480 481 fFeatures.set(index2, feature1); 482 fFeatures.set(index1, feature2); 483 484 fireStructureChanged(feature1, IModelChangedEvent.CHANGE); 485 } 486 487 } 488 | Popular Tags |