functional/ControlsTests/src/javafx/scene/control/test/treeview/TreeViewNewApp.java

Print this page




  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.treeview;
  26 
  27 import java.util.ArrayList;
  28 import static javafx.commons.Consts.BTN_SET_ON_EDIT_EVENT_HANDLERS;
  29 import javafx.event.ActionEvent;
  30 import javafx.event.Event;
  31 import javafx.event.EventHandler;
  32 import javafx.geometry.Orientation;
  33 import javafx.scene.Scene;
  34 import javafx.scene.control.*;
  35 import javafx.scene.control.test.treetable.ResetButtonNames;


  36 import static javafx.scene.control.test.treeview.TreeViewConstants.ROOT_NAME;
  37 import javafx.scene.control.test.utils.CommonPropertiesScene;
  38 import javafx.scene.control.test.utils.ptables.NodeControllerFactory;
  39 import javafx.scene.control.test.utils.ptables.NodeControllerFactory.NodesStorage;
  40 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  41 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  42 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider;
  43 import javafx.scene.control.test.utils.ptables.TabPaneWithControl;
  44 import javafx.scene.input.KeyCode;
  45 import javafx.scene.input.KeyEvent;
  46 import javafx.scene.layout.HBox;
  47 import javafx.scene.layout.VBox;
  48 import javafx.util.Callback;
  49 import test.javaclient.shared.InteroperabilityApp;
  50 import test.javaclient.shared.Utils;
  51 
  52 /**
  53  * @author Alexander Kirov
  54  */
  55 public class TreeViewNewApp extends InteroperabilityApp implements TreeViewConstants, ResetButtonNames {


 114         @Override
 115         final protected void prepareScene() {
 116             testedControl = getNewTestedControl();
 117             tb = new PropertiesTable(testedControl);
 118 
 119             allPropertiesTables = new ArrayList<PropertiesTable>();
 120             allPropertiesTables.add(tb);
 121 
 122             PropertyTablesFactory.explorePropertiesList(testedControl, tb);
 123             PropertyTablesFactory.explorePropertiesList(testedControl.getSelectionModel(), tb);
 124             PropertyTablesFactory.explorePropertiesList(testedControl.getFocusModel(), tb);
 125             SpecialTablePropertiesProvider.provideForControl(testedControl, tb);
 126 
 127             tb.addCounter(EDIT_START_COUNTER);
 128             tb.addCounter(EDIT_COMMIT_COUNTER);
 129             tb.addCounter(EDIT_CANCEL_COUNTER);
 130 
 131             tabPane = new TabPaneWithControl("TreeView", tb);
 132             getControlOverItem(ROOT_NAME);
 133 
 134             Button hardResetButton = ButtonBuilder.create().id(HARD_RESET_BUTTON_ID).text("Hard reset").build();

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

 145             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 146                 public void handle(ActionEvent t) {
 147                     refreshProcedure(2);
 148                     testedControl.getRoot().setValue(ROOT_NAME);
 149                     TreeItem someNewOneTreeItem = new TreeItem();
 150                     testedControl.getRoot().setExpanded(someNewOneTreeItem.isExpanded());
 151                     testedControl.getRoot().setGraphic(someNewOneTreeItem.getGraphic());
 152 
 153                     TreeView someNewOneTreeView = new TreeView();
 154                     testedControl.setDisable(someNewOneTreeView.isDisabled());
 155                     testedControl.setEditable(someNewOneTreeView.isEditable());
 156                     testedControl.setShowRoot(someNewOneTreeView.isShowRoot());
 157                     testedControl.getSelectionModel().setSelectionMode(someNewOneTreeView.getSelectionModel().getSelectionMode());
 158                     testedControl.setMinHeight(someNewOneTreeView.getMinHeight());
 159                     testedControl.setMinWidth(someNewOneTreeView.getMinWidth());
 160                     testedControl.setPrefHeight(someNewOneTreeView.getPrefHeight());
 161                     testedControl.setPrefWidth(someNewOneTreeView.getPrefWidth());
 162                 }
 163             });
 164 


 386             button.setOnAction(new EventHandler<ActionEvent>() {
 387                 public void handle(ActionEvent t) {
 388                     int found = testedControl.getRow(searchTreeItem(tfParentName.getText()));
 389                     index.setText(((Integer) found).toString());
 390                 }
 391             });
 392 
 393             HBox hb1 = new HBox(3);
 394             hb1.getChildren().addAll(new Label("Get index of"), tfParentName);
 395 
 396             HBox hb2 = new HBox(3);
 397             hb2.getChildren().addAll(index, button);
 398 
 399             VBox vb = new VBox();
 400             vb.getChildren().addAll(hb1, hb2);
 401             return vb;
 402         }
 403 
 404         private HBox getScrollToHBox() {
 405             HBox hb = new HBox();
 406             Button button = ButtonBuilder.create().text("ScrollTo").id(SCROLL_TO_BUTTON_ID).build();
 407             final TextField tf = TextFieldBuilder.create().text("0").id(SCROLL_TO_TEXT_FIELD_ID).prefWidth(50).build();



 408 
 409             button.setOnAction(new EventHandler<ActionEvent>() {
 410                 public void handle(ActionEvent t) {
 411                     testedControl.scrollTo(Integer.parseInt(tf.getText()));
 412                 }
 413             });
 414 
 415             hb.getChildren().addAll(tf, button);
 416             return hb;
 417         }
 418 
 419         private HBox getEditHBox() {
 420             HBox hb = new HBox();
 421             Button button = ButtonBuilder.create().text("Edit").id(EDIT_BUTTON_ID).build();
 422             final TextField tf = TextFieldBuilder.create().promptText("name").id(EDIT_TEXT_FIELD_ID).prefWidth(50).build();




 423 
 424             button.setOnAction(new EventHandler<ActionEvent>() {
 425                 public void handle(ActionEvent t) {
 426                     testedControl.edit(searchTreeItem(tf.getText()));
 427                 }
 428             });
 429 
 430             hb.getChildren().addAll(tf, button);
 431             return hb;
 432         }
 433 
 434         private VBox setEventHandlersHBox() {
 435             VBox vb = new VBox();
 436 
 437             Button btn = ButtonBuilder.create()
 438                     .text("Set onEdit event hadlers")
 439                     .id(BTN_SET_ON_EDIT_EVENT_HANDLERS)
 440                     .build();
 441 
 442             btn.setOnAction(new EventHandler<ActionEvent>() {
 443                 public void handle(ActionEvent t) {
 444                     testedControl.setOnEditStart(new EventHandler() {
 445                         public void handle(Event t) {
 446                             tb.incrementCounter(EDIT_START_COUNTER);
 447                         }
 448                     });
 449 
 450                     testedControl.setOnEditCommit(new EventHandler() {
 451                         public void handle(Event t) {
 452                             tb.incrementCounter(EDIT_COMMIT_COUNTER);
 453                         }
 454                     });
 455 
 456                     testedControl.setOnEditCancel(new EventHandler() {
 457                         public void handle(Event t) {
 458                             tb.incrementCounter(EDIT_CANCEL_COUNTER);
 459                         }
 460                     });
 461                 }
 462             });
 463 
 464             Button btnAddFactory = ButtonBuilder.create()
 465                     .text("Set cell factory for editing")
 466                     .id(SET_CELL_FACTORY_FOR_EDITING)
 467                     .build();
 468 
 469             btnAddFactory.setOnAction(new EventHandler<ActionEvent>() {
 470                 public void handle(ActionEvent t) {
 471                     testedControl.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
 472                         @Override
 473                         public TreeCell<String> call(TreeView<String> p) {
 474                             return new TextFieldTreeCellImpl();
 475                         }
 476                     });
 477                 }
 478             });
 479 
 480             vb.getChildren().addAll(btn, btnAddFactory);
 481             return vb;
 482         }
 483 
 484         private TreeItem searchTreeItem(String content) {
 485             return TreeViewNewApp.searchTreeItem(testedControl, content);
 486         }
 487 
 488         private final class TextFieldTreeCellImpl extends TreeCell<String> {




  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.treeview;
  26 
  27 import java.util.ArrayList;
  28 import static javafx.commons.Consts.BTN_SET_ON_EDIT_EVENT_HANDLERS;
  29 import javafx.event.ActionEvent;
  30 import javafx.event.Event;
  31 import javafx.event.EventHandler;
  32 import javafx.geometry.Orientation;
  33 import javafx.scene.Scene;
  34 import javafx.scene.control.*;
  35 import javafx.scene.control.test.treetable.ResetButtonNames;
  36 import static javafx.scene.control.test.treetable.ResetButtonNames.HARD_RESET_BUTTON_ID;

  37 import static javafx.scene.control.test.treetable.ResetButtonNames.SOFT_RESET_BUTTON_ID;

  38 import static javafx.scene.control.test.treeview.TreeViewConstants.ROOT_NAME;
  39 import javafx.scene.control.test.utils.CommonPropertiesScene;
  40 import javafx.scene.control.test.utils.ptables.NodeControllerFactory;
  41 import javafx.scene.control.test.utils.ptables.NodeControllerFactory.NodesStorage;
  42 import javafx.scene.control.test.utils.ptables.PropertiesTable;
  43 import javafx.scene.control.test.utils.ptables.PropertyTablesFactory;
  44 import javafx.scene.control.test.utils.ptables.SpecialTablePropertiesProvider;
  45 import javafx.scene.control.test.utils.ptables.TabPaneWithControl;
  46 import javafx.scene.input.KeyCode;
  47 import javafx.scene.input.KeyEvent;
  48 import javafx.scene.layout.HBox;
  49 import javafx.scene.layout.VBox;
  50 import javafx.util.Callback;
  51 import test.javaclient.shared.InteroperabilityApp;
  52 import test.javaclient.shared.Utils;
  53 
  54 /**
  55  * @author Alexander Kirov
  56  */
  57 public class TreeViewNewApp extends InteroperabilityApp implements TreeViewConstants, ResetButtonNames {


 116         @Override
 117         final protected void prepareScene() {
 118             testedControl = getNewTestedControl();
 119             tb = new PropertiesTable(testedControl);
 120 
 121             allPropertiesTables = new ArrayList<PropertiesTable>();
 122             allPropertiesTables.add(tb);
 123 
 124             PropertyTablesFactory.explorePropertiesList(testedControl, tb);
 125             PropertyTablesFactory.explorePropertiesList(testedControl.getSelectionModel(), tb);
 126             PropertyTablesFactory.explorePropertiesList(testedControl.getFocusModel(), tb);
 127             SpecialTablePropertiesProvider.provideForControl(testedControl, tb);
 128 
 129             tb.addCounter(EDIT_START_COUNTER);
 130             tb.addCounter(EDIT_COMMIT_COUNTER);
 131             tb.addCounter(EDIT_CANCEL_COUNTER);
 132 
 133             tabPane = new TabPaneWithControl("TreeView", tb);
 134             getControlOverItem(ROOT_NAME);
 135 
 136             Button hardResetButton = new Button("Hard reset");

 137             hardResetButton.setId(HARD_RESET_BUTTON_ID);

 138             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 139                 public void handle(ActionEvent t) {
 140                     HBox hb = (HBox) getRoot();
 141                     hb.getChildren().clear();
 142                     prepareMainSceneStructure();
 143                     prepareScene();
 144                 }
 145             });
 146 
 147             Button softResetButton = new Button("Soft reset");

 148             softResetButton.setId(SOFT_RESET_BUTTON_ID);

 149             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 150                 public void handle(ActionEvent t) {
 151                     refreshProcedure(2);
 152                     testedControl.getRoot().setValue(ROOT_NAME);
 153                     TreeItem someNewOneTreeItem = new TreeItem();
 154                     testedControl.getRoot().setExpanded(someNewOneTreeItem.isExpanded());
 155                     testedControl.getRoot().setGraphic(someNewOneTreeItem.getGraphic());
 156 
 157                     TreeView someNewOneTreeView = new TreeView();
 158                     testedControl.setDisable(someNewOneTreeView.isDisabled());
 159                     testedControl.setEditable(someNewOneTreeView.isEditable());
 160                     testedControl.setShowRoot(someNewOneTreeView.isShowRoot());
 161                     testedControl.getSelectionModel().setSelectionMode(someNewOneTreeView.getSelectionModel().getSelectionMode());
 162                     testedControl.setMinHeight(someNewOneTreeView.getMinHeight());
 163                     testedControl.setMinWidth(someNewOneTreeView.getMinWidth());
 164                     testedControl.setPrefHeight(someNewOneTreeView.getPrefHeight());
 165                     testedControl.setPrefWidth(someNewOneTreeView.getPrefWidth());
 166                 }
 167             });
 168 


 390             button.setOnAction(new EventHandler<ActionEvent>() {
 391                 public void handle(ActionEvent t) {
 392                     int found = testedControl.getRow(searchTreeItem(tfParentName.getText()));
 393                     index.setText(((Integer) found).toString());
 394                 }
 395             });
 396 
 397             HBox hb1 = new HBox(3);
 398             hb1.getChildren().addAll(new Label("Get index of"), tfParentName);
 399 
 400             HBox hb2 = new HBox(3);
 401             hb2.getChildren().addAll(index, button);
 402 
 403             VBox vb = new VBox();
 404             vb.getChildren().addAll(hb1, hb2);
 405             return vb;
 406         }
 407 
 408         private HBox getScrollToHBox() {
 409             HBox hb = new HBox();
 410             Button button = new Button("ScrollTo");

 411             button.setId(SCROLL_TO_BUTTON_ID);

 412             final TextField tf = new TextField("0");

 413             tf.setId(SCROLL_TO_TEXT_FIELD_ID);

 414             tf.setPrefWidth(50);

 415 
 416             button.setOnAction(new EventHandler<ActionEvent>() {
 417                 public void handle(ActionEvent t) {
 418                     testedControl.scrollTo(Integer.parseInt(tf.getText()));
 419                 }
 420             });
 421 
 422             hb.getChildren().addAll(tf, button);
 423             return hb;
 424         }
 425 
 426         private HBox getEditHBox() {
 427             HBox hb = new HBox();
 428             Button button = new Button("Edit");

 429             button.setId(EDIT_BUTTON_ID);

 430             final TextField tf = new TextField();

 431             tf.setPromptText("name");

 432             tf.setId(EDIT_TEXT_FIELD_ID);

 433             tf.setPrefWidth(50);

 434 
 435             button.setOnAction(new EventHandler<ActionEvent>() {
 436                 public void handle(ActionEvent t) {
 437                     testedControl.edit(searchTreeItem(tf.getText()));
 438                 }
 439             });
 440 
 441             hb.getChildren().addAll(tf, button);
 442             return hb;
 443         }
 444 
 445         private VBox setEventHandlersHBox() {
 446             VBox vb = new VBox();
 447 
 448             Button btn = new Button("Set onEdit event hadlers");

 449             btn.setId(BTN_SET_ON_EDIT_EVENT_HANDLERS);




 450             btn.setOnAction(new EventHandler<ActionEvent>() {
 451                 public void handle(ActionEvent t) {
 452                     testedControl.setOnEditStart(new EventHandler() {
 453                         public void handle(Event t) {
 454                             tb.incrementCounter(EDIT_START_COUNTER);
 455                         }
 456                     });
 457 
 458                     testedControl.setOnEditCommit(new EventHandler() {
 459                         public void handle(Event t) {
 460                             tb.incrementCounter(EDIT_COMMIT_COUNTER);
 461                         }
 462                     });
 463 
 464                     testedControl.setOnEditCancel(new EventHandler() {
 465                         public void handle(Event t) {
 466                             tb.incrementCounter(EDIT_CANCEL_COUNTER);
 467                         }
 468                     });
 469                 }
 470             });
 471 
 472             Button btnAddFactory = new Button("Set cell factory for editing");

 473             btnAddFactory.setId(SET_CELL_FACTORY_FOR_EDITING);




 474             btnAddFactory.setOnAction(new EventHandler<ActionEvent>() {
 475                 public void handle(ActionEvent t) {
 476                     testedControl.setCellFactory(new Callback<TreeView<String>, TreeCell<String>>() {
 477                         @Override
 478                         public TreeCell<String> call(TreeView<String> p) {
 479                             return new TextFieldTreeCellImpl();
 480                         }
 481                     });
 482                 }
 483             });
 484 
 485             vb.getChildren().addAll(btn, btnAddFactory);
 486             return vb;
 487         }
 488 
 489         private TreeItem searchTreeItem(String content) {
 490             return TreeViewNewApp.searchTreeItem(testedControl, content);
 491         }
 492 
 493         private final class TextFieldTreeCellImpl extends TreeCell<String> {