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/03/11 00:58:26 UTC

svn commit: r921635 - in /pivot/trunk: tests/src/org/apache/pivot/tests/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/ wtk/src/org/apache/pivot/wtk/content/

Author: gbrown
Date: Wed Mar 10 23:58:25 2010
New Revision: 921635

URL: http://svn.apache.org/viewvc?rev=921635&view=rev
Log:
Add data binding support to TableView.

Modified:
    pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewListener.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/content/TableViewRowEditor.java

Modified: pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java
URL: http://svn.apache.org/viewvc/pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java (original)
+++ pivot/trunk/tests/src/org/apache/pivot/tests/DataBindingTest.java Wed Mar 10 23:58:25 2010
@@ -85,12 +85,12 @@ public class DataBindingTest implements 
 
     public static class TestBindMapping implements ListView.SelectedItemBindMapping, Spinner.SelectedItemBindMapping {
         @SuppressWarnings("unchecked")
-        public int indexOf(List<?> list, Object item) {
+        public int indexOf(List<?> list, Object value) {
             int i = 0;
             int n = list.getLength();
             while (i < n) {
                 Map<String, ?> map = (Map<String, ?>)list.get(i);
-                if (map.get("id").equals(item)) {
+                if (map.get("id").equals(value)) {
                     break;
                 }
 

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraTableViewSkin.java Wed Mar 10 23:58:25 2010
@@ -27,6 +27,7 @@ import org.apache.pivot.collections.Dict
 import org.apache.pivot.collections.List;
 import org.apache.pivot.collections.Sequence;
 import org.apache.pivot.util.Filter;
+import org.apache.pivot.wtk.BindType;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.Component;
 import org.apache.pivot.wtk.Dimensions;
@@ -1362,6 +1363,54 @@ public class TerraTableViewSkin extends 
         repaintComponent();
     }
 
+    @Override
+    public void tableDataKeyChanged(TableView tableView, String previousTableDataKey) {
+        // No-op
+    }
+
+    @Override
+    public void tableDataBindTypeChanged(TableView tableView, BindType previousTableDataBindType) {
+        // No-op
+    }
+
+    @Override
+    public void tableDataBindMappingChanged(TableView tableView,
+        TableView.TableDataBindMapping previousTableDataBindMapping) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowKeyChanged(TableView tableView, String previousSelectedRowKey) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowBindTypeChanged(TableView tableView, BindType previousSelectedRowBindType) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowBindMappingChanged(TableView tableView,
+        TableView.SelectedRowBindMapping previousSelectedRowBindMapping) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowsKeyChanged(TableView tableView, String previousSelectedRowsKey) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowsBindTypeChanged(TableView tableView, BindType previousSelectedRowsBindType) {
+        // No-op
+    }
+
+    @Override
+    public void selectedRowsBindMappingChanged(TableView tableView,
+        TableView.SelectedRowBindMapping previousSelectedRowsBindMapping) {
+        // No-op
+    }
+
     // Table view column events
     @Override
     public void columnInserted(TableView tableView, int index) {

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Wed Mar 10 23:58:25 2010
@@ -374,10 +374,10 @@ public class ListView extends Component 
 
         /**
          * Converts list data to a context value.
-         * @param list
-         * @return
+         *
+         * @param listData
          */
-        public Object valueOf(List<?> list);
+        public Object valueOf(List<?> listData);
     }
 
     /**
@@ -390,23 +390,23 @@ public class ListView extends Component 
          * @param listData
          * The source list data.
          *
-         * @param item
-         * The item to locate.
+         * @param value
+         * The value to locate.
          *
          * @return
-         * The index of first occurrence of the item if it exists in the list;
+         * The index of first occurrence of the value if it exists in the list;
          * <tt>-1</tt>, otherwise.
          */
-        public int indexOf(List<?> listData, Object item);
+        public int indexOf(List<?> listData, Object value);
 
         /**
-         * Retrieves the item at the given index.
+         * Retrieves the value at the given index.
          *
          * @param listData
          * The source list data.
          *
          * @param index
-         * The index of the item to retrieve.
+         * The index of the value to retrieve.
          */
         public Object get(List<?> listData, int index);
     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Spinner.java Wed Mar 10 23:58:25 2010
@@ -82,23 +82,23 @@ public class Spinner extends Container {
          * @param spinnerData
          * The source spinner data.
          *
-         * @param item
-         * The item to locate.
+         * @param value
+         * The value to locate.
          *
          * @return
-         * The index of first occurrence of the item if it exists in the list;
+         * The index of first occurrence of the value if it exists in the list;
          * <tt>-1</tt>, otherwise.
          */
-        public int indexOf(List<?> spinnerData, Object item);
+        public int indexOf(List<?> spinnerData, Object value);
 
         /**
          * Retrieves the item at the given index.
          *
-         * @param listData
+         * @param spinnerData
          * The source spinner data.
          *
          * @param index
-         * The index of the item to retrieve.
+         * The index of the value to retrieve.
          */
         public Object get(List<?> spinnerData, int index);
     }

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Wed Mar 10 23:58:25 2010
@@ -28,6 +28,7 @@ import org.apache.pivot.collections.List
 import org.apache.pivot.collections.ListListener;
 import org.apache.pivot.collections.Map;
 import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.serialization.JSON;
 import org.apache.pivot.serialization.JSONSerializer;
 import org.apache.pivot.serialization.SerializationException;
 import org.apache.pivot.util.Filter;
@@ -37,7 +38,7 @@ import org.apache.pivot.util.Vote;
 import org.apache.pivot.wtk.content.TableViewCellRenderer;
 
 /**
- * Component that displays a sequence of items partitioned into columns,
+ * Component that displays a sequence of rows partitioned into columns,
  * optionally allowing a user to select one or more rows.
  */
 public class TableView extends Component {
@@ -804,6 +805,56 @@ public class TableView extends Component
     }
 
     /**
+     * Translates between table and bind context data during data binding.
+     */
+    public interface TableDataBindMapping {
+        /**
+         * Converts a context value to table data.
+         *
+         * @param value
+         */
+        public List<?> toTableData(Object value);
+
+        /**
+         * Converts table data to a context value.
+         *
+         * @param list
+         */
+        public Object valueOf(List<?> tableData);
+    }
+
+    /**
+     * Translates between selection and bind context data during data binding.
+     */
+    public interface SelectedRowBindMapping {
+        /**
+         * Returns the index of the row in the source list.
+         *
+         * @param tableData
+         * The source table data.
+         *
+         * @param value
+         * The value to locate.
+         *
+         * @return
+         * The index of first occurrence of the value if it exists in the list;
+         * <tt>-1</tt>, otherwise.
+         */
+        public int indexOf(List<?> tableData, Object value);
+
+        /**
+         * Retrieves the value at the given index.
+         *
+         * @param tableData
+         * The source table data.
+         *
+         * @param index
+         * The index of the value to retrieve.
+         */
+        public Object get(List<?> tableData, int index);
+    }
+
+    /**
      * Column sequence implementation.
      */
     public final class ColumnSequence implements Sequence<Column>, Iterable<Column> {
@@ -922,6 +973,72 @@ public class TableView extends Component
                 listener.disabledRowFilterChanged(tableView, previousDisabledRowFilter);
             }
         }
+
+        @Override
+        public void tableDataKeyChanged(TableView tableView, String previousTableDataKey) {
+            for (TableViewListener listener : this) {
+                listener.tableDataKeyChanged(tableView, previousTableDataKey);
+            }
+        }
+
+        @Override
+        public void tableDataBindTypeChanged(TableView tableView, BindType previousTableDataBindType) {
+            for (TableViewListener listener : this) {
+                listener.tableDataBindTypeChanged(tableView, previousTableDataBindType);
+            }
+        }
+
+        @Override
+        public void tableDataBindMappingChanged(TableView tableView,
+            TableView.TableDataBindMapping previousTableDataBindMapping) {
+            for (TableViewListener listener : this) {
+                listener.tableDataBindMappingChanged(tableView, previousTableDataBindMapping);
+            }
+        }
+
+        @Override
+        public void selectedRowKeyChanged(TableView tableView, String previousSelectedRowKey) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowKeyChanged(tableView, previousSelectedRowKey);
+            }
+        }
+
+        @Override
+        public void selectedRowBindTypeChanged(TableView tableView, BindType previousSelectedRowBindType) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowBindTypeChanged(tableView, previousSelectedRowBindType);
+            }
+        }
+
+        @Override
+        public void selectedRowBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowBindMapping) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowBindMappingChanged(tableView, previousSelectedRowBindMapping);
+            }
+        }
+
+        @Override
+        public void selectedRowsKeyChanged(TableView tableView, String previousSelectedRowsKey) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowsKeyChanged(tableView, previousSelectedRowsKey);
+            }
+        }
+
+        @Override
+        public void selectedRowsBindTypeChanged(TableView tableView, BindType previousSelectedRowsBindType) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowsBindTypeChanged(tableView, previousSelectedRowsBindType);
+            }
+        }
+
+        @Override
+        public void selectedRowsBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowsBindMapping) {
+            for (TableViewListener listener : this) {
+                listener.selectedRowsBindMappingChanged(tableView, previousSelectedRowsBindMapping);
+            }
+        }
     }
 
     /**
@@ -1051,7 +1168,7 @@ public class TableView extends Component
     }
 
     /**
-     * Table view item listener list.
+     * Table view row listener list.
      */
     private static class TableViewRowListenerList extends ListenerList<TableViewRowListener>
         implements TableViewRowListener {
@@ -1151,6 +1268,31 @@ public class TableView extends Component
     private ColumnSequence columnSequence = new ColumnSequence();
 
     private List<?> tableData = null;
+    private TableView columnSource = null;
+
+    private RowEditor rowEditor = null;
+
+    private ListSelection selectedRanges = new ListSelection();
+    private SelectMode selectMode = SelectMode.SINGLE;
+
+    private HashMap<String, SortDirection> sortMap = new HashMap<String, SortDirection>();
+    private ArrayList<String> sortList = new ArrayList<String>();
+    private SortDictionary sortDictionary = new SortDictionary();
+
+    private Filter<?> disabledRowFilter = null;
+
+    private String tableDataKey = null;
+    private BindType tableDataBindType = BindType.BOTH;
+    private TableDataBindMapping tableDataBindMapping = null;
+
+    private String selectedRowKey = null;
+    private BindType selectedRowBindType = BindType.BOTH;
+    private SelectedRowBindMapping selectedRowBindMapping = null;
+
+    private String selectedRowsKey = null;
+    private BindType selectedRowsBindType = BindType.BOTH;
+    private SelectedRowBindMapping selectedRowsBindMapping = null;
+
     private ListListener<Object> tableDataListener = new ListListener<Object>() {
         @Override
         public void itemInserted(List<Object> list, int index) {
@@ -1197,19 +1339,6 @@ public class TableView extends Component
         }
     };
 
-    private TableView columnSource = null;
-
-    private ListSelection selectedRanges = new ListSelection();
-    private SelectMode selectMode = SelectMode.SINGLE;
-
-    private HashMap<String, SortDirection> sortMap = new HashMap<String, SortDirection>();
-    private ArrayList<String> sortList = new ArrayList<String>();
-    private SortDictionary sortDictionary = new SortDictionary();
-
-    private Filter<?> disabledRowFilter = null;
-
-    private RowEditor rowEditor = null;
-
     private TableViewListenerList tableViewListeners = new TableViewListenerList();
     private TableViewColumnListenerList tableViewColumnListeners = new TableViewColumnListenerList();
     private TableViewRowListenerList tableViewRowListeners = new TableViewRowListenerList();
@@ -1725,6 +1854,11 @@ public class TableView extends Component
         return row;
     }
 
