1 package com.quantum.actions;
3 import java.sql.Connection;
4 import java.sql.SQLException;
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;
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;
25 public class ViewTableDetailsAction extends SelectionListenerAction {
26 private IViewPart view;
27 private ConnectionUtil connectionUtil = new ConnectionUtil();
29 public ViewTableDetailsAction(IViewPart view) {
30 super(Messages.getString(ViewTableDetailsAction.class, "text"));
31 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.TABLE_DETAILS));
36 Entity entity = getEntity();
37 Connection connection = connectionUtil.getConnection(getBookmark(), getShell());
38 if (connection != null) {
40 SQLResultSetResults results =
41 MultiSQLServer.getInstance().getMetaData(entity, connection);
42 if (results != null) {
43 SQLResultSetCollection.getInstance().addSQLResultSet(results);
45 } catch (SQLException e) {
46 ExceptionDisplayDialog.openError(getShell(), null, null, e);
50 public void selectionChanged(IAction action, ISelection selection) {
52 protected Bookmark getBookmark() {
53 return getEntity().getBookmark();
55 protected Shell getShell() {
56 return this.view.getViewSite().getShell();
58 protected Entity getEntity() {
59 List list = getSelectedNonResources();
60 return ((EntityNode) list.get(0)).getEntity();
64 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
66 protected boolean updateSelection(IStructuredSelection selection) {
67 boolean enabled = super.updateSelection(selection);
68 return enabled && selection.size() == 1;