1 package net.sourceforge.phpdt.sql.view;
5 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.jface.viewers.ILabelProvider;
9 import org.eclipse.jface.viewers.ILabelProviderListener;
10 import org.eclipse.swt.graphics.Image;
12 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
13 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
14 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
15 import net.sourceforge.phpdt.sql.view.bookmark.Root;
16 import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
17 import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
18 import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
23 * To change this generated comment edit the template variable "typecomment":
24 * Window>Preferences>Java>Templates.
25 * To enable and disable the creation of type comments go to
26 * Window>Preferences>Java>Code Generation.
28 public class BookmarkLabelProvider implements ILabelProvider {
30 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
32 public Image getImage(Object element) {
33 ImageDescriptor descriptor = null;
34 if (element instanceof BookmarkNode) {
36 URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
37 MultiSQLServer server = MultiSQLServer.getInstance();
38 URL url = new URL(installURL, "icons/bookmarks.gif");
39 if (server.getConnected() != null && element.equals(server.getConnected())){
40 url = new URL(installURL, "icons/connected.gif");
42 descriptor = ImageDescriptor.createFromURL(url);
43 } catch (Exception e) {
49 return descriptor.createImage();
53 * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
55 public String getText(Object element) {
56 if (element instanceof BookmarkNode) {
57 Bookmark bookmark = (Bookmark) element;
58 return bookmark.getName();
59 } else if (element.equals(Root.ROOT)) {
61 } else if (element instanceof TableNode) {
62 TableNode node = (TableNode) element;
63 if (node.getSize() > -1) {
64 return "T " + element.toString() + " (" + node.getSize() + ")";
66 return "T " + element.toString();
68 } else if (element instanceof ViewNode) {
69 ViewNode node = (ViewNode) element;
70 if (node.getSize() > -1) {
71 return "V " + element.toString() + " (" + node.getSize() + ")";
73 return "V " + element.toString();
75 } else if (element instanceof SequenceNode) {
76 return "S " + element.toString();
78 return element.toString();
82 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
84 public void addListener(ILabelProviderListener listener) {
88 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
90 public void dispose() {
94 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
96 public boolean isLabelProperty(Object element, String property) {
101 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
103 public void removeListener(ILabelProviderListener listener) {