Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 45786ac
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 10 deletions.
@@ -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
Expand Down Expand Up @@ -303,9 +303,11 @@ private ReadOnlyObjectWrapper<TableView<S>> tableViewPropertyImpl() {
@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;
}

Expand Down
@@ -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
Expand Down Expand Up @@ -306,9 +306,11 @@ private ReadOnlyObjectWrapper<TreeTableView<S>> treeTableViewPropertyImpl() {

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;
}

Expand Down
@@ -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
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -62,6 +65,8 @@ public class TableCellTest {
cell = new TableCell<String,String>();
model = FXCollections.observableArrayList("Four", "Five", "Fear"); // "Flop", "Food", "Fizz"
table = new TableView<String>(model);

row = new TableRow<>();
}

@After
Expand Down Expand Up @@ -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.
Expand Down
@@ -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
Expand Down Expand Up @@ -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.
Expand Down

1 comment on commit 45786ac

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.