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 NextPageAction extends ResultSetAction implements PropertyChangeListener {
22 private SQLResultSetResults resultSet;
24 public NextPageAction(IViewPart view, ISelectionProvider selectionProvider) {
25 super(view, selectionProvider);
26 setText(Messages.getString(getClass(), "text"));
27 setImageDescriptor(ImageStore.getImageDescriptor(ImageStore.NEXT));
28 setToolTipText(Messages.getString(getClass(), "text"));
29 setEnabled(hasNextPage((IStructuredSelection) selectionProvider.getSelection()));
32 protected void executeResultSetAction(SQLResultSetResults results) throws SQLException {
33 if (results instanceof Scrollable) {
34 ((Scrollable) results).nextPage(getConnection(results));
37 protected boolean updateSelection(IStructuredSelection selection) {
38 setResultSet(getResultSet(selection));
39 return hasNextPage(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 hasNextPage(IStructuredSelection selection) {
71 return !selection.isEmpty() &&
72 (selection.getFirstElement() instanceof Scrollable) &&
73 ((Scrollable) selection.getFirstElement()).hasNextPage();
76 public void propertyChange(PropertyChangeEvent event) {
77 if ("rows".equals(event.getPropertyName())) {
78 setEnabled(hasNextPage(getStructuredSelection()));