KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
14
15 import org.eclipse.pde.internal.ui.model.*;
16
17 public abstract class PluginDocumentNode implements IDocumentNode {
18     
19     private IDocumentNode fParent;
20     private ArrayList fChildren = new ArrayList();
21     private boolean fIsErrorNode;
22     private int fLength = -1;
23     private int fOffset = -1;
24     protected Map fAttributes = new TreeMap();
25     private String JavaDoc fTag;
26     private int fIndent = 0;
27     private IDocumentNode fPreviousSibling;
28     protected IDocumentTextNode fTextNode;
29
30     /* (non-Javadoc)
31      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#getChildNodes()
32      */

33     public IDocumentNode[] getChildNodes() {
34         return (IDocumentNode[]) fChildren.toArray(new IDocumentNode[fChildren.size()]);
35     }
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#indexOf(org.eclipse.pde.internal.ui.model.IDocumentNode)
39      */

40     public int indexOf(IDocumentNode child) {
41         return fChildren.indexOf(child);
42     }
43     
44     /* (non-Javadoc)
45      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getChildAt(int)
46      */

47     public IDocumentNode getChildAt(int index) {
48         if (index < fChildren.size())
49             return (IDocumentNode)fChildren.get(index);
50         return null;
51     }
52     /* (non-Javadoc)
53      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#getParentNode()
54      */

55     public IDocumentNode getParentNode() {
56         return fParent;
57     }
58     /* (non-Javadoc)
59      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#setParentNode(org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode)
60      */

61     public void setParentNode(IDocumentNode node) {
62         fParent = node;
63     }
64     /* (non-Javadoc)
65      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#addChildNode(org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode)
66      */

67     public void addChildNode(IDocumentNode child) {
68         addChildNode(child, fChildren.size());
69     }
70     
71     /* (non-Javadoc)
72      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#addChildNode(org.eclipse.pde.internal.ui.model.IDocumentNode, int)
73      */

74     public void addChildNode(IDocumentNode child, int position) {
75         fChildren.add(position, child);
76         if (position > 0 && fChildren.size() > 1)
77             child.setPreviousSibling((IDocumentNode)fChildren.get(position - 1));
78         if (fChildren.size() > 1 && position < fChildren.size() - 1)
79             ((IDocumentNode)fChildren.get(position + 1)).setPreviousSibling(child);
80         child.setParentNode(this);
81     }
82     
83     /* (non-Javadoc)
84      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#removeChildNode(org.eclipse.pde.internal.ui.model.IDocumentNode)
85      */

86     public IDocumentNode removeChildNode(IDocumentNode child) {
87         int index = fChildren.indexOf(child);
88         if (index != -1) {
89             fChildren.remove(child);
90             if (index < fChildren.size()) {
91                 IDocumentNode prevSibling = index == 0 ? null : (IDocumentNode)fChildren.get(index - 1);
92                 ((IDocumentNode)fChildren.get(index)).setPreviousSibling(prevSibling);
93                 return child;
94             }
95         }
96         return null;
97     }
98     /* (non-Javadoc)
99      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#isErrorNode()
100      */

101     public boolean isErrorNode() {
102         return fIsErrorNode;
103     }
104     /* (non-Javadoc)
105      * @see org.eclipse.pde.internal.ui.neweditor.model.IDocumentNode#setIsErrorNode(boolean)
106      */

107     public void setIsErrorNode(boolean isErrorNode) {
108         fIsErrorNode = isErrorNode;
109     }
110     /* (non-Javadoc)
111      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setOffset(int)
112      */

113     public void setOffset(int offset) {
114         fOffset = offset;
115     }
116     /* (non-Javadoc)
117      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setLength(int)
118      */

119     public void setLength(int length) {
120         fLength = length;
121     }
122     /* (non-Javadoc)
123      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getOffset()
124      */

125     public int getOffset() {
126         return fOffset;
127     }
128     /* (non-Javadoc)
129      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getLength()
130      */

131     public int getLength() {
132         return fLength;
133     }
134     /* (non-Javadoc)
135      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setAttribute(org.eclipse.pde.internal.ui.model.IDocumentAttribute)
136      */

137     public void setXMLAttribute(IDocumentAttribute attribute) {
138         fAttributes.put(attribute.getAttributeName(), attribute);
139     }
140     /* (non-Javadoc)
141      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getXMLAttributeValue(java.lang.String)
142      */

143     public String JavaDoc getXMLAttributeValue(String JavaDoc name) {
144         PluginAttribute attr = (PluginAttribute)fAttributes.get(name);
145         return attr == null ? null : attr.getValue();
146     }
147     
148     /* (non-Javadoc)
149      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setXMLTagName(java.lang.String)
150      */

151     public void setXMLTagName(String JavaDoc tag) {
152         fTag = tag;
153     }
154     
155     /* (non-Javadoc)
156      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getXMLTagName()
157      */

158     public String JavaDoc getXMLTagName() {
159         return fTag;
160     }
161     
162     /* (non-Javadoc)
163      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getDocumentAttribute(java.lang.String)
164      */

165     public IDocumentAttribute getDocumentAttribute(String JavaDoc name) {
166         return (IDocumentAttribute)fAttributes.get(name);
167     }
168     
169     /* (non-Javadoc)
170      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getLineIndent()
171      */

172     public int getLineIndent() {
173         return fIndent;
174     }
175     
176     /* (non-Javadoc)
177      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setLineIndent(int)
178      */

179     public void setLineIndent(int indent) {
180         fIndent = indent;
181     }
182     
183     /* (non-Javadoc)
184      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getAttributes()
185      */

186     public IDocumentAttribute[] getNodeAttributes() {
187         ArrayList list = new ArrayList();
188         Iterator iter = fAttributes.values().iterator();
189         while (iter.hasNext())
190             list.add(iter.next());
191         return (IDocumentAttribute[])list.toArray(new IDocumentAttribute[list.size()]);
192     }
193     
194     /* (non-Javadoc)
195      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getPreviousSibling()
196      */

197     public IDocumentNode getPreviousSibling() {
198         return fPreviousSibling;
199     }
200     
201     /* (non-Javadoc)
202      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#setPreviousSibling(org.eclipse.pde.internal.ui.model.IDocumentNode)
203      */

204     public void setPreviousSibling(IDocumentNode sibling) {
205         fPreviousSibling = sibling;
206     }
207     
208     protected String JavaDoc getIndent() {
209         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
210         for (int i = 0; i < fIndent; i++) {
211             buffer.append(" "); //$NON-NLS-1$
212
}
213         return buffer.toString();
214     }
215     
216     /* (non-Javadoc)
217      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#swap(org.eclipse.pde.internal.ui.model.IDocumentNode, org.eclipse.pde.internal.ui.model.IDocumentNode)
218      */

219     public void swap(IDocumentNode child1, IDocumentNode child2) {
220         int index1 = fChildren.indexOf(child1);
221         int index2 = fChildren.indexOf(child2);
222         
223         fChildren.set(index1, child2);
224         fChildren.set(index2, child1);
225         
226         child1.setPreviousSibling(index2 == 0 ? null : (IDocumentNode)fChildren.get(index2 - 1));
227         child2.setPreviousSibling(index1 == 0 ? null : (IDocumentNode)fChildren.get(index1 - 1));
228         
229         if (index1 < fChildren.size() - 1)
230             ((IDocumentNode)fChildren.get(index1 + 1)).setPreviousSibling(child2);
231         
232         if (index2 < fChildren.size() - 1)
233             ((IDocumentNode)fChildren.get(index2 + 1)).setPreviousSibling(child1);
234     }
235     
236     /* (non-Javadoc)
237      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#addTextNode(org.eclipse.pde.internal.ui.model.IDocumentTextNode)
238      */

239     public void addTextNode(IDocumentTextNode textNode) {
240         fTextNode = textNode;
241     }
242     
243     /* (non-Javadoc)
244      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#getTextNode()
245      */

246     public IDocumentTextNode getTextNode() {
247         return fTextNode;
248     }
249     /* (non-Javadoc)
250      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#removeTextNode()
251      */

252     public void removeTextNode() {
253         fTextNode = null;
254     }
255     
256     /* (non-Javadoc)
257      * @see org.eclipse.pde.internal.ui.model.IDocumentNode#removeDocumentAttribute(org.eclipse.pde.internal.ui.model.IDocumentAttribute)
258      */

259     public void removeDocumentAttribute(IDocumentAttribute attr) {
260         fAttributes.remove(attr.getAttributeName());
261     }
262     
263 }
264
Popular Tags