1 package com.quantum.actions;
3 import java.sql.Connection;
6 import com.quantum.adapters.DatabaseAdapter;
7 import com.quantum.model.Bookmark;
8 import com.quantum.sql.SQLResultSetCollection;
9 import com.quantum.sql.SQLResultSetResults;
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.bookmark.TreeNode;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.IViewPart;
19 import org.eclipse.ui.actions.SelectionListenerAction;
24 public abstract class BaseSequenceAction extends SelectionListenerAction {
26 protected IViewPart view;
27 private ConnectionUtil connectionUtil = new ConnectionUtil();
29 protected BaseSequenceAction(String text, IViewPart view) {
34 protected Bookmark getBookmark() {
35 TreeNode node = getEntityNode();
36 return node.getBookmark();
39 protected Connection getConnection() {
40 return connectionUtil.getConnection(getBookmark(), getShell());
43 protected EntityNode getEntityNode() {
44 List list = getSelectedNonResources();
45 return (EntityNode) list.get(0);
48 protected Shell getShell() {
49 return this.view.getViewSite().getShell();
52 protected boolean updateSelection(IStructuredSelection selection) {
53 boolean enabled = super.updateSelection(selection);
54 return enabled && selection.size() == 1
55 && (selection.getFirstElement() instanceof EntityNode)
56 && ((EntityNode) selection.getFirstElement()).isSequence();
60 EntityNode sequence = getEntityNode();
62 if (sequence.isSequence()) {
63 Bookmark bookmark = sequence.getBookmark();
64 DatabaseAdapter adapter = bookmark.getAdapter();
65 if (adapter == null) return;
66 name = sequence.getName();
67 String query = getQuery(sequence, name, adapter);
69 SQLResults results = ViewHelper.tryGetResults(view, bookmark, getConnection(), query);
70 if (results != null && results.isResultSet())
71 SQLResultSetCollection.getInstance().addSQLResultSet((SQLResultSetResults) results);
81 protected abstract String getQuery(EntityNode sequence, String name, DatabaseAdapter adapter);