Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8232825

Key navigation in TreeTableView with single cell selection does not work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3
    • tbd
    • jfx13, 9
    • javafx
    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Microsoft Windows [Version 10.0.17134.1040]
      openjdk version "13" 2019-09-17
      OpenJDK Runtime Environment AdoptOpenJDK (build 13+33)
      OpenJDK 64-Bit Server VM AdoptOpenJDK (build 13+33, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      While having set single cell selection it should be possible to navigate the tree table cells using keyboard.
      Unfortunately when we press LEFT or RIGHT button it's been only used to expand/collapse item, but if item is already expanded/collapsed it should traverse cells as it was in JavaFX 8.

      REGRESSION : Last worked in version 8u231

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Open application provided in given source code.
      2. Select second row, first column cell.
      3. Press RIGHT keyboard button.
      4. Press LEFT keyboard button.
      5. Select first row, first column cell - row with children.
      6. Press RIGHT keyboard button.
      7. Press RIGHT keyboard button.
      8. Press LEFT keyboard button.
      9. Press LEFT keyboard button.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After 3. Cell located in second column is selected.
      After 4. Cell located in first column is selected.
      After 6. Row becomes expanded.
      After 7. Cell located in second column is selected.
      After 8. Row becomes collapsed.
      After 9. Cell located in first column is selected.
      ACTUAL -
      After 3. Selection does not change
      After 4. Selection does not change
      After 6. Row becomes expanded and selection is not visible, but the first cell is still selected.
      After 7. Selection does not change
      After 8. Row becomes collapsed.
      After 9. Selection does not change

      ---------- BEGIN SOURCE ----------

      import java.util.ArrayList;
      import java.util.LinkedHashMap;
      import java.util.List;
      import java.util.Map;
      import java.util.UUID;
      import java.util.stream.Collectors;

      import javafx.application.Application;
      import javafx.beans.property.ReadOnlyStringWrapper;
      import javafx.scene.Scene;
      import javafx.scene.control.ScrollPane;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TreeItem;
      import javafx.scene.control.TreeTableColumn;
      import javafx.scene.control.TreeTableView;
      import javafx.scene.layout.Priority;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TreeTableViewNavigationIssue
      {

          public static void main( String[] args )
          {
              System.err.println( Runtime.version().toString() );
              Application.launch( MainFx.class, args );
          }

          public static class MainFx extends Application
          {

              @Override
              public void start( final Stage primaryStage ) throws Exception
              {
                  System.err.println( System.getProperty( "javafx.version" ) );
                  final VBox parent = new VBox();
                  final List< Map< String, String > > data = createData( 20 );
                  final TreeTableView< Map< String, String > > tableView = createTableView( data );
                  fillTableData( tableView, data );
                  parent.getChildren().add( tableView );
                  VBox.setVgrow( tableView, Priority.ALWAYS );
                  final ScrollPane sp = new ScrollPane( parent );
                  sp.setFitToWidth( true );
                  sp.setFitToHeight( true );
                  final Scene aScene = new Scene( sp, 800, 600 );
                  primaryStage.setScene( aScene );
                  primaryStage.show();
              }

              private void fillTableData( final TreeTableView< Map< String, String > > aTableView,
                  final List< Map< String, String > > aData )
              {
                  final TreeItem< Map< String, String > > root = new TreeItem<>();
                  root.getChildren()
                      .setAll( aData.stream().map( TreeItem::new ).collect( Collectors.toList() ) );
                  final var firstChild = root.getChildren().get( 0 );
                  final var childData = createData( 5 );
                  firstChild.getChildren()
                      .setAll( childData.stream().map( TreeItem::new ).collect( Collectors.toList() ) );
                  aTableView.setShowRoot( false );
                  aTableView.setRoot( root );
              }

              private TreeTableView< Map< String, String > > createTableView(
                  final List< Map< String, String > > aData )
              {
                  final TreeTableView< Map< String, String > > table = new TreeTableView<>();
                  final Map< String, String > firstRow = aData.get( 0 );
                  final List< TreeTableColumn< Map< String, String >, String > > columns =
                      firstRow.keySet().stream().map( text -> {
                          final TreeTableColumn< Map< String, String >, String > column =
                              new TreeTableColumn<>( text );
                          column.setCellValueFactory( param -> {
                              final TreeItem< Map< String, String > > v = param.getValue();
                              final Map< String, String > map = v.getValue();
                              return new ReadOnlyStringWrapper( map.get( text ) );
                          } );
                          return column;
                      } ).collect( Collectors.toList() );
                  table.getColumns().addAll( columns );
                  table.setMaxWidth( Double.MAX_VALUE );
                  table.setMaxHeight( Double.MAX_VALUE );
                  table.getSelectionModel().setCellSelectionEnabled( true );
                  table.getSelectionModel().setSelectionMode( SelectionMode.SINGLE );
                  return table;
              }

              private List< Map< String, String > > createData( final int rowNumber )
              {
                  final int colNumber = 12;
                  final List< Map< String, String > > data = new ArrayList<>( rowNumber );
                  for( int i = 0; i < rowNumber; i++ )
                  {
                      final Map< String, String > row = new LinkedHashMap<>( colNumber );
                      for( int k = 0; k < colNumber; k++ )
                      {
                          row.put( "Column_" + k,
                              "Value " + UUID.randomUUID().toString().substring( (int)( Math.random() * 20d ) ) );
                      }
                      data.add( row );
                  }
                  return data;
              }

          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Personal workaround is to patch com.sun.javafx.scene.control.behavior.TreeTableViewBehavior and revert changes done in https://github.com/javafxports/openjdk-jfx/commit/d8c7d7dbad62f03763ea8793911dd8558381843a and restore usage of methods rightArrowPressed() and leftArrowPressed() which are unused, but still left there.

      FREQUENCY : always


      Attachments

        Activity

          People

            kpk Karthik P K
            webbuggrp Webbug Group
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: