01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core.text.plugin;
11:
12: import java.util.ArrayList;
13:
14: import org.eclipse.core.runtime.CoreException;
15: import org.eclipse.pde.core.IModelChangedEvent;
16: import org.eclipse.pde.core.plugin.IPluginObject;
17: import org.eclipse.pde.core.plugin.IPluginParent;
18: import org.eclipse.pde.internal.core.text.IDocumentElementNode;
19:
20: public class PluginParentNode extends PluginObjectNode implements
21: IPluginParent {
22:
23: private static final long serialVersionUID = 1L;
24:
25: /* (non-Javadoc)
26: * @see org.eclipse.pde.core.plugin.IPluginParent#add(int, org.eclipse.pde.core.plugin.IPluginObject)
27: */
28: public void add(int index, IPluginObject child)
29: throws CoreException {
30: addChildNode((IDocumentElementNode) child, index);
31: fireStructureChanged(child, IModelChangedEvent.INSERT);
32: }
33:
34: /* (non-Javadoc)
35: * @see org.eclipse.pde.core.plugin.IPluginParent#add(org.eclipse.pde.core.plugin.IPluginObject)
36: */
37: public void add(IPluginObject child) throws CoreException {
38: add(getChildCount(), child);
39: child.setInTheModel(true);
40: ((PluginObjectNode) child).setModel(getModel());
41: }
42:
43: /* (non-Javadoc)
44: * @see org.eclipse.pde.core.plugin.IPluginParent#getChildCount()
45: */
46: public int getChildCount() {
47: return getChildNodes().length;
48: }
49:
50: /* (non-Javadoc)
51: * @see org.eclipse.pde.core.plugin.IPluginParent#getIndexOf(org.eclipse.pde.core.plugin.IPluginObject)
52: */
53: public int getIndexOf(IPluginObject child) {
54: return indexOf((IDocumentElementNode) child);
55: }
56:
57: /* (non-Javadoc)
58: * @see org.eclipse.pde.core.plugin.IPluginParent#swap(org.eclipse.pde.core.plugin.IPluginObject, org.eclipse.pde.core.plugin.IPluginObject)
59: */
60: public void swap(IPluginObject child1, IPluginObject child2)
61: throws CoreException {
62: swap((IDocumentElementNode) child1,
63: (IDocumentElementNode) child2);
64: firePropertyChanged(this , P_SIBLING_ORDER, child1, child2);
65: }
66:
67: /* (non-Javadoc)
68: * @see org.eclipse.pde.core.plugin.IPluginParent#getChildren()
69: */
70: public IPluginObject[] getChildren() {
71: ArrayList result = new ArrayList();
72: IDocumentElementNode[] nodes = getChildNodes();
73: for (int i = 0; i < nodes.length; i++)
74: result.add(nodes[i]);
75:
76: return (IPluginObject[]) result
77: .toArray(new IPluginObject[result.size()]);
78: }
79:
80: /* (non-Javadoc)
81: * @see org.eclipse.pde.core.plugin.IPluginParent#remove(org.eclipse.pde.core.plugin.IPluginObject)
82: */
83: public void remove(IPluginObject child) throws CoreException {
84: removeChildNode((IDocumentElementNode) child);
85: child.setInTheModel(false);
86: fireStructureChanged(child, IModelChangedEvent.REMOVE);
87: }
88: }
|