X-Git-Url: http://secure.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java index 91b9916..7975f0b 100644 --- a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/actions/ViewTableAction.java @@ -1,12 +1,22 @@ 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.ExceptionDisplayDialog; +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; @@ -16,28 +26,42 @@ 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) { + ExceptionDisplayDialog.openError(getShell(), null, null, e); + } + } + + /** + * @return + */ + private Shell getShell() { + return this.view.getSite().getShell(); } public boolean updateSelection(IStructuredSelection selection) {