< prev index next >

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

Print this page
rev 8906 : RT-46083: TimelineClipCore exceptions handling improvent


  23  * questions.
  24  */
  25 
  26 package javafx.scene.control;
  27 
  28 import com.sun.javafx.scene.control.behavior.ListCellBehavior;
  29 import com.sun.javafx.scene.control.behavior.TableCellBehavior;
  30 import javafx.beans.property.ReadOnlyStringWrapper;
  31 import javafx.collections.FXCollections;
  32 import javafx.collections.ListChangeListener;
  33 import javafx.collections.ObservableList;
  34 import javafx.scene.input.KeyCode;
  35 import javafx.scene.layout.HBox;
  36 
  37 import java.util.List;
  38 import java.util.function.Function;
  39 
  40 import com.sun.javafx.PlatformUtil;
  41 import com.sun.javafx.util.Utils;
  42 import com.sun.javafx.scene.control.behavior.TableViewAnchorRetriever;

  43 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
  44 import com.sun.javafx.scene.control.infrastructure.KeyModifier;
  45 import com.sun.javafx.scene.control.infrastructure.StageLoader;
  46 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
  47 import com.sun.javafx.tk.Toolkit;
  48 import org.junit.After;
  49 import org.junit.Before;
  50 import org.junit.Ignore;
  51 import org.junit.Test;
  52 import static org.junit.Assert.assertEquals;
  53 import static org.junit.Assert.assertFalse;
  54 import static org.junit.Assert.assertNotSame;
  55 import static org.junit.Assert.assertNull;
  56 import static org.junit.Assert.assertTrue;
  57 import static org.junit.Assert.fail;
  58 
  59 public class TableViewKeyInputTest {
  60     private TableView<String> tableView;
  61     private TableView.TableViewSelectionModel<String> sm;
  62     private TableView.TableViewFocusModel<String> fm;


3457             // we expect only one selected index change event, from 5 to 4
3458             assertEquals(4, sm.getSelectedIndex());
3459         });
3460 
3461         keyboard.doKeyPress(KeyCode.UP);
3462         assertEquals(4, getAnchor().getRow());
3463         assertTrue(fm.isFocused(4, col));
3464         assertTrue(sm.isSelected(4, col));
3465         assertFalse(sm.isSelected(5, col));
3466     }
3467 
3468     @Test public void test_rt36800_rowSelection() {
3469         test_rt36800(false);
3470     }
3471 
3472     @Test public void test_rt36800_cellSelection() {
3473         test_rt36800(true);
3474     }
3475 
3476     private void test_rt36800(boolean cellSelection) {
3477         // get the current exception handler before replacing with our own,
3478         // as ListListenerHelp intercepts the exception otherwise
3479         final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
3480         Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!"));
3481 
3482         final int items = 10;
3483         tableView.getItems().clear();
3484         for (int i = 0; i < items; i++) {
3485             tableView.getItems().add("Row " + i);
3486         }
3487 
3488         TableColumn<String, String> col = new TableColumn<>("Column");
3489         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3490         tableView.getColumns().setAll(col);
3491 
3492         sm.setSelectionMode(SelectionMode.SINGLE);
3493         sm.setCellSelectionEnabled(cellSelection);
3494 
3495         if (cellSelection) {
3496             sm.clearAndSelect(5, col);
3497             assertEquals(5, getAnchor().getRow());
3498             assertEquals(col, getAnchor().getTableColumn());
3499             assertTrue(fm.isFocused(5, col));
3500             assertTrue(sm.isSelected(5, col));
3501         } else {
3502             sm.clearAndSelect(5);
3503             assertEquals(5, getAnchor().getRow());
3504             assertTrue(fm.isFocused(5));
3505             assertTrue(sm.isSelected(5));
3506         }
3507 
3508         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
3509         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
3510         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
3511         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
3512         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0



3513         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?



3514 
3515         if (cellSelection) {
3516             assertEquals(0, getAnchor().getRow());
3517             assertEquals(col, getAnchor().getTableColumn());
3518             assertTrue(fm.isFocused(0, col));
3519             assertTrue(sm.isSelected(0, col));
3520             assertFalse(sm.isSelected(1, col));
3521             assertFalse(sm.isSelected(2, col));
3522             assertFalse(sm.isSelected(3, col));
3523             assertFalse(sm.isSelected(4, col));
3524             assertFalse(sm.isSelected(5, col));
3525         } else {
3526             assertEquals(0, getAnchor().getRow());
3527             assertTrue(fm.isFocused(0));
3528             assertTrue(sm.isSelected(0));
3529             assertFalse(sm.isSelected(1));
3530             assertFalse(sm.isSelected(2));
3531             assertFalse(sm.isSelected(3));
3532             assertFalse(sm.isSelected(4));
3533             assertFalse(sm.isSelected(5));
3534         }
3535 
3536         // reset the exception handler
3537         Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
3538     }
3539 
3540     @Test public void test_rt_36942() {
3541         // get the current exception handler before replacing with our own,
3542         // as ListListenerHelp intercepts the exception otherwise
3543         final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
3544         Thread.currentThread().setUncaughtExceptionHandler((t, e) -> fail("We don't expect any exceptions in this test!"));
3545 
3546         final int items = 3;
3547         tableView.getItems().clear();
3548         for (int i = 0; i < items; i++) {
3549             tableView.getItems().add("Row " + i);
3550         }
3551 
3552         TableColumn<String, String> col = new TableColumn<>("Column");
3553         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3554         tableView.getColumns().setAll(col);
3555 
3556         MultipleSelectionModel<String> sm = tableView.getSelectionModel();
3557         sm.setSelectionMode(SelectionMode.MULTIPLE);
3558         ObservableList<String> selectedItems = sm.getSelectedItems();
3559 
3560         TableView<String> selectedItemsTableView = new TableView<>(selectedItems);
3561         selectedItemsTableView.getColumns().setAll(col);
3562 
3563         HBox root = new HBox(5, tableView, selectedItemsTableView);
3564 
3565         StageLoader sl = new StageLoader(root);
3566 
3567         sm.select(0);
3568         keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1
3569         keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2



3570         keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception?



3571 
3572         sl.dispose();
3573 
3574         // reset the exception handler
3575         Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
3576     }
3577 
3578     @Test public void test_rt_37130_pageUpAtTop() {
3579         final int items = 100;
3580         tableView.getItems().clear();
3581         for (int i = 0; i < items; i++) {
3582             tableView.getItems().add("Row " + i);
3583         }
3584 
3585         TableColumn<String, String> col = new TableColumn<>("Column");
3586         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3587         tableView.getColumns().setAll(col);
3588 
3589         TableSelectionModel<String> sm = tableView.getSelectionModel();
3590         sm.setSelectionMode(SelectionMode.MULTIPLE);
3591         sm.setCellSelectionEnabled(true);
3592 
3593         StageLoader sl = new StageLoader(tableView);
3594 
3595         sm.select(5, col);




  23  * questions.
  24  */
  25 
  26 package javafx.scene.control;
  27 
  28 import com.sun.javafx.scene.control.behavior.ListCellBehavior;
  29 import com.sun.javafx.scene.control.behavior.TableCellBehavior;
  30 import javafx.beans.property.ReadOnlyStringWrapper;
  31 import javafx.collections.FXCollections;
  32 import javafx.collections.ListChangeListener;
  33 import javafx.collections.ObservableList;
  34 import javafx.scene.input.KeyCode;
  35 import javafx.scene.layout.HBox;
  36 
  37 import java.util.List;
  38 import java.util.function.Function;
  39 
  40 import com.sun.javafx.PlatformUtil;
  41 import com.sun.javafx.util.Utils;
  42 import com.sun.javafx.scene.control.behavior.TableViewAnchorRetriever;
  43 import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
  44 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
  45 import com.sun.javafx.scene.control.infrastructure.KeyModifier;
  46 import com.sun.javafx.scene.control.infrastructure.StageLoader;
  47 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
  48 import com.sun.javafx.tk.Toolkit;
  49 import org.junit.After;
  50 import org.junit.Before;
  51 import org.junit.Ignore;
  52 import org.junit.Test;
  53 import static org.junit.Assert.assertEquals;
  54 import static org.junit.Assert.assertFalse;
  55 import static org.junit.Assert.assertNotSame;
  56 import static org.junit.Assert.assertNull;
  57 import static org.junit.Assert.assertTrue;
  58 import static org.junit.Assert.fail;
  59 
  60 public class TableViewKeyInputTest {
  61     private TableView<String> tableView;
  62     private TableView.TableViewSelectionModel<String> sm;
  63     private TableView.TableViewFocusModel<String> fm;


3458             // we expect only one selected index change event, from 5 to 4
3459             assertEquals(4, sm.getSelectedIndex());
3460         });
3461 
3462         keyboard.doKeyPress(KeyCode.UP);
3463         assertEquals(4, getAnchor().getRow());
3464         assertTrue(fm.isFocused(4, col));
3465         assertTrue(sm.isSelected(4, col));
3466         assertFalse(sm.isSelected(5, col));
3467     }
3468 
3469     @Test public void test_rt36800_rowSelection() {
3470         test_rt36800(false);
3471     }
3472 
3473     @Test public void test_rt36800_cellSelection() {
3474         test_rt36800(true);
3475     }
3476 
3477     private void test_rt36800(boolean cellSelection) {





3478         final int items = 10;
3479         tableView.getItems().clear();
3480         for (int i = 0; i < items; i++) {
3481             tableView.getItems().add("Row " + i);
3482         }
3483 
3484         TableColumn<String, String> col = new TableColumn<>("Column");
3485         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3486         tableView.getColumns().setAll(col);
3487 
3488         sm.setSelectionMode(SelectionMode.SINGLE);
3489         sm.setCellSelectionEnabled(cellSelection);
3490 
3491         if (cellSelection) {
3492             sm.clearAndSelect(5, col);
3493             assertEquals(5, getAnchor().getRow());
3494             assertEquals(col, getAnchor().getTableColumn());
3495             assertTrue(fm.isFocused(5, col));
3496             assertTrue(sm.isSelected(5, col));
3497         } else {
3498             sm.clearAndSelect(5);
3499             assertEquals(5, getAnchor().getRow());
3500             assertTrue(fm.isFocused(5));
3501             assertTrue(sm.isSelected(5));
3502         }
3503 
3504         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
3505         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
3506         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
3507         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
3508         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0
3509 
3510         final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
3511         try {
3512             keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
3513         } finally {
3514             ControlTestUtils.resetHandler(exceptionHandler);
3515         }
3516 
3517         if (cellSelection) {
3518             assertEquals(0, getAnchor().getRow());
3519             assertEquals(col, getAnchor().getTableColumn());
3520             assertTrue(fm.isFocused(0, col));
3521             assertTrue(sm.isSelected(0, col));
3522             assertFalse(sm.isSelected(1, col));
3523             assertFalse(sm.isSelected(2, col));
3524             assertFalse(sm.isSelected(3, col));
3525             assertFalse(sm.isSelected(4, col));
3526             assertFalse(sm.isSelected(5, col));
3527         } else {
3528             assertEquals(0, getAnchor().getRow());
3529             assertTrue(fm.isFocused(0));
3530             assertTrue(sm.isSelected(0));
3531             assertFalse(sm.isSelected(1));
3532             assertFalse(sm.isSelected(2));
3533             assertFalse(sm.isSelected(3));
3534             assertFalse(sm.isSelected(4));
3535             assertFalse(sm.isSelected(5));
3536         }



3537     }
3538 
3539     @Test public void test_rt_36942() {





3540         final int items = 3;
3541         tableView.getItems().clear();
3542         for (int i = 0; i < items; i++) {
3543             tableView.getItems().add("Row " + i);
3544         }
3545 
3546         TableColumn<String, String> col = new TableColumn<>("Column");
3547         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3548         tableView.getColumns().setAll(col);
3549 
3550         MultipleSelectionModel<String> sm = tableView.getSelectionModel();
3551         sm.setSelectionMode(SelectionMode.MULTIPLE);
3552         ObservableList<String> selectedItems = sm.getSelectedItems();
3553 
3554         TableView<String> selectedItemsTableView = new TableView<>(selectedItems);
3555         selectedItemsTableView.getColumns().setAll(col);
3556 
3557         HBox root = new HBox(5, tableView, selectedItemsTableView);
3558 
3559         StageLoader sl = new StageLoader(root);
3560 
3561         sm.select(0);
3562         keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1
3563         keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2
3564 
3565         final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
3566         try {
3567             keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.SHIFT); // 0,1,2,Exception?
3568         } finally {
3569             ControlTestUtils.resetHandler(exceptionHandler);
3570         }
3571 
3572         sl.dispose();



3573     }
3574 
3575     @Test public void test_rt_37130_pageUpAtTop() {
3576         final int items = 100;
3577         tableView.getItems().clear();
3578         for (int i = 0; i < items; i++) {
3579             tableView.getItems().add("Row " + i);
3580         }
3581 
3582         TableColumn<String, String> col = new TableColumn<>("Column");
3583         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue()));
3584         tableView.getColumns().setAll(col);
3585 
3586         TableSelectionModel<String> sm = tableView.getSelectionModel();
3587         sm.setSelectionMode(SelectionMode.MULTIPLE);
3588         sm.setCellSelectionEnabled(true);
3589 
3590         StageLoader sl = new StageLoader(tableView);
3591 
3592         sm.select(5, col);


< prev index next >