1 /* 2 * Copyright (c) 2011, 2014, 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 javafx.scene.control; 27 28 import com.sun.javafx.scene.control.infrastructure.StageLoader; 29 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils; 30 import javafx.scene.control.skin.TableColumnHeader; 31 import javafx.scene.control.skin.VirtualFlow; 32 import com.sun.javafx.scene.control.test.Person; 33 import javafx.beans.property.DoubleProperty; 34 import javafx.beans.property.ObjectProperty; 35 import javafx.beans.property.SimpleBooleanProperty; 36 import javafx.beans.property.SimpleDoubleProperty; 37 import javafx.beans.property.SimpleObjectProperty; 38 import javafx.beans.property.SimpleStringProperty; 39 import javafx.beans.property.StringProperty; 40 import javafx.beans.value.ObservableValue; 41 import javafx.event.EventHandler; 42 import javafx.event.EventType; 43 import javafx.scene.Node; 44 import javafx.scene.shape.Rectangle; 45 import javafx.util.Callback; 46 47 import java.util.Arrays; 48 import java.util.Collections; 49 import java.util.Comparator; 50 import java.util.List; 51 import javafx.beans.property.BooleanProperty; 52 53 import org.junit.Before; 54 import org.junit.Ignore; 55 import org.junit.Test; 56 57 import static org.junit.Assert.*; 58 import static org.junit.Assert.assertEquals; 59 60 /** 61 */ 62 public class TreeTableColumnTest { 63 private static final double MIN_WIDTH = 35; 64 private static final double MAX_WIDTH = 2000; 65 private static final double PREF_WIDTH = 100; 66 67 private TreeTableColumn<Person,String> column; 68 private TreeTableView<Person> table; 69 private TreeItem<Person> root; 70 71 @Before public void setup() { 72 root = new TreeItem<Person>(null); 73 root.setExpanded(true); 74 75 root.getChildren().setAll( 76 new TreeItem(new Person("Humphrey McPhee", 76)), 77 new TreeItem(new Person("Justice Caldwell", 30)), 78 new TreeItem(new Person("Orrin Davies", 30)), 79 new TreeItem(new Person("Emma Wilson", 8))); 80 81 column = new TreeTableColumn<Person,String>(""); 82 table = new TreeTableView<Person>(root); 83 } 84 85 86 /********************************************************************* 87 * Tests for the constructors * 88 ********************************************************************/ 89 90 @Test public void defaultConstructorHasDefaultCellFactory() { 91 assertSame(TreeTableColumn.DEFAULT_CELL_FACTORY, column.getCellFactory()); 92 assertSame(TreeTableColumn.DEFAULT_CELL_FACTORY, column.cellFactoryProperty().get()); 93 } 94 95 @Test public void defaultConstructorHasDefaultComparator() { 96 assertSame(TreeTableColumn.DEFAULT_COMPARATOR, column.getComparator()); 97 assertSame(TreeTableColumn.DEFAULT_COMPARATOR, column.comparatorProperty().get()); 98 } 99 100 @Test public void defaultConstructorHasEmptyStringText() { 101 assertEquals("", column.getText()); 102 assertEquals("", column.textProperty().get()); 103 } 104 105 // @Test public void defaultConstructorHasNonNullEditCommitHandler() { 106 // // This is questionable 107 // } 108 109 /********************************************************************* 110 * Tests for the tableView property * 111 ********************************************************************/ 112 113 @Test public void tableViewIsNullByDefault() { 114 assertNull(column.getTreeTableView()); 115 assertNull(column.treeTableViewProperty().get()); 116 } 117 118 @Test public void tableViewCanBeSpecified() { 119 column.setTreeTableView(table); 120 assertSame(table, column.getTreeTableView()); 121 assertSame(table, column.treeTableViewProperty().get()); 122 } 123 124 @Test public void tableViewCanBeResetToNull() { 125 column.setTreeTableView(table); 126 column.setTreeTableView(null); 127 assertNull(column.getTreeTableView()); 128 assertNull(column.treeTableViewProperty().get()); 129 } 130 131 @Test public void treeTableViewPropertyBeanIsCorrect() { 132 assertSame(column, column.treeTableViewProperty().getBean()); 133 } 134 135 @Test public void treeTableViewPropertyNameIsCorrect() { 136 assertEquals("treeTableView", column.treeTableViewProperty().getName()); 137 } 138 139 @Test public void whenTableViewIsChangedChildColumnsAreUpdated() { 140 TreeTableColumn<Person,String> child = new TreeTableColumn<Person,String>(); 141 column.getColumns().add(child); 142 table.getColumns().add(column); 143 144 TreeTableView<Person> other = new TreeTableView<Person>(); 145 table.getColumns().clear(); 146 other.getColumns().add(column); 147 148 assertSame(other, child.getTreeTableView()); 149 } 150 151 /********************************************************************* 152 * Tests for the text property * 153 ********************************************************************/ 154 155 @Test public void textIsEmptyByDefault() { 156 assertEquals("", column.getText()); 157 assertEquals("", column.textProperty().get()); 158 } 159 160 @Test public void textCanBeSpecified() { 161 column.setText("Name"); 162 assertEquals("Name", column.getText()); 163 assertEquals("Name", column.textProperty().get()); 164 } 165 166 @Test public void textCanBeSetToNull() { 167 column.setText(null); 168 assertNull(column.getText()); 169 assertNull(column.textProperty().get()); 170 } 171 172 @Test public void textPropertyBeanIsCorrect() { 173 assertSame(column, column.textProperty().getBean()); 174 } 175 176 @Test public void textPropertyNameIsCorrect() { 177 assertEquals("text", column.textProperty().getName()); 178 } 179 180 @Test public void textCanBeBound() { 181 StringProperty other = new SimpleStringProperty("Name"); 182 column.textProperty().bind(other); 183 assertEquals("Name", column.getText()); 184 assertEquals("Name", column.textProperty().get()); 185 other.set("Age"); 186 assertEquals("Age", column.getText()); 187 assertEquals("Age", column.textProperty().get()); 188 } 189 190 /********************************************************************* 191 * Tests for the visible property * 192 ********************************************************************/ 193 194 @Test public void visibleIsTrueByDefault() { 195 assertTrue(column.isVisible()); 196 assertTrue(column.visibleProperty().get()); 197 } 198 199 @Test public void visibleCanBeSpecified() { 200 column.setVisible(false); 201 assertFalse(column.isVisible()); 202 assertFalse(column.visibleProperty().get()); 203 } 204 205 @Test public void visiblePropertyBeanIsCorrect() { 206 assertSame(column, column.visibleProperty().getBean()); 207 } 208 209 @Test public void visiblePropertyNameIsCorrect() { 210 assertEquals("visible", column.visibleProperty().getName()); 211 } 212 213 @Test public void visibleCanBeBound() { 214 BooleanProperty other = new SimpleBooleanProperty(false); 215 column.visibleProperty().bind(other); 216 assertFalse(column.isVisible()); 217 assertFalse(column.visibleProperty().get()); 218 other.set(true); 219 assertTrue(column.isVisible()); 220 assertTrue(column.visibleProperty().get()); 221 } 222 223 /********************************************************************* 224 * Tests for the parentColumn property * 225 ********************************************************************/ 226 227 @Test public void parentColumnIsNullByDefault() { 228 TreeTableColumn child = new TreeTableColumn(); 229 assertNull(child.getParentColumn()); 230 assertNull(child.parentColumnProperty().get()); 231 } 232 233 @Test public void parentColumnIsUpdatedWhenAddedToParent() { 234 TreeTableColumn child = new TreeTableColumn(); 235 column.getColumns().add(child); 236 assertSame(column, child.getParentColumn()); 237 assertSame(column, child.parentColumnProperty().get()); 238 } 239 240 @Test public void parentColumnIsClearedWhenRemovedFromParent() { 241 TreeTableColumn child = new TreeTableColumn(); 242 column.getColumns().add(child); 243 column.getColumns().remove(child); 244 assertNull(child.getParentColumn()); 245 assertNull(child.parentColumnProperty().get()); 246 } 247 248 @Test public void parentColumnIsClearedWhenParentColumnsIsCleared() { 249 TreeTableColumn child = new TreeTableColumn(); 250 column.getColumns().add(child); 251 column.getColumns().clear(); 252 assertNull(child.getParentColumn()); 253 assertNull(child.parentColumnProperty().get()); 254 } 255 256 @Test public void tableViewReferenceIsUpdatedWhenAddedToParent() { 257 table.getColumns().add(column); 258 TreeTableColumn child = new TreeTableColumn(); 259 column.getColumns().add(child); 260 assertSame(table, child.getTreeTableView()); 261 assertSame(table, child.treeTableViewProperty().get()); 262 } 263 264 @Test public void tableViewReferenceIsClearedWhenRemovedFromParent() { 265 table.getColumns().add(column); 266 TreeTableColumn child = new TreeTableColumn(); 267 column.getColumns().add(child); 268 column.getColumns().remove(child); 269 assertNull(child.getTreeTableView()); 270 assertNull(child.treeTableViewProperty().get()); 271 } 272 273 @Test public void tableViewReferenceIsClearedWhenParentColumnsIsCleared() { 274 table.getColumns().add(column); 275 TreeTableColumn child = new TreeTableColumn(); 276 column.getColumns().add(child); 277 column.getColumns().clear(); 278 assertNull(child.getTreeTableView()); 279 assertNull(child.treeTableViewProperty().get()); 280 } 281 282 @Test public void visibleIsUpdatedWhenParentColumnVisibleChanges() { 283 TreeTableColumn child = new TreeTableColumn(); 284 column.getColumns().add(child); 285 column.setVisible(true); 286 assertTrue(child.visibleProperty().get()); 287 column.setVisible(false); 288 assertFalse(child.isVisible()); 289 } 290 291 @Test public void visibleIsTrueWhenAddedToParentColumnWithVisibleTrue() { 292 TreeTableColumn child = new TreeTableColumn(); 293 column.setVisible(true); 294 column.getColumns().add(child); 295 assertTrue(child.isVisible()); 296 assertTrue(child.visibleProperty().get()); 297 } 298 299 @Test public void visibleIsNotChangedWhenAddedToParentColumnWithVisibleFalse() { 300 TreeTableColumn child = new TreeTableColumn(); 301 child.setVisible(true); 302 column.setVisible(false); 303 column.getColumns().add(child); 304 assertTrue(child.isVisible()); 305 assertFalse(column.isVisible()); 306 } 307 308 @Test public void visibleIsNotChangedWhenRemovedFromParentColumn() { 309 TreeTableColumn child = new TreeTableColumn(); 310 column.getColumns().add(child); 311 column.setVisible(false); 312 column.getColumns().clear(); 313 assertFalse(child.isVisible()); 314 assertFalse(child.visibleProperty().get()); 315 } 316 317 @Test public void childVisibleChangesAccordingToParentVisibleWhenParentVisibleIsBound() { 318 TreeTableColumn<Person,String> child = new TreeTableColumn<Person,String>(); 319 column.getColumns().add(child); 320 BooleanProperty other = new SimpleBooleanProperty(false); 321 column.visibleProperty().bind(other); 322 assertFalse(child.isVisible()); 323 assertFalse(child.visibleProperty().get()); 324 other.set(true); 325 assertTrue(child.isVisible()); 326 assertTrue(child.visibleProperty().get()); 327 } 328 329 /********************************************************************* 330 * Tests for the contextMenu property * 331 ********************************************************************/ 332 333 @Test public void contextMenuIsNullByDefault() { 334 assertNull(column.getContextMenu()); 335 assertNull(column.contextMenuProperty().get()); 336 } 337 338 @Test public void contextMenuCanBeSpecified() { 339 ContextMenu ctx = new ContextMenu(); 340 column.setContextMenu(ctx); 341 assertSame(ctx, column.getContextMenu()); 342 assertSame(ctx, column.contextMenuProperty().get()); 343 } 344 345 @Test public void contextMenuCanBeSetBackToNull() { 346 ContextMenu ctx = new ContextMenu(); 347 column.setContextMenu(ctx); 348 column.setContextMenu(null); 349 assertNull(column.getContextMenu()); 350 assertNull(column.contextMenuProperty().get()); 351 } 352 353 @Test public void contextMenuPropertyBeanIsCorrect() { 354 assertSame(column, column.contextMenuProperty().getBean()); 355 } 356 357 @Test public void contextMenuPropertyNameIsCorrect() { 358 assertEquals("contextMenu", column.contextMenuProperty().getName()); 359 } 360 361 @Test public void contextMenuCanBeBound() { 362 ContextMenu ctx = new ContextMenu(); 363 ObjectProperty<ContextMenu> other = new SimpleObjectProperty<ContextMenu>(ctx); 364 column.contextMenuProperty().bind(other); 365 assertSame(ctx, column.getContextMenu()); 366 assertSame(ctx, column.contextMenuProperty().get()); 367 other.set(null); 368 assertNull(column.getContextMenu()); 369 assertNull(column.contextMenuProperty().get()); 370 } 371 372 /********************************************************************* 373 * Tests for the cellValueFactory property * 374 ********************************************************************/ 375 376 @Test public void cellValueFactoryIsNullByDefault() { 377 assertNull(column.getCellValueFactory()); 378 assertNull(column.cellValueFactoryProperty().get()); 379 } 380 381 @Test public void cellValueFactoryCanBeSpecified() { 382 CellValueFactory<Person,String> factory = param -> param.getValue().getValue().firstNameProperty(); 383 384 column.setCellValueFactory(factory); 385 assertSame(factory, column.getCellValueFactory()); 386 assertSame(factory, column.cellValueFactoryProperty().get()); 387 } 388 389 @Test public void cellValueFactoryCanBeResetToNull() { 390 CellValueFactory<Person,String> factory = param -> param.getValue().getValue().firstNameProperty(); 391 392 column.setCellValueFactory(factory); 393 column.setCellValueFactory(null); 394 assertNull(column.getCellValueFactory()); 395 assertNull(column.cellValueFactoryProperty().get()); 396 } 397 398 @Test public void cellValueFactoryPropertyBeanIsCorrect() { 399 assertSame(column, column.cellValueFactoryProperty().getBean()); 400 } 401 402 @Test public void cellValueFactoryPropertyNameIsCorrect() { 403 assertEquals("cellValueFactory", column.cellValueFactoryProperty().getName()); 404 } 405 406 @Test public void cellValueFactoryCanBeBound() { 407 CellValueFactory<Person,String> factory = param -> param.getValue().getValue().firstNameProperty(); 408 ObjectProperty<CellValueFactory<Person,String>> other = 409 new SimpleObjectProperty<CellValueFactory<Person, String>>(factory); 410 column.cellValueFactoryProperty().bind(other); 411 assertSame(factory, column.getCellValueFactory()); 412 assertSame(factory, column.cellValueFactoryProperty().get()); 413 other.set(null); 414 assertNull(column.getCellValueFactory()); 415 assertNull(column.cellValueFactoryProperty().get()); 416 } 417 418 /********************************************************************* 419 * Tests for the cellFactory property * 420 ********************************************************************/ 421 422 @Test public void cellFactoryCanBeSpecified() { 423 CellFactory<Person,String> factory = param -> null; 424 column.setCellFactory(factory); 425 assertSame(factory, column.getCellFactory()); 426 assertSame(factory, column.cellFactoryProperty().get()); 427 } 428 429 @Test public void cellFactoryCanBeResetToNull() { 430 CellFactory<Person,String> factory = param -> null; 431 column.setCellFactory(factory); 432 column.setCellFactory(null); 433 assertNull(column.getCellFactory()); 434 assertNull(column.cellFactoryProperty().get()); 435 } 436 437 @Test public void cellFactoryPropertyBeanIsCorrect() { 438 assertSame(column, column.cellFactoryProperty().getBean()); 439 } 440 441 @Test public void cellFactoryPropertyNameIsCorrect() { 442 assertEquals("cellFactory", column.cellFactoryProperty().getName()); 443 } 444 445 @Test public void cellFactoryCanBeBound() { 446 CellFactory<Person,String> factory = param -> null; 447 ObjectProperty<CellFactory<Person,String>> other = 448 new SimpleObjectProperty<CellFactory<Person, String>>(factory); 449 column.cellFactoryProperty().bind(other); 450 assertSame(factory, column.getCellFactory()); 451 assertSame(factory, column.cellFactoryProperty().get()); 452 other.set(null); 453 assertNull(column.getCellFactory()); 454 assertNull(column.cellFactoryProperty().get()); 455 } 456 457 /**************************************************************************** 458 * minWidth Tests * 459 ***************************************************************************/ 460 461 @Ignore ("Fails with hardcoded value of 10") 462 @Test public void minWidthIs_USE_COMPUTED_SIZE_ByDefault() { 463 assertEquals(Control.USE_COMPUTED_SIZE, column.getMinWidth(), 0); 464 assertEquals(Control.USE_COMPUTED_SIZE, column.minWidthProperty().get(), 0); 465 } 466 467 @Test public void minWidthCanBeSet() { 468 column.setMinWidth(234); 469 assertEquals(234, column.getMinWidth(), 0); 470 assertEquals(234, column.minWidthProperty().get(), 0); 471 } 472 473 @Test public void minWidthCanBeBound() { 474 DoubleProperty other = new SimpleDoubleProperty(939); 475 column.minWidthProperty().bind(other); 476 assertEquals(939, column.getMinWidth(), 0); 477 other.set(332); 478 assertEquals(332, column.getMinWidth(), 0); 479 } 480 481 @Test public void minWidthPropertyHasBeanReference() { 482 assertSame(column, column.minWidthProperty().getBean()); 483 } 484 485 @Test public void minWidthPropertyHasName() { 486 assertEquals("minWidth", column.minWidthProperty().getName()); 487 } 488 489 /**************************************************************************** 490 * maxWidth Tests * 491 ***************************************************************************/ 492 493 @Ignore ("Fails with hardcoded value of 5000") 494 @Test public void maxWidthIs_USE_COMPUTED_SIZE_ByDefault() { 495 assertEquals(Control.USE_COMPUTED_SIZE, column.getMaxWidth(), 0); 496 assertEquals(Control.USE_COMPUTED_SIZE, column.maxWidthProperty().get(), 0); 497 } 498 499 @Test public void maxWidthCanBeSet() { 500 column.setMaxWidth(500); 501 assertEquals(500, column.getMaxWidth(), 0); 502 assertEquals(500, column.maxWidthProperty().get(), 0); 503 } 504 505 @Test public void maxWidthCanBeBound() { 506 DoubleProperty other = new SimpleDoubleProperty(939); 507 column.maxWidthProperty().bind(other); 508 assertEquals(939, column.getMaxWidth(), 0); 509 other.set(332); 510 assertEquals(332, column.getMaxWidth(), 0); 511 } 512 513 @Test public void maxWidthPropertyHasBeanReference() { 514 assertSame(column, column.maxWidthProperty().getBean()); 515 } 516 517 @Test public void maxWidthPropertyHasName() { 518 assertEquals("maxWidth", column.maxWidthProperty().getName()); 519 } 520 521 /**************************************************************************** 522 * prefWidth Tests * 523 ***************************************************************************/ 524 525 @Ignore ("Fails with hardcoded value of 80") 526 @Test public void prefWidthIs_USE_COMPUTED_SIZE_ByDefault() { 527 assertEquals(Control.USE_COMPUTED_SIZE, column.getPrefWidth(), 0); 528 assertEquals(Control.USE_COMPUTED_SIZE, column.prefWidthProperty().get(), 0); 529 } 530 531 @Test public void prefWidthCanBeSet() { 532 column.setPrefWidth(80); 533 assertEquals(80, column.getPrefWidth(), 0); 534 assertEquals(80, column.prefWidthProperty().get(), 0); 535 } 536 537 @Test public void prefWidthCanBeBound() { 538 DoubleProperty other = new SimpleDoubleProperty(939); 539 column.prefWidthProperty().bind(other); 540 assertEquals(939, column.getPrefWidth(), 0); 541 other.set(332); 542 assertEquals(332, column.getPrefWidth(), 0); 543 } 544 545 @Test public void prefWidthPropertyHasBeanReference() { 546 assertSame(column, column.prefWidthProperty().getBean()); 547 } 548 549 @Test public void prefWidthPropertyHasName() { 550 assertEquals("prefWidth", column.prefWidthProperty().getName()); 551 } 552 553 /********************************************************************* 554 * Tests for the resizable property * 555 ********************************************************************/ 556 557 @Test public void resizableIsTrueByDefault() { 558 assertTrue(column.isResizable()); 559 assertTrue(column.resizableProperty().get()); 560 } 561 562 @Test public void resizableCanBeSpecified() { 563 column.setResizable(false); 564 assertFalse(column.isResizable()); 565 assertFalse(column.resizableProperty().get()); 566 } 567 568 @Test public void resizablePropertyBeanIsCorrect() { 569 assertSame(column, column.resizableProperty().getBean()); 570 } 571 572 @Test public void resizablePropertyNameIsCorrect() { 573 assertEquals("resizable", column.resizableProperty().getName()); 574 } 575 576 @Test public void resizableCanBeBound() { 577 BooleanProperty other = new SimpleBooleanProperty(false); 578 column.resizableProperty().bind(other); 579 assertFalse(column.isResizable()); 580 assertFalse(column.resizableProperty().get()); 581 other.set(true); 582 assertTrue(column.isResizable()); 583 assertTrue(column.resizableProperty().get()); 584 } 585 586 /********************************************************************* 587 * Tests for the sortable property * 588 ********************************************************************/ 589 590 @Test public void sortableIsTrueByDefault() { 591 assertTrue(column.isSortable()); 592 assertTrue(column.sortableProperty().get()); 593 } 594 595 @Test public void sortableCanBeSpecified() { 596 column.setSortable(false); 597 assertFalse(column.isSortable()); 598 assertFalse(column.sortableProperty().get()); 599 } 600 601 @Test public void sortablePropertyBeanIsCorrect() { 602 assertSame(column, column.sortableProperty().getBean()); 603 } 604 605 @Test public void sortablePropertyNameIsCorrect() { 606 assertEquals("sortable", column.sortableProperty().getName()); 607 } 608 609 @Test public void sortableCanBeBound() { 610 BooleanProperty other = new SimpleBooleanProperty(false); 611 column.sortableProperty().bind(other); 612 assertFalse(column.isSortable()); 613 assertFalse(column.sortableProperty().get()); 614 other.set(true); 615 assertTrue(column.isSortable()); 616 assertTrue(column.sortableProperty().get()); 617 } 618 619 /********************************************************************* 620 * Tests for the sortType property * 621 ********************************************************************/ 622 623 @Test public void sortTypeIsASCENDINGByDefault() { 624 assertSame(TreeTableColumn.SortType.ASCENDING, column.getSortType()); 625 assertSame(TreeTableColumn.SortType.ASCENDING, column.sortTypeProperty().get()); 626 } 627 628 @Test public void sortTypeCanBeSpecified() { 629 column.setSortType(TreeTableColumn.SortType.DESCENDING); 630 assertSame(TreeTableColumn.SortType.DESCENDING, column.getSortType()); 631 assertSame(TreeTableColumn.SortType.DESCENDING, column.sortTypeProperty().get()); 632 } 633 634 @Test public void sortTypeCanBeNull() { 635 column.setSortType(null); 636 assertNull(column.getSortType()); 637 assertNull(column.sortTypeProperty().get()); 638 } 639 640 @Test public void sortTypePropertyBeanIsCorrect() { 641 assertSame(column, column.sortTypeProperty().getBean()); 642 } 643 644 @Test public void sortTypePropertyNameIsCorrect() { 645 assertEquals("sortType", column.sortTypeProperty().getName()); 646 } 647 648 @Test public void sortTypeCanBeBound() { 649 ObjectProperty<TreeTableColumn.SortType> other = 650 new SimpleObjectProperty<TreeTableColumn.SortType>(TreeTableColumn.SortType.DESCENDING); 651 column.sortTypeProperty().bind(other); 652 assertSame(TreeTableColumn.SortType.DESCENDING, column.getSortType()); 653 assertSame(TreeTableColumn.SortType.DESCENDING, column.sortTypeProperty().get()); 654 other.set(null); 655 assertNull(column.getSortType()); 656 assertNull(column.sortTypeProperty().get()); 657 } 658 659 /********************************************************************* 660 * Tests for the editable property * 661 ********************************************************************/ 662 663 @Test public void editableIsTrueByDefault() { 664 assertTrue(column.isEditable()); 665 assertTrue(column.editableProperty().get()); 666 } 667 668 @Test public void editableCanBeSpecified() { 669 column.setEditable(false); 670 assertFalse(column.isEditable()); 671 assertFalse(column.editableProperty().get()); 672 } 673 674 @Test public void editablePropertyBeanIsCorrect() { 675 assertSame(column, column.editableProperty().getBean()); 676 } 677 678 @Test public void editablePropertyNameIsCorrect() { 679 assertEquals("editable", column.editableProperty().getName()); 680 } 681 682 @Test public void editableCanBeBound() { 683 BooleanProperty other = new SimpleBooleanProperty(false); 684 column.editableProperty().bind(other); 685 assertFalse(column.isEditable()); 686 assertFalse(column.editableProperty().get()); 687 other.set(true); 688 assertTrue(column.isEditable()); 689 assertTrue(column.editableProperty().get()); 690 } 691 692 /********************************************************************* 693 * Tests for the reorderable property * 694 ********************************************************************/ 695 696 @Test public void reorderableIsTrueByDefault() { 697 assertTrue(column.impl_isReorderable()); 698 assertTrue(column.impl_reorderableProperty().get()); 699 } 700 701 @Test public void reorderableCanBeSpecified() { 702 column.impl_setReorderable(false); 703 assertFalse(column.impl_isReorderable()); 704 assertFalse(column.impl_reorderableProperty().get()); 705 } 706 707 @Test public void reorderablePropertyBeanIsCorrect() { 708 assertSame(column, column.impl_reorderableProperty().getBean()); 709 } 710 711 @Test public void reorderablePropertyNameIsCorrect() { 712 assertEquals("reorderable", column.impl_reorderableProperty().getName()); 713 } 714 715 @Test public void reorderableCanBeBound() { 716 BooleanProperty other = new SimpleBooleanProperty(false); 717 column.impl_reorderableProperty().bind(other); 718 assertFalse(column.impl_isReorderable()); 719 assertFalse(column.impl_reorderableProperty().get()); 720 other.set(true); 721 assertTrue(column.impl_isReorderable()); 722 assertTrue(column.impl_reorderableProperty().get()); 723 } 724 725 /********************************************************************* 726 * Tests for the comparator property * 727 ********************************************************************/ 728 729 @Test public void comparatorCanBeSpecified() { 730 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 731 column.setComparator(comparator); 732 assertSame(comparator, column.getComparator()); 733 assertSame(comparator, column.comparatorProperty().get()); 734 } 735 736 @Test public void comparatorCanBeResetToNull() { 737 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 738 column.setComparator(comparator); 739 column.setComparator(null); 740 assertNull(column.getComparator()); 741 assertNull(column.comparatorProperty().get()); 742 } 743 744 @Test public void comparatorPropertyBeanIsCorrect() { 745 assertSame(column, column.comparatorProperty().getBean()); 746 } 747 748 @Test public void comparatorPropertyNameIsCorrect() { 749 assertEquals("comparator", column.comparatorProperty().getName()); 750 } 751 752 @Test public void comparatorCanBeBound() { 753 Comparator<String> comparator = (o1, o2) -> o1.compareTo(o2); 754 ObjectProperty<Comparator<String>> other = 755 new SimpleObjectProperty<Comparator<String>>(comparator); 756 column.comparatorProperty().bind(other); 757 assertSame(comparator, column.getComparator()); 758 assertSame(comparator, column.comparatorProperty().get()); 759 other.set(null); 760 assertNull(column.getComparator()); 761 assertNull(column.comparatorProperty().get()); 762 } 763 764 /********************************************************************* 765 * Tests for the onEditStart property * 766 ********************************************************************/ 767 768 @Test public void onEditStartIsNullByDefault() { 769 assertNull(column.getOnEditStart()); 770 assertNull(column.onEditStartProperty().get()); 771 } 772 773 @Test public void onEditStartCanBeSpecified() { 774 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 775 event -> { 776 }; 777 column.setOnEditStart(handler); 778 assertSame(handler, column.getOnEditStart()); 779 assertSame(handler, column.onEditStartProperty().get()); 780 } 781 782 @Test public void onEditStartCanBeResetToNull() { 783 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 784 event -> { 785 }; 786 column.setOnEditStart(handler); 787 column.setOnEditStart(null); 788 assertNull(column.getOnEditStart()); 789 assertNull(column.onEditStartProperty().get()); 790 } 791 792 @Test public void onEditStartPropertyBeanIsCorrect() { 793 assertSame(column, column.onEditStartProperty().getBean()); 794 } 795 796 @Test public void onEditStartPropertyNameIsCorrect() { 797 assertEquals("onEditStart", column.onEditStartProperty().getName()); 798 } 799 800 @Test public void onEditStartCanBeBound() { 801 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 802 event -> { 803 }; 804 ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person,String>>> other = 805 new SimpleObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person, String>>>(handler); 806 column.onEditStartProperty().bind(other); 807 assertSame(handler, column.getOnEditStart()); 808 assertSame(handler, column.onEditStartProperty().get()); 809 other.set(null); 810 assertNull(column.getOnEditStart()); 811 assertNull(column.onEditStartProperty().get()); 812 } 813 814 /********************************************************************* 815 * Tests for the onEditCancel property * 816 ********************************************************************/ 817 818 @Test public void onEditCancelIsNullByDefault() { 819 assertNull(column.getOnEditCancel()); 820 assertNull(column.onEditCancelProperty().get()); 821 } 822 823 @Test public void onEditCancelCanBeSpecified() { 824 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 825 event -> { 826 }; 827 column.setOnEditCancel(handler); 828 assertSame(handler, column.getOnEditCancel()); 829 assertSame(handler, column.onEditCancelProperty().get()); 830 } 831 832 @Test public void onEditCancelCanBeResetToNull() { 833 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 834 event -> { 835 }; 836 column.setOnEditCancel(handler); 837 column.setOnEditCancel(null); 838 assertNull(column.getOnEditCancel()); 839 assertNull(column.onEditCancelProperty().get()); 840 } 841 842 @Test public void onEditCancelPropertyBeanIsCorrect() { 843 assertSame(column, column.onEditCancelProperty().getBean()); 844 } 845 846 @Test public void onEditCancelPropertyNameIsCorrect() { 847 assertEquals("onEditCancel", column.onEditCancelProperty().getName()); 848 } 849 850 @Test public void onEditCancelCanBeBound() { 851 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 852 event -> { 853 }; 854 ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person,String>>> other = 855 new SimpleObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person, String>>>(handler); 856 column.onEditCancelProperty().bind(other); 857 assertSame(handler, column.getOnEditCancel()); 858 assertSame(handler, column.onEditCancelProperty().get()); 859 other.set(null); 860 assertNull(column.getOnEditCancel()); 861 assertNull(column.onEditCancelProperty().get()); 862 } 863 864 /********************************************************************* 865 * Tests for the onEditCommit property * 866 ********************************************************************/ 867 868 // @Test public void onEditCommitIsNullByDefault() { 869 // assertNull(column.getOnEditCommit()); 870 // assertNull(column.onEditCommitProperty().get()); 871 // } 872 873 @Test public void onEditCommitCanBeSpecified() { 874 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 875 event -> { 876 }; 877 column.setOnEditCommit(handler); 878 assertSame(handler, column.getOnEditCommit()); 879 assertSame(handler, column.onEditCommitProperty().get()); 880 } 881 882 @Test public void onEditCommitCanBeResetToNull() { 883 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 884 event -> { 885 }; 886 column.setOnEditCommit(handler); 887 column.setOnEditCommit(null); 888 assertNull(column.getOnEditCommit()); 889 assertNull(column.onEditCommitProperty().get()); 890 } 891 892 @Test public void onEditCommitPropertyBeanIsCorrect() { 893 assertSame(column, column.onEditCommitProperty().getBean()); 894 } 895 896 @Test public void onEditCommitPropertyNameIsCorrect() { 897 assertEquals("onEditCommit", column.onEditCommitProperty().getName()); 898 } 899 900 @Test public void onEditCommitCanBeBound() { 901 EventHandler<TreeTableColumn.CellEditEvent<Person,String>> handler = 902 event -> { 903 }; 904 ObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person,String>>> other = 905 new SimpleObjectProperty<EventHandler<TreeTableColumn.CellEditEvent<Person, String>>>(handler); 906 column.onEditCommitProperty().bind(other); 907 assertSame(handler, column.getOnEditCommit()); 908 assertSame(handler, column.onEditCommitProperty().get()); 909 other.set(null); 910 assertNull(column.getOnEditCommit()); 911 assertNull(column.onEditCommitProperty().get()); 912 } 913 914 /********************************************************************* 915 * Tests for getCellData * 916 ********************************************************************/ 917 918 @Test public void getCellDataReturnsNullWhenTableViewIsNull() { 919 assertNull(column.getCellData(0)); 920 } 921 922 // @Test public void getCellDataReturnsNullWhenTableViewIsNull2() { 923 // assertNull(column.getCellData(table.getItems().get(1))); 924 // } 925 // 926 // @Test public void getCellDataReturnsNullWhenTableViewItemsIsNull() { 927 // table.getColumns().add(column); 928 // table.setItems(null); 929 // assertNull(column.getCellData(0)); 930 // } 931 // 932 // @Test public void getCellDataReturnsNullWhenTableViewItemsIsNull2() { 933 // final Person person = table.getItems().get(1); 934 // table.getColumns().add(column); 935 // table.setItems(null); 936 // assertNull(column.getCellData(person)); 937 // } 938 // 939 // @Test public void getCellDataReturnsNullWhenRowDataIsNullByDefault() { 940 // table.getColumns().add(column); 941 // table.getItems().set(0, null); 942 // assertNull(column.getCellData(0)); 943 // } 944 945 @Test public void getCellDataReturnsNullWhenRowDataIsNullByDefault2() { 946 table.getColumns().add(column); 947 assertNull(column.getCellData(null)); 948 } 949 950 @Test public void getCellDataReturnsNullWhenIndexIsNegative() { 951 table.getColumns().add(column); 952 assertNull(column.getCellData(-1)); 953 } 954 955 // @Test public void getCellDataReturnsNullWhenIndexIsTooLarge() { 956 // table.getColumns().add(column); 957 // assertNull(column.getCellData(table.getItems().size())); 958 // } 959 960 @Test public void getCellDataReturnsNullWhenCellValueFactoryIsNull() { 961 table.getColumns().add(column); 962 assertNull(column.getCellData(0)); 963 } 964 965 // @Test public void getCellDataReturnsNullWhenCellValueFactoryIsNull2() { 966 // table.getColumns().add(column); 967 // assertNull(column.getCellData(table.getItems().get(1))); 968 // } 969 970 @Test public void getCellDataReturnsValue() { 971 table.getColumns().add(column); 972 column.setCellValueFactory(param -> param.getValue().getValue().firstNameProperty()); 973 assertEquals("Humphrey McPhee", column.getCellData(1)); 974 } 975 976 // @Test public void getCellDataReturnsValue2() { 977 // table.getColumns().add(column); 978 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 979 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 980 // return param.getValue().getValue().firstNameProperty(); 981 // } 982 // }); 983 // assertEquals("Humphrey McPhee", column.getCellData(table.getItems().get(0))); 984 // } 985 // 986 // @Test public void cellDataFeaturesHasTableViewSpecified() { 987 // final boolean[] passed = new boolean[] { false }; 988 // table.getColumns().add(column); 989 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 990 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 991 // passed[0] = param.getTreeTableView() == table; 992 // return param.getValue().getValue().firstNameProperty(); 993 // } 994 // }); 995 // column.getCellData(table.getItems().get(0)); 996 // assertTrue(passed[0]); 997 // } 998 // 999 // @Test public void cellDataFeaturesHasTreeTableColumnSpecified() { 1000 // final boolean[] passed = new boolean[] { false }; 1001 // table.getColumns().add(column); 1002 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 1003 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 1004 // passed[0] = param.getTreeTableColumn() == column; 1005 // return param.getValue().getValue().firstNameProperty(); 1006 // } 1007 // }); 1008 // column.getCellData(table.getItems().get(0)); 1009 // assertTrue(passed[0]); 1010 // } 1011 // 1012 // @Test public void cellDataFeaturesHasRowItemSpecified() { 1013 // final boolean[] passed = new boolean[] { false }; 1014 // table.getColumns().add(column); 1015 // column.setCellValueFactory(new CellValueFactory<Person,String>() { 1016 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 1017 // passed[0] = param.getValue() == table.getItems().get(0); 1018 // return param.getValue().firstNameProperty(); 1019 // } 1020 // }); 1021 // column.getCellData(table.getItems().get(0)); 1022 // assertTrue(passed[0]); 1023 // } 1024 1025 /********************************************************************* 1026 * Tests for the DEFAULT_EDIT_COMMIT_HANDLER. By default each * 1027 * TreeTableColumn has a DEFAULT_EDIT_COMMIT_HANDLER installed which * 1028 * will, if the value returned by cellValueFactory is a * 1029 * WritableValue, commit. If not, then nothing happens. * 1030 ********************************************************************/ 1031 1032 @Test public void onEditCommitHandlerInstalledByDefault() { 1033 assertNotNull(column.getOnEditCommit()); 1034 } 1035 1036 // @Test public void defaultOnEditCommitHandlerWillSaveToWritableValue() { 1037 // table.getColumns().add(column); 1038 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 1039 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 1040 // return param.getValue().getValue().firstNameProperty(); 1041 // } 1042 // }); 1043 // TreeTablePosition<Person,String> pos = new TreeTablePosition<Person, String>(table, 0, column); 1044 // EventType<TreeTableColumn.CellEditEvent<Person,String>> eventType = TreeTableColumn.editCommitEvent(); 1045 // column.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person,String>( 1046 // table, pos, (EventType)eventType, "Richard Bair")); 1047 // assertEquals("Richard Bair", table.getItems().get(0).getName()); 1048 // } 1049 // 1050 // @Test public void defaultOnEditCommitHandlerWillIgnoreReadOnlyValue() { 1051 // TreeTableColumn<Person,Number> ageColumn = new TreeTableColumn<Person,Number>(); 1052 // table.getColumns().add(ageColumn); 1053 // ageColumn.setCellValueFactory(new CellValueFactory<Person, Number>() { 1054 // @Override public ObservableValue<Number> call(TreeTableColumn.CellDataFeatures<Person, Number> param) { 1055 // return param.getValue().getValue().ageProperty(); 1056 // } 1057 // }); 1058 // TreeTablePosition<Person,Number> pos = new TreeTablePosition<Person, Number>(table, 0, ageColumn); 1059 // EventType<TreeTableColumn.CellEditEvent<Person,Number>> eventType = TreeTableColumn.editCommitEvent(); 1060 // ageColumn.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person,Number>( 1061 // table, pos, (EventType)eventType, 109)); 1062 // assertEquals(76, table.getItems().get(0).getAge()); 1063 // } 1064 1065 @Test(expected=NullPointerException.class) 1066 public void defaultOnEditCommitHandlerDealsWithNullTableView() { 1067 table.getColumns().add(column); 1068 column.setCellValueFactory(param -> param.getValue().getValue().firstNameProperty()); 1069 TreeTablePosition<Person,String> pos = new TreeTablePosition<Person, String>(table, 0, column); 1070 EventType<TreeTableColumn.CellEditEvent<Person,String>> eventType = TreeTableColumn.editCommitEvent(); 1071 column.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person, String>( 1072 null, pos, (EventType) eventType, "Richard Bair")); 1073 } 1074 1075 @Test(expected=NullPointerException.class) 1076 public void defaultOnEditCommitHandlerDealsWithNullTablePosition() { 1077 table.getColumns().add(column); 1078 column.setCellValueFactory(param -> param.getValue().getValue().firstNameProperty()); 1079 TreeTablePosition<Person,String> pos = new TreeTablePosition<Person, String>(table, 0, column); 1080 EventType<TreeTableColumn.CellEditEvent<Person,String>> eventType = TreeTableColumn.editCommitEvent(); 1081 column.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person, String>( 1082 table, null, (EventType) eventType, "Richard Bair")); 1083 } 1084 // 1085 // @Test public void defaultOnEditCommitHandlerDealsWithInvalidTablePosition_indexIsNegative() { 1086 // table.getColumns().add(column); 1087 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 1088 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 1089 // return param.getValue().getValue().firstNameProperty(); 1090 // } 1091 // }); 1092 // TreeTablePosition<Person,String> pos = new TreeTablePosition<Person, String>(table, -1, column); 1093 // EventType<TreeTableColumn.CellEditEvent<Person,String>> eventType = TreeTableColumn.editCommitEvent(); 1094 // column.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person,String>( 1095 // table, pos, (EventType)eventType, "Richard Bair")); 1096 // assertEquals("Humphrey McPhee", table.getItems().get(0).getName()); 1097 // } 1098 // 1099 // @Test public void defaultOnEditCommitHandlerDealsWithInvalidTablePosition_indexIsTooLarge() { 1100 // table.getColumns().add(column); 1101 // column.setCellValueFactory(new CellValueFactory<Person, String>() { 1102 // @Override public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<Person, String> param) { 1103 // return param.getValue().getValue().firstNameProperty(); 1104 // } 1105 // }); 1106 // TreeTablePosition<Person,String> pos = new TreeTablePosition<Person, String>(table, 100, column); 1107 // EventType<TreeTableColumn.CellEditEvent<Person,String>> eventType = TreeTableColumn.editCommitEvent(); 1108 // column.getOnEditCommit().handle(new TreeTableColumn.CellEditEvent<Person, String>( 1109 // table, pos, (EventType) eventType, "Richard Bair")); 1110 // assertEquals("Humphrey McPhee", table.getItems().get(0).getName()); 1111 // } 1112 1113 /********************************************************************* 1114 * Tests for the default comparator * 1115 ********************************************************************/ 1116 1117 @Test public void sortingWithNullItems() { 1118 List<String> items = Arrays.asList("Hippo", null, "Fish", "Eagle", null); 1119 Collections.sort(items, TreeTableColumn.DEFAULT_COMPARATOR); 1120 assertNull(items.get(0)); 1121 assertNull(items.get(1)); 1122 assertEquals("Eagle", items.get(2)); 1123 assertEquals("Fish", items.get(3)); 1124 assertEquals("Hippo", items.get(4)); 1125 } 1126 1127 @Test public void sortingWithSameItems() { 1128 List<String> items = Arrays.asList("Hippo", "Hippo", "Fish", "Eagle", "Fish"); 1129 Collections.sort(items, TreeTableColumn.DEFAULT_COMPARATOR); 1130 assertEquals("Eagle", items.get(0)); 1131 assertEquals("Fish", items.get(1)); 1132 assertEquals("Fish", items.get(2)); 1133 assertEquals("Hippo", items.get(3)); 1134 assertEquals("Hippo", items.get(4)); 1135 } 1136 1137 @Test public void sortingWithNonComparableItemsSortsByToString() { 1138 Person fred = new Person("Fred", 36); 1139 Person wilma = new Person("Wilma", 34); 1140 Person barney = new Person("Barney", 34); 1141 List<Person> items = Arrays.asList(fred, wilma, barney); 1142 Collections.sort(items, TreeTableColumn.DEFAULT_COMPARATOR); 1143 assertSame(barney, items.get(0)); 1144 assertSame(fred, items.get(1)); 1145 assertSame(wilma, items.get(2)); 1146 } 1147 1148 @Ignore("This started failing when I upgraded to Java 7") 1149 @Test public void sortingMixOfComparableAndNonComparable() { 1150 Person fred = new Person("Fred", 36); 1151 Person wilma = new Person("Wilma", 34); 1152 Person barney = new Person("Barney", 34); 1153 List<Object> items = Arrays.asList(fred, wilma, barney, "Pebbles"); 1154 Collections.sort(items, TreeTableColumn.DEFAULT_COMPARATOR); 1155 assertSame(barney, items.get(0)); 1156 assertSame(fred, items.get(1)); 1157 assertEquals("Pebbles", items.get(2)); 1158 assertSame(wilma, items.get(3)); 1159 } 1160 1161 /********************************************************************* 1162 * Tests for the default cell factory * 1163 ********************************************************************/ 1164 1165 @Test public void defaultCellFactoryHasNullTextByDefault() { 1166 table.getColumns().add(column); 1167 TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1168 assertNull(cell.getText()); 1169 } 1170 1171 @Test public void defaultCellFactoryHasNullGraphicByDefault() { 1172 table.getColumns().add(column); 1173 TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1174 assertNull(cell.getGraphic()); 1175 } 1176 1177 // @Test public void defaultCellFactorySetsTextToNameWhenItemIsPerson() { 1178 // table.getColumns().add(column); 1179 // TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1180 // cell.updateIndex(0); 1181 // cell.updateItem(table.getItems().get(0).getName(), false); 1182 // assertEquals(table.getItems().get(0).getName(), cell.getText()); 1183 // } 1184 // 1185 // @Test public void defaultCellFactorySetsTextToNullWhenItemIsNull() { 1186 // table.getColumns().add(column); 1187 // TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1188 // // First have to set to a value, or it short-cuts 1189 // cell.updateIndex(0); 1190 // cell.updateItem(table.getItems().get(0).getName(), false); 1191 // // Now we're good to go 1192 // table.getItems().set(0, null); 1193 // cell.updateItem(null, false); 1194 // assertNull(cell.getText()); 1195 // } 1196 // 1197 // @Test public void defaultCellFactorySetsGraphicToNullWhenItemIsPerson() { 1198 // table.getColumns().add(column); 1199 // TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1200 // cell.updateIndex(0); 1201 // cell.updateItem(table.getItems().get(0).getName(), false); 1202 // assertNull(cell.getGraphic()); 1203 // } 1204 // 1205 // @Test public void defaultCellFactorySetsGraphicToNullWhenItemIsNull() { 1206 // table.getColumns().add(column); 1207 // TreeTableCell<Person,String> cell = column.getCellFactory().call(column); 1208 // table.getItems().set(0, null); 1209 // cell.updateIndex(0); 1210 // cell.updateItem(null, false); 1211 // assertNull(cell.getGraphic()); 1212 // } 1213 1214 @Test public void defaultCellFactorySetsGraphicToItemWhenItemIsNode() { 1215 TreeTableView<Node> nodeTable = new TreeTableView<Node>(); 1216 Rectangle rect = new Rectangle(); 1217 nodeTable.setRoot(new TreeItem<Node>(rect)); 1218 TreeTableColumn<Node,Node> nodeColumn = new TreeTableColumn<Node,Node>(); 1219 nodeTable.getColumns().add(nodeColumn); 1220 TreeTableCell<Node,Node> cell = nodeColumn.getCellFactory().call(nodeColumn); 1221 cell.updateIndex(0); 1222 cell.updateItem(rect, false); 1223 assertSame(rect, cell.getGraphic()); 1224 } 1225 1226 @Test public void defaultCellFactorySetsTextToNullWhenItemIsNode() { 1227 TreeTableView<Node> nodeTable = new TreeTableView<Node>(); 1228 Rectangle rect = new Rectangle(); 1229 nodeTable.setRoot(new TreeItem<Node>(rect)); 1230 TreeTableColumn<Node,Node> nodeColumn = new TreeTableColumn<Node,Node>(); 1231 nodeTable.getColumns().add(nodeColumn); 1232 TreeTableCell<Node,Node> cell = nodeColumn.getCellFactory().call(nodeColumn); 1233 cell.updateIndex(0); 1234 cell.updateItem(rect, false); 1235 assertNull(cell.getText()); 1236 } 1237 1238 @Test public void test_rt36715_idIsNullAtStartup() { 1239 assertNull(column.getId()); 1240 } 1241 1242 @Test public void test_rt36715_idIsSettable() { 1243 column.setId("test-id"); 1244 assertEquals("test-id", column.getId()); 1245 } 1246 1247 @Test public void test_rt36715_columnHeaderIdMirrorsTableColumnId_setIdBeforeHeaderInstantiation() { 1248 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(true, true, false, false); 1249 } 1250 1251 @Test public void test_rt36715_columnHeaderIdMirrorsTableColumnId_setIdAfterHeaderInstantiation() { 1252 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(true, false, false, false); 1253 } 1254 1255 @Test public void test_rt36715_styleIsEmptyStringAtStartup() { 1256 assertEquals("", column.getStyle()); 1257 } 1258 1259 @Test public void test_rt36715_styleIsSettable() { 1260 column.setStyle("-fx-border-color: red"); 1261 assertEquals("-fx-border-color: red", column.getStyle()); 1262 } 1263 1264 @Test public void test_rt36715_columnHeaderStyleMirrorsTableColumnStyle_setStyleBeforeHeaderInstantiation() { 1265 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(false, false, true, true); 1266 } 1267 1268 @Test public void test_rt36715_columnHeaderStyleMirrorsTableColumnStyle_setStyleAfterHeaderInstantiation() { 1269 test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties(false, false, true, false); 1270 } 1271 1272 private void test_rt36715_columnHeaderPropertiesMirrorTableColumnProperties( 1273 boolean setId, boolean setIdBeforeHeaderInstantiation, 1274 boolean setStyle, boolean setStyleBeforeHeaderInstantiation) { 1275 table.getColumns().add(column); 1276 1277 if (setId && setIdBeforeHeaderInstantiation) { 1278 column.setId("test-id"); 1279 } 1280 if (setStyle && setStyleBeforeHeaderInstantiation) { 1281 column.setStyle("-fx-border-color: red"); 1282 } 1283 1284 StageLoader sl = new StageLoader(table); 1285 TableColumnHeader header = VirtualFlowTestUtils.getTableColumnHeader(table, column); 1286 1287 if (setId && ! setIdBeforeHeaderInstantiation) { 1288 column.setId("test-id"); 1289 } 1290 if (setStyle && ! setStyleBeforeHeaderInstantiation) { 1291 column.setStyle("-fx-border-color: red"); 1292 } 1293 1294 if (setId) { 1295 assertEquals("test-id", header.getId()); 1296 } 1297 if (setStyle) { 1298 assertEquals("-fx-border-color: red", header.getStyle()); 1299 } 1300 1301 sl.dispose(); 1302 } 1303 1304 1305 1306 1307 public interface CellValueFactory<S,T> extends Callback<TreeTableColumn.CellDataFeatures<S,T>, ObservableValue<T>> { 1308 } 1309 1310 public interface CellFactory<S,T> extends Callback<TreeTableColumn<S,T>, TreeTableCell<S,T>> { 1311 } 1312 }