KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > model > plugin > PluginObjectNode


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.model.plugin;
12
13 import java.io.PrintWriter JavaDoc;
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 JavaDoc fName;
36     private boolean fInTheModel;
37     private transient ISharedPluginModel fModel;
38
39     /*
40      * (non-Javadoc)
41      *
42      * @see org.eclipse.pde.core.plugin.IPluginObject#getModel()
43      */

44     public ISharedPluginModel getModel() {
45         return fModel;
46     }
47     /*
48      * (non-Javadoc)
49      *
50      * @see org.eclipse.pde.core.plugin.IPluginObject#getPluginModel()
51      */

52     public IPluginModelBase getPluginModel() {
53         return (IPluginModelBase) fModel;
54     }
55     /*
56      * (non-Javadoc)
57      *
58      * @see org.eclipse.pde.core.plugin.IPluginObject#getName()
59      */

60     public String JavaDoc getName() {
61         return fName;
62     }
63     /*
64      * (non-Javadoc)
65      *
66      * @see org.eclipse.pde.core.plugin.IPluginObject#isInTheModel()
67      */

68     public boolean isInTheModel() {
69         return fInTheModel;
70     }
71     /*
72      * (non-Javadoc)
73      *
74      * @see org.eclipse.pde.core.plugin.IPluginObject#getTranslatedName()
75      */

76     public String JavaDoc getTranslatedName() {
77         return getResourceString(getName());
78     }
79     /*
80      * (non-Javadoc)
81      *
82      * @see org.eclipse.pde.core.plugin.IPluginObject#getParent()
83      */

84     public IPluginObject getParent() {
85         return (IPluginObject) getParentNode();
86     }
87     /*
88      * (non-Javadoc)
89      *
90      * @see org.eclipse.pde.core.plugin.IPluginObject#getPluginBase()
91      */

92     public IPluginBase getPluginBase() {
93         return fModel != null
94                 ? ((IPluginModelBase) fModel).getPluginBase()
95                 : null;
96     }
97     /*
98      * (non-Javadoc)
99      *
100      * @see org.eclipse.pde.core.plugin.IPluginObject#getResourceString(java.lang.String)
101      */

102     public String JavaDoc getResourceString(String JavaDoc key) {
103         return fModel != null ? fModel.getResourceString(key) : key;
104     }
105     /*
106      * (non-Javadoc)
107      *
108      * @see org.eclipse.pde.core.plugin.IPluginObject#setName(java.lang.String)
109      */

110     public void setName(String JavaDoc name) throws CoreException {
111         fName = name;
112     }
113     /*
114      * (non-Javadoc)
115      *
116      * @see org.eclipse.pde.core.plugin.IPluginObject#isValid()
117      */

118     public boolean isValid() {
119         return false;
120     }
121     /*
122      * (non-Javadoc)
123      *
124      * @see org.eclipse.pde.core.IWritable#write(java.lang.String,
125      * java.io.PrintWriter)
126      */

127     public void write(String JavaDoc indent, PrintWriter JavaDoc writer) {
128     }
129     /*
130      * (non-Javadoc)
131      *
132      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
133      */

134     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
135         return null;
136     }
137     /*
138      * (non-Javadoc)
139      *
140      * @see org.eclipse.pde.core.plugin.IPluginObject#setInTheModel(boolean)
141      */

142     public void setInTheModel(boolean inModel) {
143         fInTheModel = inModel;
144     }
145
146     public void setModel(ISharedPluginModel model) {
147         fModel = model;
148     }
149     /*
150      * (non-Javadoc)
151      *
152      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setXMLAttribute(java.lang.String,
153      * java.lang.String)
154      */

155     public void setXMLAttribute(String JavaDoc name, String JavaDoc value) {
156         String JavaDoc oldValue = getXMLAttributeValue(name);
157         PluginAttribute attr = (PluginAttribute) fAttributes.get(name);
158         try {
159             if (value == null)
160                 value = ""; //$NON-NLS-1$
161
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); //$NON-NLS-1$
168
} 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 JavaDoc property,
176             Object JavaDoc oldValue, Object JavaDoc 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 JavaDoc[]{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 JavaDoc getWritableString(String JavaDoc source) {
200         return CoreUtility.getWritableString(source);
201     }
202     /*
203      * (non-Javadoc)
204      *
205      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#writeShallow()
206      */

207     public String JavaDoc writeShallow(boolean terminate) {
208         return ""; //$NON-NLS-1$
209
}
210
211     /*
212      * (non-Javadoc)
213      *
214      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#write()
215      */

216     public String JavaDoc write(boolean indent) {
217         return ""; //$NON-NLS-1$
218
}
219
220     protected void appendAttribute(StringBuffer JavaDoc buffer, String JavaDoc attrName) {
221         appendAttribute(buffer, attrName, ""); //$NON-NLS-1$
222
}
223     
224     protected void appendAttribute(StringBuffer JavaDoc buffer, String JavaDoc attrName, String JavaDoc defaultValue) {
225         IDocumentAttribute attr = getDocumentAttribute(attrName);
226         if (attr != null) {
227             String JavaDoc value = attr.getAttributeValue();
228             if (value != null && value.trim().length() > 0 && !value.equals(defaultValue))
229                 buffer.append(" " + attr.write()); //$NON-NLS-1$
230
}
231     }
232     
233     public String JavaDoc getLineDelimiter() {
234         return TextUtilities.getDefaultLineDelimiter(((IEditingModel)getModel()).getDocument());
235     }
236     
237
238
239 }
240
Popular Tags