changeset 259:5771e7157e47

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.1/scrum/controls/jfx/rt
author jgiles
date Fri, 13 Jan 2012 10:28:30 +1300
parents 0ae14bbf91a1 e4d7464ce84a
children 75ca7cbe81d6 3d82c6b24da7
files
diffstat 3 files changed, 84 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/ReadOnlyUnbackedObservableList.java	Wed Jan 11 23:52:24 2012 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/ReadOnlyUnbackedObservableList.java	Fri Jan 13 10:28:30 2012 +1300
@@ -37,7 +37,6 @@
 
 import com.sun.javafx.collections.ListInvalidationListenerWrapper;
 import com.sun.javafx.collections.ListenerList;
-import java.util.ArrayList;
 import java.util.Collections;
 
 /**
@@ -97,7 +96,6 @@
         }
     }
 
-
     @Override public int indexOf(Object o) {
         if (o == null) return -1;
 
@@ -154,13 +152,18 @@
      * NOTE: This method does not fulfill the subList contract from Collections,
      * it simply returns a list containing the values in the given range.
      */
-    @Override public List<T> subList(int fromIndex, int toIndex) {
+    @Override public List<T> subList(final int fromIndex, final int toIndex) {
         if (fromIndex >= toIndex) return Collections.emptyList();
-        List<T> sublist = new ArrayList<T>();
-        for (int i = fromIndex; i < toIndex; i++) {
-            sublist.add(get(i));
-        }
-        return sublist;
+        final List<T> outer = this;
+        return new ReadOnlyUnbackedObservableList<T>() {
+            @Override public T get(int i) {
+                return outer.get(i + fromIndex);
+            }
+
+            @Override public int size() {
+                return toIndex - fromIndex;
+            }
+        };
     }
 
     @Override
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableViewBehavior.java	Wed Jan 11 23:52:24 2012 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableViewBehavior.java	Fri Jan 13 10:28:30 2012 +1300
@@ -233,8 +233,9 @@
                 } 
                 
                 int addedSize = c.getAddedSize();
