Refactory: xdebug.ui plugin.
[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.ui.dialog.SQLExceptionDialog;
16 import com.quantum.util.connection.ConnectionUtil;
17 import com.quantum.view.bookmark.EntityNode;
18
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.swt.widgets.Shell;
23 import org.eclipse.ui.IViewPart;
24 import org.eclipse.ui.actions.SelectionListenerAction;
25
26 public class ViewTableDetailsAction extends SelectionListenerAction  {
27         private IViewPart view;
28     private ConnectionUtil connectionUtil = new ConnectionUtil();
29         
30         public ViewTableDetailsAction(IViewPart view) {
31         super(Messages.getString(ViewTableDetailsAction.class, "text"));
32         setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.TABLE_DETAILS));
33                 this.view = view;
34         }
35
36         public void run() {
37         Entity entity = getEntity();
38         Connection connection = connectionUtil.getConnection(getBookmark(), getShell());
39         if (connection != null) {
40                 try {
41                     SQLResultSetResults results = 
42                         MultiSQLServer.getInstance().getMetaData(entity, connection);
43                     if (results != null) {
44                         SQLResultSetCollection.getInstance().addSQLResultSet(results);
45                     }
46                 } catch (SQLException e) {
47                         SQLExceptionDialog.openException(getShell(), 
48                                         entity == null ? null : entity.getBookmark(), e);
49                 }
50         }
51         }
52         public void selectionChanged(IAction action, ISelection selection) {
53         }
54     protected Bookmark getBookmark() {
55         return getEntity().getBookmark();
56     }
57     protected Shell getShell() {
58         return this.view.getViewSite().getShell();
59     }
60     protected Entity getEntity() {
61         List list = getSelectedNonResources();
62         return ((EntityNode) list.get(0)).getEntity();
63     }
64
65     /**
66      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
67      */
68     protected boolean updateSelection(IStructuredSelection selection) {
69         boolean enabled = super.updateSelection(selection);
70         return enabled && selection.size() == 1;
71     }
72
73 }