1 package com.quantum.view.subset;
3 import java.sql.SQLException;
4 import java.util.Vector;
6 import com.quantum.Messages;
7 import com.quantum.model.NotConnectedException;
8 import com.quantum.sql.metadata.MetaDataXMLInterface;
9 import com.quantum.view.bookmark.ColumnNode;
10 import com.quantum.view.bookmark.TreeNode;
12 import org.eclipse.jface.viewers.ITreeContentProvider;
13 import org.eclipse.jface.viewers.Viewer;
14 import org.w3c.dom.Element;
15 import org.w3c.dom.NodeList;
17 public class SubsetContentProvider implements ITreeContentProvider {
18 private Vector subsets = new Vector();
19 private static SubsetContentProvider instance = null;
20 private boolean hasChanged = false;
25 public static synchronized SubsetContentProvider getInstance() {
26 if (instance == null) {
27 instance = new SubsetContentProvider();
32 private SubsetContentProvider() {
35 public void exportXML(Element root) {
36 System.out.println("Subsets: Saving to Element"); //$NON-NLS-1$
37 Element subsetRoot = MetaDataXMLInterface.createElementText(root,Messages.getString("ExportXMLAction.Subsets"), ""); //$NON-NLS-1$ //$NON-NLS-2$
38 for (int i = 0; i < subsets.size(); i++) {
39 SubsetNode current = (SubsetNode) subsets.get(i);
40 current.exportXML(subsetRoot);
45 * Imports the data from an XML file to the tree. Does not set the tree to
46 * changed because it's usually invoked from the initial import routine.
49 public void importXML(Element root){
50 System.out.println("Bookmarks: Loading from Element"); //$NON-NLS-1$
51 Vector newSubsets = new Vector();
52 NodeList nodes = root.getElementsByTagName(Messages.getString("ExportXMLAction.Subset")); //$NON-NLS-1$
53 for (int i = 0; i < nodes.getLength(); i++) {
54 SubsetNode subset = new SubsetNode();
55 Element node = (Element) nodes.item(i);
56 subset.importXML(node,true);
57 newSubsets.add(subset);
63 public Object[] getChildren(Object parentElement) {
64 if (parentElement.equals(SubsetRoot.ROOT)) {
65 return subsets.toArray();
66 } else if (parentElement instanceof TreeNode) {
67 TreeNode node = (TreeNode) parentElement;
69 return node.getChildren();
70 } catch (NotConnectedException e) {
71 } catch (SQLException e) {
74 return SubsetRoot.EMPTY_ARRAY;
77 public Object[] getElements(Object inputElement) {
78 return getChildren(inputElement);
81 public Object getParent(Object element) {
82 if (element.equals(SubsetRoot.ROOT)) {
84 } else if (element instanceof TreeNode) {
85 TreeNode node = (TreeNode) element;
86 return node.getParent();
91 public boolean hasChildren(Object element) {
92 if (element.equals(SubsetRoot.ROOT)) {
94 } else if (element instanceof TreeNode) {
95 TreeNode node = (TreeNode) element;
96 return node.hasChildren();
101 public void setChildren(SubsetNode b, Vector tables) {
102 b.setChildren(tables);
105 public void addSubset(SubsetNode b) {
107 if (!subsets.contains(b)) {
108 subsets.addElement(b);
111 public void removeSubset(SubsetNode b) {
113 if (subsets.contains(b)) {
114 subsets.removeElement(b);
118 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
121 public void dispose() {
124 public boolean hasChanged() {
128 public int getSize() {
129 return subsets.size();
135 public void setHasChanged(boolean b) {
142 public void deleteColumn(ColumnNode column) {
143 // TODO: reinstate this
144 // TreeNode node = (TreeNode) column.getParent();
145 // if (!(node instanceof HasMetaData)) return;
146 // ObjectMetaData metadata = ((HasMetaData)node).getMetaData();
147 // if (metadata == null) return;
148 // metadata.dropColumn(column.getName());
149 // setHasChanged(true);
156 public void deleteObject(ObjectNode object) {
157 SubsetNode node = (SubsetNode) object.getParent();
158 if (!(node instanceof SubsetNode)) return;