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.util.connection.ConnectionUtil;
10 import org.eclipse.jface.viewers.ISelectionProvider;
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.swt.widgets.Shell;
13 import org.eclipse.ui.IViewPart;
14 import org.eclipse.ui.actions.SelectionListenerAction;
19 public abstract class ResultSetAction extends SelectionListenerAction {
20 private IViewPart view;
21 private ConnectionUtil connectionUtil = new ConnectionUtil();
22 private final ISelectionProvider selectionProvider;
25 * @see org.eclipse.ui.IViewActionDelegate#init(IViewPart)
27 public ResultSetAction(IViewPart view, ISelectionProvider selectionProvider) {
29 this.selectionProvider = selectionProvider;
31 this.selectionProvider.addSelectionChangedListener(this);
36 IStructuredSelection selection =
37 (IStructuredSelection) this.selectionProvider.getSelection();
38 if (!selection.isEmpty()) {
39 SQLResultSetResults results = (SQLResultSetResults) selection.getFirstElement();
40 executeResultSetAction(results);
42 } catch (SQLException e) {
43 ExceptionDisplayDialog.openError(getShell(), null, null, e);
44 } catch (RuntimeException e) {
45 ExceptionDisplayDialog.openError(getShell(), null, null, e);
49 protected boolean updateSelection(IStructuredSelection selection) {
50 return selection != null && !selection.isEmpty();
54 * @throws SQLException
56 protected abstract void executeResultSetAction(SQLResultSetResults results) throws SQLException;
62 protected Connection getConnection(SQLResultSetResults results) {
63 return this.connectionUtil.connect(results.getBookmark(), getShell());
69 private Shell getShell() {
70 return this.view.getSite().getShell();