Fixed #1721079 - Can not set breakpoint in different files on the same line
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ViewTableAction.java
1 package net.sourceforge.phpdt.sql.actions;
2
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;
8
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;
18
19 /**
20  * @author root
21  * Implements action for "View Table"
22 */
23 public class ViewTableAction extends Action implements IViewActionDelegate {
24     IViewPart view;
25         /**
26          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
27          */
28         public void init(IViewPart view) {
29                 this.view = view;
30         }
31
32         /**
33          * @see org.eclipse.ui.IActionDelegate#run(IAction)
34          */
35         public void run(IAction action) {
36                 run();
37         }
38         
39         public void run() {
40                 PHPEclipseSQLPlugin PHPEclipsePluginPluginInstance = PHPEclipseSQLPlugin.getDefault();
41                 PHPEclipsePluginPluginInstance.showView("net.sourceforge.phpdt.sql.view.tableview"); //$NON-NLS-1$
42                 TreeNode node = null;
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); 
57
58                         String query = objectNode.getQuery();
59                         MultiSQLServer server = MultiSQLServer.getInstance();
60                         
61                         TableView.getInstance().loadQuery(bookmark, server.execute(bookmark.getConnection(), query));
62
63                 }
64         }
65
66         /**
67          * @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
68          */
69         public void selectionChanged(IAction action, ISelection selection) {
70         }
71
72 }