2 * Created on 27/06/2003
5 package net.sourceforge.phpdt.sql.view.bookmark;
7 import java.net.MalformedURLException;
9 import java.util.Collections;
10 import java.util.Vector;
12 import org.eclipse.jface.resource.ImageDescriptor;
13 import org.eclipse.swt.graphics.Image;
15 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
16 import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
19 * GroupNode represents a level of grouping in the BookmarkView hierarchy
20 * It will have categories like "TABLE", "VIEW" and so on, usually gotten from
25 public class GroupNode implements TreeNode, Comparable {
26 private BookmarkNode parent = null;
27 private Vector children = new Vector();
28 private String name = null;
29 private int size = -1;
31 public GroupNode(BookmarkNode parent, String name) {
35 public ObjectMetaData getMetaData() {
36 return null; //no metadata
39 public boolean hasChildren() {
40 if (children != null && children.size() > 0) {
45 public Object[] getChildren() {
46 return children.toArray();
49 public Object getParent() {
52 public String getName() {
56 public String toString() {
60 public void addChild(Object child)
62 if (!(child instanceof TreeNode)) return;
63 if (name == "TABLE" && !(child instanceof TableNode)) return;
64 if (name == "VIEW" && !(child instanceof ViewNode)) return;
65 if (name == "SEQUENCE" && !(child instanceof SequenceNode)) return;
67 Collections.sort(children);
70 public int compareTo(Object o) {
71 if (o instanceof GroupNode) {
72 GroupNode node = (GroupNode) o;
73 return name.compareTo(node.getName());
78 * @return an Image object to appear in the view
79 * @throws MalformedURLException
81 public Image getImage() throws MalformedURLException {
82 // We'll return an icon if it's part of the primary key
83 URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
85 if (name == "TABLE") {
86 url = new URL(installURL, "icons/greentable.gif"); //$NON-NLS-1$
87 } else if (name == "VIEW") {
88 url = new URL(installURL, "icons/view.gif"); //$NON-NLS-1$
89 } else if (name == "SEQUENCE") {
90 url = new URL(installURL, "icons/sequence.gif"); //$NON-NLS-1$
94 ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
95 return descriptor.createImage();