1 package com.quantum.actions;
3 import java.sql.SQLException;
5 import com.quantum.ImageStore;
6 import com.quantum.Messages;
7 import com.quantum.adapters.DatabaseAdapter;
8 import com.quantum.model.Bookmark;
9 import com.quantum.model.Entity;
10 import com.quantum.sql.MultiSQLServer;
11 import com.quantum.sql.SQLResultSetCollection;
12 import com.quantum.sql.SQLResultSetResults;
13 import com.quantum.sql.SQLResults;
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.viewers.IStructuredSelection;
19 import org.eclipse.swt.widgets.Shell;
20 import org.eclipse.ui.IViewPart;
21 import org.eclipse.ui.actions.SelectionListenerAction;
25 * Implements action for "View Table"
27 public class ViewTableAction extends SelectionListenerAction {
28 private Entity entity;
29 private ConnectionUtil connectionUtil = new ConnectionUtil();
30 private final IViewPart view;
32 public ViewTableAction(IViewPart view) {
33 super(Messages.getString(ViewTableAction.class, "text"));
36 ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
41 Bookmark bookmark = this.entity.getBookmark();
42 DatabaseAdapter adapter = bookmark.getAdapter();
43 String query = adapter.getTableQuery((entity).getQualifiedName());
46 SQLResults results = MultiSQLServer.getInstance().execute(
48 this.connectionUtil.connect(bookmark, getShell()),
52 if (results != null && results.isResultSet()) {
53 SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results);
55 } catch (SQLException e) {
56 ExceptionDisplayDialog.openError(getShell(), null, null, e);
63 private Shell getShell() {
64 return this.view.getSite().getShell();
67 public boolean updateSelection(IStructuredSelection selection) {
68 boolean enabled = super.updateSelection(selection);
69 enabled &= (selection.size() == 1);
72 Object object = selection.getFirstElement();
73 if (object != null && object instanceof EntityNode) {
74 EntityNode entityNode = (EntityNode) object;
75 this.entity = entityNode.getEntity();
76 enabled &= (entityNode.isTable() || entityNode.isView());