1 package com.quantum.actions;
3 import java.sql.Connection;
6 import com.quantum.ImageStore;
7 import com.quantum.Messages;
8 import com.quantum.model.Bookmark;
9 import com.quantum.model.Entity;
10 import com.quantum.sql.SQLResults;
11 import com.quantum.util.connection.ConnectionUtil;
12 import com.quantum.view.ViewHelper;
13 import com.quantum.view.bookmark.EntityNode;
14 import com.quantum.view.tableview.TableView;
16 import org.eclipse.jface.action.IAction;
17 import org.eclipse.jface.viewers.ISelection;
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;
23 public class ViewTableDetailsAction extends SelectionListenerAction {
24 private IViewPart view;
25 private ConnectionUtil connectionUtil = new ConnectionUtil();
27 public ViewTableDetailsAction(IViewPart view) {
28 super(Messages.getString(ViewTableDetailsAction.class, "text"));
29 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
34 Entity entity = getEntity();
35 StringBuffer query = new StringBuffer();
36 query.append(Messages.getString("MetaDataKey")+Messages.getString("MetaDataKeySeparator")); //$NON-NLS-1$ //$NON-NLS-2$
37 query.append(entity.getQuotedTableName());
38 Connection connection = connectionUtil.getConnection(getBookmark(), getShell());
39 if (connection != null) {
40 SQLResults results = ViewHelper.tryGetResults(view, connection, query.toString());
41 if (results != null && ! results.isError())
42 TableView.getInstance().loadQuery(entity.getBookmark(), results);
45 public void selectionChanged(IAction action, ISelection selection) {
47 protected Bookmark getBookmark() {
48 return getEntity().getBookmark();
50 protected Shell getShell() {
51 return this.view.getViewSite().getShell();
53 protected Entity getEntity() {
54 List list = getSelectedNonResources();
55 return ((EntityNode) list.get(0)).getEntity();
59 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
61 protected boolean updateSelection(IStructuredSelection selection) {
62 boolean enabled = super.updateSelection(selection);
63 return enabled && selection.size() == 1;