1 11 package org.eclipse.pde.internal.core.text.plugin; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.TextUtilities; 18 import org.eclipse.pde.core.IModel; 19 import org.eclipse.pde.core.IModelChangeProvider; 20 import org.eclipse.pde.core.IModelChangedEvent; 21 import org.eclipse.pde.core.ModelChangedEvent; 22 import org.eclipse.pde.core.plugin.IPluginBase; 23 import org.eclipse.pde.core.plugin.IPluginModelBase; 24 import org.eclipse.pde.core.plugin.IPluginObject; 25 import org.eclipse.pde.core.plugin.ISharedPluginModel; 26 import org.eclipse.pde.internal.core.ischema.ISchema; 27 import org.eclipse.pde.internal.core.plugin.IWritableDelimiter; 28 import org.eclipse.pde.internal.core.text.IDocumentAttribute; 29 import org.eclipse.pde.internal.core.text.IDocumentNode; 30 import org.eclipse.pde.internal.core.text.IDocumentObject; 31 import org.eclipse.pde.internal.core.text.IDocumentRange; 32 import org.eclipse.pde.internal.core.text.IEditingModel; 33 import org.eclipse.pde.internal.core.util.PDEXMLHelper; 34 35 public class PluginObjectNode extends PluginDocumentNode implements 36 IPluginObject, IDocumentObject, IWritableDelimiter { 37 38 private transient boolean fInTheModel; 39 private transient ISharedPluginModel fModel; 40 41 private static final long serialVersionUID = 1L; 42 private String fName; 43 44 49 public ISharedPluginModel getModel() { 50 return fModel; 51 } 52 57 public IPluginModelBase getPluginModel() { 58 return (IPluginModelBase) fModel; 59 } 60 65 public String getName() { 66 return fName; 67 } 68 73 public boolean isInTheModel() { 74 return fInTheModel; 75 } 76 81 public String getTranslatedName() { 82 return getResourceString(getName()); 83 } 84 89 public IPluginObject getParent() { 90 return (IPluginObject) getParentNode(); 91 } 92 97 public IPluginBase getPluginBase() { 98 return fModel != null 99 ? ((IPluginModelBase) fModel).getPluginBase() 100 : null; 101 } 102 107 public String getResourceString(String key) { 108 return fModel != null ? fModel.getResourceString(key) : key; 109 } 110 115 public void setName(String name) throws CoreException { 116 fName = name; 117 } 118 123 public boolean isValid() { 124 return false; 125 } 126 132 public void write(String indent, PrintWriter writer) { 133 } 134 139 public Object getAdapter(Class adapter) { 140 return null; 141 } 142 147 public void setInTheModel(boolean inModel) { 148 fInTheModel = inModel; 149 } 150 151 public void setModel(ISharedPluginModel model) { 152 fModel = model; 153 } 154 160 public void setXMLAttribute(String name, String value) { 161 String oldValue = getXMLAttributeValue(name); 162 if (oldValue != null && oldValue.equals(value)) 163 return; 164 PluginAttribute attr = (PluginAttribute) fAttributes.get(name); 165 try { 166 if (value == null) 167 value = ""; if (attr == null) { 169 attr = new PluginAttribute(); 170 attr.setName(name); 171 attr.setEnclosingElement(this); 172 fAttributes.put(name, attr); 173 } 174 attr.setValue(value == null ? "" : value); } catch (CoreException e) { 176 } 177 if (fInTheModel) 178 firePropertyChanged(attr.getEnclosingElement(), attr 179 .getAttributeName(), oldValue, value); 180 } 181 182 protected void firePropertyChanged(IDocumentRange node, String property, 183 Object oldValue, Object newValue) { 184 if (fModel.isEditable()) { 185 fModel.fireModelObjectChanged(node, property, oldValue, newValue); 186 } 187 } 188 189 protected void fireStructureChanged(IPluginObject child, int changeType) { 190 IModel model = getModel(); 191 if (model.isEditable() && model instanceof IModelChangeProvider) { 192 IModelChangedEvent e = new ModelChangedEvent(fModel, changeType, 193 new Object []{child}, null); 194 fireModelChanged(e); 195 } 196 } 197 198 protected void fireStructureChanged(IPluginObject[] children, int changeType) { 199 IModel model = getModel(); 200 if (model.isEditable() && model instanceof IModelChangeProvider) { 201 IModelChangedEvent e = new ModelChangedEvent(fModel, changeType, 202 children, null); 203 fireModelChanged(e); 204 } 205 } 206 207 protected void fireModelChanged(IModelChangedEvent e) { 208 IModel model = getModel(); 209 if (model.isEditable() && model instanceof IModelChangeProvider) { 210 IModelChangeProvider provider = (IModelChangeProvider) model; 211 provider.fireModelChanged(e); 212 } 213 } 214 215 public String getWritableString(String source) { 216 return PDEXMLHelper.getWritableString(source); 217 } 218 223 public String writeShallow(boolean terminate) { 224 return ""; } 226 227 232 public String write(boolean indent) { 233 return ""; } 235 236 protected void appendAttribute(StringBuffer buffer, String attrName) { 237 appendAttribute(buffer, attrName, ""); } 239 240 protected void appendAttribute(StringBuffer buffer, String attrName, String defaultValue) { 241 IDocumentAttribute attr = getDocumentAttribute(attrName); 242 if (attr != null) { 243 String value = attr.getAttributeValue(); 244 if (value != null && value.trim().length() > 0 && !value.equals(defaultValue)) 245 buffer.append(" " + attr.write()); } 247 } 248 249 252 public String getLineDelimiter() { 253 ISharedPluginModel model = getModel(); 254 IDocument document = ((IEditingModel)model).getDocument(); 255 return TextUtilities.getDefaultLineDelimiter(document); 256 } 257 258 public void addChildNode(IDocumentNode child, int position) { 259 super.addChildNode(child, position); 260 ((IPluginObject)child).setInTheModel(true); 261 } 262 263 public String toString() { 264 return write(false); 265 } 266 267 public boolean isRoot() { 268 return false; 269 } 270 271 274 public void reconnect(ISharedPluginModel model, ISchema schema, IDocumentNode parent) { 275 super.reconnect(model, schema, parent); 276 fInTheModel = false; 279 fModel = model; 283 } 284 285 288 public void writeDelimeter(PrintWriter writer) { 289 } 292 293 } 294 | Popular Tags |