/* * Created on 27/06/2003 * */ package net.sourceforge.phpdt.sql.view.bookmark; import java.net.MalformedURLException; import java.net.URL; import java.util.Collections; import java.util.Vector; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin; import net.sourceforge.phpdt.sql.sql.metadata.ObjectMetaData; /** * GroupNode represents a level of grouping in the BookmarkView hierarchy * It will have categories like "TABLE", "VIEW" and so on, usually gotten from * the JDBC driver. * @author panic * */ public class GroupNode implements TreeNode, Comparable { private BookmarkNode parent = null; private Vector children = new Vector(); private String name = null; private int size = -1; public GroupNode(BookmarkNode parent, String name) { this.parent = parent; this.name = name; } public ObjectMetaData getMetaData() { return null; //no metadata } public boolean hasChildren() { if (children != null && children.size() > 0) { return true; } return false; } public Object[] getChildren() { return children.toArray(); } public Object getParent() { return parent; } public String getName() { return name; } public String toString() { return name; } public void addChild(Object child) { if (!(child instanceof TreeNode)) return; if (name == "TABLE" && !(child instanceof TableNode)) return; if (name == "VIEW" && !(child instanceof ViewNode)) return; if (name == "SEQUENCE" && !(child instanceof SequenceNode)) return; children.add(child); Collections.sort(children); } public int compareTo(Object o) { if (o instanceof GroupNode) { GroupNode node = (GroupNode) o; return name.compareTo(node.getName()); } return 0; } /** * @return an Image object to appear in the view * @throws MalformedURLException */ public Image getImage() throws MalformedURLException { // We'll return an icon if it's part of the primary key URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL(); URL url = null; if (name == "TABLE") { url = new URL(installURL, "icons/greentable.gif"); //$NON-NLS-1$ } else if (name == "VIEW") { url = new URL(installURL, "icons/view.gif"); //$NON-NLS-1$ } else if (name == "SEQUENCE") { url = new URL(installURL, "icons/sequence.gif"); //$NON-NLS-1$ } if (url != null) { ImageDescriptor descriptor = ImageDescriptor.createFromURL(url); return descriptor.createImage(); } else return null; } }