1 package com.quantum.view.subset;
3 import java.util.Collections;
4 import java.util.Vector;
6 import com.quantum.Messages;
7 import com.quantum.sql.metadata.MetaDataXMLInterface;
8 import com.quantum.view.bookmark.TreeNode;
10 import org.w3c.dom.Element;
11 import org.w3c.dom.NodeList;
13 public class SubsetNode extends TreeNode {
14 private String name = null;
15 private Vector children = new Vector();
17 public SubsetNode(SubsetNode param) {
18 super(param.getParent());
20 children.addAll(param.children);
24 super(SubsetRoot.ROOT);
27 public SubsetNode(String name) {
28 super(SubsetRoot.ROOT);
32 public void setName(String name) {
36 public String getName(){
40 public Object[] getChildren() {
41 return children.toArray();
44 public boolean hasChildren() {
45 if (children != null && children.size() > 0) {
51 public void setChildren(Vector children) {
52 for (int i = 0; i < children.size(); i++) {
53 Object obj = children.elementAt(i);
56 Collections.sort(children);
57 this.children = children;
60 public void isValid(Object child) {
61 boolean valid = false;
62 if (child instanceof ObjectNode ) {
66 throw new RuntimeException("Invalid SubsetNode child: " + child.getClass().getName()); //$NON-NLS-1$
72 * Finds a child of the SubsetNode with the said name
74 * @return the TreeNode found. null if none
76 public TreeNode find(String name){
77 for (int i = 0; i < children.size(); i++) {
78 Object obj = children.elementAt(i);
79 if (obj instanceof TreeNode){
80 TreeNode node = (TreeNode) obj;
81 if (name.equals(node.getName())) return node;
87 public boolean add(ObjectNode object){
88 if (children.indexOf(object) >= 0) return false;
93 public boolean addReplace(ObjectNode object){
94 children.remove(object);
98 public boolean remove(ObjectNode object){
99 return children.remove(object);
102 public void exportXML(Element root) {
103 Element sub = MetaDataXMLInterface.createElementText(root,Messages.getString("ExportXMLAction.Subset"), ""); //$NON-NLS-1$ //$NON-NLS-2$
104 MetaDataXMLInterface.createElementText(sub,Messages.getString("ExportXMLAction.SubsetName"), getName()); //$NON-NLS-1$
105 for (int i = 0; i < children.size(); i++) {
106 Object obj = children.elementAt(i);
107 if (obj instanceof ObjectNode){
108 ((ObjectNode) obj).exportXML(sub);
115 * Imports a set of XML tags (parsed into a XMLDocument) into a Subset
116 * @param root Document to get the data from
117 * @param replace True if you want to replace already-existing elements with the same name, false if not
119 public void importXML(Element root, boolean replace) {
121 String name = MetaDataXMLInterface.getElementText(root, Messages.getString("ExportXMLAction.SubsetName")); //$NON-NLS-1$
122 if (name == "") return; //$NON-NLS-1$
125 importElementXML(root, replace, Messages.getString("ExportXMLAction.Table")); //$NON-NLS-1$
126 importElementXML(root, replace, Messages.getString("ExportXMLAction.View")); //$NON-NLS-1$
133 * Imports one type of element from a XMLDocument (possibly a part of one) into a Subset
134 * @param root Document to get the data from
135 * @param replace True if you want to replace already-existing elements with the same name, false if not
136 * @param type The type of element to import, has to correspond with the XML tag
138 private void importElementXML(Element root, boolean replace, String type) {
139 // We get all the tags named as the type
140 NodeList tables = root.getElementsByTagName(type);
141 for (int i = 0; i < tables.getLength(); i++) {
142 Element table = (Element) tables.item(i);
143 ObjectNode objectNode = ObjectNode.importXML(table, this);
144 if (replace)addReplace(objectNode);
145 else add(objectNode);
150 * @see com.quantum.view.bookmark.TreeNode#getImageName()
152 protected String getImageName() {
157 * @see com.quantum.view.bookmark.TreeNode#initializeChildren()
159 protected void initializeChildren() {