< prev index next >

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

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


  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.behavior.TableCellBehavior;
  29 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
  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 java.util.List;
  36 import java.util.function.Function;
  37 
  38 import com.sun.javafx.PlatformUtil;
  39 import com.sun.javafx.util.Utils;
  40 import com.sun.javafx.scene.control.behavior.TreeTableViewAnchorRetriever;

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


3984             // we expect only one selected index change event, from 5 to 4
3985             assertEquals(4, sm.getSelectedIndex());
3986         });
3987 
3988         keyboard.doKeyPress(KeyCode.UP);
3989         assertEquals(4, getAnchor().getRow());
3990         assertTrue(fm.isFocused(4, col));
3991         assertTrue(sm.isSelected(4, col));
3992         assertFalse(sm.isSelected(5, col));
3993     }
3994 
3995     @Test public void test_rt36800_rowSelection() {
3996         test_rt36800(false);
3997     }
3998 
3999     @Test public void test_rt36800_cellSelection() {
4000         test_rt36800(true);
4001     }
4002 
4003     private void test_rt36800(boolean cellSelection) {
4004         // get the current exception handler before replacing with our own,
4005         // as ListListenerHelp intercepts the exception otherwise
4006         final Thread.UncaughtExceptionHandler exceptionHandler = Thread.currentThread().getUncaughtExceptionHandler();
4007         Thread.currentThread().setUncaughtExceptionHandler((t, e) -> {
4008             e.printStackTrace();
4009             fail("We don't expect any exceptions in this test!");
4010         });
4011 
4012         final int items = 10;
4013         root.getChildren().clear();
4014         root.setExpanded(true);
4015         for (int i = 0; i < items; i++) {
4016             root.getChildren().add(new TreeItem<>("Row " + i));
4017         }
4018 
4019         TreeTableColumn<String, String> col = new TreeTableColumn<>("Column");
4020         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getValue()));
4021         tableView.getColumns().setAll(col);
4022 
4023         sm.setSelectionMode(SelectionMode.SINGLE);
4024         sm.setCellSelectionEnabled(cellSelection);
4025 
4026         if (cellSelection) {
4027             sm.clearAndSelect(5, col);
4028             assertEquals(5, getAnchor().getRow());
4029             assertEquals(col, getAnchor().getTableColumn());
4030             assertTrue(fm.isFocused(5, col));
4031             assertTrue(sm.isSelected(5, col));
4032         } else {
4033             sm.clearAndSelect(5);
4034             assertEquals(5, getAnchor().getRow());
4035             assertTrue(fm.isFocused(5));
4036             assertTrue(sm.isSelected(5));
4037         }
4038 
4039         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
4040         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
4041         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
4042         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
4043         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0



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



