1 11 package org.eclipse.pde.internal.ui.model.plugin; 12 13 import java.io.PrintWriter ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.jface.text.TextUtilities; 17 import org.eclipse.pde.core.IModel; 18 import org.eclipse.pde.core.IModelChangeProvider; 19 import org.eclipse.pde.core.IModelChangedEvent; 20 import org.eclipse.pde.core.ModelChangedEvent; 21 import org.eclipse.pde.core.plugin.IPluginBase; 22 import org.eclipse.pde.core.plugin.IPluginModelBase; 23 import org.eclipse.pde.core.plugin.IPluginObject; 24 import org.eclipse.pde.core.plugin.ISharedPluginModel; 25 import org.eclipse.pde.internal.core.util.CoreUtility; 26 import org.eclipse.pde.internal.ui.model.IDocumentAttribute; 27 import org.eclipse.pde.internal.ui.model.IDocumentNode; 28 import org.eclipse.pde.internal.ui.model.IEditingModel; 29 30 public class PluginObjectNode extends PluginDocumentNode 31 implements 32 IPluginObject { 33 34 private static final long serialVersionUID = 1L; 35 private String fName; 36 private boolean fInTheModel; 37 private transient ISharedPluginModel fModel; 38 39 44 public ISharedPluginModel getModel() { 45 return fModel; 46 } 47 52 public IPluginModelBase getPluginModel() { 53 return (IPluginModelBase) fModel; 54 } 55 60 public String getName() { 61 return fName; 62 } 63 68 public boolean isInTheModel() { 69 return fInTheModel; 70 } 71 76 public String getTranslatedName() { 77 return getResourceString(getName()); 78 } 79 84 public IPluginObject getParent() { 85 return (IPluginObject) getParentNode(); 86 } 87 92 public IPluginBase getPluginBase() { 93 return fModel != null 94 ? ((IPluginModelBase) fModel).getPluginBase() 95 : null; 96 } 97 102 public String getResourceString(String key) { 103 return fModel != null ? fModel.getResourceString(key) : key; 104 } 105 110 public void setName(String name) throws CoreException { 111 fName = name; 112 } 113 118 public boolean isValid() { 119 return false; 120 } 121 127 public void write(String indent, PrintWriter writer) { 128 } 129 134 public Object getAdapter(Class adapter) { 135 return null; 136 } 137 142 public void setInTheModel(boolean inModel) { 143 fInTheModel = inModel; 144 } 145 146 public void setModel(ISharedPluginModel model) { 147 fModel = model; 148 } 149 155 public void setXMLAttribute(String name, String value) { 156 String oldValue = getXMLAttributeValue(name); 157 PluginAttribute attr = (PluginAttribute) fAttributes.get(name); 158 try { 159 if (value == null) 160 value = ""; if (attr == null) { 162 attr = new PluginAttribute(); 163 attr.setName(name); 164 attr.setEnclosingElement(this); 165 fAttributes.put(name, attr); 166 } 167 attr.setValue(value == null ? "" : value); } catch (CoreException e) { 169 } 170 if (fInTheModel) 171 firePropertyChanged(attr.getEnclosingElement(), attr 172 .getAttributeName(), oldValue, value); 173 } 174 175 protected void firePropertyChanged(IDocumentNode node, String property, 176 Object oldValue, Object newValue) { 177 if (fModel.isEditable()) { 178 fModel.fireModelObjectChanged(node, property, oldValue, newValue); 179 } 180 } 181 182 protected void fireStructureChanged(IPluginObject child, int changeType) { 183 IModel model = getModel(); 184 if (model.isEditable() && model instanceof IModelChangeProvider) { 185 IModelChangedEvent e = new ModelChangedEvent(fModel, changeType, 186 new Object []{child}, null); 187 fireModelChanged(e); 188 } 189 } 190 191 protected void fireModelChanged(IModelChangedEvent e) { 192 IModel model = getModel(); 193 if (model.isEditable() && model instanceof IModelChangeProvider) { 194 IModelChangeProvider provider = (IModelChangeProvider) model; 195 provider.fireModelChanged(e); 196 } 197 } 198 199 public String getWritableString(String source) { 200 return CoreUtility.getWritableString(source); 201 } 202 207 public String writeShallow(boolean terminate) { 208 return ""; } 210 211 216 public String write(boolean indent) { 217 return ""; } 219 220 protected void appendAttribute(StringBuffer buffer, String attrName) { 221 appendAttribute(buffer, attrName, ""); } 223 224 protected void appendAttribute(StringBuffer buffer, String attrName, String defaultValue) { 225 IDocumentAttribute attr = getDocumentAttribute(attrName); 226 if (attr != null) { 227 String value = attr.getAttributeValue(); 228 if (value != null && value.trim().length() > 0 && !value.equals(defaultValue)) 229 buffer.append(" " + attr.write()); } 231 } 232 233 public String getLineDelimiter() { 234 return TextUtilities.getDefaultLineDelimiter(((IEditingModel)getModel()).getDocument()); 235 } 236 237 238 239 } 240 | Popular Tags |