1 11 package org.eclipse.pde.internal.core.feature; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.pde.core.plugin.IFragment; 17 import org.eclipse.pde.core.plugin.IFragmentModel; 18 import org.eclipse.pde.core.plugin.IPluginBase; 19 import org.eclipse.pde.core.plugin.IPluginModel; 20 import org.eclipse.pde.core.plugin.IPluginModelBase; 21 import org.eclipse.pde.core.plugin.ModelEntry; 22 import org.eclipse.pde.core.plugin.PluginRegistry; 23 import org.eclipse.pde.internal.core.ifeature.IFeaturePlugin; 24 import org.w3c.dom.Node ; 25 26 public class FeaturePlugin extends FeatureData implements IFeaturePlugin { 27 private static final long serialVersionUID = 1L; 28 private boolean fFragment; 29 private String fVersion; 30 private boolean fUnpack = true; 31 32 public FeaturePlugin() { 33 } 34 35 protected void reset() { 36 super.reset(); 37 fVersion = null; 38 fFragment = false; 39 } 40 41 public boolean isFragment() { 42 return fFragment; 43 } 44 45 public IPluginBase getPluginBase() { 46 if (id == null) { 47 return null; 48 } 49 String version = getVersion(); 50 IPluginModelBase model = null; 51 if (version == null || version.equals("0.0.0")) model = PluginRegistry.findModel(id); 53 else { 54 ModelEntry entry = PluginRegistry.findEntry(id); 55 if (entry != null) { 57 IPluginModelBase bases[] = entry.getActiveModels(); 58 for (int i = 0; i < bases.length; i++) { 59 if (bases[i].getPluginBase().getVersion().equals(version)) { 60 model = bases[i]; 61 break; 62 } 63 } 64 } 65 } 66 if (fFragment && model instanceof IFragmentModel) 67 return model.getPluginBase(); 68 if (!fFragment && model instanceof IPluginModel) 69 return model.getPluginBase(); 70 return null; 71 } 72 73 public String getVersion() { 74 return fVersion; 75 } 76 public boolean isUnpack() { 77 return fUnpack; 78 } 79 public void setVersion(String version) throws CoreException { 80 ensureModelEditable(); 81 Object oldValue = this.fVersion; 82 this.fVersion = version; 83 firePropertyChanged(this, P_VERSION, oldValue, version); 84 } 85 86 public void setUnpack(boolean unpack) throws CoreException { 87 ensureModelEditable(); 88 boolean oldValue = fUnpack; 89 this.fUnpack = unpack; 90 firePropertyChanged(this, P_UNPACK, new Boolean (oldValue), new Boolean (unpack)); 91 } 92 93 public void restoreProperty(String name, Object oldValue, Object newValue) 94 throws CoreException { 95 if (name.equals(P_VERSION)) { 96 setVersion(newValue != null ? newValue.toString() : null); 97 } else 98 super.restoreProperty(name, oldValue, newValue); 99 } 100 101 public void setFragment(boolean fragment) throws CoreException { 102 ensureModelEditable(); 103 this.fFragment = fragment; 104 } 105 106 protected void parse(Node node) { 107 super.parse(node); 108 fVersion = getNodeAttribute(node, "version"); String f = getNodeAttribute(node, "fragment"); if (f != null && f.equalsIgnoreCase("true")) fFragment = true; 112 String unpack = getNodeAttribute(node, "unpack"); if (unpack != null && unpack.equalsIgnoreCase("false")) fUnpack = false; 115 } 116 117 public void loadFrom(IPluginBase plugin) { 118 id = plugin.getId(); 119 label = plugin.getTranslatedName(); 120 fVersion = plugin.getVersion(); 121 fFragment = plugin instanceof IFragment; 122 } 123 124 public void write(String indent, PrintWriter writer) { 125 writer.print(indent + "<plugin"); String indent2 = indent + Feature.INDENT + Feature.INDENT; 127 writeAttributes(indent2, writer); 128 if (getVersion() != null) { 129 writer.println(); 130 writer.print(indent2 + "version=\"" + getVersion() + "\""); } 132 if (isFragment()) { 133 writer.println(); 134 writer.print(indent2 + "fragment=\"true\""); } 136 if (!isUnpack()) { 137 writer.println(); 138 writer.print(indent2 + "unpack=\"false\""); } 140 writer.println("/>"); } 143 144 public String getLabel() { 145 IPluginBase pluginBase = getPluginBase(); 146 if (pluginBase != null) { 147 return pluginBase.getTranslatedName(); 148 } 149 String name = super.getLabel(); 150 if (name == null) 151 name = getId(); 152 return name; 153 } 154 155 public String toString() { 156 return getLabel(); 157 } 158 159 } 160 | Popular Tags |