Added the PHP wizards again
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / view / bookmark / GroupNode.java
1 /*
2  * Created on 27/06/2003
3  *
4  */
5 package net.sourceforge.phpdt.sql.view.bookmark;
6
7 import java.net.MalformedURLException;
8 import java.net.URL;
9 import java.util.Collections;
10 import java.util.Vector;
11
12 import org.eclipse.jface.resource.ImageDescriptor;
13 import org.eclipse.swt.graphics.Image;
14
15 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
16 import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData;
17
18 /**
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
21  * the JDBC driver.
22  * @author panic
23  *
24  */
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;
30
31         public GroupNode(BookmarkNode parent, String name) {
32                 this.parent = parent;
33                 this.name = name;
34         }
35         public ObjectMetaData getMetaData() {
36                 return null;    //no metadata
37         }
38
39         public boolean hasChildren() {
40                 if (children != null && children.size() > 0) {
41                         return true;
42                 }
43                 return false;
44         }
45         public Object[] getChildren() {
46                 return children.toArray();
47         }
48
49         public Object getParent() {
50                 return parent;
51         }
52         public String getName() {
53                 return name;
54         }
55         
56         public String toString() {
57                 return name;
58         }
59         
60         public void addChild(Object child)
61         {
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;
66                 children.add(child);
67                 Collections.sort(children);
68         }
69
70         public int compareTo(Object o) {
71                 if (o instanceof GroupNode) {
72                         GroupNode node = (GroupNode) o;
73                         return name.compareTo(node.getName());
74                 } 
75                 return 0;
76         }
77         /**
78          * @return an Image object to appear in the view
79          * @throws MalformedURLException
80          */
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();
84                 URL url = null; 
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$
91                 }
92                 
93                 if (url != null) {
94                         ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
95                         return descriptor.createImage();
96                 } else
97                         return null;
98         }
99
100
101 }