changeset 135:2053e699ee06

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.1/scrum/controls/jfx/rt
author jgiles
date Fri, 09 Dec 2011 15:16:46 +1000
parents f6abb0dd0f61 8d6e25f7e160
children 3ec084f7363e
files
diffstat 15 files changed, 111 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableViewBehavior.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableViewBehavior.java	Fri Dec 09 15:16:46 2011 +1000
@@ -870,6 +870,7 @@
         
         if (sm.isSelected(focusedCell.getRow(), focusedCell.getTableColumn())) {
             sm.clearSelection(focusedCell.getRow(), focusedCell.getTableColumn());
+            fm.focus(focusedCell.getRow(), focusedCell.getTableColumn());
         } else {
             sm.select(focusedCell.getRow(), focusedCell.getTableColumn());
         }
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListViewSkin.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ListViewSkin.java	Fri Dec 09 15:16:46 2011 +1000
@@ -37,7 +37,6 @@
 import javafx.scene.control.SelectionModel;
 import javafx.scene.input.MouseEvent;
 
-import com.sun.javafx.runnable.Runnable0;
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import com.sun.javafx.scene.control.behavior.ListViewBehavior;
 import javafx.util.Callback;
@@ -59,8 +58,8 @@
         flow.setPannable(false);
         flow.setVertical(getSkinnable().getOrientation() == Orientation.VERTICAL);
         flow.setFocusTraversable(getSkinnable().isFocusTraversable());
