1 package com.quantum.view.tableview;
3 import java.sql.Connection;
4 import java.sql.SQLException;
6 import com.quantum.sql.SQLResultSetResults;
7 import com.quantum.ui.dialog.ExceptionDisplayDialog;
8 import com.quantum.ui.dialog.SQLExceptionDialog;
9 import com.quantum.util.connection.ConnectionUtil;
11 import org.eclipse.jface.viewers.ISelectionProvider;
12 import org.eclipse.jface.viewers.IStructuredSelection;
13 import org.eclipse.swt.widgets.Shell;
14 import org.eclipse.ui.IViewPart;
15 import org.eclipse.ui.actions.SelectionListenerAction;
20 public abstract class ResultSetAction extends SelectionListenerAction {
21 private IViewPart view;
22 private ConnectionUtil connectionUtil = new ConnectionUtil();
23 private final ISelectionProvider selectionProvider;
26 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
28 public ResultSetAction(IViewPart view, ISelectionProvider selectionProvider) {
30 this.selectionProvider = selectionProvider;
32 this.selectionProvider.addSelectionChangedListener(this);
37 IStructuredSelection selection =
38 (IStructuredSelection) this.selectionProvider.getSelection();
39 if (!selection.isEmpty()) {
40 SQLResultSetResults results = (SQLResultSetResults) selection.getFirstElement();
41 executeResultSetAction(results);
43 } catch (SQLException e) {
44 SQLExceptionDialog.openException(getShell(), null, e);
45 } catch (RuntimeException e) {
46 ExceptionDisplayDialog.openError(getShell(), null, null, e);
50 protected boolean updateSelection(IStructuredSelection selection) {
51 return selection != null && !selection.isEmpty();
55 * @throws SQLException
57 protected abstract void executeResultSetAction(SQLResultSetResults results) throws SQLException;
63 protected Connection getConnection(SQLResultSetResults results) {
64 return this.connectionUtil.connect(results.getBookmark(), getShell());
70 private Shell getShell() {
71 return this.view.getSite().getShell();