+    @SuppressWarnings("unchecked")
+    public void setSelectedRow(Object row) {
+        setSelectedIndex((row == null) ? -1 : ((List<Object>)tableData).indexOf(row));
+    }
+
     public Sequence<?> getSelectedRows() {
         ArrayList<Object> rows = new ArrayList<Object>();
 
@@ -1740,6 +1874,31 @@ public class TableView extends Component
         return rows;
     }
 
+    @SuppressWarnings("unchecked")
+    public void setSelectedRows(Sequence<Object> rows) {
+        if (rows == null) {
+            throw new IllegalArgumentException();
+        }
+
+        ArrayList<Span> selectedRanges = new ArrayList<Span>();
+
+        for (int i = 0, n = rows.getLength(); i < n; i++) {
+            Object row = rows.get(i);
+            if (row == null) {
+                throw new IllegalArgumentException("item is null");
+            }
+
+            int index = ((List<Object>)tableData).indexOf(row);
+            if (index == -1) {
+                throw new IllegalArgumentException("\"" + row + "\" is not a valid selection.");
+            }
+
+            selectedRanges.add(new Span(index));
+        }
+
+        setSelectedRanges(selectedRanges);
+    }
+
     /**
      * Returns the current selection mode.
      */
@@ -1932,6 +2091,284 @@ public class TableView extends Component
         }
     }
 
