Moved to test plugin to eliminate dependency upon junit plugin
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / NextSequenceAction.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.adapters.AdapterFactory;
10 import net.sourceforge.phpdt.sql.adapters.DatabaseAdapter;
11 import net.sourceforge.phpdt.sql.adapters.NoSuchAdapterException;
12 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
13 import net.sourceforge.phpdt.sql.sql.SQLResults;
14 import net.sourceforge.phpdt.sql.view.BookmarkView;
15 import net.sourceforge.phpdt.sql.view.TableView;
16 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
17 import net.sourceforge.phpdt.sql.view.bookmark.SequenceNode;
18 import net.sourceforge.phpdt.sql.view.bookmark.TreeNode;
19
20 public class NextSequenceAction extends Action implements IViewActionDelegate {
21         BookmarkView view;
22         
23         public void init(IViewPart view) {
24                 this.view = (BookmarkView) view;
25         }
26
27         public void run(IAction action) {
28                 run();
29         }
30
31         public void run() {
32                 TreeNode node = (TreeNode) view.getCurrent();
33                 String name = null;
34                 try {
35                         if (node instanceof SequenceNode) {
36                                 SequenceNode sequence = (SequenceNode) node;
37                                 BookmarkNode parent = (BookmarkNode) sequence.getParent();
38                                 DatabaseAdapter adapter = AdapterFactory.getInstance().getAdapter(parent.getType());
39                                 name = sequence.getName();
40                                 String query = adapter.getNextValue(name);
41                                 MultiSQLServer server = MultiSQLServer.getInstance();
42                                 SQLResults results = server.execute(query);
43                                 TableView.getInstance().loadQuery(results);
44                         }
45                 } catch (NoSuchAdapterException e) {
46                 }
47         }
48
49         public void selectionChanged(IAction action, ISelection selection) {
50         }
51
52 }