Skip to content

Commit adcc40d

Browse files
author
Jeanette Winzenburg
committed
8187474: Tree-/TableCell, TreeCell: editingCell/Item not updated in cell.startEdit
Reviewed-by: mhanl, aghaisas
1 parent a947405 commit adcc40d

File tree

7 files changed

+55
-31
lines changed

7 files changed

+55
-31
lines changed

modules/javafx.controls/src/main/java/javafx/scene/control/ListCell.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,18 @@ public void changed(
369369
super.startEdit();
370370

371371
if (!isEditing()) return;
372+
373+
indexAtStartEdit = getIndex();
372374
// Inform the ListView of the edit starting.
373375
if (list != null) {
374376
list.fireEvent(new ListView.EditEvent<T>(list,
375377
ListView.<T>editStartEvent(),
376378
null,
377-
getIndex()));
378-
list.edit(getIndex());
379+
indexAtStartEdit));
380+
list.edit(indexAtStartEdit);
379381
list.requestFocus();
380382
}
381383

382-
indexAtStartEdit = getIndex();
383384
}
384385

385386
/** {@inheritDoc} */

modules/javafx.controls/src/main/java/javafx/scene/control/TableCell.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ TablePosition<S, T> getEditingCellAtStartEdit() {
332332
super.startEdit();
333333

334334
if (!isEditing()) return;
335+
335336
editingCellAtStartEdit = new TablePosition<>(table, getIndex(), column);
336337
if (column != null) {
337338
CellEditEvent<S,?> editEvent = new CellEditEvent<>(
@@ -343,6 +344,9 @@ TablePosition<S, T> getEditingCellAtStartEdit() {
343344

344345
Event.fireEvent(column, editEvent);
345346
}
347+
if (table != null) {
348+
table.edit(editingCellAtStartEdit.getRow(), editingCellAtStartEdit.getTableColumn());
349+
}
346350
}
347351

348352
/** {@inheritDoc} */

modules/javafx.controls/src/main/java/javafx/scene/control/TreeCell.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,18 @@ public String getName() {
377377
super.startEdit();
378378

379379
if (!isEditing()) return;
380+
381+
treeItemAtStartEdit = getTreeItem();
380382
// Inform the TreeView of the edit starting.
381383
if (tree != null) {
382384
tree.fireEvent(new TreeView.EditEvent<T>(tree,
383385
TreeView.<T>editStartEvent(),
384-
getTreeItem(),
386+
treeItemAtStartEdit,
385387
getItem(),
386388
null));
387-
389+
tree.edit(treeItemAtStartEdit);
388390
tree.requestFocus();
389391
}
390-
treeItemAtStartEdit = getTreeItem();
391392
}
392393

393394
/** {@inheritDoc} */

modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableCell.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ TreeTablePosition<S, T> getEditingCellAtStartEdit() {
349349
super.startEdit();
350350

351351
if (!isEditing()) return;
352+
352353
editingCellAtStartEdit = new TreeTablePosition<>(table, getIndex(), column);
353354
if (column != null) {
354355
CellEditEvent<S, T> editEvent = new CellEditEvent<>(
@@ -360,6 +361,9 @@ TreeTablePosition<S, T> getEditingCellAtStartEdit() {
360361

361362
Event.fireEvent(column, editEvent);
362363
}
364+
if (table != null) {
365+
table.edit(editingCellAtStartEdit.getRow(), editingCellAtStartEdit.getTableColumn());
366+
}
363367
}
364368

365369
/** {@inheritDoc} */

modules/javafx.controls/src/test/java/test/javafx/scene/control/TableCellTest.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.junit.After;
3333
import org.junit.Before;
34-
import org.junit.Ignore;
3534
import org.junit.Test;
3635

3736
import com.sun.javafx.tk.Toolkit;
@@ -541,6 +540,28 @@ public void testEditStartFiresEvent() {
541540
assertEquals("startEdit must fire", 1, events.size());
542541
}
543542

543+
@Test
544+
public void testEditStartOnCellUpdatesControl() {
545+
setupForEditing();
546+
int editingRow = 1;
547+
cell.updateIndex(editingRow);
548+
TablePosition<?, ?> editingCell = new TablePosition<>(table, editingRow, editingColumn);
549+
cell.startEdit();
550+
assertEquals("table must be editing at", editingCell, table.getEditingCell());
551+
}
552+
553+
@Test
554+
public void testEditStartOnCellNoColumnUpdatesControl() {
555+
int editingRow = 1;
556+
// note: cell index must be != -1 because table.edit(-1, null) sets editingCell to null
557+
cell.updateIndex(editingRow);
558+
setupForcedEditing(table, null);
559+
TablePosition<?, ?> editingCell = new TablePosition<>(table, editingRow, null);
560+
cell.startEdit();
561+
assertTrue(cell.isEditing());
562+
assertEquals("table must be editing at", editingCell, table.getEditingCell());
563+
}
564+
544565
@Test
545566
public void testEditStartDoesNotFireEventWhileEditing() {
546567
setupForEditing();
@@ -586,9 +607,7 @@ public void testEditCommitEvent() {
586607
setupForEditing();
587608
int editingIndex = 1;
588609
cell.updateIndex(editingIndex);
589-
// FIXME JDK-8187474
590-
// should use cell.startEdit for consistency with the following tests
591-
table.edit(editingIndex, editingColumn);
610+
cell.startEdit();
592611
TablePosition<?, ?> editingPosition = table.getEditingCell();
593612
List<CellEditEvent<?, ?>> events = new ArrayList<>();
594613
editingColumn.setOnEditCommit(events::add);
@@ -714,10 +733,6 @@ public void testStartEditOffRangeMustNotFireStartEdit() {
714733
assertEquals("must not fire editStart", 0, events.size());
715734
}
716735

717-
/**
718-
* Note: this is a false green until JDK-8187474 (update control editing location) is fixed
719-
*/
720-
@Ignore("JDK-8187474")
721736
@Test
722737
public void testStartEditOffRangeMustNotUpdateEditingLocation() {
723738
setupForEditing();

modules/javafx.controls/src/test/java/test/javafx/scene/control/TreeCellTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ public void cleanup() {
599599
assertNull(tree.getEditingItem());
600600
}
601601

602-
@Ignore // TODO file bug!
603602
@Test public void editCellWithTreeResultsInUpdatedEditingIndexProperty() {
604603
tree.setEditable(true);
605604
cell.updateTreeView(tree);
@@ -848,23 +847,21 @@ public void testEditCommitMemoryLeakAfterRemoveEditingItem() {
848847
public void testStartEditOffRangeMustNotFireStartEdit() {
849848
tree.setEditable(true);
850849
cell.updateTreeView(tree);
851-
cell.updateIndex(tree.getExpandedItemCount());
850+
// update cell's treeItem so there is something to update
851+
cell.updateTreeItem(new TreeItem<>("not-contained"));
852852
List<EditEvent<?>> events = new ArrayList<>();
853853
tree.addEventHandler(TreeView.editStartEvent(), events::add);
854854
cell.startEdit();
855855
assertFalse("sanity: off-range cell must not be editing", cell.isEditing());
856856
assertEquals("cell must not fire editStart if not editing", 0, events.size());
857857
}
858858

859-
/**
860-
* Note: this is a false green until JDK-8187474 (update control editing location) is fixed
861-
*/
862-
@Ignore("JDK-8187474")
863859
@Test
864860
public void testStartEditOffRangeMustNotUpdateEditingLocation() {
865861
tree.setEditable(true);
866862
cell.updateTreeView(tree);
867-
cell.updateIndex(tree.getExpandedItemCount());
863+
// update cell's treeItem so there is something to update
864+
cell.updateTreeItem(new TreeItem<>("not-contained"));
868865
cell.startEdit();
869866
assertFalse("sanity: off-range cell must not be editing", cell.isEditing());
870867
assertNull("tree editing location must not be updated", tree.getEditingItem());

modules/javafx.controls/src/test/java/test/javafx/scene/control/TreeTableCellTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,23 @@ public void cleanup() {
304304
assertNull(tree.getEditingCell());
305305
}
306306

307-
@Ignore // TODO file bug!
308307
@Test public void editCellWithTreeResultsInUpdatedEditingIndexProperty() {
309-
tree.setEditable(true);
310-
cell.updateTreeTableView(tree);
308+
setupForEditing();
311309
cell.updateIndex(1);
312310
cell.startEdit();
313311
assertEquals(apples, tree.getEditingCell().getTreeItem());
314312
}
315313

314+
@Test public void editCellWithTreeNoColumnResultsInUpdatedEditingIndexProperty() {
315+
// note: cell index must be != -1 because table.edit(-1, null) sets editingCell to null
316+
cell.updateIndex(1);
317+
setupForcedEditing(tree, null);
318+
cell.startEdit();
319+
assertTrue(cell.isEditing());
320+
assertNotNull(tree.getEditingCell());
321+
assertEquals(apples, tree.getEditingCell().getTreeItem());
322+
}
323+
316324
// @Ignore // TODO file bug!
317325
// @Test public void editCellFiresEventOnTree() {
318326
// tree.setEditable(true);
@@ -911,9 +919,7 @@ public void testEditCommitEvent() {
911919
setupForEditing();
912920
int editingIndex = 1;
913921
cell.updateIndex(editingIndex);
914-
// FIXME JDK-8187474
915-
// should use cell.startEdit for consistency with the following tests
916-
tree.edit(editingIndex, editingColumn);
922+
cell.startEdit();
917923
TreeTablePosition<?, ?> editingPosition = tree.getEditingCell();
918924
List<CellEditEvent<?, ?>> events = new ArrayList<>();
919925
editingColumn.setOnEditCommit(events::add);
@@ -1038,10 +1044,6 @@ public void testStartEditOffRangeMustNotFireStartEdit() {
10381044
assertEquals("cell must not fire editStart if not editing", 0, events.size());
10391045
}
10401046

1041-
/**
1042-
* Note: this would be a false green until JDK-8187474 (update control editing location) is fixed
1043-
*/
1044-
@Ignore("JDK-8187474")
10451047
@Test
10461048
public void testStartEditOffRangeMustNotUpdateEditingLocation() {
10471049
setupForEditing();

0 commit comments

Comments
 (0)