+    public String getTableDataKey() {
+        return tableDataKey;
+    }
+
+    public void setTableDataKey(String tableDataKey) {
+        String previousTableDataKey = this.tableDataKey;
+        if (previousTableDataKey != tableDataKey) {
+            this.tableDataKey = tableDataKey;
+            tableViewListeners.tableDataKeyChanged(this, previousTableDataKey);
+        }
+    }
+
+    public BindType getTableDataBindType() {
+        return tableDataBindType;
+    }
+
+    public void setTableDataBindType(BindType tableDataBindType) {
+        if (tableDataBindType == null) {
+            throw new IllegalArgumentException();
+        }
+
+        BindType previousTableDataBindType = this.tableDataBindType;
+
+        if (previousTableDataBindType != tableDataBindType) {
+            this.tableDataBindType = tableDataBindType;
+            tableViewListeners.tableDataBindTypeChanged(this, previousTableDataBindType);
+        }
+    }
+
+    public TableDataBindMapping getTableDataBindMapping() {
+        return tableDataBindMapping;
+    }
+
+    public void setTableDataBindMapping(TableDataBindMapping tableDataBindMapping) {
+        TableDataBindMapping previousTableDataBindMapping = this.tableDataBindMapping;
+
+        if (previousTableDataBindMapping != tableDataBindMapping) {
+            this.tableDataBindMapping = tableDataBindMapping;
+            tableViewListeners.tableDataBindMappingChanged(this, previousTableDataBindMapping);
+        }
+    }
+
+    public String getSelectedRowKey() {
+        return selectedRowKey;
+    }
+
+    public void setSelectedRowKey(String selectedRowKey) {
+        String previousSelectedRowKey = this.selectedRowKey;
+
+        if (previousSelectedRowKey != selectedRowKey) {
+            this.selectedRowKey = selectedRowKey;
+            tableViewListeners.selectedRowKeyChanged(this, previousSelectedRowKey);
+        }
+    }
+
+    public BindType getSelectedRowBindType() {
+        return selectedRowBindType;
+    }
+
+    public void setSelectedRowBindType(BindType selectedRowBindType) {
+        if (selectedRowBindType == null) {
+            throw new IllegalArgumentException();
+        }
+
+        BindType previousSelectedRowBindType = this.selectedRowBindType;
+        if (previousSelectedRowBindType != selectedRowBindType) {
+            this.selectedRowBindType = selectedRowBindType;
+            tableViewListeners.selectedRowBindTypeChanged(this, previousSelectedRowBindType);
+        }
+    }
+
+    public SelectedRowBindMapping getSelectedRowBindMapping() {
+        return selectedRowBindMapping;
+    }
+
+    public void setSelectedRowBindMapping(SelectedRowBindMapping selectedRowBindMapping) {
+        SelectedRowBindMapping previousSelectedRowBindMapping = this.selectedRowBindMapping;
+
+        if (previousSelectedRowBindMapping != selectedRowBindMapping) {
+            this.selectedRowBindMapping = selectedRowBindMapping;
+            tableViewListeners.selectedRowBindMappingChanged(this, previousSelectedRowBindMapping);
+        }
+    }
+
+    public String getSelectedRowsKey() {
+        return selectedRowsKey;
+    }
+
+    public void setSelectedRowsKey(String selectedRowsKey) {
+        String previousSelectedRowsKey = this.selectedRowsKey;
+
+        if (previousSelectedRowsKey != selectedRowsKey) {
+            this.selectedRowsKey = selectedRowsKey;
+            tableViewListeners.selectedRowsKeyChanged(this, previousSelectedRowsKey);
+        }
+    }
+
+    public BindType getSelectedRowsBindType() {
+        return selectedRowsBindType;
+    }
+
+    public void setSelectedRowsBindType(BindType selectedRowsBindType) {
+        if (selectedRowsBindType == null) {
+            throw new IllegalArgumentException();
+        }
+
+        BindType previousSelectedRowsBindType = this.selectedRowsBindType;
+        if (previousSelectedRowsBindType != selectedRowsBindType) {
+            this.selectedRowsBindType = selectedRowsBindType;
+            tableViewListeners.selectedRowsBindTypeChanged(this, previousSelectedRowsBindType);
+        }
+    }
+
+    public SelectedRowBindMapping getSelectedRowsBindMapping() {
+        return selectedRowsBindMapping;
+    }
+
+    public void setSelectedRowsBindMapping(SelectedRowBindMapping selectedRowsBindMapping) {
+        SelectedRowBindMapping previousSelectedRowsBindMapping = this.selectedRowsBindMapping;
+
+        if (previousSelectedRowsBindMapping != selectedRowsBindMapping) {
+            this.selectedRowsBindMapping = selectedRowsBindMapping;
+            tableViewListeners.selectedRowsBindMappingChanged(this, previousSelectedRowsBindMapping);
+        }
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void load(Dictionary<String, ?> context) {
+        // Bind to list data
+        if (tableDataKey != null
+            && tableDataBindType != BindType.STORE
+            && JSON.containsKey(context, tableDataKey)) {
+            Object value = JSON.get(context, tableDataKey);
+
+            List<?> tableData;
+            if (tableDataBindMapping == null) {
+                tableData = (List<?>)value;
+            } else {
+                tableData = tableDataBindMapping.toTableData(value);
+            }
+
+            setTableData(tableData);
+        }
+
+        switch (selectMode) {
+            case SINGLE: {
+                // Bind using selected row key
+                if (selectedRowKey != null
+                    && selectedRowBindType != BindType.STORE
+                    && JSON.containsKey(context, selectedRowKey)) {
+                    Object row = JSON.get(context, selectedRowKey);
+
+                    int index;
+                    if (selectedRowBindMapping == null) {
+                        index = ((List<Object>)tableData).indexOf(row);
+                    } else {
+                        index = selectedRowBindMapping.indexOf(tableData, row);
+                    }
+
+                    setSelectedIndex(index);
+                }
+
+                break;
+            }
+
+            case MULTI: {
+                // Bind using selected rows key
+                if (selectedRowsKey != null
+                    && selectedRowsBindType != BindType.STORE
+                    && JSON.containsKey(context, selectedRowsKey)) {
+                    Sequence<Object> rows = (Sequence<Object>)JSON.get(context, selectedRowsKey);
+
+                    clearSelection();
+
+                    for (int i = 0, n = rows.getLength(); i < n; i++) {
+                        Object row = rows.get(i);
+
+                        int index;
+                        if (selectedRowsBindMapping == null) {
+                            index = ((List<Object>)tableData).indexOf(row);
+                        } else {
+                            index = selectedRowsBindMapping.indexOf(tableData, row);
+                        }
+
+                        if (index != -1) {
+                            addSelectedIndex(index);
+                        }
+                    }
+                }
+
+                break;
+            }
+        }
+    }
+
+    @Override
+    public void store(Dictionary<String, ?> context) {
+        // Bind to table data
+        if (tableDataKey != null
+            && tableDataBindType != BindType.LOAD) {
+
+            Object value;
+            if (tableDataBindMapping == null) {
+                value = tableData;
+            } else {
+                value = tableDataBindMapping.valueOf(tableData);
+            }
+
+            JSON.put(context, tableDataKey, value);
+        }
+
+        switch (selectMode) {
+            case SINGLE: {
+                // Bind using selected row key
+                if (selectedRowKey != null
+                    && selectedRowBindType != BindType.LOAD) {
+                    Object row;
+
+                    int selectedIndex = getSelectedIndex();
+                    if (selectedIndex == -1) {
+                        row = null;
+                    } else {
+                        if (selectedRowBindMapping == null) {
+                            row = tableData.get(selectedIndex);
+                        } else {
+                            row = selectedRowBindMapping.get(tableData, selectedIndex);
+                        }
+                    }
+
+                    JSON.put(context, selectedRowKey, row);
+                }
+
+                break;
+            }
+
+            case MULTI: {
+                // Bind using selected rows key
+                if (selectedRowsKey != null
+                    && selectedRowsBindType != BindType.LOAD) {
+                    ArrayList<Object> rows = new ArrayList<Object>();
+
+                    Sequence<Span> selectedRanges = getSelectedRanges();
+                    for (int i = 0, n = selectedRanges.getLength(); i < n; i++) {
+                        Span range = selectedRanges.get(i);
+
+                        for (int index = range.start; index <= range.end; index++) {
+                            Object row;
+                            if (selectedRowsBindMapping == null) {
+                                row = tableData.get(index);
+                            } else {
+                                row = selectedRowsBindMapping.get(tableData, index);
+                            }
+
+                            rows.add(row);
+                        }
+                    }
+
+                    JSON.put(context, selectedRowsKey, rows);
+                }
+
+                break;
+            }
+        }
+    }
+
+    @Override
+    public void clear() {
+        if (tableDataKey != null) {
+            setTableData(new ArrayList<Object>());
+        }
+
+        if (selectedRowKey != null
+            || selectedRowsKey != null) {
+            setSelectedRow(null);
+        }
+    }
+
     /**
      * Returns the index of the row at a given location.
      *

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewListener.java?rev=921635&r1=921634&r2=921635&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewListener.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TableViewListener.java Wed Mar 10 23:58:25 2010
@@ -46,6 +46,45 @@ public interface TableViewListener {
         @Override
         public void disabledRowFilterChanged(TableView tableView, Filter<?> previousDisabledRowFilter) {
         }
+
+        @Override
+        public void tableDataKeyChanged(TableView tableView, String previousTableDataKey) {
+        }
+
+        @Override
+        public void tableDataBindTypeChanged(TableView tableView, BindType previousTableDataBindType) {
+        }
+
+        @Override
+        public void tableDataBindMappingChanged(TableView tableView,
+            TableView.TableDataBindMapping previousTableDataBindMapping) {
+        }
+
+        @Override
+        public void selectedRowKeyChanged(TableView tableView, String previousSelectedRowKey) {
+        }
+
+        @Override
+        public void selectedRowBindTypeChanged(TableView tableView, BindType previousSelectedRowBindType) {
+        }
+
+        @Override
+        public void selectedRowBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowBindMapping) {
+        }
+
+        @Override
+        public void selectedRowsKeyChanged(TableView tableView, String previousSelectedRowsKey) {
+        }
+
+        @Override
+        public void selectedRowsBindTypeChanged(TableView tableView, BindType previousSelectedRowsBindType) {
+        }
+
+        @Override
+        public void selectedRowsBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowsBindMapping) {
+        }
     }
 
     /**
@@ -87,4 +126,78 @@ public interface TableViewListener {
      * @param previousDisabledRowFilter
      */
     public void disabledRowFilterChanged(TableView tableView, Filter<?> previousDisabledRowFilter);
+
+    /**
+     * Called when a table view's table data key has changed.
+     *
+     * @param tableView
+     * @param previousTableDataKey
+     */
+    public void tableDataKeyChanged(TableView tableView, String previousTableDataKey);
+
+    /**
+     * Called when a table view's table data bind type has changed.
+     *
+     * @param tableView
+     * @param previousTableDataBindType
+     */
+    public void tableDataBindTypeChanged(TableView tableView, BindType previousTableDataBindType);
+
+    /**
+     * Called when a table view's table data bind mapping has changed.
+     *
+     * @param tableView
+     * @param previousTableDataBindMapping
+     */
+    public void tableDataBindMappingChanged(TableView tableView, TableView.TableDataBindMapping previousTableDataBindMapping);
+
+    /**
+     * Called when a table view's selected item key has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowKey
+     */
+    public void selectedRowKeyChanged(TableView tableView, String previousSelectedRowKey);
+
+    /**
+     * Called when a table view's selected item bind type has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowBindType
+     */
+    public void selectedRowBindTypeChanged(TableView tableView, BindType previousSelectedRowBindType);
+
+    /**
+     * Called when a table view's selected item bind mapping has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowBindMapping
+     */
+    public void selectedRowBindMappingChanged(TableView tableView,
+        TableView.SelectedRowBindMapping previousSelectedRowBindMapping);
+
+    /**
+     * Called when a table view's selected items key has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowsKey
+     */
+    public void selectedRowsKeyChanged(TableView tableView, String previousSelectedRowsKey);
+
+    /**
+     * Called when a table view's selected items bind type has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowsBindType
+     */
+    public void selectedRowsBindTypeChanged(TableView tableView, BindType previousSelectedRowsBindType);
+
+    /**
+     * Called when a table view's selected items bind mapping has changed.
+     *
+     * @param tableView
+     * @param previousSelectedRowsBindMapping
+     */
+    public void selectedRowsBindMappingChanged(TableView tableView,
+        TableView.SelectedRowBindMapping previousSelectedRowsBindMapping);
 }

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=921635&r1=921634&r2=921635&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 Wed Mar 10 23:58:25 2010
@@ -26,6 +26,7 @@ import org.apache.pivot.util.Filter;
 import org.apache.pivot.util.ListenerList;
 import org.apache.pivot.util.Vote;
 import org.apache.pivot.wtk.ApplicationContext;
