You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2010/10/26 14:33:04 UTC

svn commit: r1027510 - /pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java

Author: gbrown
Date: Tue Oct 26 12:33:03 2010
New Revision: 1027510

URL: http://svn.apache.org/viewvc?rev=1027510&view=rev
Log:
Add a validate() method to TableViewRowEditor to allow subclasses to easily validate editor contents.

Modified:
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java?rev=1027510&r1=1027509&r2=1027510&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java Tue Oct 26 12:33:03 2010
@@ -313,6 +313,8 @@ public class TableViewRowEditor extends 
 
     @SuppressWarnings("unchecked")
     public void close(boolean result) {
+        boolean valid = true;
+
         if (result) {
             // Update the row data
             List<Object> tableData = (List<Object>)tableView.getTableData();
@@ -320,43 +322,53 @@ public class TableViewRowEditor extends 
             Object tableRow = tableData.get(rowIndex);
             tablePane.store(tableRow);
 
-            if (tableData.getComparator() == null) {
-                tableData.update(rowIndex, tableRow);
-            } else {
-                tableData.remove(rowIndex, 1);
-                tableData.add(tableRow);
+            valid = validate(tableRow);
 
-                // Re-select the item, and make sure it's visible
-                rowIndex = tableData.indexOf(tableRow);
-                tableView.setSelectedIndex(rowIndex);
-                tableView.scrollAreaToVisible(tableView.getRowBounds(rowIndex));
+            if (valid) {
+                if (tableData.getComparator() == null) {
+                    tableData.update(rowIndex, tableRow);
+                } else {
+                    tableData.remove(rowIndex, 1);
+                    tableData.add(tableRow);
+
+                    // Re-select the item, and make sure it's visible
+                    rowIndex = tableData.indexOf(tableRow);
+                    tableView.setSelectedIndex(rowIndex);
+                    tableView.scrollAreaToVisible(tableView.getRowBounds(rowIndex));
+                }
             }
         }
 
-        if (cardPane.getSelectedIndex() == EDITOR_CARD_INDEX) {
-            cardPane.setSelectedIndex(IMAGE_CARD_INDEX);
-        } else {
-            getOwner().moveToFront();
-            tableView.requestFocus();
-
-            Display display = getDisplay();
-            display.getContainerMouseListeners().remove(displayMouseHandler);
-
-            super.close();
-
-            // Clear the editor components
-            TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();
-            tablePaneColumns.remove(0, tablePaneColumns.getLength());
-            editorRow.remove(0, editorRow.getLength());
-
-            tableView = null;
-            rowIndex = -1;
-            columnIndex = -1;
+        if (valid) {
+            if (cardPane.getSelectedIndex() == EDITOR_CARD_INDEX) {
+                cardPane.setSelectedIndex(IMAGE_CARD_INDEX);
+            } else {
+                getOwner().moveToFront();
+                tableView.requestFocus();
+
+                Display display = getDisplay();
+                display.getContainerMouseListeners().remove(displayMouseHandler);
+
+                super.close();
 
-            tableViewScrollPane = null;
+                // Clear the editor components
+                TablePane.ColumnSequence tablePaneColumns = tablePane.getColumns();
+                tablePaneColumns.remove(0, tablePaneColumns.getLength());
+                editorRow.remove(0, editorRow.getLength());
+
+                tableView = null;
+                rowIndex = -1;
+                columnIndex = -1;
+
+                tableViewScrollPane = null;
+            }
         }
     }
 
+    protected boolean validate(Object tableRow) {
+        return true;
+    }
+
     @Override
     public boolean keyPressed(int keyCode, Keyboard.KeyLocation keyLocation) {
         boolean consumed = false;