+                List<TablePosition> addedSubList = (List<TablePosition>) c.getAddedSubList();
+                
                 if (! hasAnchor() && addedSize > 0) {
-                    List<TablePosition> addedSubList = (List<TablePosition>) c.getAddedSubList();
                     for (int i = 0; i < addedSize; i++) {
                         TablePosition tp = addedSubList.get(i);
                         if (tp.getRow() >= 0) {
@@ -247,9 +248,8 @@
                 if (!hasAnchor() && cellSelectionEnabled && ! selectionPathDeviated) {
                     // check if the selection is on the same row or column, 
                     // otherwise set selectionPathDeviated to true
-                    
-                    for (int i = 0; i < c.getAddedSize(); i++) {
-                        TablePosition tp = (TablePosition) c.getAddedSubList().get(i);
+                    for (int i = 0; i < addedSize; i++) {
+                        TablePosition tp = addedSubList.get(i);
                         if (anchor.getRow() != -1 && tp.getRow() != anchor.getRow() && tp.getColumn() != anchor.getColumn()) {
                             selectionPathDeviated = true;
                             break;
--- a/javafx-ui-controls/test/javafx/scene/control/TreeViewKeyInputTest.java	Wed Jan 11 23:52:24 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/TreeViewKeyInputTest.java	Fri Jan 13 10:28:30 2012 +1300
@@ -29,16 +29,19 @@
     private Group group;
     
     private final TreeItem<String> root = new TreeItem<String>("Root");
-    private final TreeItem<String> child1 = new TreeItem<String>("Child 1");
-    private final TreeItem<String> child2 = new TreeItem<String>("Child 2");
-    private final TreeItem<String> child3 = new TreeItem<String>("Child 3");
-    private final TreeItem<String> child4 = new TreeItem<String>("Child 4");
-    private final TreeItem<String> child5 = new TreeItem<String>("Child 5");
-    private final TreeItem<String> child6 = new TreeItem<String>("Child 6");
-    private final TreeItem<String> child7 = new TreeItem<String>("Child 7");
-    private final TreeItem<String> child8 = new TreeItem<String>("Child 8");
-    private final TreeItem<String> child9 = new TreeItem<String>("Child 9");
-    private final TreeItem<String> child10 = new TreeItem<String>("Child 10");
+        private final TreeItem<String> child1 = new TreeItem<String>("Child 1");
+        private final TreeItem<String> child2 = new TreeItem<String>("Child 2");
+        private final TreeItem<String> child3 = new TreeItem<String>("Child 3");
+            private final TreeItem<String> subchild1 = new TreeItem<String>("Subchild 1");
+            private final TreeItem<String> subchild2 = new TreeItem<String>("Subchild 2");
+            private final TreeItem<String> subchild3 = new TreeItem<String>("Subchild 3");
+        private final TreeItem<String> child4 = new TreeItem<String>("Child 4");
+        private final TreeItem<String> child5 = new TreeItem<String>("Child 5");
+        private final TreeItem<String> child6 = new TreeItem<String>("Child 6");
+        private final TreeItem<String> child7 = new TreeItem<String>("Child 7");
+        private final TreeItem<String> child8 = new TreeItem<String>("Child 8");
+        private final TreeItem<String> child9 = new TreeItem<String>("Child 9");
+        private final TreeItem<String> child10 = new TreeItem<String>("Child 10");
 
     @Before public void setup() {
         treeView = new TreeView<String>();
@@ -58,9 +61,13 @@
         group.getChildren().setAll(treeView);
         stage.show();
 
+        child3.setExpanded(true);
+        child3.getChildren().setAll(subchild1, subchild2, subchild3);
+
+        root.setExpanded(true);
         root.getChildren().setAll(child1, child2, child3, child4, child5, child6, 
                                     child7, child8, child9, child10 );
-        root.setExpanded(true);
+        
         treeView.setRoot(root);
         sm.clearAndSelect(0);
     }
@@ -113,7 +120,7 @@
     }
     
     private int getItemCount() {
-        return root.getChildren().size();
+        return root.getChildren().size() + child3.getChildren().size();
     }
     
     
@@ -762,6 +769,56 @@
 //        
 //    }
     
+    
+    /***************************************************************************
+     * Tests for TreeView-specific functionality
+     **************************************************************************/ 
+    
+    // Test 1 (TreeView test cases)
+    @Test public void testRightArrowExpandsBranch() {
+        sm.clearAndSelect(0);
+        root.setExpanded(false);
+        assertFalse(root.isExpanded());
+        keyboard.doRightArrowPress();
+        assertTrue(root.isExpanded());
+    }
+    
+    // Test 2 (TreeView test cases)
+    @Test public void testRightArrowOnExpandedBranch() {
+        sm.clearAndSelect(0);
+        keyboard.doRightArrowPress();
+        assertTrue(isNotSelected(0));
+        assertTrue(isSelected(1));
+    }
+    
+    // Test 3 (TreeView test cases)
+    @Test public void testRightArrowOnLeafNode() {
+        sm.clearAndSelect(1);
+        keyboard.doRightArrowPress();
+        assertTrue(isNotSelected(0));
+        assertTrue(isSelected(1));
+        assertTrue(isNotSelected(2));
+    }
+    
+    // Test 4 (TreeView test cases)
+    @Test public void testLeftArrowCollapsesBranch() {
+        sm.clearAndSelect(0);
+        assertTrue(root.isExpanded());
+        keyboard.doLeftArrowPress();
+        assertFalse(root.isExpanded());
+    }
+    
+    // Test 5 (TreeView test cases)
+    @Test public void testLeftArrowOnLeafMovesSelectionToParent() {
+        sm.clearAndSelect(2);
+        assertTrue(root.isExpanded());
+        keyboard.doLeftArrowPress();
+        assertTrue(root.isExpanded());
+        assertTrue(isSelected(0));
+        assertTrue(isNotSelected(2));
+    }
+    
+    
     /***************************************************************************
      * Tests for specific bug reports
      **************************************************************************/