Fixed some bugs in the syntax editor preference page
[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 org.eclipse.jface.resource.ImageDescriptor;
6 import org.eclipse.jface.viewers.ILabelProvider;
7 import org.eclipse.jface.viewers.ILabelProviderListener;
8 import org.eclipse.swt.graphics.Image;
9
10 import net.sourceforge.phpdt.sql.Messages;
11 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
12 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
13 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
14 import net.sourceforge.phpdt.sql.view.bookmark.ColumnMetaData;
15 import net.sourceforge.phpdt.sql.view.bookmark.GroupNode;
16 import net.sourceforge.phpdt.sql.view.bookmark.Root;
17 import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
18 import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
19 import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
20
21 /**
22  * @author root
23  *
24  * Implements the ILabelProvider for the Bookmarks.
25  */
26 public class BookmarkLabelProvider implements ILabelProvider {
27         /**
28          * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
29          */
30         public Image getImage(Object element) {
31          ImageDescriptor descriptor = null;
32            if (element instanceof BookmarkNode) {
33                 try {
34            URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
35            BookmarkNode bookmark = (BookmarkNode) element;
36                    URL url = new URL(installURL, (bookmark.isConnected()) ? "icons/connected.gif" :  "icons/bookmarks.gif"); //$NON-NLS-1$ //$NON-NLS-2$
37            descriptor = ImageDescriptor.createFromURL(url);
38                 } catch (Exception e) {
39                         e.printStackTrace();
40                 }
41            } else if (element instanceof ColumnMetaData){
42                 try {
43                         ColumnMetaData columnMetaData = (ColumnMetaData) element;
44                         return columnMetaData.getImage();
45                  } catch (Exception e) {
46                          e.printStackTrace();
47                  }
48            } else if (element instanceof GroupNode){
49                 try {
50                         GroupNode groupNode = (GroupNode) element;
51                         return groupNode.getImage();
52                  } catch (Exception e) {
53                          e.printStackTrace();
54                  }
55            } else if (element instanceof TableNode){
56                 try {
57                         TableNode TableNode = (TableNode) element;
58                         return TableNode.getImage();
59                  } catch (Exception e) {
60                          e.printStackTrace();
61                  }
62            } else if (element instanceof ViewNode){
63                 try {
64                         ViewNode ViewNode = (ViewNode) element;
65                         return ViewNode.getImage();
66                  } catch (Exception e) {
67                          e.printStackTrace();
68                  }
69            } else if (element instanceof SequenceNode){
70                 try {
71                         SequenceNode SequenceNode = (SequenceNode) element;
72                         return SequenceNode.getImage();
73                  } catch (Exception e) {
74                          e.printStackTrace();
75                  }
76                 } else {
77                 return null;
78                 }
79            return descriptor.createImage();
80         }
81
82         /**
83          * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
84          */
85         public String getText(Object element) {
86                 if (element instanceof BookmarkNode) {
87                         Bookmark bookmark = (Bookmark) element;
88                         return bookmark.getName();
89                 } else if (element.equals(Root.ROOT)) {
90                         return "ROOT"; //$NON-NLS-1$
91                 } else if (element instanceof TableNode) {
92                         TableNode node = (TableNode) element;
93                         if (node.isSizeVisible()) {
94                                 return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
95                         } else {
96                                 return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
97                         }
98                 } else if (element instanceof ViewNode) {
99                         ViewNode node = (ViewNode) element;
100                         if (node.isSizeVisible()) {
101                                 return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
102                         } else {
103                                 return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
104                         }
105                 } else if (element instanceof SequenceNode) {
106                         return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
107                 }
108                 return element.toString();
109         }
110
111         /**
112          * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
113          */
114         public void addListener(ILabelProviderListener listener) {
115         }
116
117         /**
118          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
119          */
120         public void dispose() {
121         }
122
123         /**
124          * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
125          */
126         public boolean isLabelProperty(Object element, String property) {
127                 return false;
128         }
129
130         /**
131          * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
132          */
133         public void removeListener(ILabelProviderListener listener) {
134      }
135 }