functional/ControlsTests/src/javafx/scene/control/test/tableview/NewTableViewApp.java

Print this page




   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 package javafx.scene.control.test.tableview;
  26 
  27 import com.sun.javafx.scene.control.skin.NestedTableColumnHeader;
  28 import com.sun.javafx.scene.control.skin.TableColumnHeader;
  29 import com.sun.javafx.scene.control.skin.TableHeaderRow;
  30 import com.sun.javafx.scene.control.skin.TableViewSkin;
  31 import java.util.ArrayList;
  32 import java.util.HashMap;
  33 import java.util.Map;
  34 import javafx.beans.property.SimpleStringProperty;
  35 import javafx.beans.property.StringProperty;
  36 import javafx.beans.value.ChangeListener;
  37 import javafx.beans.value.ObservableValue;
  38 import javafx.collections.FXCollections;
  39 import javafx.collections.ObservableList;
  40 import javafx.collections.transformation.SortedList;
  41 import javafx.event.ActionEvent;
  42 import javafx.event.Event;
  43 import javafx.event.EventHandler;
  44 import javafx.geometry.Orientation;
  45 import javafx.scene.Scene;
  46 import javafx.scene.control.*;
  47 import javafx.scene.control.TableColumn.CellDataFeatures;
  48 import javafx.scene.control.cell.ChoiceBoxTableCell;
  49 import javafx.scene.control.cell.ComboBoxTableCell;
  50 import javafx.scene.control.cell.TextFieldTableCell;
  51 import javafx.scene.control.test.treetable.ResetButtonNames;
  52 import javafx.scene.control.test.utils.CommonPropertiesScene;
  53 import javafx.scene.control.test.utils.ComponentsFactory.MultipleIndexFormComponent;
  54 import javafx.scene.control.test.utils.ptables.NodeControllerFactory;
  55 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  56 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  57 import javafx.scene.control.test.utils.ptables.TabPaneWithControl;
  58 import javafx.scene.input.KeyCode;
  59 import javafx.scene.input.KeyEvent;
  60 import javafx.scene.layout.HBox;
  61 import javafx.scene.layout.Pane;
  62 import javafx.scene.layout.VBox;
  63 import javafx.util.Callback;
  64 import test.javaclient.shared.InteroperabilityApp;
  65 import test.javaclient.shared.Utils;
  66 import static javafx.commons.Consts.*;
  67 import static javafx.commons.Consts.Cell.*;
  68 import javafx.scene.Node;


  69 import javafx.scene.control.test.utils.ComponentsFactory.MultipleIndexFormComponent.MultipleIndicesAction;
  70 import static org.junit.Assert.assertTrue;
  71 
  72 /**
  73  * @author Alexander Kirov
  74  */
  75 public class NewTableViewApp extends InteroperabilityApp implements ResetButtonNames {
  76 
  77     public final static String TESTED_TABLE_VIEW_ID = "TESTED_TABLEVIEW_ID";
  78 
  79     public static void main(String[] args) {
  80         Utils.launch(NewTableViewApp.class, args);
  81     }
  82 
  83     @Override
  84     protected Scene getScene() {
  85         Utils.setTitleToStage(stage, "TableViewTestApp");
  86         Scene scene = new TableViewScene();
  87         Utils.addBrowser(scene);
  88         return scene;


 112             testedTableView = new TableView<DataItem>(allData);
 113             testedTableView.setId(TESTED_TABLE_VIEW_ID);
 114 
 115             tb = new PropertiesTable(testedTableView);
 116 
 117             PropertyTablesFactory.explorePropertiesList(testedTableView, tb);
 118 
 119             tb.addCounter(COUNTER_EDIT_START);
 120             tb.addCounter(COUNTER_EDIT_COMMIT);
 121             tb.addCounter(COUNTER_EDIT_CANCEL);
 122             tb.addCounter(COUNTER_ON_SORT);
 123             testedTableView.setOnSort(new EventHandler<SortEvent<TableView<DataItem>>>() {
 124                 public void handle(SortEvent<TableView<DataItem>> event) {
 125                     tb.incrementCounter(COUNTER_ON_SORT);
 126                 }
 127             });
 128 
 129             tabPane = new TabPaneWithControl("TableView", tb);
 130             tabPane.setMinSize(1000, 1000);
 131 
 132             Button hardResetButton = ButtonBuilder.create().id(HARD_RESET_BUTTON_ID).text("Hard reset").build();

 133             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 134                 public void handle(ActionEvent t) {
 135                     HBox hb = (HBox) getRoot();
 136                     hb.getChildren().clear();
 137                     prepareMainSceneStructure();
 138                     prepareScene();
 139                 }
 140             });
 141 
 142             Button softResetButton = ButtonBuilder.create().id(SOFT_RESET_BUTTON_ID).text("Soft reset").build();

 143             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 144                 public void handle(ActionEvent t) {
 145                     TableView newOne = new TableView();
 146                     refreshProcedure(1);
 147                     allData.clear();
 148                     existingColumns.clear();
 149                     testedTableView.setPrefHeight(newOne.getPrefHeight());
 150                     testedTableView.setPrefWidth(newOne.getPrefWidth());
 151                     testedTableView.getColumns().clear();
 152                     testedTableView.setPlaceholder(newOne.getPlaceholder());
 153                     testedTableView.setEditable(newOne.isEditable());
 154                     testedTableView.setVisible(newOne.isVisible());
 155                     testedTableView.setTableMenuButtonVisible(newOne.isTableMenuButtonVisible());
 156                     testedTableView.setDisable(newOne.isDisable());
 157                     testedTableView.setContextMenu(newOne.getContextMenu());
 158                 }
 159             });
 160 
 161             HBox resetButtonsHBox = new HBox();
 162             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);


 310             hb1.getChildren().addAll(new Label("With name"), tfColumnName);
 311 
 312             HBox hb2 = new HBox(3);
 313             hb2.getChildren().addAll(new Label("At index"), indexTf, button);
 314 
 315             VBox vb = new VBox();
 316             vb.getChildren().addAll(hb1, addDataPropertiesTabToTab, addColumnPropertiesTableToTab, hb2);
 317             return vb;
 318         }
 319 
 320         Node getReplaceTableHeaderImplementationButton() {
 321             Button replaceButton = new Button("Replace skin implementation");
 322             replaceButton.setId(REPLACE_SKIN_IMPLEMENTATION_BUTTON_ID);
 323             replaceButton.setOnAction(new EventHandler<ActionEvent>() {
 324                 public void handle(ActionEvent t) {
 325                     testedTableView.setSkin(new TableViewSkin(testedTableView) {
 326                         @Override
 327                         public String toString() {
 328                             return "CUSTOM " + super.toString();
 329                         }
 330 
 331                         @Override
 332                         protected TableHeaderRow createTableHeaderRow() {
 333                             return new TableHeaderRow(this) {
 334                                 @Override
 335                                 protected NestedTableColumnHeader createRootHeader() {
 336                                     return new NestedTableColumnHeader((TableViewSkin) testedTableView.getSkin(), null) {
 337                                         @Override
 338                                         protected TableColumnHeader createTableColumnHeader(TableColumnBase col) {
 339                                             if (col.getColumns().isEmpty()) {
 340                                                 final TableColumnHeader tableColumnHeader = new TableColumnHeader(getTableViewSkin(), col);
 341                                                 tableColumnHeader.setId(CUSTOM_IMPLEMENTATION_MARKER);
 342                                                 return tableColumnHeader;
 343                                             } else {
 344                                                 final NestedTableColumnHeader nestedTableColumnHeader = new NestedTableColumnHeader(getTableViewSkin(), col);
 345                                                 nestedTableColumnHeader.setId(CUSTOM_IMPLEMENTATION_MARKER);
 346                                                 return nestedTableColumnHeader;
 347                                             }
 348                                         }
 349                                     };
 350                                 }
 351                             };
 352                         }

 353                     });
 354                 }
 355             });
 356 
 357             return replaceButton;
 358         }
 359 
 360         VBox getAddNestedColumnVBox() {
 361             final TextField nestedColumnAtIndexTF = new TextField("0");
 362             nestedColumnAtIndexTF.setPromptText("index");
 363             nestedColumnAtIndexTF.setId(NESTED_COLUMN_INDEX_TEXT_FIELD_ID);
 364 
 365             final TextField nestedColumnNameTF = new TextField();
 366             nestedColumnNameTF.setPromptText("namex");
 367             nestedColumnNameTF.setId(NESTED_COLUMN_NAME_TEXT_FIELD_ID);
 368 
 369             HBox nestedColumnAdditionalNodes = new HBox();
 370             nestedColumnAdditionalNodes.getChildren().addAll(nestedColumnAtIndexTF, nestedColumnNameTF);
 371 
 372             MultipleIndicesAction executor = new MultipleIndexFormComponent.MultipleIndicesAction() {


 439             HBox hb = new HBox(3.0);
 440 
 441             final ComboBox cmbEditors = new ComboBox();
 442             cmbEditors.setId(CMB_EDITORS_ID);
 443             cmbEditors.getItems().addAll((Object[]) CellEditorType.values());
 444 
 445             final CheckBox chbCustom = new CheckBox("Custom");
 446             chbCustom.setId(CHB_IS_CUSTOM_ID);
 447 
 448             Button btnSetEditor = new Button("Set editor");
 449             btnSetEditor.setId(BTN_SET_CELLS_EDITOR_ID);
 450             btnSetEditor.setOnAction(new EventHandler<ActionEvent>() {
 451                 public void handle(ActionEvent t) {
 452                     CellEditorType editor = (CellEditorType) cmbEditors.getSelectionModel().getSelectedItem();
 453                     setCellEditor(editor, chbCustom.isSelected());
 454                 }
 455             });
 456 
 457             hb.getChildren().addAll(cmbEditors, chbCustom, btnSetEditor);
 458 
 459             Button btn = ButtonBuilder.create()
 460                     .text("Set onEdit event hadlers")
 461                     .id(BTN_SET_ON_EDIT_EVENT_HANDLERS)
 462                     .build();
 463 
 464             btn.setOnAction(new EventHandler<ActionEvent>() {
 465                 public void handle(ActionEvent t) {
 466                     final EventHandler eventHandlerOnEditStart = new EventHandler() {
 467                         public void handle(Event t) {
 468 //                                new Throwable().printStackTrace();
 469                             tb.incrementCounter(COUNTER_EDIT_START);
 470                         }
 471                     };
 472 
 473                     final EventHandler eventHandlerOnEditCommit = new EventHandler() {
 474                         public void handle(Event t) {
 475                             tb.incrementCounter(COUNTER_EDIT_COMMIT);
 476                         }
 477                     };
 478 
 479                     final EventHandler eventHandlerOnEditCancel = new EventHandler() {
 480                         public void handle(Event t) {
 481                             t.consume();
 482                             tb.incrementCounter(COUNTER_EDIT_CANCEL);




   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 package javafx.scene.control.test.tableview;
  26 
  27 import javafx.scene.control.skin.NestedTableColumnHeader;
  28 import javafx.scene.control.skin.TableColumnHeader;
  29 import javafx.scene.control.skin.TableHeaderRow;
  30 import javafx.scene.control.skin.TableViewSkin;
  31 import java.util.ArrayList;
  32 import java.util.HashMap;
  33 import java.util.Map;
  34 import javafx.beans.property.SimpleStringProperty;
  35 import javafx.beans.property.StringProperty;
  36 import javafx.beans.value.ChangeListener;
  37 import javafx.beans.value.ObservableValue;
  38 import javafx.collections.FXCollections;
  39 import javafx.collections.ObservableList;
  40 import javafx.collections.transformation.SortedList;
  41 import javafx.event.ActionEvent;
  42 import javafx.event.Event;
  43 import javafx.event.EventHandler;
  44 import javafx.geometry.Orientation;
  45 import javafx.scene.Scene;
  46 import javafx.scene.control.*;
  47 import javafx.scene.control.TableColumn.CellDataFeatures;
  48 import javafx.scene.control.cell.ChoiceBoxTableCell;
  49 import javafx.scene.control.cell.ComboBoxTableCell;
  50 import javafx.scene.control.cell.TextFieldTableCell;
  51 import javafx.scene.control.test.treetable.ResetButtonNames;
  52 import javafx.scene.control.test.utils.CommonPropertiesScene;
  53 import javafx.scene.control.test.utils.ComponentsFactory.MultipleIndexFormComponent;
  54 import javafx.scene.control.test.utils.ptables.NodeControllerFactory;
  55 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  56 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  57 import javafx.scene.control.test.utils.ptables.TabPaneWithControl;
  58 import javafx.scene.input.KeyCode;
  59 import javafx.scene.input.KeyEvent;
  60 import javafx.scene.layout.HBox;
  61 import javafx.scene.layout.Pane;
  62 import javafx.scene.layout.VBox;
  63 import javafx.util.Callback;
  64 import test.javaclient.shared.InteroperabilityApp;
  65 import test.javaclient.shared.Utils;
  66 import static javafx.commons.Consts.*;
  67 import static javafx.commons.Consts.Cell.*;
  68 import javafx.scene.Node;
  69 import static javafx.scene.control.test.treetable.ResetButtonNames.HARD_RESET_BUTTON_ID;
  70 import static javafx.scene.control.test.treetable.ResetButtonNames.SOFT_RESET_BUTTON_ID;
  71 import javafx.scene.control.test.utils.ComponentsFactory.MultipleIndexFormComponent.MultipleIndicesAction;
  72 import static org.junit.Assert.assertTrue;
  73 
  74 /**
  75  * @author Alexander Kirov
  76  */
  77 public class NewTableViewApp extends InteroperabilityApp implements ResetButtonNames {
  78 
  79     public final static String TESTED_TABLE_VIEW_ID = "TESTED_TABLEVIEW_ID";
  80 
  81     public static void main(String[] args) {
  82         Utils.launch(NewTableViewApp.class, args);
  83     }
  84 
  85     @Override
  86     protected Scene getScene() {
  87         Utils.setTitleToStage(stage, "TableViewTestApp");
  88         Scene scene = new TableViewScene();
  89         Utils.addBrowser(scene);
  90         return scene;


 114             testedTableView = new TableView<DataItem>(allData);
 115             testedTableView.setId(TESTED_TABLE_VIEW_ID);
 116 
 117             tb = new PropertiesTable(testedTableView);
 118 
 119             PropertyTablesFactory.explorePropertiesList(testedTableView, tb);
 120 
 121             tb.addCounter(COUNTER_EDIT_START);
 122             tb.addCounter(COUNTER_EDIT_COMMIT);
 123             tb.addCounter(COUNTER_EDIT_CANCEL);
 124             tb.addCounter(COUNTER_ON_SORT);
 125             testedTableView.setOnSort(new EventHandler<SortEvent<TableView<DataItem>>>() {
 126                 public void handle(SortEvent<TableView<DataItem>> event) {
 127                     tb.incrementCounter(COUNTER_ON_SORT);
 128                 }
 129             });
 130 
 131             tabPane = new TabPaneWithControl("TableView", tb);
 132             tabPane.setMinSize(1000, 1000);
 133 
 134             Button hardResetButton = new Button("Hard reset");
 135             hardResetButton.setId(HARD_RESET_BUTTON_ID);
 136             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 137                 public void handle(ActionEvent t) {
 138                     HBox hb = (HBox) getRoot();
 139                     hb.getChildren().clear();
 140                     prepareMainSceneStructure();
 141                     prepareScene();
 142                 }
 143             });
 144 
 145             Button softResetButton = new Button("Soft reset");
 146             softResetButton.setId(SOFT_RESET_BUTTON_ID);
 147             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 148                 public void handle(ActionEvent t) {
 149                     TableView newOne = new TableView();
 150                     refreshProcedure(1);
 151                     allData.clear();
 152                     existingColumns.clear();
 153                     testedTableView.setPrefHeight(newOne.getPrefHeight());
 154                     testedTableView.setPrefWidth(newOne.getPrefWidth());
 155                     testedTableView.getColumns().clear();
 156                     testedTableView.setPlaceholder(newOne.getPlaceholder());
 157                     testedTableView.setEditable(newOne.isEditable());
 158                     testedTableView.setVisible(newOne.isVisible());
 159                     testedTableView.setTableMenuButtonVisible(newOne.isTableMenuButtonVisible());
 160                     testedTableView.setDisable(newOne.isDisable());
 161                     testedTableView.setContextMenu(newOne.getContextMenu());
 162                 }
 163             });
 164 
 165             HBox resetButtonsHBox = new HBox();
 166             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);


 314             hb1.getChildren().addAll(new Label("With name"), tfColumnName);
 315 
 316             HBox hb2 = new HBox(3);
 317             hb2.getChildren().addAll(new Label("At index"), indexTf, button);
 318 
 319             VBox vb = new VBox();
 320             vb.getChildren().addAll(hb1, addDataPropertiesTabToTab, addColumnPropertiesTableToTab, hb2);
 321             return vb;
 322         }
 323 
 324         Node getReplaceTableHeaderImplementationButton() {
 325             Button replaceButton = new Button("Replace skin implementation");
 326             replaceButton.setId(REPLACE_SKIN_IMPLEMENTATION_BUTTON_ID);
 327             replaceButton.setOnAction(new EventHandler<ActionEvent>() {
 328                 public void handle(ActionEvent t) {
 329                     testedTableView.setSkin(new TableViewSkin(testedTableView) {
 330                         @Override
 331                         public String toString() {
 332                             return "CUSTOM " + super.toString();
 333                         }
 334 /*
 335                         @Override
 336                         protected TableHeaderRow createTableHeaderRow() {
 337                             return new TableHeaderRow(this) {
 338                                 @Override
 339                                 protected NestedTableColumnHeader createRootHeader() {
 340                                     return new NestedTableColumnHeader((TableViewSkin) testedTableView.getSkin(), null) {
 341                                         @Override
 342                                         protected TableColumnHeader createTableColumnHeader(TableColumnBase col) {
 343                                             if (col.getColumns().isEmpty()) {
 344                                                 final TableColumnHeader tableColumnHeader = new TableColumnHeader(getTableViewSkin(), col);
 345                                                 tableColumnHeader.setId(CUSTOM_IMPLEMENTATION_MARKER);
 346                                                 return tableColumnHeader;
 347                                             } else {
 348                                                 final NestedTableColumnHeader nestedTableColumnHeader = new NestedTableColumnHeader(getTableViewSkin(), col);
 349                                                 nestedTableColumnHeader.setId(CUSTOM_IMPLEMENTATION_MARKER);
 350                                                 return nestedTableColumnHeader;
 351                                             }
 352                                         }
 353                                     };
 354                                 }
 355                             };
 356                         }
 357                         */
 358                     });
 359                 }
 360             });
 361 
 362             return replaceButton;
 363         }
 364 
 365         VBox getAddNestedColumnVBox() {
 366             final TextField nestedColumnAtIndexTF = new TextField("0");
 367             nestedColumnAtIndexTF.setPromptText("index");
 368             nestedColumnAtIndexTF.setId(NESTED_COLUMN_INDEX_TEXT_FIELD_ID);
 369 
 370             final TextField nestedColumnNameTF = new TextField();
 371             nestedColumnNameTF.setPromptText("namex");
 372             nestedColumnNameTF.setId(NESTED_COLUMN_NAME_TEXT_FIELD_ID);
 373 
 374             HBox nestedColumnAdditionalNodes = new HBox();
 375             nestedColumnAdditionalNodes.getChildren().addAll(nestedColumnAtIndexTF, nestedColumnNameTF);
 376 
 377             MultipleIndicesAction executor = new MultipleIndexFormComponent.MultipleIndicesAction() {


 444             HBox hb = new HBox(3.0);
 445 
 446             final ComboBox cmbEditors = new ComboBox();
 447             cmbEditors.setId(CMB_EDITORS_ID);
 448             cmbEditors.getItems().addAll((Object[]) CellEditorType.values());
 449 
 450             final CheckBox chbCustom = new CheckBox("Custom");
 451             chbCustom.setId(CHB_IS_CUSTOM_ID);
 452 
 453             Button btnSetEditor = new Button("Set editor");
 454             btnSetEditor.setId(BTN_SET_CELLS_EDITOR_ID);
 455             btnSetEditor.setOnAction(new EventHandler<ActionEvent>() {
 456                 public void handle(ActionEvent t) {
 457                     CellEditorType editor = (CellEditorType) cmbEditors.getSelectionModel().getSelectedItem();
 458                     setCellEditor(editor, chbCustom.isSelected());
 459                 }
 460             });
 461 
 462             hb.getChildren().addAll(cmbEditors, chbCustom, btnSetEditor);
 463 
 464             Button btn = new Button("Set onEdit event hadlers");
 465             btn.setId(BTN_SET_ON_EDIT_EVENT_HANDLERS);


 466 
 467             btn.setOnAction(new EventHandler<ActionEvent>() {
 468                 public void handle(ActionEvent t) {
 469                     final EventHandler eventHandlerOnEditStart = new EventHandler() {
 470                         public void handle(Event t) {
 471 //                                new Throwable().printStackTrace();
 472                             tb.incrementCounter(COUNTER_EDIT_START);
 473                         }
 474                     };
 475 
 476                     final EventHandler eventHandlerOnEditCommit = new EventHandler() {
 477                         public void handle(Event t) {
 478                             tb.incrementCounter(COUNTER_EDIT_COMMIT);
 479                         }
 480                     };
 481 
 482                     final EventHandler eventHandlerOnEditCancel = new EventHandler() {
 483                         public void handle(Event t) {
 484                             t.consume();
 485                             tb.incrementCounter(COUNTER_EDIT_CANCEL);