SQL Plugin copied from Quantum plugin and refactored for PHPEclipse
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / actions / ConnectAction.java
diff --git a/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ConnectAction.java b/archive/net.sourceforge.phpeclipse.sql/src/net/sourceforge/phpdt/sql/actions/ConnectAction.java
new file mode 100644 (file)
index 0000000..e58acec
--- /dev/null
@@ -0,0 +1,66 @@
+package net.sourceforge.phpdt.sql.actions;
+
+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.IWorkbenchPart;
+
+import net.sourceforge.phpdt.sql.sql.MultiSQLServer;
+import net.sourceforge.phpdt.sql.sql.SQLHelper;
+import net.sourceforge.phpdt.sql.view.BookmarkView;
+import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
+
+public class ConnectAction extends Action implements IViewActionDelegate {
+       private SQLHelper helper = new SQLHelper();
+       private BookmarkView view;
+       /**
+        * Constructor for Action1.
+        */
+       public ConnectAction() {
+               super();
+       }
+
+       /**
+        * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+        */
+       public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+       }
+
+       /**
+        * @see IActionDelegate#run(IAction)
+        */
+       public void run(IAction action) {
+               run();
+       }
+
+       /**
+        * @see IActionDelegate#selectionChanged(IAction, ISelection)
+        */
+       public void selectionChanged(IAction action, ISelection selection) {
+       }
+
+       /**
+        * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
+        */
+       public void init(IViewPart view) {
+               this.view = (BookmarkView) view;
+       }
+
+       /**
+        * @see org.eclipse.jface.action.IAction#run()
+        */
+       public void run() {
+               view.disconnect();
+               BookmarkNode current = view.getCurrentBookmark();
+               view.setStatus("Connecting to " + current.getName() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
+               boolean status = MultiSQLServer.getInstance().connect(current);
+               if (status) {
+                       view.refreshBookmarkData();
+                       view.expandCurrent(current);
+               } else {
+                       view.setStatus("Error while connecting to " + current.getName()); //$NON-NLS-1$
+               }
+       }
+}
\ No newline at end of file