Skip to content
Permalink
Browse files
8252238: TableView: Editable (pseudo-editable) cells should respect t…
…he row editability

Reviewed-by: fastegal, aghaisas
  • Loading branch information
Marius Hanl authored and aghaisas committed Jun 23, 2021
1 parent 04493e5 commit 45786ac4f6c3abda45b162b27d158e2dee9e9c14
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -303,9 +303,11 @@ private void setTableView(TableView<S> value) {
@Override public void startEdit() {
final TableView<S> table = getTableView();
final TableColumn<S,T> column = getTableColumn();
if (! isEditable() ||
(table != null && ! table.isEditable()) ||
(column != null && ! getTableColumn().isEditable())) {
final TableRow<S> row = getTableRow();
if (!isEditable() ||
(table != null && !table.isEditable()) ||
(column != null && !column.isEditable()) ||
(row != null && !row.isEditable())) {
return;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -306,9 +306,11 @@ private void setTreeTableView(TreeTableView<S> value) {

final TreeTableView<S> table = getTreeTableView();
final TreeTableColumn<S,T> column = getTableColumn();
if (! isEditable() ||
(table != null && ! table.isEditable()) ||
(column != null && ! getTableColumn().isEditable())) {
final TreeTableRow<S> row = getTreeTableRow();
if (!isEditable() ||
(table != null && !table.isEditable()) ||
(column != null && !column.isEditable()) ||
(row != null && !row.isEditable())) {
return;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,8 @@

package test.javafx.scene.control;

import javafx.scene.control.TableRow;
import javafx.scene.control.TreeTableRow;
import javafx.scene.control.skin.TableCellSkin;
import test.com.sun.javafx.scene.control.infrastructure.StageLoader;
import test.com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
@@ -48,6 +50,7 @@
public class TableCellTest {
private TableCell<String,String> cell;
private TableView<String> table;
private TableRow<String> row;
private ObservableList<String> model;

@Before public void setup() {
@@ -62,6 +65,8 @@
cell = new TableCell<String,String>();
model = FXCollections.observableArrayList("Four", "Five", "Fear"); // "Flop", "Food", "Fizz"
table = new TableView<String>(model);

row = new TableRow<>();
}

@After
@@ -322,6 +327,81 @@ private void test_rt36715_cellPropertiesMirrorTableColumnProperties(
cell.setSkin(new TableCellSkin(cell));
}

/**
* Table: Editable<br>
* Row: Not editable<br>
* Column: Editable<br>
* Expected: Cell can not be edited because the row is not editable.
*/
@Test
public void testCellInUneditableRowIsNotEditable() {
table.setEditable(true);
row.setEditable(false);

TableColumn<String, String> tableColumn = new TableColumn<>();
tableColumn.setEditable(true);
table.getColumns().add(tableColumn);

cell.updateTableColumn(tableColumn);
cell.updateTableRow(row);
cell.updateTableView(table);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Table: Not editable<br>
* Row: Editable<br>
* Column: Editable<br>
* Expected: Cell can not be edited because the table is not editable.
*/
@Test
public void testCellInUneditableTableIsNotEditable() {
table.setEditable(false);
row.setEditable(true);

TableColumn<String, String> tableColumn = new TableColumn<>();
tableColumn.setEditable(true);
table.getColumns().add(tableColumn);

cell.updateTableColumn(tableColumn);
cell.updateTableRow(row);
cell.updateTableView(table);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Table: Editable<br>
* Row: Editable<br>
* Column: Not editable<br>
* Expected: Cell can not be edited because the column is not editable.
*/
@Test
public void testCellInUneditableColumnIsNotEditable() {
table.setEditable(true);
row.setEditable(true);

TableColumn<String, String> tableColumn = new TableColumn<>();
tableColumn.setEditable(false);
table.getColumns().add(tableColumn);

cell.updateTableColumn(tableColumn);
cell.updateTableRow(row);
cell.updateTableView(table);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Test that cell.cancelEdit can switch table editing off
* even if a subclass violates its contract.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -633,6 +633,81 @@ private void test_rt36715_cellPropertiesMirrorTableColumnProperties(
cell.setSkin(new TreeTableCellSkin(cell));
}

/**
* Table: Editable<br>
* Row: Not editable<br>
* Column: Editable<br>
* Expected: Cell can not be edited because the row is not editable.
*/
@Test
public void testCellInUneditableRowIsNotEditable() {
tree.setEditable(true);
row.setEditable(false);

TreeTableColumn<String, String> treeTableColumn = new TreeTableColumn<>();
treeTableColumn.setEditable(true);
tree.getColumns().add(treeTableColumn);

cell.updateTreeTableColumn(treeTableColumn);
cell.updateTreeTableRow(row);
cell.updateTreeTableView(tree);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Table: Not editable<br>
* Row: Editable<br>
* Column: Editable<br>
* Expected: Cell can not be edited because the table is not editable.
*/
@Test
public void testCellInUneditableTableIsNotEditable() {
tree.setEditable(false);
row.setEditable(true);

TreeTableColumn<String, String> treeTableColumn = new TreeTableColumn<>();
treeTableColumn.setEditable(true);
tree.getColumns().add(treeTableColumn);

cell.updateTreeTableColumn(treeTableColumn);
cell.updateTreeTableRow(row);
cell.updateTreeTableView(tree);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Table: Editable<br>
* Row: Editable<br>
* Column: Not editable<br>
* Expected: Cell can not be edited because the column is not editable.
*/
@Test
public void testCellInUneditableColumnIsNotEditable() {
tree.setEditable(true);
row.setEditable(true);

TreeTableColumn<String, String> treeTableColumn = new TreeTableColumn<>();
treeTableColumn.setEditable(false);
tree.getColumns().add(treeTableColumn);

cell.updateTreeTableColumn(treeTableColumn);
cell.updateTreeTableRow(row);
cell.updateTreeTableView(tree);

cell.updateIndex(0);
cell.startEdit();

assertFalse(cell.isEditing());
}

/**
* Test that cell.cancelEdit can switch table editing off
* even if a subclass violates its contract.

1 comment on commit 45786ac

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 45786ac Jun 23, 2021

Please sign in to comment.