1 11 package org.eclipse.help.internal.workingset; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.w3c.dom.*; 18 19 public class WorkingSet { 20 private String name; 21 private List elements; 22 23 public WorkingSet(String name) { 24 this(name, (List ) null); 25 } 26 27 public WorkingSet(String name, List elements) { 28 this.name = name; 29 if (elements == null) 30 elements = new ArrayList (); 31 32 this.elements = elements; 33 } 34 35 public WorkingSet(String name, AdaptableHelpResource[] elements) { 36 this.name = name; 37 if (elements == null) 38 elements = new AdaptableHelpResource[0]; 39 40 this.elements = new ArrayList (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 elements.remove(element); 50 } 51 52 public String getName() { 53 return name; 54 } 55 56 public void setName(String 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 (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"); ws.setAttribute("name", name); parent.appendChild(ws); 80 81 for (Iterator it = elements.iterator(); it.hasNext();) { 82 Element child = doc.createElement("item"); AdaptableHelpResource helpResource = (AdaptableHelpResource) it 84 .next(); 85 helpResource.saveState(child); 86 ws.appendChild(child); 87 } 88 } 89 } 90 | Popular Tags |