KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > workingset > WorkingSet


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.help.internal.workingset;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.w3c.dom.*;
18
19 public class WorkingSet {
20     private String JavaDoc name;
21     private List JavaDoc elements;
22
23     public WorkingSet(String JavaDoc name) {
24         this(name, (List JavaDoc) null);
25     }
26
27     public WorkingSet(String JavaDoc name, List JavaDoc elements) {
28         this.name = name;
29         if (elements == null)
30             elements = new ArrayList JavaDoc();
31
32         this.elements = elements;
33     }
34
35     public WorkingSet(String JavaDoc name, AdaptableHelpResource[] elements) {
36         this.name = name;
37         if (elements == null)
38             elements = new AdaptableHelpResource[0];
39
40         this.elements = new ArrayList JavaDoc(elements.length);
41         for (int i = 0; i < elements.length; i++) {
42             this.elements.add(elements[i]);
43         }
44     }
45
46     public void removeElement(AdaptableHelpResource element) {
47         // Note: this is based on equality of IHelpResource and
48
// AdaptableHelpResource
49
elements.remove(element);
50     }
51
52     public String JavaDoc getName() {
53         return name;
54     }
55
56     public void setName(String JavaDoc newName) {
57         if (newName == null)
58             return;
59         name = newName;
60     }
61
62     public AdaptableHelpResource[] getElements() {
63         AdaptableHelpResource[] array = new AdaptableHelpResource[elements
64                 .size()];
65         elements.toArray(array);
66         return array;
67     }
68
69     public void setElements(AdaptableHelpResource[] elements) {
70         this.elements = new ArrayList JavaDoc(elements.length);
71         for (int i = 0; i < elements.length; i++)
72             this.elements.add(elements[i]);
73     }
74
75     public void saveState(Element parent) {
76         Document doc = parent.getOwnerDocument();
77         Element ws = doc.createElement("workingSet"); //$NON-NLS-1$
78
ws.setAttribute("name", name); //$NON-NLS-1$
79
parent.appendChild(ws);
80
81         for (Iterator JavaDoc it = elements.iterator(); it.hasNext();) {
82             Element child = doc.createElement("item"); //$NON-NLS-1$
83
AdaptableHelpResource helpResource = (AdaptableHelpResource) it
84                     .next();
85             helpResource.saveState(child);
86             ws.appendChild(child);
87         }
88     }
89 }
90
Popular Tags