put connection Listener and report listener as seperate threads.
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / actions / ViewTableDetailsAction.java
1 package com.quantum.actions;
2
3 import java.sql.Connection;
4 import java.sql.SQLException;
5 import java.util.List;
6
7 import com.quantum.ImageStore;
8 import com.quantum.Messages;
9 import com.quantum.model.Bookmark;
10 import com.quantum.model.Entity;
11 import com.quantum.sql.MultiSQLServer;
12 import com.quantum.sql.SQLResultSetCollection;
13 import com.quantum.sql.SQLResultSetResults;
14 import com.quantum.ui.dialog.ExceptionDisplayDialog;
15 import com.quantum.util.connection.ConnectionUtil;
16 import com.quantum.view.bookmark.EntityNode;
17
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.swt.widgets.Shell;
22 import org.eclipse.ui.IViewPart;
23 import org.eclipse.ui.actions.SelectionListenerAction;
24
25 public class ViewTableDetailsAction extends SelectionListenerAction  {
26         private IViewPart view;
27     private ConnectionUtil connectionUtil = new ConnectionUtil();
28         
29         public ViewTableDetailsAction(IViewPart view) {
30         super(Messages.getString(ViewTableDetailsAction.class, "text"));
31         setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.TABLE_DETAILS));
32                 this.view = view;
33         }
34
35         public void run() {
36         Entity entity = getEntity();
37         Connection connection = connectionUtil.getConnection(getBookmark(), getShell());
38         if (connection != null) {
39                 try {
40                     SQLResultSetResults results = 
41                         MultiSQLServer.getInstance().getMetaData(entity, connection);
42                     if (results != null) {
43                         SQLResultSetCollection.getInstance().addSQLResultSet(results);
44                     }
45                 } catch (SQLException e) {
46                         ExceptionDisplayDialog.openError(getShell(), null, null, e);
47                 }
48         }
49         }
50         public void selectionChanged(IAction action, ISelection selection) {
51         }
52     protected Bookmark getBookmark() {
53         return getEntity().getBookmark();
54     }
55     protected Shell getShell() {
56         return this.view.getViewSite().getShell();
57     }
58     protected Entity getEntity() {
59         List list = getSelectedNonResources();
60         return ((EntityNode) list.get(0)).getEntity();
61     }
62
63     /**
64      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
65      */
66     protected boolean updateSelection(IStructuredSelection selection) {
67         boolean enabled = super.updateSelection(selection);
68         return enabled && selection.size() == 1;
69     }
70
71 }