1 package net.sourceforge.phpdt.sql.actions;
3 import org.eclipse.jface.action.Action;
4 import org.eclipse.jface.action.IAction;
5 import org.eclipse.jface.viewers.ISelection;
6 import org.eclipse.ui.IViewActionDelegate;
7 import org.eclipse.ui.IViewPart;
9 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
10 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
11 import net.sourceforge.phpdt.sql.view.BookmarkView;
12 import net.sourceforge.phpdt.sql.view.SubsetView;
13 import net.sourceforge.phpdt.sql.view.TableView;
14 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkContentProvider;
15 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
16 import net.sourceforge.phpdt.sql.view.bookmark.ObjectNode;
17 import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
21 * Implements action for "View Table"
23 public class ViewTableAction extends Action implements IViewActionDelegate {
26 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
28 public void init(IViewPart view) {
33 * @see org.eclipse.ui.IActionDelegate#run(IAction)
35 public void run(IAction action) {
40 PHPEclipseSQLPlugin PHPEclipsePluginPluginInstance = PHPEclipseSQLPlugin.getDefault();
41 PHPEclipsePluginPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
43 BookmarkNode bookmark = null;
44 if (view instanceof BookmarkView){
45 BookmarkView bookmarkView = (BookmarkView) view;
46 node = (TreeNode) bookmarkView.getCurrent();
47 bookmark = bookmarkView.getCurrentBookmark();
48 if (bookmark != null && node != null)
49 TableView.getInstance().loadTable(bookmark, node.getName());
50 } else if (view instanceof SubsetView){
51 SubsetView subsetView = (SubsetView) view;
52 node = (TreeNode) subsetView.getCurrent();
53 if (!(node instanceof ObjectNode)) return;
54 ObjectNode objectNode = (ObjectNode) node;
55 String bookmarkName = objectNode.getBookmark();
56 bookmark = BookmarkContentProvider.getInstance().find(bookmarkName);
58 String query = objectNode.getQuery();
59 MultiSQLServer server = MultiSQLServer.getInstance();
61 TableView.getInstance().loadQuery(bookmark, server.execute(bookmark.getConnection(), query));
67 * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
69 public void selectionChanged(IAction action, ISelection selection) {