[power-matchmaker] r2781 committed - Corrected the paging of the addresses. Now the user cannot move before...

0 views
Skip to first unread message

power-ma...@googlecode.com

unread,
Jan 31, 2011, 12:13:16 PM1/31/11
to matchmake...@googlegroups.com
Revision: 2781
Author: ThomasObrien95
Date: Mon Jan 31 09:12:36 2011
Log: Corrected the paging of the addresses. Now the user cannot move before
the first address or after the last.

Also corrected an error where changing the number of visible addresses
would move the addresses displayed forward by 1.
http://code.google.com/p/power-matchmaker/source/detail?r=2781

Modified:
/branches/0.9.7/src/ca/sqlpower/matchmaker/address/AddressPool.java

/branches/0.9.7/src/ca/sqlpower/matchmaker/swingui/address/AddressValidationPanel.java

=======================================
--- /branches/0.9.7/src/ca/sqlpower/matchmaker/address/AddressPool.java Fri
Jan 28 13:03:44 2011
+++ /branches/0.9.7/src/ca/sqlpower/matchmaker/address/AddressPool.java Mon
Jan 31 09:12:36 2011
@@ -268,9 +268,34 @@

addresses.clear();
}
+
+ public long findAddressCount() throws SQLException {
+ SQLTable resultTable = project.getResultTable();
+ Connection con = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try {
+ con = project.createResultTableConnection();
+
+ stmt = con.createStatement();
+
+ StringBuilder sql;
+ sql = new StringBuilder("SELECT COUNT(*) FROM ");
+ appendFullyQualifiedTableName(sql, resultTable);
+ rs = stmt.executeQuery(sql.toString());
+ rs.next();
+ return rs.getLong(1);
+ } finally {
+ setFinished(true);
+ if (rs != null) rs.close();
+ if (stmt != null) stmt.close();
+ if (con != null) con.close();
+ }
+ }

public void load(Logger engineLogger) throws SQLException,
SQLObjectException {
- load(engineLogger, true, 0, true, null);
+ load(engineLogger, true, 0, true, null, true);
}

/**
@@ -296,7 +321,7 @@
* SEE ABOVE HACK
*/
public void load(Logger engineLogger, boolean selectAll, int entryCount,
- boolean forward, List<Object> startPoint)
+ boolean forward, List<Object> startPoint, boolean includeStartPoint)
throws SQLException, SQLObjectException {
setCancelled(false);
setStarted(true);
@@ -356,9 +381,14 @@
}
sql.append(SOURCE_ADDRESS_KEY_COLUMN_BASE).append(i).append(" ");
if (forward) {
- sql.append("> ");
+ sql.append(">");
} else {
- sql.append("< ");
+ sql.append("<");
+ }
+ if (includeStartPoint) {
+ sql.append("= ");
+ } else {
+ sql.append(" ");
}

if (SQL.isNumeric(column.getType()) ||
SQL.isBoolean(column.getType())) {
=======================================
---
/branches/0.9.7/src/ca/sqlpower/matchmaker/swingui/address/AddressValidationPanel.java
Thu Jan 27 10:06:15 2011
+++
/branches/0.9.7/src/ca/sqlpower/matchmaker/swingui/address/AddressValidationPanel.java
Mon Jan 31 09:12:36 2011
@@ -109,20 +109,32 @@
*/
private int displayCount = 5;

+ /**
+ * The total number of addresses that can be contained in the address
pool. Used
+ * to decide if there are further pages the user can move to with the
next button.
+ */
+ private long correctableAddressCount;
+
+ /**
+ * The number of the first address in the list. Used to decide if
there is an address
+ * that can be moved to with the next and previous buttons.
+ */
+ private long currentAddressBeingDisplayed = 0;
+
private final List<Object> startPoint;
private final List<Object> endPoint;
private final int pkeyChildCount;

private final JButton prevButton = new JButton(new AbstractAction("Prev")
{
public void actionPerformed(ActionEvent e) {
- updateDisplayedAddresses(false, startPoint);
+ updateDisplayedAddresses(false, startPoint, false);
nextButton.setEnabled(true);
}
});

private final JButton nextButton = new JButton(new AbstractAction("Next")
{
public void actionPerformed(ActionEvent e) {
- updateDisplayedAddresses(true, endPoint);
+ updateDisplayedAddresses(true, endPoint, false);
prevButton.setEnabled(true);
}
});
@@ -141,8 +153,13 @@
throw new RuntimeException("A database exception occured while trying
to connect to the Berkley DB", e);
}
this.pool = pool;
-
- updateDisplayedAddresses(true, startPoint);
+ try {
+ correctableAddressCount = pool.findAddressCount();
+ } catch (SQLException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ updateDisplayedAddresses(true, startPoint, true);

needsValidationList = new JList(allResults);

needsValidationList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
@@ -180,7 +197,7 @@
public void focusLost(FocusEvent e) {
try {
displayCount = Integer.parseInt(displayCountField.getText());
- updateDisplayedAddresses(true, startPoint);
+ updateDisplayedAddresses(true, startPoint, true);
} catch (NumberFormatException ex) {
displayCountField.setText(Integer.toString(displayCount));
}
@@ -211,10 +228,10 @@
* Call this method to change the addresses displayed depending on the
* {@link #displayCount} and {@link #displayPage}.
*/
- private void updateDisplayedAddresses(boolean forward, List<Object>
queryPoint) {
+ private void updateDisplayedAddresses(boolean forward, List<Object>
queryPoint, boolean includeStartPoint) {
addressResults.clear();
try {
- pool.load(logger, false, displayCount, forward, queryPoint);
+ pool.load(logger, false, displayCount, forward, queryPoint,
includeStartPoint);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -237,6 +254,17 @@
// invalidResults.add(0, address);
// }
}
+
+ if (!queryPoint.isEmpty() && !forward && startPoint.equals(queryPoint)) {
+ currentAddressBeingDisplayed -= displayCount;
+ } else if (!queryPoint.isEmpty() && forward &&
endPoint.equals(queryPoint)) {
+ currentAddressBeingDisplayed += displayCount;
+ }
+ if (currentAddressBeingDisplayed < 0) {
+ currentAddressBeingDisplayed = 0;
+ }
+
+
startPoint.clear();
endPoint.clear();
if (addressArray.length > 0) {
@@ -254,12 +282,18 @@
endPoint.add(((AddressResult)
addressArray[endArrayPoint]).getKeyValues().get(i));
}
}
- if (addressArray.length < displayCount) {
- if (forward) {
- nextButton.setEnabled(false);
- } else {
- prevButton.setEnabled(false);
- }
+ prevButton.setEnabled(true);
+ nextButton.setEnabled(true);
+ if (currentAddressBeingDisplayed == 0) {
+ prevButton.setEnabled(false);
+ }
+ if (currentAddressBeingDisplayed >= correctableAddressCount -
displayCount) {
+ nextButton.setEnabled(false);
+ }
+ //DisplayCount == 0 means all values are being displayed
+ if (displayCount == 0) {
+ prevButton.setEnabled(false);
+ nextButton.setEnabled(false);
}
}

Reply all
Reply to author
Forward
0 new messages