package com.quantum.actions;
+import java.sql.SQLException;
+
import com.quantum.ImageStore;
import com.quantum.Messages;
+import com.quantum.adapters.DatabaseAdapter;
+import com.quantum.model.Bookmark;
import com.quantum.model.Entity;
+import com.quantum.sql.MultiSQLServer;
+import com.quantum.sql.SQLResultSetCollection;
+import com.quantum.sql.SQLResultSetResults;
+import com.quantum.sql.SQLResults;
+import com.quantum.ui.dialog.SQLExceptionDialog;
+import com.quantum.util.connection.ConnectionUtil;
import com.quantum.view.bookmark.EntityNode;
-import com.quantum.view.tableview.TableView;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.actions.SelectionListenerAction;
*/
public class ViewTableAction extends SelectionListenerAction {
private Entity entity;
+ private ConnectionUtil connectionUtil = new ConnectionUtil();
+ private final IViewPart view;
public ViewTableAction(IViewPart view) {
super(Messages.getString(ViewTableAction.class, "text"));
+ this.view = view;
setImageDescriptor(
ImageStore.getImageDescriptor(ImageStore.OPEN_TABLE));
}
public void run() {
- TableView.getInstance().loadTable(this.entity);
- // TODO: reinstate this
-// } else if (view instanceof SubsetView){
-// SubsetView subsetView = (SubsetView) view;
-// node = (TreeNode) subsetView.getCurrent();
-// if (!(node instanceof ObjectNode)) return;
-// ObjectNode objectNode = (ObjectNode) node;
-//
-// String query = objectNode.getQuery();
-//
-// SQLResults results = ViewHelper.tryGetResults(view, objectNode.getConnection(), query);
-// if (results != null && ! results.isError())
-// TableView.getInstance().loadQuery(bookmark.getBookmark(), results);
-//
+
+ Bookmark bookmark = this.entity.getBookmark();
+ DatabaseAdapter adapter = bookmark.getAdapter();
+ String query = adapter.getTableQuery((entity).getQualifiedName());
+
+ try {
+ SQLResults results = MultiSQLServer.getInstance().execute(
+ bookmark,
+ this.connectionUtil.connect(bookmark, getShell()),
+ this.entity,
+ query);
+
+ if (results != null && results.isResultSet()) {
+ SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results);
+ }
+ } catch (SQLException e) {
+ SQLExceptionDialog.openException(getShell(), bookmark, e);
+ }
+ }
+
+ /**
+ * @return
+ */
+ private Shell getShell() {
+ return this.view.getSite().getShell();
}
public boolean updateSelection(IStructuredSelection selection) {