< prev index next >

modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/TextFieldTableCellTest.java

Print this page
rev 10463 : 8089514: [TableView, TreeView, ListView, TreeTableView] Clicking outside of the edited cell, node, or entry should commit the value
   1 /*
   2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene.control.cell;
  27 

  28 import test.com.sun.javafx.scene.control.infrastructure.MouseEventFirer;
  29 import javafx.beans.property.ReadOnlyStringWrapper;
  30 import javafx.collections.FXCollections;
  31 import javafx.scene.control.TableCell;
  32 import javafx.scene.control.TableColumn;
  33 import javafx.scene.control.TableView;
  34 import javafx.scene.control.TextField;
  35 import javafx.scene.control.cell.TextFieldTableCell;
  36 import javafx.scene.input.MouseButton;
  37 import javafx.util.Callback;
  38 import javafx.util.StringConverter;
  39 import org.junit.Before;
  40 import org.junit.Test;
  41 
  42 import static org.junit.Assert.*;
  43 
  44 public class TextFieldTableCellTest {
  45 
  46     private StringConverter<Object> converter;
  47 


 344     @Test public void test_cancelEdit_usingCellCancelEdit() {
 345         TableColumn tc = new TableColumn();
 346         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 347         tableView.getColumns().add(tc);
 348         tableView.setEditable(true);
 349         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();
 350         cell.updateTableView(tableView);
 351         cell.updateIndex(0);
 352         cell.updateTableColumn(tc);
 353         cell.setEditable(true);
 354 
 355         tableView.edit(0, tc);
 356         assertTrue(cell.isEditing());
 357         assertNotNull(cell.getGraphic());
 358 
 359         cell.cancelEdit();
 360         assertFalse(cell.isEditing());
 361         assertNull(cell.getGraphic());
 362     }
 363 
 364     @Test public void test_cancelEdit_usingTableCancelEdit() {

 365         TableColumn tc = new TableColumn();
 366         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 367         tableView.getColumns().add(tc);
 368         tableView.setEditable(true);
 369         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();
 370         cell.updateTableView(tableView);
 371         cell.updateIndex(0);
 372         cell.updateTableColumn(tc);
 373         cell.setEditable(true);
 374 
 375         tableView.edit(0, tc);
 376         assertTrue(cell.isEditing());
 377         assertNotNull(cell.getGraphic());
 378 























 379         tableView.edit(-1, null);
 380         assertFalse(cell.isEditing());
 381         assertNull(cell.getGraphic());
 382     }
 383 
 384 
 385     /**************************************************************************
 386      *
 387      * Tests for specific bugs
 388      *
 389      **************************************************************************/
 390 
 391     @Test public void test_rt_32869() {
 392         TableColumn tc = new TableColumn();
 393         tc.setCellValueFactory(param -> new ReadOnlyStringWrapper("Dummy Text"));
 394 
 395         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 396         tableView.getColumns().add(tc);
 397         tableView.setEditable(true);
 398         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();


   1 /*
   2  * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene.control.cell;
  27 
  28 import javafx.util.converter.DefaultStringConverter;
  29 import test.com.sun.javafx.scene.control.infrastructure.MouseEventFirer;
  30 import javafx.beans.property.ReadOnlyStringWrapper;
  31 import javafx.collections.FXCollections;
  32 import javafx.scene.control.TableCell;
  33 import javafx.scene.control.TableColumn;
  34 import javafx.scene.control.TableView;
  35 import javafx.scene.control.TextField;
  36 import javafx.scene.control.cell.TextFieldTableCell;
  37 import javafx.scene.input.MouseButton;
  38 import javafx.util.Callback;
  39 import javafx.util.StringConverter;
  40 import org.junit.Before;
  41 import org.junit.Test;
  42 
  43 import static org.junit.Assert.*;
  44 
  45 public class TextFieldTableCellTest {
  46 
  47     private StringConverter<Object> converter;
  48 


 345     @Test public void test_cancelEdit_usingCellCancelEdit() {
 346         TableColumn tc = new TableColumn();
 347         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 348         tableView.getColumns().add(tc);
 349         tableView.setEditable(true);
 350         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();
 351         cell.updateTableView(tableView);
 352         cell.updateIndex(0);
 353         cell.updateTableColumn(tc);
 354         cell.setEditable(true);
 355 
 356         tableView.edit(0, tc);
 357         assertTrue(cell.isEditing());
 358         assertNotNull(cell.getGraphic());
 359 
 360         cell.cancelEdit();
 361         assertFalse(cell.isEditing());
 362         assertNull(cell.getGraphic());
 363     }
 364 
 365     @Test
 366     public void test_cancelEdit_usingTableCancelEdit_nullConverter() {
 367         TableColumn tc = new TableColumn();
 368         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 369         tableView.getColumns().add(tc);
 370         tableView.setEditable(true);
 371         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();
 372         cell.updateTableView(tableView);
 373         cell.updateIndex(0);
 374         cell.updateTableColumn(tc);
 375         cell.setEditable(true);
 376 
 377         tableView.edit(0, tc);
 378         assertTrue(cell.isEditing());
 379         assertNotNull(cell.getGraphic());
 380 
 381         // a null converter will mean that when editing is cancelled, the currently-editing cell
 382         // will be unable to be committed as the returned value internally will be empty.
 383         // Editing will stop as usual though.
 384         tableView.edit(-1, null);
 385         assertFalse(cell.isEditing());
 386         assertNull(cell.getGraphic());
 387     }
 388 
 389     @Test public void test_cancelEdit_usingTableCancelEdit_nonNullConverter() {
 390         TableColumn tc = new TableColumn();
 391         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 392         tableView.getColumns().add(tc);
 393         tableView.setEditable(true);
 394         TextFieldTableCell<Object,String> cell = new TextFieldTableCell<>(new DefaultStringConverter());
 395         cell.updateTableView(tableView);
 396         cell.updateIndex(0);
 397         cell.updateTableColumn(tc);
 398         cell.setEditable(true);
 399 
 400         tableView.edit(0, tc);
 401         assertTrue(cell.isEditing());
 402         assertNotNull(cell.getGraphic());
 403 
 404         tableView.edit(-1, null);
 405         assertFalse(cell.isEditing());
 406         assertNull(cell.getGraphic());
 407     }
 408 
 409 
 410     /**************************************************************************
 411      *
 412      * Tests for specific bugs
 413      *
 414      **************************************************************************/
 415 
 416     @Test public void test_rt_32869() {
 417         TableColumn tc = new TableColumn();
 418         tc.setCellValueFactory(param -> new ReadOnlyStringWrapper("Dummy Text"));
 419 
 420         TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
 421         tableView.getColumns().add(tc);
 422         tableView.setEditable(true);
 423         TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();


< prev index next >