KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > plugin > PluginParent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.core.plugin;
12
13 import java.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.pde.core.IModelChangedEvent;
17 import org.eclipse.pde.core.plugin.IPluginElement;
18 import org.eclipse.pde.core.plugin.IPluginObject;
19 import org.eclipse.pde.core.plugin.IPluginParent;
20 import org.eclipse.pde.internal.core.PDECoreMessages;
21
22 public abstract class PluginParent extends IdentifiablePluginObject implements
23         IPluginParent {
24     protected ArrayList JavaDoc fChildren = new ArrayList JavaDoc(1);
25
26     public PluginParent() {
27     }
28
29     public void add(int index, IPluginObject child) throws CoreException {
30         ensureModelEditable();
31         fChildren.add(index, child);
32         postAdd(child);
33     }
34
35     public void add(IPluginObject child) throws CoreException {
36         ensureModelEditable();
37         fChildren.add(child);
38         postAdd(child);
39     }
40
41     void appendChild(IPluginElement child) {
42         fChildren.add(child);
43     }
44
45     protected void postAdd(IPluginObject child) {
46         ((PluginObject) child).setInTheModel(true);
47         ((PluginObject) child).setParent(this);
48         fireStructureChanged(child, IModelChangedEvent.INSERT);
49     }
50
51     public int getChildCount() {
52         return fChildren.size();
53     }
54
55     public boolean equals(Object JavaDoc obj) {
56         if (this == obj)
57             return true;
58         if (obj == null)
59             return false;
60         if (obj instanceof IPluginParent) {
61             IPluginParent target = (IPluginParent) obj;
62             if (target.getChildCount() != getChildCount())
63                 return false;
64             IPluginObject[] tchildren = target.getChildren();
65             for (int i = 0; i < tchildren.length; i++) {
66                 IPluginObject tchild = tchildren[i];
67                 if (tchild.equals(fChildren.get(i)) == false)
68                     return false;
69             }
70             return true;
71         }
72         return false;
73     }
74
75     public int getIndexOf(IPluginObject child) {
76         return fChildren.indexOf(child);
77     }
78
79     public void swap(IPluginObject child1, IPluginObject child2)
80             throws CoreException {
81         ensureModelEditable();
82         int index1 = fChildren.indexOf(child1);
83         int index2 = fChildren.indexOf(child2);
84         if (index1 == -1 || index2 == -1)
85             throwCoreException(PDECoreMessages.PluginParent_siblingsNotFoundException);
86         fChildren.set(index2, child1);
87         fChildren.set(index1, child2);
88         firePropertyChanged(this, P_SIBLING_ORDER, child1, child2);
89     }
90
91     public IPluginObject[] getChildren() {
92         return (IPluginObject[])fChildren.toArray(new IPluginObject[fChildren.size()]);
93     }
94
95     public void remove(IPluginObject child) throws CoreException {
96         ensureModelEditable();
97         fChildren.remove(child);
98         ((PluginObject) child).setInTheModel(false);
99         fireStructureChanged(child, IModelChangedEvent.REMOVE);
100     }
101
102 }
103
Popular Tags