A lot of changes
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ConnectAction.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 import org.eclipse.ui.IWorkbenchPart;
9
10 import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
11 import net.sourceforge.phpdt.sql.sql.SQLHelper;
12 import net.sourceforge.phpdt.sql.view.BookmarkView;
13 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
14
15 public class ConnectAction extends Action implements IViewActionDelegate {
16         private SQLHelper helper = new SQLHelper();
17         private BookmarkView view;
18         /**
19          * Constructor for Action1.
20          */
21         public ConnectAction() {
22                 super();
23         }
24
25         /**
26          * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
27          */
28         public void setActivePart(IAction action, IWorkbenchPart targetPart) {
29         }
30
31         /**
32          * @see IActionDelegate#run(IAction)
33          */
34         public void run(IAction action) {
35                 run();
36         }
37
38         /**
39          * @see IActionDelegate#selectionChanged(IAction, ISelection)
40          */
41         public void selectionChanged(IAction action, ISelection selection) {
42         }
43
44         /**
45          * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
46          */
47         public void init(IViewPart view) {
48                 this.view = (BookmarkView) view;
49         }
50
51         /**
52          * @see org.eclipse.jface.action.IAction#run()
53          */
54         public void run() {
55                 view.disconnect();
56                 BookmarkNode current = view.getCurrentBookmark();
57                 view.setStatus("Connecting to " + current.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
58                 boolean status = MultiSQLServer.getInstance().connect(current);
59                 if (status) {
60                         view.refreshBookmarkData();
61                         view.expandCurrent(current);
62                 } else {
63                         view.setStatus("Error while connecting to " + current.getName()); //$NON-NLS-1$
64                 }
65         }
66 }