changeset 130:d06073f52116

RT-18339: [ListView/TableView/TreeView] Editing index property changes, when Space press.
author jgiles
date Thu, 08 Dec 2011 18:03:49 +1000
parents 39b77f7b2433
children 1b515bf64da6
files javafx-ui-controls/src/javafx/scene/control/ListView.java javafx-ui-controls/src/javafx/scene/control/TableView.java javafx-ui-controls/src/javafx/scene/control/TreeView.java javafx-ui-controls/test/javafx/scene/control/ListViewTest.java javafx-ui-controls/test/javafx/scene/control/TableViewTest.java javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java
diffstat 6 files changed, 69 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/ListView.java	Thu Dec 08 17:47:34 2011 +1000
+++ b/javafx-ui-controls/src/javafx/scene/control/ListView.java	Thu Dec 08 18:03:49 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/TableView.java	Thu Dec 08 17:47:34 2011 +1000
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Thu Dec 08 18:03:49 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/TreeView.java	Thu Dec 08 17:47:34 2011 +1000
+++ b/javafx-ui-controls/src/javafx/scene/control/TreeView.java	Thu Dec 08 18:03:49 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/javafx/scene/control/ListViewTest.java	Thu Dec 08 17:47:34 2011 +1000
+++ b/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Thu Dec 08 18:03:49 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 17:47:34 2011 +1000
+++ b/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Thu Dec 08 18:03:49 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 17:47:34 2011 +1000
+++ b/javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java	Thu Dec 08 18:03:49 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());
+    }
 }