KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.runtime.*;
16 import org.eclipse.pde.core.*;
17 import org.eclipse.pde.core.plugin.*;
18 import org.eclipse.pde.internal.ui.model.*;
19
20 public class PluginLibraryNode extends PluginObjectNode implements IPluginLibrary {
21
22     private static final long serialVersionUID = 1L;
23
24     /* (non-Javadoc)
25      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getContentFilters()
26      */

27     public String JavaDoc[] getContentFilters() {
28         IDocumentNode[] children = getChildNodes();
29         ArrayList result = new ArrayList();
30         for (int i = 0; i < children.length; i++) {
31             PluginObjectNode node = (PluginObjectNode)children[i];
32             if (node.getName().equals(P_EXPORTED)) {
33                 String JavaDoc name = children[i].getXMLAttributeValue(P_NAME);
34                 if (name != null && !name.equals("*")) { //$NON-NLS-1$
35
int index = name.indexOf(".*"); //$NON-NLS-1$
36
if (index != -1)
37                         name = name.substring(0, index);
38                     result.add(name);
39                 }
40             }
41         }
42         return (String JavaDoc[])result.toArray(new String JavaDoc[result.size()]);
43     }
44     /* (non-Javadoc)
45      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getPackages()
46      */

47     public String JavaDoc[] getPackages() {
48         return new String JavaDoc[0];
49     }
50     /* (non-Javadoc)
51      * @see org.eclipse.pde.core.plugin.IPluginLibrary#isExported()
52      */

53     public boolean isExported() {
54         IDocumentNode[] children = getChildNodes();
55         for (int i = 0; i < children.length; i++) {
56             PluginObjectNode node = (PluginObjectNode)children[i];
57             if (node.getName().equals(P_EXPORTED))
58                 return true;
59         }
60         return false;
61     }
62     /* (non-Javadoc)
63      * @see org.eclipse.pde.core.plugin.IPluginLibrary#isFullyExported()
64      */

65     public boolean isFullyExported() {
66         IDocumentNode[] children = getChildNodes();
67         for (int i = 0; i < children.length; i++) {
68             PluginObjectNode node = (PluginObjectNode)children[i];
69             if (node.getName().equals(P_EXPORTED)) {
70                 String JavaDoc name = children[i].getXMLAttributeValue(P_NAME);
71                 if (name != null && name.equals("*")) //$NON-NLS-1$
72
return true;
73             }
74         }
75         return false;
76     }
77     
78     /* (non-Javadoc)
79      * @see org.eclipse.pde.core.plugin.IPluginLibrary#getType()
80      */

81     public String JavaDoc getType() {
82         String JavaDoc type = getXMLAttributeValue(P_TYPE);
83         return (type != null && type.equals("resource")) ? IPluginLibrary.RESOURCE : IPluginLibrary.CODE; //$NON-NLS-1$
84
}
85     /* (non-Javadoc)
86      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setContentFilters(java.lang.String[])
87      */

88     public void setContentFilters(String JavaDoc[] filters) throws CoreException {
89     }
90     /* (non-Javadoc)
91      * @see org.eclipse.pde.core.plugin.IPluginLibrary#addContentFilter(java.lang.String)
92      */

93     public void addContentFilter(String JavaDoc filter) throws CoreException {
94         PluginElementNode node = new PluginElementNode();
95         node.setXMLTagName(P_EXPORTED);
96         node.setParentNode(this);
97         node.setModel(getModel());
98         node.setXMLAttribute(P_NAME, "*".equals(filter) || filter.endsWith(".*") ? filter : filter + ".*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
99
addContentFilter(node);
100     }
101     
102     public void addContentFilter(PluginElementNode node) throws CoreException {
103         addChildNode(node);
104         if (isInTheModel()) {
105             node.setInTheModel(true);
106             fireStructureChanged(node, IModelChangedEvent.INSERT);
107         }
108     }
109     
110     /* (non-Javadoc)
111      * @see org.eclipse.pde.core.plugin.IPluginLibrary#removeContentFilter(java.lang.String)
112      */

113     public void removeContentFilter(String JavaDoc filter) throws CoreException {
114         if (!filter.endsWith(".*")) //$NON-NLS-1$
115
filter += ".*"; //$NON-NLS-1$
116
IDocumentNode[] children = getChildNodes();
117         for (int i = 0; i < children.length; i++) {
118             if (children[i].getXMLTagName().equals(P_EXPORTED)
119                    && filter.equals(children[i].getXMLAttributeValue(P_NAME))) {
120                 removeContentFilter((PluginElementNode)children[i]);
121             }
122         }
123     }
124     
125     public void removeContentFilter(PluginElementNode node) {
126         removeChildNode(node);
127         if (isInTheModel()) {
128             node.setInTheModel(false);
129             fireStructureChanged(node, IModelChangedEvent.REMOVE);
130         }
131     }
132     
133     /* (non-Javadoc)
134      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setPackages(java.lang.String[])
135      */

136     public void setPackages(String JavaDoc[] packages) throws CoreException {
137     }
138     /* (non-Javadoc)
139      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setExported(boolean)
140      */

141     public void setExported(boolean exported) throws CoreException {
142         IDocumentNode[] children = getChildNodes();
143         boolean alreadyExported = false;
144         for (int i = 0; i < children.length; i++) {
145             if (children[i].getXMLTagName().equals(P_EXPORTED)) {
146                 if (!"*".equals(children[i].getXMLAttributeValue(P_NAME))) { //$NON-NLS-1$
147
removeContentFilter((PluginElementNode)children[i]);
148                 } else {
149                     alreadyExported = true;
150                     if (!exported) {
151                         removeContentFilter((PluginElementNode)children[i]);
152                     }
153                 }
154             }
155         }
156         if (exported && !alreadyExported) {
157             addContentFilter("*"); //$NON-NLS-1$
158
}
159     }
160     
161     /* (non-Javadoc)
162      * @see org.eclipse.pde.core.plugin.IPluginLibrary#setType(java.lang.String)
163      */

164     public void setType(String JavaDoc type) throws CoreException {
165     }
166     
167     /* (non-Javadoc)
168      * @see org.eclipse.pde.core.plugin.IPluginObject#getName()
169      */

170     public String JavaDoc getName() {
171         return getXMLAttributeValue(P_NAME);
172     }
173     
174     /* (non-Javadoc)
175      * @see org.eclipse.pde.core.plugin.IPluginObject#setName(java.lang.String)
176      */

177     public void setName(String JavaDoc name) throws CoreException {
178         setXMLAttribute(P_NAME, name);
179     }
180     
181     /* (non-Javadoc)
182      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#write()
183      */

184     public String JavaDoc write(boolean indent) {
185         String JavaDoc sep = getLineDelimiter();
186         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
187         if (indent)
188             buffer.append(getIndent());
189         
190         IDocumentNode[] children = getChildNodes();
191         if (children.length > 0) {
192             buffer.append(writeShallow(false) + sep);
193             for (int i = 0; i < children.length; i++) {
194                 children[i].setLineIndent(getLineIndent() + 3);
195                 buffer.append(children[i].write(true) + sep);
196             }
197             buffer.append(getIndent() + "</" + getXMLTagName() + ">"); //$NON-NLS-1$ //$NON-NLS-2$
198
} else {
199             buffer.append(writeShallow(true));
200         }
201         return buffer.toString();
202     }
203     
204     /* (non-Javadoc)
205      * @see org.eclipse.pde.internal.ui.model.plugin.PluginObjectNode#writeShallow(boolean)
206      */

207     public String JavaDoc writeShallow(boolean terminate) {
208         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("<" + getXMLTagName()); //$NON-NLS-1$
209

210         IDocumentAttribute[] attrs = getNodeAttributes();
211         for (int i = 0; i < attrs.length; i++) {
212             appendAttribute(buffer, attrs[i].getAttributeName());
213         }
214         if (terminate)
215             buffer.append("/"); //$NON-NLS-1$
216
buffer.append(">"); //$NON-NLS-1$
217
return buffer.toString();
218     }
219     
220     public String JavaDoc toString() {
221         return getName();
222     }
223
224 }
225
Popular Tags