*** empty log message ***
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / view / SubsetLabelProvider.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.view.bookmark.ColumnMetaData;
13 import net.sourceforge.phpdt.sql.view.bookmark.Root;
14 import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
15 import net.sourceforge.phpdt.sql.view.bookmark.SubsetNode;
16 import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
17 import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
18
19 /**
20  * @author root
21  *
22  * Implements the ILabelProvider for the Bookmarks.
23  */
24 public class SubsetLabelProvider implements ILabelProvider {
25         /**
26          * @see org.eclipse.jface.viewers.ILabelProvider#getImage(Object)
27          */
28         public Image getImage(Object element) {
29          ImageDescriptor descriptor = null;
30            if (element instanceof SubsetNode) {
31                 try {
32            URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
33            URL url = new URL(installURL, "icons/subset.gif"); //$NON-NLS-1$
34            descriptor = ImageDescriptor.createFromURL(url);
35                 } catch (Exception e) {
36                         e.printStackTrace();
37                 }
38            } else if (element instanceof ColumnMetaData){
39                 try {
40                         ColumnMetaData columnMetaData = (ColumnMetaData) element;
41                         return columnMetaData.getImage();
42                  } catch (Exception e) {
43                          e.printStackTrace();
44                  }
45            } else {
46                 return null;
47         }
48            return descriptor.createImage();
49         }
50
51         /**
52          * @see org.eclipse.jface.viewers.ILabelProvider#getText(Object)
53          */
54         public String getText(Object element) {
55                 if (element instanceof SubsetNode) {
56                         SubsetNode subset = (SubsetNode) element;
57                         return subset.getName();
58                 } else if (element.equals(Root.ROOT)) {
59                         return "ROOT"; //$NON-NLS-1$
60                 } else if (element instanceof TableNode) {
61                         TableNode node = (TableNode) element;
62                         if (node.isSizeVisible()) {
63                                 return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64                         } else {
65                                 return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
66                         }
67                 } else if (element instanceof ViewNode) {
68                         ViewNode node = (ViewNode) element;
69                         if (node.isSizeVisible()) {
70                                 return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
71                         } else {
72                                 return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
73                         }
74                 } else if (element instanceof SequenceNode) {
75                         return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
76                 }
77                 return element.toString();
78         }
79
80         /**
81          * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(ILabelProviderListener)
82          */
83         public void addListener(ILabelProviderListener listener) {
84         }
85
86         /**
87          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
88          */
89         public void dispose() {
90         }
91
92         /**
93          * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(Object, String)
94          */
95         public boolean isLabelProperty(Object element, String property) {
96                 return false;
97         }
98
99         /**
100          * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(ILabelProviderListener)
101          */
102         public void removeListener(ILabelProviderListener listener) {
103      }
104 }