Moved to test plugin to eliminate dependency upon junit plugin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / view / BookmarkLabelProvider.java
1 package net.sourceforge.phpdt.sql.view;
2
3 import java.net.URL;
4
5 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
6
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;
11
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;
19
20 /**
21  * @author root
22  *
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.
27  */
28 public class BookmarkLabelProvider implements ILabelProvider {
29         /**
30          * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
31          */
32         public Image getImage(Object element) {
33          ImageDescriptor descriptor = null;
34            if (element instanceof BookmarkNode) {
35                 try {
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");
41            }
42             descriptor = ImageDescriptor.createFromURL(url);
43                 } catch (Exception e) {
44                         e.printStackTrace();
45                 }
46            } else {
47                   return null;
48            }
49            return descriptor.createImage();
50         }
51
52         /**
53          * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
54          */
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)) {
60                         return "ROOT";
61                 } else if (element instanceof TableNode) {
62                         TableNode node = (TableNode) element;
63                         if (node.getSize() > -1) {
64                                 return "T " + element.toString() + " (" + node.getSize() + ")";
65                         } else {
66                                 return "T " + element.toString();
67                         }
68                 } else if (element instanceof ViewNode) {
69                         ViewNode node = (ViewNode) element;
70                         if (node.getSize() > -1) {
71                                 return "V " + element.toString() + " (" + node.getSize() + ")";
72                         } else {
73                                 return "V " + element.toString();
74                         }
75                 } else if (element instanceof SequenceNode) {
76                         return "S " + element.toString();
77                 }
78                 return element.toString();
79         }
80
81         /**
82          * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
83          */
84         public void addListener(ILabelProviderListener listener) {
85         }
86
87         /**
88          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
89          */
90         public void dispose() {
91         }
92
93         /**
94          * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
95          */
96         public boolean isLabelProperty(Object element, String property) {
97                 return false;
98         }
99
100         /**
101          * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
102          */
103         public void removeListener(ILabelProviderListener listener) {
104      }
105 }