Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / view / BookmarkLabelProvider.java
index c3437b8..347bc26 100644 (file)
@@ -2,16 +2,17 @@ package net.sourceforge.phpdt.sql.view;
 
 import java.net.URL;
 
-import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
-
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
 import org.eclipse.swt.graphics.Image;
 
+import net.sourceforge.phpdt.sql.Messages;
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
 import net.sourceforge.phpdt.sql.bookmarks.Bookmark;
-import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ColumnMetaData;
+import net.sourceforge.phpdt.sql.view.bookmark.GroupNode;
 import net.sourceforge.phpdt.sql.view.bookmark.Root;
 import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
 import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
@@ -20,10 +21,7 @@ import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
 /**
  * @author root
  *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
+ * Implements the ILabelProvider for the Bookmarks.
  */
 public class BookmarkLabelProvider implements ILabelProvider {
        /**
@@ -34,18 +32,50 @@ public class BookmarkLabelProvider implements ILabelProvider {
           if (element instanceof BookmarkNode) {
                try {
            URL installURL = PHPEclipseSQLPlugin.getDefault().getDescriptor().getInstallURL();
-           MultiSQLServer server = MultiSQLServer.getInstance();
-            URL url = new URL(installURL, "icons/bookmarks.gif");
-           if (server.getConnected() != null && element.equals(server.getConnected())){
-            url = new URL(installURL, "icons/connected.gif");
-           }
-           descriptor = ImageDescriptor.createFromURL(url);
+           BookmarkNode bookmark = (BookmarkNode) element;
+                  URL url = new URL(installURL, (bookmark.isConnected()) ? "icons/connected.gif" :  "icons/bookmarks.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+          descriptor = ImageDescriptor.createFromURL(url);
                } catch (Exception e) {
                        e.printStackTrace();
                }
-          } else {
-                 return null;
-          }
+          } else if (element instanceof ColumnMetaData){
+               try {
+                       ColumnMetaData columnMetaData = (ColumnMetaData) element;
+                       return columnMetaData.getImage();
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+          } else if (element instanceof GroupNode){
+               try {
+                       GroupNode groupNode = (GroupNode) element;
+                       return groupNode.getImage();
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+          } else if (element instanceof TableNode){
+               try {
+                       TableNode TableNode = (TableNode) element;
+                       return TableNode.getImage();
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+          } else if (element instanceof ViewNode){
+               try {
+                       ViewNode ViewNode = (ViewNode) element;
+                       return ViewNode.getImage();
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+          } else if (element instanceof SequenceNode){
+               try {
+                       SequenceNode SequenceNode = (SequenceNode) element;
+                       return SequenceNode.getImage();
+                } catch (Exception e) {
+                        e.printStackTrace();
+                }
+               } else {
+               return null;
+               }
           return descriptor.createImage();
        }
 
@@ -57,23 +87,23 @@ public class BookmarkLabelProvider implements ILabelProvider {
                        Bookmark bookmark = (Bookmark) element;
                        return bookmark.getName();
                } else if (element.equals(Root.ROOT)) {
-                       return "ROOT";
+                       return "ROOT"; //$NON-NLS-1$
                } else if (element instanceof TableNode) {
                        TableNode node = (TableNode) element;
-                       if (node.getSize() > -1) {
-                               return "T " + element.toString() + " (" + node.getSize() + ")";
+                       if (node.isSizeVisible()) {
+                               return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                        } else {
-                               return "T " + element.toString();
+                               return Messages.getString("BookmarkLabelProvider.TablePrefix") + element.toString(); //$NON-NLS-1$
                        }
                } else if (element instanceof ViewNode) {
                        ViewNode node = (ViewNode) element;
-                       if (node.getSize() > -1) {
-                               return "V " + element.toString() + " (" + node.getSize() + ")";
+                       if (node.isSizeVisible()) {
+                               return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString() + " (" + node.getSize() + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                        } else {
-                               return "V " + element.toString();
+                               return Messages.getString("BookmarkLabelProvider.ViewPrefix") + element.toString(); //$NON-NLS-1$
                        }
                } else if (element instanceof SequenceNode) {
-                       return "S " + element.toString();
+                       return Messages.getString("BookmarkLabelProvider.SequencePrefix") + element.toString(); //$NON-NLS-1$
                }
                return element.toString();
        }