1 package net.sourceforge.phpdt.sql.view;
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;
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;
24 * Implements the ILabelProvider for the Bookmarks.
26 public class BookmarkLabelProvider implements ILabelProvider {
28 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
30 public Image getImage(Object element) {
31 ImageDescriptor descriptor = null;
32 if (element instanceof BookmarkNode) {
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) {
41 } else if (element instanceof ColumnMetaData){
43 ColumnMetaData columnMetaData = (ColumnMetaData) element;
44 return columnMetaData.getImage();
45 } catch (Exception e) {
48 } else if (element instanceof GroupNode){
50 GroupNode groupNode = (GroupNode) element;
51 return groupNode.getImage();
52 } catch (Exception e) {
55 } else if (element instanceof TableNode){
57 TableNode TableNode = (TableNode) element;
58 return TableNode.getImage();
59 } catch (Exception e) {
62 } else if (element instanceof ViewNode){
64 ViewNode ViewNode = (ViewNode) element;
65 return ViewNode.getImage();
66 } catch (Exception e) {
69 } else if (element instanceof SequenceNode){
71 SequenceNode SequenceNode = (SequenceNode) element;
72 return SequenceNode.getImage();
73 } catch (Exception e) {
79 return descriptor.createImage();
83 * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
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$
96 return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
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$
103 return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
105 } else if (element instanceof SequenceNode) {
106 return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
108 return element.toString();
112 * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
114 public void addListener(ILabelProviderListener listener) {
118 * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
120 public void dispose() {
124 * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
126 public boolean isLabelProperty(Object element, String property) {
131 * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
133 public void removeListener(ILabelProviderListener listener) {