Refactory: removed unnecessary local variables and imports.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ViewTableAction.java
index f61a384..9c917f6 100644 (file)
@@ -1,66 +1,72 @@
 package net.sourceforge.phpdt.sql.actions;
 
-import net.sourceforge.phpdt.sql.view.BookmarkView;
-import net.sourceforge.phpdt.sql.view.TableView;
-import net.sourceforge.phpdt.sql.view.bookmark.TableNode;
-import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
-import net.sourceforge.phpdt.sql.view.bookmark.ViewNode;
-
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.ui.IViewActionDelegate;
 import org.eclipse.ui.IViewPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
+
+import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.SubsetView;
+import net.sourceforge.phpdt.sql.view.TableView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
+import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
 
 /**
  * @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 action for "View Table"
+*/
 public class ViewTableAction extends Action implements IViewActionDelegate {
-  BookmarkView view;
-  /**
-   * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
-   */
-  public void init(IViewPart view) {
-    this.view = (BookmarkView) view;
-  }
+    IViewPart view;
+       /**
+        * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+        */
+       public void init(IViewPart view) {
+               this.view = view;
+       }
 
-  /**
-   * @see org.eclipse.ui.IActionDelegate#run(IAction)
-   */
-  public void run(IAction action) {
-    run();
-  }
+       /**
+        * @see org.eclipse.ui.IActionDelegate#run(IAction)
+        */
+       public void run(IAction action) {
+               run();
+       }
+       
+       public void run() {
+               PHPEclipseSQLPlugin PHPEclipsePluginPluginInstance = PHPEclipseSQLPlugin.getDefault();
+               PHPEclipsePluginPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
+               TreeNode node = null;
+               BookmarkNode bookmark = null; 
+               if (view instanceof BookmarkView){
+                       BookmarkView bookmarkView = (BookmarkView) view;
+                       node = (TreeNode) bookmarkView.getCurrent();
+                       bookmark = bookmarkView.getCurrentBookmark(); 
+                       if (bookmark != null && node != null)
+                               TableView.getInstance().loadTable(bookmark, node.getName());
+               } else if (view instanceof SubsetView){
+                       SubsetView subsetView = (SubsetView) view;
+                       node = (TreeNode) subsetView.getCurrent();
+                       if (!(node instanceof ObjectNode)) return;
+                       ObjectNode objectNode = (ObjectNode) node;
+                       String bookmarkName = objectNode.getBookmark();
+                       bookmark = BookmarkContentProvider.getInstance().find(bookmarkName); 
 
-  public void run() {
-    TreeNode node = (TreeNode) view.getCurrent();
-    String name = null;
-    if (node instanceof TableNode) {
-      name = ((TableNode) node).getName();
-    } else if (node instanceof ViewNode) {
-      name = ((ViewNode) node).getName();
-    }
+                       String query = objectNode.getQuery();
+                       MultiSQLServer server = MultiSQLServer.getInstance();
+                       
+                       TableView.getInstance().loadQuery(bookmark, server.execute(bookmark.getConnection(), query));
 
-    try {
-      IWorkbenchPage page =
-        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
-      page.showView(TableView.TABLEVIEW_ID);
-    } catch (PartInitException e) {
-    }
-    TableView.getInstance().loadTable(name);
-  }
+               }
+       }
 
-  /**
-   * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
-   */
-  public void selectionChanged(IAction action, ISelection selection) {
-  }
+       /**
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
+        */
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
 
 }