1 package com.quantum.view.tableview;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
5 import java.sql.SQLException;
7 import com.quantum.ImageStore;
8 import com.quantum.Messages;
9 import com.quantum.sql.SQLResultSetResults;
10 import com.quantum.sql.Scrollable;
12 import org.eclipse.jface.viewers.ISelectionProvider;
13 import org.eclipse.jface.viewers.IStructuredSelection;
14 import org.eclipse.ui.IViewPart;
20 public class PreviousPageAction extends ResultSetAction implements PropertyChangeListener {
22 private SQLResultSetResults resultSet;
24 public PreviousPageAction(IViewPart view, ISelectionProvider selectionProvider) {
25 super(view, selectionProvider);
26 setText(Messages.getString(getClass(), "text"));
27 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.PREVIOUS));
28 setToolTipText(Messages.getString(getClass(), "text"));
29 setEnabled(hasPreviousPage((IStructuredSelection) selectionProvider.getSelection()));
32 protected void executeResultSetAction(SQLResultSetResults results) throws SQLException {
33 if (results instanceof Scrollable) {
34 ((Scrollable) results).previousPage(getConnection(results));
37 protected boolean updateSelection(IStructuredSelection selection) {
38 setResultSet(getResultSet(selection));
39 return hasPreviousPage(selection);
45 private void setResultSet(SQLResultSetResults results) {
46 if (this.resultSet != null) {
47 this.resultSet.removePropertyChangeListener(this);
50 this.resultSet = results;
51 if (results != null) {
52 this.resultSet.addPropertyChangeListener(this);
59 private SQLResultSetResults getResultSet(IStructuredSelection selection) {
60 return (selection != null && !selection.isEmpty() &&
61 (selection.getFirstElement() instanceof SQLResultSetResults))
62 ? (SQLResultSetResults) selection.getFirstElement()
70 private boolean hasPreviousPage(IStructuredSelection selection) {
71 return !selection.isEmpty() &&
72 (selection.getFirstElement() instanceof Scrollable) &&
73 ((Scrollable) selection.getFirstElement()).hasPreviousPage();
76 public void propertyChange(PropertyChangeEvent event) {
77 if ("rows".equals(event.getPropertyName())) {
78 setEnabled(hasPreviousPage(getStructuredSelection()));