-        flow.setCreateCell(new Runnable0<ListCell>() {
-            @Override public ListCell run() {
+        flow.setCreateCell(new Callback<VirtualFlow, ListCell>() {
+            @Override public ListCell call(VirtualFlow flow) {
                 return ListViewSkin.this.createCell();
             }
         });
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PositionMapper.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/PositionMapper.java	Fri Dec 09 15:16:46 2011 +1000
@@ -26,13 +26,13 @@
 package com.sun.javafx.scene.control.skin;
 
 import com.sun.javafx.Utils;
-import com.sun.javafx.runnable.Runnable1;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.IntegerProperty;
 import javafx.beans.property.ReadOnlyDoubleProperty;
 import javafx.beans.property.ReadOnlyDoubleWrapper;
 import javafx.beans.property.SimpleDoubleProperty;
 import javafx.beans.property.SimpleIntegerProperty;
+import javafx.util.Callback;
 
 /**
  * Base implementation of a helper class used by virtualized Controls such as
@@ -121,9 +121,9 @@
      * item size would be the height of the cell, whereas in a horizontal
      * list the item size would be the width of the cell.
      */
-    private Runnable1<Double, Integer> itemSize;
-    private Runnable1<Double, Integer> getItemSize() { return itemSize; }
-    public void setGetItemSize(Runnable1<Double, Integer> itemSize) {
+    private Callback<Integer, Double> itemSize;
+    private Callback<Integer, Double> getItemSize() { return itemSize; }
+    public void setGetItemSize(Callback<Integer, Double> itemSize) {
         this.itemSize = itemSize;
     }
 
@@ -140,7 +140,7 @@
         double fractionalPosition = p * count;
         int cellIndex = (int) fractionalPosition;
         double fraction = fractionalPosition - cellIndex;
-        double cellSize = getItemSize().run(cellIndex);
+        double cellSize = getItemSize().call(cellIndex);
         double pixelOffset = cellSize * fraction;
         double viewportOffset = getViewportSize() * p;
         return pixelOffset - viewportOffset;
@@ -191,7 +191,7 @@
         double fractionalPosition = getPosition() * count;
         int cellIndex = (int) fractionalPosition;
         if (forward && cellIndex == count) return;
-        double cellSize = getItemSize().run(cellIndex);
+        double cellSize = getItemSize().call(cellIndex);
         double fraction = fractionalPosition - cellIndex;
         double pixelOffset = cellSize * fraction;
 
@@ -225,7 +225,7 @@
         while (n > remaining && ((forward && cellIndex < count - 1) || (! forward && cellIndex > 0))) {
             if (forward) cellIndex++; else cellIndex--;
             n -= remaining;
-            cellSize = getItemSize().run(cellIndex);
+            cellSize = getItemSize().call(cellIndex);
             start = computeOffsetForCell(cellIndex);
             end = cellSize + computeOffsetForCell(cellIndex + 1);
             remaining = end - start;
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableViewSkin.java	Fri Dec 09 15:16:46 2011 +1000
@@ -37,7 +37,6 @@
 import javafx.event.EventHandler;
 import javafx.geometry.Insets;
 import javafx.scene.Node;
-import javafx.scene.control.IndexedCell;
 import javafx.scene.control.Label;
 import javafx.scene.control.SelectionModel;
 import javafx.scene.control.TableColumn;
@@ -49,7 +48,6 @@
 import javafx.scene.layout.StackPane;
 import javafx.util.Callback;
 
-import com.sun.javafx.runnable.Runnable0;
 import com.sun.javafx.scene.control.behavior.TableViewBehavior;
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import com.sun.javafx.scene.control.skin.resources.ControlResources;
@@ -65,8 +63,8 @@
         flow = new VirtualFlow();
         flow.setPannable(false);
         flow.setFocusTraversable(getSkinnable().isFocusTraversable());
-        flow.setCreateCell(new Runnable0<TableRow>() {
-            @Override public TableRow run() {
+        flow.setCreateCell(new Callback<VirtualFlow, TableRow>() {
+            @Override public TableRow call(VirtualFlow flow) {
                 return TableViewSkin.this.createCell();
             }
         });
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TreeViewSkin.java	Fri Dec 09 15:16:46 2011 +1000
@@ -26,11 +26,8 @@
 package com.sun.javafx.scene.control.skin;
 
 import javafx.event.EventHandler;
-import javafx.geometry.Pos;
 import javafx.scene.Node;
 import javafx.scene.control.IndexedCell;
-import javafx.scene.control.Label;
-import javafx.scene.control.SelectionModel;
 import javafx.scene.control.TreeCell;
 import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeItem.TreeModificationEvent;
@@ -39,8 +36,6 @@
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.StackPane;
 
-import com.sun.javafx.runnable.Runnable0;
-import com.sun.javafx.runnable.Runnable1;
 import com.sun.javafx.scene.control.WeakEventHandler;
 import com.sun.javafx.scene.control.behavior.TreeViewBehavior;
 import java.lang.ref.WeakReference;
@@ -56,8 +51,8 @@
         flow = new VirtualFlow();
         flow.setPannable(false);
         flow.setFocusTraversable(getSkinnable().isFocusTraversable());
-        flow.setCreateCell(new Runnable0<TreeCell>() {
-            @Override public TreeCell run() {
+        flow.setCreateCell(new Callback<VirtualFlow, TreeCell>() {
+            @Override public TreeCell call(VirtualFlow flow) {
                 return TreeViewSkin.this.createCell();
             }
         });
@@ -209,12 +204,19 @@
             ((TreeCell)flow.cells.get(i)).updateTreeView(null);
         }
         
-        flow.setCellCount(getItemCount());
-
-        // This needs to be recreateCells here (rather than reconfigureCells)
-        // otherwise issues appear when expanding/collapsing branches. For example,
-        // see RT-14013.
-        flow.recreateCells();
+        int oldCount = flow.getCellCount();
+        int newCount = getItemCount();
+        
+        // if this is not called even when the count is the same, we get a 
+        // memory leak in VirtualFlow.sheet.children. This can probably be 
+        // optimised in the future when time permits.
+        flow.setCellCount(newCount);
+        
+        if (newCount != oldCount) {
+            flow.recreateCells();
+        } else {
+            flow.reconfigureCells();
+        }
     }
 
     @Override public TreeCell<T> createCell() {
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/VirtualFlow.java	Fri Dec 09 15:16:46 2011 +1000
@@ -49,8 +49,7 @@
 import javafx.scene.layout.StackPane;
 import javafx.scene.shape.Rectangle;
 
-import com.sun.javafx.runnable.Runnable0;
-import com.sun.javafx.runnable.Runnable1;
+import javafx.util.Callback;
 
 /**
  * Implementation of a virtualized container using a cell based mechanism.
@@ -266,9 +265,9 @@
      * IndexedCell. The VirtualFlow attempts to reuse cells whenever possible
      * and only creates the minimal number of cells necessary.
      */
-    private Runnable0<? extends IndexedCell> createCell;
-    public Runnable0<? extends IndexedCell> getCreateCell() { return createCell; }
-    protected void setCreateCell(Runnable0<? extends IndexedCell> cc) {
+    private Callback<VirtualFlow, ? extends IndexedCell> createCell;
+    public Callback<VirtualFlow, ? extends IndexedCell> getCreateCell() { return createCell; }
+    protected void setCreateCell(Callback<VirtualFlow, ? extends IndexedCell> cc) {
         this.createCell = cc;
 
         if (createCell != null) {
@@ -471,8 +470,8 @@
 
     public VirtualFlow() {
         mapper = new PositionMapper();
-        mapper.setGetItemSize(new Runnable1<Double, Integer>() {
-            @Override public Double run(Integer itemIndex) {
+        mapper.setGetItemSize(new Callback<Integer, Double>() {
+            @Override public Double call(Integer itemIndex) {
                 return getCellLength(itemIndex);
             }
         });
@@ -1364,7 +1363,7 @@
 
         // We need to use the accumCell and return that
         if (accumCell == null && getCreateCell() != null) {
-            accumCell = getCreateCell().run();
+            accumCell = getCreateCell().call(this);
             accumCellParent.getChildren().add(accumCell);
         }
         setCellIndex(accumCell, index);
@@ -1497,7 +1496,7 @@
             if (pile.size() > 0) {
                 cell = pile.removeFirst();
             } else {
-                cell = createCell.run();
+                cell = createCell.call(this);
             }
         }
         
--- a/javafx-ui-controls/src/javafx/scene/control/ListView.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/javafx/scene/control/ListView.java	Fri Dec 09 15:16:46 2011 +1000
@@ -665,7 +665,8 @@
      **************************************************************************/
 
     /**
-     * Instructs the ListView to begin editing the item in the given index. Once
+     * Instructs the ListView to begin editing the item in the given index, if 
+     * the ListView is {@link #editableProperty() editable}. Once
      * this method is called, if the current {@link #cellFactoryProperty()} is
      * set up to support editing, the Cell will switch its visual state to enable
      * for user input to take place.
@@ -674,6 +675,7 @@
      *     edited.
      */
     public void edit(int itemIndex) {
+        if (!isEditable()) return;
         setEditingIndex(itemIndex);
     }
 
--- a/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Fri Dec 09 15:16:46 2011 +1000
@@ -103,8 +103,7 @@
     };
     
     @Override void indexChanged() {
-        itemDirty = true;
-        requestLayout();
+        updateItem();
     }
 
     /*
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Fri Dec 09 15:16:46 2011 +1000
@@ -1180,9 +1180,11 @@
 
     /**
      * Causes the cell at the given row/column view indexes to switch into
-     * its editing state, if it is not already in it.
+     * its editing state, if it is not already in it, and assuming that the 
+     * TableView and column are also editable.
      */
     public void edit(int row, TableColumn<S,?> column) {
+        if (!isEditable() || (column != null && ! column.isEditable())) return;
         setEditingCell(new TablePosition(this, row, column));
     }
     
--- a/javafx-ui-controls/src/javafx/scene/control/TreeItem.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/javafx/scene/control/TreeItem.java	Fri Dec 09 15:16:46 2011 +1000
@@ -722,7 +722,7 @@
         if (this.getParent() != other.getParent() && (this.getParent() == null || !this.getParent().equals(other.getParent()))) {
             return false;
         }
-        if (this.getChildren() != other.getChildren() && (this.getChildren() == null || !this.getChildren().equals(other.getChildren()))) {
+        if (this.children != other.children && (this.children == null || !this.children.equals(other.children))) {
             return false;
         }
         return true;
--- a/javafx-ui-controls/src/javafx/scene/control/TreeView.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/src/javafx/scene/control/TreeView.java	Fri Dec 09 15:16:46 2011 +1000
@@ -730,7 +730,8 @@
     
     
     /**
-     * Instructs the TreeView to begin editing the given TreeItem. Once
+     * Instructs the TreeView to begin editing the given TreeItem, if 
+     * the TreeView is {@link #editableProperty() editable}. Once
      * this method is called, if the current 
      * {@link #cellFactoryProperty() cell factory} is set up to support editing,
      * the Cell will switch its visual state to enable the user input to take place.
@@ -738,6 +739,7 @@
      * @param item The TreeItem in the TreeView that should be edited.
      */
     public void edit(TreeItem<T> item) {
+        if (!isEditable()) return;
         setEditingItem(item);
     }
     
--- a/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/VirtualFlowTest.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/test/com/sun/javafx/scene/control/skin/VirtualFlowTest.java	Fri Dec 09 15:16:46 2011 +1000
@@ -21,11 +21,10 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.sun.javafx.runnable.Runnable0;
-import com.sun.javafx.runnable.Runnable1;
 import com.sun.javafx.scene.CSSFlags;
 import com.sun.javafx.scene.control.skin.VirtualFlow.ArrayLinkedList;
 import java.util.List;
+import javafx.util.Callback;
 
 /**
  * Tests for the VirtualFlow class. VirtualFlow is the guts of the ListView,
@@ -53,8 +52,8 @@
         flow = new VirtualFlow();
 //        flow.setManaged(false);
         flow.setVertical(true);
-        flow.setCreateCell(new Runnable0<IndexedCell>() {
-            @Override public IndexedCell run() {
+        flow.setCreateCell(new Callback<VirtualFlow, IndexedCell>() {
+            @Override public IndexedCell call(VirtualFlow p) {
                 return new CellStub(flow) {
                     @Override protected double computeMinWidth(double height) { return computePrefWidth(height); }
                     @Override protected double computeMaxWidth(double height) { return computePrefWidth(height); }
@@ -838,8 +837,8 @@
         assertFalse(flow.isNeedsLayout());
         flow.getCellLength(49); // forces accum cell to be created
         assertNotNull("Accum cell was null", flow.accumCell);
-        flow.setCreateCell(new Runnable0<IndexedCell>() {
-            @Override public IndexedCell run() {
+        flow.setCreateCell(new Callback<VirtualFlow, IndexedCell>() {
+            @Override public IndexedCell call(VirtualFlow p) {
                 return new CellStub(flow);
             }
         });
--- a/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Fri Dec 09 15:16:46 2011 +1000
@@ -306,4 +306,16 @@
         assertEquals(1, listView.getSelectionModel().getSelectedIndices().size());
         assertEquals(1, listView.getSelectionModel().getSelectedItems().size());
     }
+    
+    @Test public void test_rt18339_onlyEditWhenListViewIsEditable_editableIsFalse() {
+        listView.setEditable(false);
+        listView.edit(1);
+        assertEquals(-1, listView.getEditingIndex());
+    }
+    
+    @Test public void test_rt18339_onlyEditWhenListViewIsEditable_editableIsTrue() {
+        listView.setEditable(true);
+        listView.edit(1);
+        assertEquals(1, listView.getEditingIndex());
+    }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Fri Dec 09 15:16:46 2011 +1000
@@ -369,4 +369,40 @@
         assertEquals(1, table.getSelectionModel().getSelectedItems().size());
         assertEquals(1, table.getSelectionModel().getSelectedCells().size());
     }
+    
+    @Test public void test_rt18339_onlyEditWhenTableViewIsEditable_tableEditableIsFalse_columnEditableIsFalse() {
+        TableColumn<String,String> first = new TableColumn<String,String>("first");
+        first.setEditable(false);
+        table.getColumns().add(first);
+        table.setEditable(false);
+        table.edit(1, first);
+        assertEquals(null, table.getEditingCell());
+    }
+    
+    @Test public void test_rt18339_onlyEditWhenTableViewIsEditable_tableEditableIsFalse_columnEditableIsTrue() {
+        TableColumn<String,String> first = new TableColumn<String,String>("first");
+        first.setEditable(true);
+        table.getColumns().add(first);
+        table.setEditable(false);
+        table.edit(1, first);
+        assertEquals(null, table.getEditingCell());
+    }
+    
+    @Test public void test_rt18339_onlyEditWhenTableViewIsEditable_tableEditableIsTrue_columnEditableIsFalse() {
+        TableColumn<String,String> first = new TableColumn<String,String>("first");
+        first.setEditable(false);
+        table.getColumns().add(first);
+        table.setEditable(true);
+        table.edit(1, first);
+        assertEquals(null, table.getEditingCell());
+    }
+    
+    @Test public void test_rt18339_onlyEditWhenTableViewIsEditable_tableEditableIsTrue_columnEditableIsTrue() {
+        TableColumn<String,String> first = new TableColumn<String,String>("first");
+        first.setEditable(true);
+        table.getColumns().add(first);
+        table.setEditable(true);
+        table.edit(1, first);
+        assertEquals(new TablePosition(table, 1, first), table.getEditingCell());
+    }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java	Thu Dec 08 14:01:27 2011 +0000
+++ b/javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java	Fri Dec 09 15:16:46 2011 +1000
@@ -389,4 +389,16 @@
         assertEquals(1, treeView.getSelectionModel().getSelectedIndices().size());
         assertEquals(1, treeView.getSelectionModel().getSelectedItems().size());
     }
+    
+    @Test public void test_rt18339_onlyEditWhenTreeViewIsEditable_editableIsFalse() {
+        treeView.setEditable(false);
+        treeView.edit(root);
+        assertEquals(null, treeView.getEditingItem());
+    }
+    
+    @Test public void test_rt18339_onlyEditWhenTreeViewIsEditable_editableIsTrue() {
+        treeView.setEditable(true);
+        treeView.edit(root);
+        assertEquals(root, treeView.getEditingItem());
+    }
 }