1 package com.quantum.view.subset;
3 import java.util.Vector;
5 import com.quantum.Messages;
6 import com.quantum.sql.metadata.MetaDataXMLInterface;
7 import com.quantum.view.bookmark.ColumnNode;
8 import com.quantum.view.bookmark.TreeNode;
10 import org.eclipse.jface.viewers.ITreeContentProvider;
11 import org.eclipse.jface.viewers.Viewer;
12 import org.w3c.dom.Element;
13 import org.w3c.dom.NodeList;
15 public class SubsetContentProvider implements ITreeContentProvider {
16 private Vector subsets = new Vector();
17 private static SubsetContentProvider instance = null;
18 private boolean hasChanged = false;
23 public static synchronized SubsetContentProvider getInstance() {
24 if (instance == null) {
25 instance = new SubsetContentProvider();
30 private SubsetContentProvider() {
33 public void exportXML(Element root) {
34 System.out.println("Subsets: Saving to Element"); //$NON-NLS-1$
35 Element subsetRoot = MetaDataXMLInterface.createElementText(root,Messages.getString("ExportXMLAction.Subsets"), ""); //$NON-NLS-1$ //$NON-NLS-2$
36 for (int i = 0; i < subsets.size(); i++) {
37 SubsetNode current = (SubsetNode) subsets.get(i);
38 current.exportXML(subsetRoot);
43 * Imports the data from an XML file to the tree. Does not set the tree to
44 * changed because it's usually invoked from the initial import routine.
47 public void importXML(Element root){
48 System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
49 Vector newSubsets = new Vector();
50 NodeList nodes = root.getElementsByTagName(Messages.getString("ExportXMLAction.Subset")); //$NON-NLS-1$
51 for (int i = 0; i < nodes.getLength(); i++) {
52 SubsetNode subset = new SubsetNode();
53 Element node = (Element) nodes.item(i);
54 subset.importXML(node,true);
55 newSubsets.add(subset);
61 public Object[] getChildren(Object parentElement) {
62 if (parentElement.equals(SubsetRoot.ROOT)) {
63 return subsets.toArray();
64 } else if (parentElement instanceof TreeNode) {
65 TreeNode node = (TreeNode) parentElement;
66 return node.getChildren();
68 return SubsetRoot.EMPTY_ARRAY;
71 public Object[] getElements(Object inputElement) {
72 return getChildren(inputElement);
75 public Object getParent(Object element) {
76 if (element.equals(SubsetRoot.ROOT)) {
78 } else if (element instanceof TreeNode) {
79 TreeNode node = (TreeNode) element;
80 return node.getParent();
85 public boolean hasChildren(Object element) {
86 if (element.equals(SubsetRoot.ROOT)) {
88 } else if (element instanceof TreeNode) {
89 TreeNode node = (TreeNode) element;
90 return node.hasChildren();
95 public void setChildren(SubsetNode b, Vector tables) {
96 b.setChildren(tables);
99 public void addSubset(SubsetNode b) {
101 if (!subsets.contains(b)) {
102 subsets.addElement(b);
105 public void removeSubset(SubsetNode b) {
107 if (subsets.contains(b)) {
108 subsets.removeElement(b);
112 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
115 public void dispose() {
118 public boolean hasChanged() {
122 public int getSize() {
123 return subsets.size();
129 public void setHasChanged(boolean b) {
136 public void deleteColumn(ColumnNode column) {
137 // TODO: reinstate this
138 // TreeNode node = (TreeNode) column.getParent();
139 // if (!(node instanceof HasMetaData)) return;
140 // ObjectMetaData metadata = ((HasMetaData)node).getMetaData();
141 // if (metadata == null) return;
142 // metadata.dropColumn(column.getName());
143 // setHasChanged(true);
150 public void deleteObject(ObjectNode object) {
151 SubsetNode node = (SubsetNode) object.getParent();
152 if (!(node instanceof SubsetNode)) return;