4045 
4046         if (cellSelection) {
4047             assertEquals(0, getAnchor().getRow());
4048             assertEquals(col, getAnchor().getTableColumn());
4049             assertTrue(fm.isFocused(0, col));
4050             assertTrue(sm.isSelected(0, col));
4051             assertFalse(sm.isSelected(1, col));
4052             assertFalse(sm.isSelected(2, col));
4053             assertFalse(sm.isSelected(3, col));
4054             assertFalse(sm.isSelected(4, col));
4055             assertFalse(sm.isSelected(5, col));
4056         } else {
4057             assertEquals(0, getAnchor().getRow());
4058             assertTrue(fm.isFocused(0));
4059             assertTrue(sm.isSelected(0));
4060             assertFalse(sm.isSelected(1));
4061             assertFalse(sm.isSelected(2));
4062             assertFalse(sm.isSelected(3));
4063             assertFalse(sm.isSelected(4));
4064             assertFalse(sm.isSelected(5));
4065         }
4066 
4067         // reset the exception handler
4068         Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);
4069     }
4070 
4071     @Test public void test_rt_37130_pageUpAtTop() {
4072         final int items = 100;
4073         root.getChildren().clear();
4074         root.setExpanded(true);
4075         for (int i = 0; i < items; i++) {
4076             root.getChildren().add(new TreeItem<>("Row " + i));
4077         }
4078 
4079         TreeTableColumn<String, String> col = new TreeTableColumn<>("Column");
4080         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getValue()));
4081         tableView.getColumns().setAll(col);
4082 
4083         sm.setSelectionMode(SelectionMode.MULTIPLE);
4084         sm.setCellSelectionEnabled(true);
4085 
4086         StageLoader sl = new StageLoader(tableView);
4087 
4088         sm.select(5, col);




  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.behavior.TableCellBehavior;
  29 import com.sun.javafx.scene.control.behavior.TreeTableCellBehavior;
  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 java.util.List;
  36 import java.util.function.Function;
  37 
  38 import com.sun.javafx.PlatformUtil;
  39 import com.sun.javafx.util.Utils;
  40 import com.sun.javafx.scene.control.behavior.TreeTableViewAnchorRetriever;
  41 import com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
  42 import com.sun.javafx.scene.control.infrastructure.KeyEventFirer;
  43 import com.sun.javafx.scene.control.infrastructure.KeyModifier;
  44 import com.sun.javafx.scene.control.infrastructure.StageLoader;
  45 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
  46 import com.sun.javafx.tk.Toolkit;
  47 import org.junit.After;
  48 import org.junit.Before;
  49 import org.junit.Ignore;
  50 import org.junit.Test;
  51 import static org.junit.Assert.assertEquals;
  52 import static org.junit.Assert.assertFalse;
  53 import static org.junit.Assert.assertNotSame;
  54 import static org.junit.Assert.assertNull;
  55 import static org.junit.Assert.assertTrue;
  56 import static org.junit.Assert.fail;
  57 
  58 public class TreeTableViewKeyInputTest {
  59     private TreeTableView<String> tableView;
  60     private TreeTableView.TreeTableViewSelectionModel<String> sm;
  61     private TreeTableView.TreeTableViewFocusModel<String> fm;


3985             // we expect only one selected index change event, from 5 to 4
3986             assertEquals(4, sm.getSelectedIndex());
3987         });
3988 
3989         keyboard.doKeyPress(KeyCode.UP);
3990         assertEquals(4, getAnchor().getRow());
3991         assertTrue(fm.isFocused(4, col));
3992         assertTrue(sm.isSelected(4, col));
3993         assertFalse(sm.isSelected(5, col));
3994     }
3995 
3996     @Test public void test_rt36800_rowSelection() {
3997         test_rt36800(false);
3998     }
3999 
4000     @Test public void test_rt36800_cellSelection() {
4001         test_rt36800(true);
4002     }
4003 
4004     private void test_rt36800(boolean cellSelection) {








4005         final int items = 10;
4006         root.getChildren().clear();
4007         root.setExpanded(true);
4008         for (int i = 0; i < items; i++) {
4009             root.getChildren().add(new TreeItem<>("Row " + i));
4010         }
4011 
4012         TreeTableColumn<String, String> col = new TreeTableColumn<>("Column");
4013         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getValue()));
4014         tableView.getColumns().setAll(col);
4015 
4016         sm.setSelectionMode(SelectionMode.SINGLE);
4017         sm.setCellSelectionEnabled(cellSelection);
4018 
4019         if (cellSelection) {
4020             sm.clearAndSelect(5, col);
4021             assertEquals(5, getAnchor().getRow());
4022             assertEquals(col, getAnchor().getTableColumn());
4023             assertTrue(fm.isFocused(5, col));
4024             assertTrue(sm.isSelected(5, col));
4025         } else {
4026             sm.clearAndSelect(5);
4027             assertEquals(5, getAnchor().getRow());
4028             assertTrue(fm.isFocused(5));
4029             assertTrue(sm.isSelected(5));
4030         }
4031 
4032         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 4
4033         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 3
4034         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 2
4035         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 1
4036         keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // 0
4037 
4038         final Thread.UncaughtExceptionHandler exceptionHandler = ControlTestUtils.setHandler();
4039         try {
4040             keyboard.doKeyPress(KeyCode.UP, KeyModifier.SHIFT); // bug time?
4041         } finally {
4042             ControlTestUtils.resetHandler(exceptionHandler);
4043         }
4044 
4045         if (cellSelection) {
4046             assertEquals(0, getAnchor().getRow());
4047             assertEquals(col, getAnchor().getTableColumn());
4048             assertTrue(fm.isFocused(0, col));
4049             assertTrue(sm.isSelected(0, col));
4050             assertFalse(sm.isSelected(1, col));
4051             assertFalse(sm.isSelected(2, col));
4052             assertFalse(sm.isSelected(3, col));
4053             assertFalse(sm.isSelected(4, col));
4054             assertFalse(sm.isSelected(5, col));
4055         } else {
4056             assertEquals(0, getAnchor().getRow());
4057             assertTrue(fm.isFocused(0));
4058             assertTrue(sm.isSelected(0));
4059             assertFalse(sm.isSelected(1));
4060             assertFalse(sm.isSelected(2));
4061             assertFalse(sm.isSelected(3));
4062             assertFalse(sm.isSelected(4));
4063             assertFalse(sm.isSelected(5));
4064         }



4065     }
4066 
4067     @Test public void test_rt_37130_pageUpAtTop() {
4068         final int items = 100;
4069         root.getChildren().clear();
4070         root.setExpanded(true);
4071         for (int i = 0; i < items; i++) {
4072             root.getChildren().add(new TreeItem<>("Row " + i));
4073         }
4074 
4075         TreeTableColumn<String, String> col = new TreeTableColumn<>("Column");
4076         col.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getValue()));
4077         tableView.getColumns().setAll(col);
4078 
4079         sm.setSelectionMode(SelectionMode.MULTIPLE);
4080         sm.setCellSelectionEnabled(true);
4081 
4082         StageLoader sl = new StageLoader(tableView);
4083 
4084         sm.select(5, col);


< prev index next >