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.ui.dialog.SQLExceptionDialog;
16 import com.quantum.util.connection.ConnectionUtil;
17 import com.quantum.view.bookmark.EntityNode;
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;
26 public class ViewTableDetailsAction extends SelectionListenerAction {
27 private IViewPart view;
28 private ConnectionUtil connectionUtil = new ConnectionUtil();
30 public ViewTableDetailsAction(IViewPart view) {
31 super(Messages.getString(ViewTableDetailsAction.class, "text"));
32 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.TABLE_DETAILS));
37 Entity entity = getEntity();
38 Connection connection = connectionUtil.getConnection(getBookmark(), getShell());
39 if (connection != null) {
41 SQLResultSetResults results =
42 MultiSQLServer.getInstance().getMetaData(entity, connection);
43 if (results != null) {
44 SQLResultSetCollection.getInstance().addSQLResultSet(results);
46 } catch (SQLException e) {
47 SQLExceptionDialog.openException(getShell(),
48 entity == null ? null : entity.getBookmark(), e);
52 public void selectionChanged(IAction action, ISelection selection) {
54 protected Bookmark getBookmark() {
55 return getEntity().getBookmark();
57 protected Shell getShell() {
58 return this.view.getViewSite().getShell();
60 protected Entity getEntity() {
61 List list = getSelectedNonResources();
62 return ((EntityNode) list.get(0)).getEntity();
66 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
68 protected boolean updateSelection(IStructuredSelection selection) {
69 boolean enabled = super.updateSelection(selection);
70 return enabled && selection.size() == 1;