+import org.apache.pivot.wtk.BindType;
 import org.apache.pivot.wtk.Bounds;
 import org.apache.pivot.wtk.CardPane;
 import org.apache.pivot.wtk.CardPaneListener;
@@ -98,9 +99,6 @@ public class TableViewRowEditor implemen
         }
     }
 
-    /**
-     *
-     */
     private class EditorPopup extends Window implements ContainerMouseListener,
         ComponentListener, TableViewListener, TableViewRowListener {
         // Fields that determine what is being edited
@@ -570,6 +568,54 @@ public class TableViewRowEditor implemen
             // No-op
         }
 
+        @Override
+        public void tableDataKeyChanged(TableView tableView, String previousTableDataKey) {
+            // No-op
+        }
+
+        @Override
+        public void tableDataBindTypeChanged(TableView tableView, BindType previousTableDataBindType) {
+            // No-op
+        }
+
+        @Override
+        public void tableDataBindMappingChanged(TableView tableView,
+            TableView.TableDataBindMapping previousTableDataBindMapping) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowKeyChanged(TableView tableView, String previousSelectedRowKey) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowBindTypeChanged(TableView tableView, BindType previousSelectedRowBindType) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowBindMapping) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowsKeyChanged(TableView tableView, String previousSelectedRowsKey) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowsBindTypeChanged(TableView tableView, BindType previousSelectedRowsBindType) {
+            // No-op
+        }
+
+        @Override
+        public void selectedRowsBindMappingChanged(TableView tableView,
+            TableView.SelectedRowBindMapping previousSelectedRowsBindMapping) {
+            // No-op
+        }
+
         // TableViewRowListener methods
 
         @Override