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/08/17 23:24:01 UTC

svn commit: r986489 - in /pivot/trunk: demos/src/org/apache/pivot/demos/lists/ demos/src/org/apache/pivot/demos/roweditor/ wtk-terra/src/org/apache/pivot/wtk/skin/terra/ wtk/src/org/apache/pivot/wtk/

Author: gbrown
Date: Tue Aug 17 21:24:00 2010
New Revision: 986489

URL: http://svn.apache.org/viewvc?rev=986489&view=rev
Log:
Resolve PIVOT-369 for ListView and TableView.

Removed:
    pivot/trunk/demos/src/org/apache/pivot/demos/lists/MultiSelect.java
Modified:
    pivot/trunk/demos/src/org/apache/pivot/demos/lists/multi_select.bxml
    pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml
    pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.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/TableView.java

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/lists/multi_select.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/lists/multi_select.bxml?rev=986489&r1=986488&r2=986489&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/lists/multi_select.bxml (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/lists/multi_select.bxml Tue Aug 17 21:24:00 2010
@@ -16,12 +16,17 @@ See the License for the specific languag
 limitations under the License.
 -->
 
-<lists:MultiSelect title="Multiple Selection Demo" maximized="true"
+<Window title="Multiple Selection Demo" maximized="true"
     xmlns:bxml="http://pivot.apache.org/bxml"
     xmlns:collections="org.apache.pivot.collections"
     xmlns:content="org.apache.pivot.wtk.content"
-    xmlns:lists="org.apache.pivot.demos.lists"
     xmlns="org.apache.pivot.wtk">
+    <windowStateListeners>
+    function windowOpened(window) {
+        dataListView.requestFocus();
+    }
+    </windowStateListeners>
+
     <TablePane styles="{horizontalSpacing:8}">
         <columns>
             <TablePane.Column width="1*"/>
@@ -31,10 +36,17 @@ limitations under the License.
         <TablePane.Row height="1*">
             <Border styles="{color:10}">
                 <ScrollPane horizontalScrollBarPolicy="fill">
-                    <ListView bxml:id="dataListView" selectMode="multi">
+                    <ListView bxml:id="dataListView" selectMode="multi" checkmarksEnabled="true">
                         <listData>
                             <content:NumericSpinnerData lowerBound="0" upperBound="31" increment="1"/>
                         </listData>
+
+                        <listViewSelectionListeners>
+                        importPackage(org.apache.pivot.collections);
+                        function selectedRangesChanged(listView, previousSelectedRanges) {
+                            selectionListView.listData = new ArrayList(dataListView.selectedRanges);
+                        }
+                        </listViewSelectionListeners>
                     </ListView>
                 </ScrollPane>
             </Border>
@@ -45,4 +57,4 @@ limitations under the License.
             </Border>
         </TablePane.Row>
     </TablePane>
-</lists:MultiSelect>
+</Window>

Modified: pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml
URL: http://svn.apache.org/viewvc/pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml?rev=986489&r1=986488&r2=986489&view=diff
==============================================================================
--- pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml (original)
+++ pivot/trunk/demos/src/org/apache/pivot/demos/roweditor/row_editor_demo.bxml Tue Aug 17 21:24:00 2010
@@ -41,7 +41,7 @@ limitations under the License.
 
     <Border styles="{color:7}">
         <ScrollPane horizontalScrollBarPolicy="fill_to_capacity">
-            <TableView bxml:id="tableView" selectMode="single">
+            <TableView bxml:id="tableView" selectMode="multi">
                 <columns>
                     <TableView.Column name="date" width="87" headerData="%headers.date"/>
                     <TableView.Column name="type" width="125" headerData="%headers.type"/>

Modified: pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java
URL: http://svn.apache.org/viewvc/pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java?rev=986489&r1=986488&r2=986489&view=diff
==============================================================================
--- pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java (original)
+++ pivot/trunk/wtk-terra/src/org/apache/pivot/wtk/skin/terra/TerraListViewSkin.java Tue Aug 17 21:24:00 2010
@@ -64,8 +64,8 @@ public class TerraListViewSkin extends C
     private boolean variableItemHeight;
     private Insets checkboxPadding = new Insets(2, 2, 2, 0);
 
-    private int highlightedIndex = -1;
-    private int editIndex = -1;
+    private int highlightIndex = -1;
+    private int selectIndex = -1;
 
     private ArrayList<Integer> itemBoundaries = null;
     private int fixedItemHeight;
@@ -335,7 +335,7 @@ public class TerraListViewSkin extends C
         // Paint the item content
         for (int itemIndex = itemStart; itemIndex <= itemEnd; itemIndex++) {
             Object item = listData.get(itemIndex);
-            boolean highlighted = (itemIndex == highlightedIndex
+            boolean highlighted = (itemIndex == highlightIndex
                 && listView.getSelectMode() != ListView.SelectMode.NONE);
             boolean selected = listView.isItemSelected(itemIndex);
             boolean disabled = listView.isItemDisabled(itemIndex);
@@ -414,11 +414,11 @@ public class TerraListViewSkin extends C
             }
         } else {
             index = (y / fixedItemHeight);
-        }
 
-        List<Object> listData = (List<Object>)listView.getListData();
-        if (index >= listData.getLength()) {
-            index = -1;
+            List<Object> listData = (List<Object>)listView.getListData();
+            if (index >= listData.getLength()) {
+                index = -1;
+            }
         }
 
         return index;
@@ -797,18 +797,18 @@ public class TerraListViewSkin extends C
 
         ListView listView = (ListView)getComponent();
 
-        int previousHighlightedIndex = this.highlightedIndex;
-        highlightedIndex = getItemAt(y);
+        int previousHighlightIndex = this.highlightIndex;
+        highlightIndex = getItemAt(y);
 
-        if (previousHighlightedIndex != highlightedIndex
+        if (previousHighlightIndex != highlightIndex
             && listView.getSelectMode() != ListView.SelectMode.NONE
             && showHighlight) {
-            if (previousHighlightedIndex != -1) {
-                repaintComponent(getItemBounds(previousHighlightedIndex));
+            if (previousHighlightIndex != -1) {
+                repaintComponent(getItemBounds(previousHighlightIndex));
             }
 
-            if (highlightedIndex != -1) {
-                repaintComponent(getItemBounds(highlightedIndex));
+            if (highlightIndex != -1) {
+                repaintComponent(getItemBounds(highlightIndex));
             }
         }
 
@@ -821,42 +821,35 @@ public class TerraListViewSkin extends C
 
         ListView listView = (ListView)getComponent();
 
-        if (highlightedIndex != -1
+        if (highlightIndex != -1
             && listView.getSelectMode() != ListView.SelectMode.NONE
             && showHighlight) {
-            Bounds itemBounds = getItemBounds(highlightedIndex);
+            Bounds itemBounds = getItemBounds(highlightIndex);
             repaintComponent(itemBounds.x, itemBounds.y, itemBounds.width, itemBounds.height);
         }
 
-        highlightedIndex = -1;
-        editIndex = -1;
+        highlightIndex = -1;
+        selectIndex = -1;
     }
 
     @Override
-    @SuppressWarnings("unchecked")
     public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
         boolean consumed = super.mouseDown(component, button, x, y);
 
         ListView listView = (ListView)getComponent();
-        List<Object> listData = (List<Object>)listView.getListData();
-
         int itemIndex = getItemAt(y);
 
         if (itemIndex != -1
-            && itemIndex < listData.getLength()
             && !listView.isItemDisabled(itemIndex)) {
             int itemY = getItemBounds(itemIndex).y;
 
             if (!(listView.getCheckmarksEnabled()
-                && x > checkboxPadding.left
-                && x < checkboxPadding.left + CHECKBOX.getWidth()
-                && y > itemY + checkboxPadding.top
-                && y < itemY + checkboxPadding.top + CHECKBOX.getHeight())) {
+                && isMouseOverCheckbox(itemY, x, y))) {
                 ListView.SelectMode selectMode = listView.getSelectMode();
 
                 if (button == Mouse.Button.RIGHT) {
-                    if (!listView.isItemSelected(itemIndex)
-                        && selectMode != ListView.SelectMode.NONE) {
+                    if (selectMode != ListView.SelectMode.NONE
+                        && !listView.isItemSelected(itemIndex)) {
                         listView.setSelectedIndex(itemIndex);
                     }
                 } else {
@@ -888,14 +881,11 @@ public class TerraListViewSkin extends C
                         }
                     } else {
                         if (selectMode != ListView.SelectMode.NONE) {
-                            if (listView.isItemSelected(itemIndex)
-                                && listView.isFocused()) {
-                                // Edit the item
-                                editIndex = itemIndex;
+                            if (listView.isItemSelected(itemIndex)) {
+                                selectIndex = itemIndex;
+                            } else {
+                                listView.setSelectedIndex(itemIndex);
                             }
-
-                            // Select the item
-                            listView.setSelectedIndex(itemIndex);
                         }
                     }
                 }
@@ -908,53 +898,66 @@ public class TerraListViewSkin extends C
     }
 
     @Override
-    @SuppressWarnings("unchecked")
-    public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
-        boolean consumed = super.mouseClick(component, button, x, y, count);
+    public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
+        boolean consumed = super.mouseUp(component, button, x, y);
 
         ListView listView = (ListView)getComponent();
+        if (selectIndex != -1
+            && listView.getFirstSelectedIndex() != listView.getLastSelectedIndex()) {
+            listView.setSelectedIndex(selectIndex);
+            selectIndex = -1;
+        }
 
-        List<Object> listData = (List<Object>)listView.getListData();
+        return consumed;
+    }
+
+    @Override
+    public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
+        boolean consumed = super.mouseClick(component, button, x, y, count);
 
+        ListView listView = (ListView)getComponent();
         int itemIndex = getItemAt(y);
 
-        if (itemIndex < listData.getLength()
-            && !listView.isItemDisabled(itemIndex)) {
+        if (!listView.isItemDisabled(itemIndex)) {
             int itemY = getItemBounds(itemIndex).y;
 
             if (listView.getCheckmarksEnabled()
                 && !listView.isCheckmarkDisabled(itemIndex)
-                && x > checkboxPadding.left
-                && x < checkboxPadding.left + CHECKBOX.getWidth()
-                && y > itemY + checkboxPadding.top
-                && y < itemY + checkboxPadding.top + CHECKBOX.getHeight()) {
+                && isMouseOverCheckbox(itemY, x, y)) {
                 listView.setItemChecked(itemIndex, !listView.isItemChecked(itemIndex));
             } else {
-                if (editIndex != -1
+                if (selectIndex != -1
                     && count == 1) {
                     ListView.ItemEditor itemEditor = listView.getItemEditor();
 
                     if (itemEditor != null) {
-                        itemEditor.editItem(listView, editIndex);
+                        itemEditor.editItem(listView, selectIndex);
                     }
                 }
-
-                editIndex = -1;
             }
         }
 
+        selectIndex = -1;
+
         return consumed;
     }
 
+    private boolean isMouseOverCheckbox(int itemY, int x, int y) {
+        return (x > checkboxPadding.left
+            && x < checkboxPadding.left + CHECKBOX.getWidth()
+            && y > itemY + checkboxPadding.top
+            && y < itemY + checkboxPadding.top + CHECKBOX.getHeight());
+    }
+
     @Override
     public boolean mouseWheel(Component component, Mouse.ScrollType scrollType, int scrollAmount,
         int wheelRotation, int x, int y) {
         ListView listView = (ListView)getComponent();
 
-        if (highlightedIndex != -1) {
-            Bounds itemBounds = getItemBounds(highlightedIndex);
+        if (highlightIndex != -1) {
+            Bounds itemBounds = getItemBounds(highlightIndex);
 
-            highlightedIndex = -1;
+            highlightIndex = -1;
 
             if (listView.getSelectMode() != ListView.SelectMode.NONE
                 && showHighlight) {
@@ -1025,13 +1028,13 @@ public class TerraListViewSkin extends C
         }
 
         // Clear the highlight
-        if (highlightedIndex != -1
+        if (highlightIndex != -1
             && listView.getSelectMode() != ListView.SelectMode.NONE
             && showHighlight) {
-            repaintComponent(getItemBounds(highlightedIndex));
+            repaintComponent(getItemBounds(highlightIndex));
         }
 
-        highlightedIndex = -1;
+        highlightIndex = -1;
 
         return consumed;
     }

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=986489&r1=986488&r2=986489&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 Tue Aug 17 21:24:00 2010
@@ -81,8 +81,8 @@ public class TerraTableViewSkin extends 
     private int fixedRowHeight = -1;
     private int defaultWidthColumnCount = 0;
 
-    private int highlightedIndex = -1;
-    private int editIndex = -1;
+    private int highlightIndex = -1;
+    private int selectIndex = -1;
 
     private boolean validateSelection = false;
 
@@ -400,7 +400,7 @@ public class TerraTableViewSkin extends 
         // Paint the row content
         for (int rowIndex = rowStart; rowIndex <= rowEnd; rowIndex++) {
             Object rowData = tableData.get(rowIndex);
-            boolean rowHighlighted = (rowIndex == highlightedIndex
+            boolean rowHighlighted = (rowIndex == highlightIndex
                 && tableView.getSelectMode() != TableView.SelectMode.NONE);
             boolean rowSelected = tableView.isRowSelected(rowIndex);
             boolean rowDisabled = tableView.isRowDisabled(rowIndex);
@@ -570,7 +570,6 @@ public class TerraTableViewSkin extends 
         }
 
         TableView tableView = (TableView)getComponent();
-        List<Object> tableData = (List<Object>)tableView.getTableData();
 
         int rowIndex;
         if (variableRowHeight) {
@@ -584,10 +583,11 @@ public class TerraTableViewSkin extends 
             }
         } else {
             rowIndex = (y / (fixedRowHeight + 1));
-        }
 
-        if (rowIndex >= tableData.getLength()) {
-            rowIndex = -1;
+            List<Object> tableData = (List<Object>)tableView.getTableData();
+            if (rowIndex >= tableData.getLength()) {
+                rowIndex = -1;
+            }
         }
 
         return rowIndex;
@@ -1140,18 +1140,18 @@ public class TerraTableViewSkin extends 
 
         TableView tableView = (TableView)getComponent();
 
-        int previousHighlightedIndex = this.highlightedIndex;
-        highlightedIndex = getRowAt(y);
+        int previousHighlightIndex = this.highlightIndex;
+        highlightIndex = getRowAt(y);
 
-        if (previousHighlightedIndex != highlightedIndex
+        if (previousHighlightIndex != highlightIndex
             && tableView.getSelectMode() != TableView.SelectMode.NONE
             && showHighlight) {
-            if (previousHighlightedIndex != -1) {
-                repaintComponent(getRowBounds(previousHighlightedIndex));
+            if (previousHighlightIndex != -1) {
+                repaintComponent(getRowBounds(previousHighlightIndex));
             }
 
-            if (highlightedIndex != -1) {
-                repaintComponent(getRowBounds(highlightedIndex));
+            if (highlightIndex != -1) {
+                repaintComponent(getRowBounds(highlightIndex));
             }
         }
 
@@ -1164,14 +1164,14 @@ public class TerraTableViewSkin extends 
 
         TableView tableView = (TableView)getComponent();
 
-        if (highlightedIndex != -1
+        if (highlightIndex != -1
             && tableView.getSelectMode() != TableView.SelectMode.NONE
             && showHighlight) {
-            repaintComponent(getRowBounds(highlightedIndex));
+            repaintComponent(getRowBounds(highlightIndex));
         }
 
-        highlightedIndex = -1;
-        editIndex = -1;
+        highlightIndex = -1;
+        selectIndex = -1;
     }
 
     @Override
@@ -1186,8 +1186,8 @@ public class TerraTableViewSkin extends 
             TableView.SelectMode selectMode = tableView.getSelectMode();
 
             if (button == Mouse.Button.RIGHT) {
-                if (!tableView.isRowSelected(rowIndex)
-                    && selectMode != TableView.SelectMode.NONE) {
+                if (selectMode != TableView.SelectMode.NONE
+                    && !tableView.isRowSelected(rowIndex)) {
                     tableView.setSelectedIndex(rowIndex);
                 }
             } else {
@@ -1219,14 +1219,11 @@ public class TerraTableViewSkin extends 
                     }
                 } else {
                     if (selectMode != TableView.SelectMode.NONE) {
-                        if (tableView.isRowSelected(rowIndex)
-                            && tableView.isFocused()) {
-                            // Edit the row
-                            editIndex = rowIndex;
+                        if (tableView.isRowSelected(rowIndex)) {
+                            selectIndex = rowIndex;
+                        } else {
+                            tableView.setSelectedIndex(rowIndex);
                         }
-
-                        // Select the row
-                        tableView.setSelectedIndex(rowIndex);
                     }
                 }
             }
@@ -1238,21 +1235,35 @@ public class TerraTableViewSkin extends 
     }
 
     @Override
+    public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
+        boolean consumed = super.mouseUp(component, button, x, y);
+
+        TableView tableView = (TableView)getComponent();
+        if (selectIndex != -1
+            && tableView.getFirstSelectedIndex() != tableView.getLastSelectedIndex()) {
+            tableView.setSelectedIndex(selectIndex);
+            selectIndex = -1;
+        }
+
+        return consumed;
+    }
+
+    @Override
     public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
         boolean consumed = super.mouseClick(component, button, x, y, count);
 
         TableView tableView = (TableView)getComponent();
-        if (editIndex != -1
+        if (selectIndex != -1
             && count == 2) {
             TableView.RowEditor rowEditor = tableView.getRowEditor();
 
             if (rowEditor != null
                 && !rowEditor.isEditing()) {
-                rowEditor.editRow(tableView, editIndex, getColumnAt(x));
+                rowEditor.editRow(tableView, selectIndex, getColumnAt(x));
             }
         }
 
-        editIndex = -1;
+        selectIndex = -1;
 
         return consumed;
     }
@@ -1262,10 +1273,10 @@ public class TerraTableViewSkin extends 
         int wheelRotation, int x, int y) {
         TableView tableView = (TableView)getComponent();
 
-        if (highlightedIndex != -1) {
-            Bounds rowBounds = getRowBounds(highlightedIndex);
+        if (highlightIndex != -1) {
+            Bounds rowBounds = getRowBounds(highlightIndex);
 
-            highlightedIndex = -1;
+            highlightIndex = -1;
 
             if (tableView.getSelectMode() != TableView.SelectMode.NONE
                 && showHighlight) {
@@ -1335,13 +1346,13 @@ public class TerraTableViewSkin extends 
         }
 
         // Clear the highlight
-        if (highlightedIndex != -1
+        if (highlightIndex != -1
             && tableView.getSelectMode() != TableView.SelectMode.NONE
             && showHighlight) {
-            repaintComponent(getRowBounds(highlightedIndex));
+            repaintComponent(getRowBounds(highlightIndex));
         }
 
-        highlightedIndex = -1;
+        highlightIndex = -1;
 
         return consumed;
     }

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=986489&r1=986488&r2=986489&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/ListView.java Tue Aug 17 21:24:00 2010
@@ -1305,7 +1305,9 @@ public class ListView extends Component 
      * Clears the selection.
      */
     public void clearSelection() {
-        setSelectedRanges(new ArrayList<Span>(0));
+        if (selectedRanges.getLength() > 0) {
+            setSelectedRanges(new ArrayList<Span>(0));
+        }
     }
 
     /**

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=986489&r1=986488&r2=986489&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/TableView.java Tue Aug 17 21:24:00 2010
@@ -1961,7 +1961,9 @@ public class TableView extends Component
      * Clears the selection.
      */
     public void clearSelection() {
-        setSelectedRanges(new ArrayList<Span>(0));
+        if (selectedRanges.getLength() > 0) {
+            setSelectedRanges(new ArrayList<Span>(0));
+        }
     }
 
     /**