< prev index next >

functional/ControlsTests/src/javafx/scene/control/test/combobox/ComboBoxApp.java

Print this page




 150                     tb.incrementCounter(ON_ACTION_EVENT_COUNTER_ID);
 151                 }
 152             });
 153 
 154             tb.addCounter(CUSTOM_CELL_CANCEL_EDIT_COUNTER);
 155             tb.addCounter(CUSTOM_CELL_START_EDIT_COUNTER);
 156             tb.addCounter(CUSTOM_CELL_UPDATE_EDIT_COUNTER);
 157             tb.addCounter(CALLBACK_CALLED_ID);
 158 
 159             final SingleSelectionModel<String> selectionModel = new SingleSelectionModelImpl<String>(testedComboBox.getItems());
 160             Button flushCalledMethodsInSelectionModel = new Button("Flush called methods");
 161 //            flushCalledMethodsInSelectionModel.setOnAction(new EventHandler<ActionEvent>() {
 162 //
 163 //                public void handle(ActionEvent t) {
 164 //                    CMSM.setLogBuf(PropertyValueController.getLogger().textProperty());
 165 //                    CMSM.flushCalledMethods();
 166 //                    testedComboBox.setSelectionModel(selectionModel);
 167 //                }
 168 //            });
 169 
 170             Button applyCustomSelectionModel = ButtonBuilder.create().text("Apply custom selection model").id(APPLY_CUSTOM_SELECTION_MODEL_BUTTON_ID).build();

 171             applyCustomSelectionModel.setOnAction(new EventHandler<ActionEvent>() {
 172                 public void handle(ActionEvent t) {
 173                     testedComboBox.selectionModelProperty().setValue(selectionModel);
 174                 }
 175             });
 176 
 177             Button applyCustomStringConverter = ButtonBuilder.create().text("Apply custom string converter").id(APPLY_CUSTOM_STRING_CONVERTER_BUTTON_ID).build();

 178             applyCustomStringConverter.setOnAction(new EventHandler<ActionEvent>() {
 179                 public void handle(ActionEvent t) {
 180                     testedComboBox.setConverter(new CustomStringConverter());
 181                 }
 182             });
 183 
 184             Button applyCustomCellFactory = ButtonBuilder.create().text("Apply custom cell factory").id(APPLY_CUSTOM_CELL_FACTORY_BUTTON_ID).build();

 185             applyCustomCellFactory.setOnAction(new EventHandler<ActionEvent>() {
 186                 public void handle(ActionEvent t) {
 187                     testedComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
 188                         public ListCell<String> call(ListView<String> p) {
 189                             tb.incrementCounter(CALLBACK_CALLED_ID);
 190                             return new TextFieldListCell();
 191                         }
 192                     });
 193                 }
 194             });
 195 
 196             Button hardResetButton = ButtonBuilder.create().id(HARD_RESET_BUTTON_ID).text("Hard reset").build();

 197             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 198                 public void handle(ActionEvent t) {
 199                     HBox hb = (HBox) getRoot();
 200                     hb.getChildren().clear();
 201                     prepareMainSceneStructure();
 202                     prepareScene();
 203                 }
 204             });
 205 
 206             Button softResetButton = ButtonBuilder.create().id(SOFT_RESET_BUTTON_ID).text("Soft reset").build();

 207             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 208                 public void handle(ActionEvent t) {
 209                     tb.refresh();
 210                     ComboBox<String> newOne = new ComboBox<String>();
 211                     //testedComboBox.setItems(FXCollections.observableArrayList());//RT-18945
 212                     while (testedComboBox.getItems().size() != 0) {
 213                         testedComboBox.getItems().remove(0);
 214                     }
 215                     testedComboBox.setPrefHeight(newOne.getPrefHeight());
 216                     testedComboBox.setPrefWidth(newOne.getPrefWidth());
 217                     testedComboBox.setVisibleRowCount(newOne.getVisibleRowCount());
 218                     testedComboBox.setPromptText(newOne.getPromptText());
 219                     testedComboBox.setValue(null);
 220                     testedComboBox.setEditable(newOne.isEditable());
 221                     testedComboBox.setVisible(newOne.isVisible());
 222                     //testedComboBox.showingProperty().setValue(newOne.isShowing());//Showing is readonly from 2.1.0b10.
 223                     testedComboBox.setConverter(newOne.getConverter());
 224                     testedComboBox.setCellFactory(newOne.getCellFactory());
 225                 }
 226             });
 227 
 228             HBox resetButtonsHBox = new HBox();
 229             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);
 230 
 231             Button setAddingElementsOnShowing = ButtonBuilder.create()
 232                     .id(SET_ADDING_ELEMENTS_ON_SHOWING)
 233                     .text("Set adding elements on showing")
 234                     .build();
 235 
 236             setAddingElementsOnShowing.setOnAction(new EventHandler<ActionEvent>() {
 237                 public void handle(ActionEvent t) {
 238                     testedComboBox.setOnShowing(new EventHandler<Event>() {
 239                         public void handle(Event t) {
 240                             int index = ((ComboBox) testedComboBox).getItems().size();
 241                             ((ComboBox) testedComboBox).getItems().add(index, INITIAL_VALUE);
 242 
 243                             tb.incrementCounter(SET_ON_SHOWING_COUNTER);
 244                         }
 245                     });
 246                 }
 247             });
 248 
 249             Button restoreDefaultOnShowingHandler = ButtonBuilder.create()
 250                     .id(RESTORE_ON_SHOWING_EVENT_HANDLER)
 251                     .text("Restore default onShowing handler")
 252                     .build();
 253 
 254             restoreDefaultOnShowingHandler.setOnAction(new EventHandler<ActionEvent>() {
 255                 public void handle(ActionEvent t) {
 256                     testedComboBox.setOnShowing(new EventHandler<Event>() {
 257                         public void handle(Event t) {
 258                             tb.incrementCounter(SET_ON_SHOWING_COUNTER);
 259                         }
 260                     });
 261                 }
 262             });
 263 
 264             Button populateComboBoxWithFontSizes = ButtonBuilder.create()
 265                     .id(POPULATE_COMBOBOX_WITH_FONT_SIZES)
 266                     .text("Populate ComboBox with font sizes")
 267                     .build();
 268 
 269             populateComboBoxWithFontSizes.setOnAction(new EventHandler<ActionEvent>() {
 270                 public void handle(ActionEvent t) {
 271 
 272                     testedComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
 273                         @Override
 274                         public ListCell<String> call(ListView<String> p) {
 275                             return new ListCell<String>() {
 276                                 {
 277                                     setContentDisplay(ContentDisplay.TEXT_ONLY);
 278                                 }
 279 
 280                                 @Override
 281                                 protected void updateItem(String item, boolean empty) {
 282                                     super.updateItem(item, empty);
 283 
 284                                     if (item == null || empty) {
 285                                         setText(null);
 286                                     } else {
 287                                         setText(item);
 288                                         setFont(new Font(Double.valueOf(item)));


 300 
 301             setTestedControl(testedComboBox);
 302 
 303             VBox vb = new VBox();
 304             vb.setSpacing(5);
 305             vb.getChildren().addAll(resetButtonsHBox, getAddItemHBox(), getRemoveItemHBox(),
 306                     applyCustomSelectionModel, applyCustomStringConverter,
 307                     flushCalledMethodsInSelectionModel, applyCustomCellFactory,
 308                     setAddingElementsOnShowing,
 309                     restoreDefaultOnShowingHandler,
 310                     populateComboBoxWithFontSizes,
 311                     getSetItemsNullHBox());
 312             setControllersContent(vb);
 313 
 314             setPropertiesContent(tb);
 315         }
 316 
 317         private HBox getAddItemHBox() {
 318             HBox hb = new HBox();
 319             Label lb = new Label("Add item");
 320             final TextField tf = TextFieldBuilder.create().prefWidth(50).id(ADD_ITEM_TEXT_FIELD_ID).build();


 321             Label atLb = new Label("at pos");
 322             final TextField tfPos = TextFieldBuilder.create().prefWidth(50).id(ADD_ITEM_POSITION_TEXT_FIELD_ID).build();
 323             Button bt = ButtonBuilder.create().text("Add!").id(ADD_ITEM_BUTTON_ID).build();



 324             bt.setOnAction(new EventHandler() {
 325                 public void handle(Event t) {
 326                     int index = Integer.parseInt(tfPos.getText());
 327                     ((ComboBox) testedComboBox).getItems().add(index, tf.getText());
 328                 }
 329             });
 330             hb.getChildren().addAll(lb, tf, atLb, tfPos, bt);
 331             return hb;
 332         }
 333 
 334         private HBox getRemoveItemHBox() {
 335             HBox hb = new HBox();
 336             Label lb = new Label("From position");
 337             final TextField tf = TextFieldBuilder.create().text("0").prefWidth(50).id(REMOVE_ITEM_POS_TEXT_FIELD_ID).build();
 338             Button bt = ButtonBuilder.create().text("Remove!").id(REMOVE_BUTTON_ID).build();



 339             bt.setOnAction(new EventHandler() {
 340                 public void handle(Event t) {
 341                     int index = Integer.parseInt(tf.getText());
 342                     ((ComboBox) testedComboBox).getItems().remove(index);
 343                 }
 344             });
 345             hb.getChildren().addAll(lb, tf, bt);
 346             return hb;
 347         }
 348 
 349         private HBox getSetItemsNullHBox() {
 350             HBox hb = new HBox();
 351 
 352             Button bt = ButtonBuilder.create().text("Set items null").id(SET_ITEMS_NULL_BUTTON_ID).build();

 353             bt.setOnAction(new EventHandler() {
 354                 public void handle(Event t) {
 355                     ((ComboBox) testedComboBox).setItems(null);
 356                 }
 357             });
 358             hb.getChildren().addAll(bt);
 359             return hb;
 360         }
 361 
 362         class TextFieldListCell extends ListCell<String> {
 363 
 364             public TextFieldListCell() {
 365                 setEditable(true);
 366             }
 367 
 368             @Override
 369             public void startEdit() {
 370                 tb.incrementCounter(CUSTOM_CELL_START_EDIT_COUNTER);
 371                 super.startEdit();
 372 




 150                     tb.incrementCounter(ON_ACTION_EVENT_COUNTER_ID);
 151                 }
 152             });
 153 
 154             tb.addCounter(CUSTOM_CELL_CANCEL_EDIT_COUNTER);
 155             tb.addCounter(CUSTOM_CELL_START_EDIT_COUNTER);
 156             tb.addCounter(CUSTOM_CELL_UPDATE_EDIT_COUNTER);
 157             tb.addCounter(CALLBACK_CALLED_ID);
 158 
 159             final SingleSelectionModel<String> selectionModel = new SingleSelectionModelImpl<String>(testedComboBox.getItems());
 160             Button flushCalledMethodsInSelectionModel = new Button("Flush called methods");
 161 //            flushCalledMethodsInSelectionModel.setOnAction(new EventHandler<ActionEvent>() {
 162 //
 163 //                public void handle(ActionEvent t) {
 164 //                    CMSM.setLogBuf(PropertyValueController.getLogger().textProperty());
 165 //                    CMSM.flushCalledMethods();
 166 //                    testedComboBox.setSelectionModel(selectionModel);
 167 //                }
 168 //            });
 169 
 170             Button applyCustomSelectionModel = new Button("Apply custom selection model");
 171             applyCustomSelectionModel.setId(APPLY_CUSTOM_SELECTION_MODEL_BUTTON_ID);
 172             applyCustomSelectionModel.setOnAction(new EventHandler<ActionEvent>() {
 173                 public void handle(ActionEvent t) {
 174                     testedComboBox.selectionModelProperty().setValue(selectionModel);
 175                 }
 176             });
 177 
 178             Button applyCustomStringConverter = new Button("Apply custom string converter");
 179             applyCustomStringConverter.setId(APPLY_CUSTOM_STRING_CONVERTER_BUTTON_ID);
 180             applyCustomStringConverter.setOnAction(new EventHandler<ActionEvent>() {
 181                 public void handle(ActionEvent t) {
 182                     testedComboBox.setConverter(new CustomStringConverter());
 183                 }
 184             });
 185 
 186             Button applyCustomCellFactory = new Button("Apply custom cell factory");
 187             applyCustomCellFactory.setId(APPLY_CUSTOM_CELL_FACTORY_BUTTON_ID);
 188             applyCustomCellFactory.setOnAction(new EventHandler<ActionEvent>() {
 189                 public void handle(ActionEvent t) {
 190                     testedComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
 191                         public ListCell<String> call(ListView<String> p) {
 192                             tb.incrementCounter(CALLBACK_CALLED_ID);
 193                             return new TextFieldListCell();
 194                         }
 195                     });
 196                 }
 197             });
 198 
 199             Button hardResetButton = new Button("Hard reset");
 200             hardResetButton.setId(HARD_RESET_BUTTON_ID);
 201             hardResetButton.setOnAction(new EventHandler<ActionEvent>() {
 202                 public void handle(ActionEvent t) {
 203                     HBox hb = (HBox) getRoot();
 204                     hb.getChildren().clear();
 205                     prepareMainSceneStructure();
 206                     prepareScene();
 207                 }
 208             });
 209 
 210             Button softResetButton = new Button("Soft reset");
 211             softResetButton.setId(SOFT_RESET_BUTTON_ID);
 212             softResetButton.setOnAction(new EventHandler<ActionEvent>() {
 213                 public void handle(ActionEvent t) {
 214                     tb.refresh();
 215                     ComboBox<String> newOne = new ComboBox<String>();
 216                     //testedComboBox.setItems(FXCollections.observableArrayList());//RT-18945
 217                     while (testedComboBox.getItems().size() != 0) {
 218                         testedComboBox.getItems().remove(0);
 219                     }
 220                     testedComboBox.setPrefHeight(newOne.getPrefHeight());
 221                     testedComboBox.setPrefWidth(newOne.getPrefWidth());
 222                     testedComboBox.setVisibleRowCount(newOne.getVisibleRowCount());
 223                     testedComboBox.setPromptText(newOne.getPromptText());
 224                     testedComboBox.setValue(null);
 225                     testedComboBox.setEditable(newOne.isEditable());
 226                     testedComboBox.setVisible(newOne.isVisible());
 227                     //testedComboBox.showingProperty().setValue(newOne.isShowing());//Showing is readonly from 2.1.0b10.
 228                     testedComboBox.setConverter(newOne.getConverter());
 229                     testedComboBox.setCellFactory(newOne.getCellFactory());
 230                 }
 231             });
 232 
 233             HBox resetButtonsHBox = new HBox();
 234             resetButtonsHBox.getChildren().addAll(hardResetButton, softResetButton);
 235 
 236             Button setAddingElementsOnShowing = new Button("Set adding elements on showing");
 237             setAddingElementsOnShowing.setId(SET_ADDING_ELEMENTS_ON_SHOWING);



 238             setAddingElementsOnShowing.setOnAction(new EventHandler<ActionEvent>() {
 239                 public void handle(ActionEvent t) {
 240                     testedComboBox.setOnShowing(new EventHandler<Event>() {
 241                         public void handle(Event t) {
 242                             int index = ((ComboBox) testedComboBox).getItems().size();
 243                             ((ComboBox) testedComboBox).getItems().add(index, INITIAL_VALUE);
 244 
 245                             tb.incrementCounter(SET_ON_SHOWING_COUNTER);
 246                         }
 247                     });
 248                 }
 249             });
 250 
 251             Button restoreDefaultOnShowingHandler = new Button("Restore default onShowing handler");
 252             restoreDefaultOnShowingHandler.setId(RESTORE_ON_SHOWING_EVENT_HANDLER);



 253             restoreDefaultOnShowingHandler.setOnAction(new EventHandler<ActionEvent>() {
 254                 public void handle(ActionEvent t) {
 255                     testedComboBox.setOnShowing(new EventHandler<Event>() {
 256                         public void handle(Event t) {
 257                             tb.incrementCounter(SET_ON_SHOWING_COUNTER);
 258                         }
 259                     });
 260                 }
 261             });
 262 
 263             Button populateComboBoxWithFontSizes = new Button("Populate ComboBox with font sizes");
 264             populateComboBoxWithFontSizes.setId(POPULATE_COMBOBOX_WITH_FONT_SIZES);



 265             populateComboBoxWithFontSizes.setOnAction(new EventHandler<ActionEvent>() {
 266                 public void handle(ActionEvent t) {
 267 
 268                     testedComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
 269                         @Override
 270                         public ListCell<String> call(ListView<String> p) {
 271                             return new ListCell<String>() {
 272                                 {
 273                                     setContentDisplay(ContentDisplay.TEXT_ONLY);
 274                                 }
 275 
 276                                 @Override
 277                                 protected void updateItem(String item, boolean empty) {
 278                                     super.updateItem(item, empty);
 279 
 280                                     if (item == null || empty) {
 281                                         setText(null);
 282                                     } else {
 283                                         setText(item);
 284                                         setFont(new Font(Double.valueOf(item)));


 296 
 297             setTestedControl(testedComboBox);
 298 
 299             VBox vb = new VBox();
 300             vb.setSpacing(5);
 301             vb.getChildren().addAll(resetButtonsHBox, getAddItemHBox(), getRemoveItemHBox(),
 302                     applyCustomSelectionModel, applyCustomStringConverter,
 303                     flushCalledMethodsInSelectionModel, applyCustomCellFactory,
 304                     setAddingElementsOnShowing,
 305                     restoreDefaultOnShowingHandler,
 306                     populateComboBoxWithFontSizes,
 307                     getSetItemsNullHBox());
 308             setControllersContent(vb);
 309 
 310             setPropertiesContent(tb);
 311         }
 312 
 313         private HBox getAddItemHBox() {
 314             HBox hb = new HBox();
 315             Label lb = new Label("Add item");
 316             final TextField tf = new TextField();
 317             tf.setPrefWidth(50);
 318             tf.setId(ADD_ITEM_TEXT_FIELD_ID);
 319             Label atLb = new Label("at pos");
 320             final TextField tfPos = new TextField();
 321             tfPos.setPrefWidth(50);
 322             tfPos.setId(ADD_ITEM_POSITION_TEXT_FIELD_ID);
 323             Button bt = new Button("Add!");
 324             bt.setId(ADD_ITEM_BUTTON_ID);
 325             bt.setOnAction(new EventHandler() {
 326                 public void handle(Event t) {
 327                     int index = Integer.parseInt(tfPos.getText());
 328                     ((ComboBox) testedComboBox).getItems().add(index, tf.getText());
 329                 }
 330             });
 331             hb.getChildren().addAll(lb, tf, atLb, tfPos, bt);
 332             return hb;
 333         }
 334 
 335         private HBox getRemoveItemHBox() {
 336             HBox hb = new HBox();
 337             Label lb = new Label("From position");
 338             final TextField tf = new TextField("0");
 339             tf.setPrefWidth(50);
 340             tf.setId(REMOVE_ITEM_POS_TEXT_FIELD_ID);
 341             Button bt = new Button("Remove!");
 342             bt.setId(REMOVE_BUTTON_ID);
 343             bt.setOnAction(new EventHandler() {
 344                 public void handle(Event t) {
 345                     int index = Integer.parseInt(tf.getText());
 346                     ((ComboBox) testedComboBox).getItems().remove(index);
 347                 }
 348             });
 349             hb.getChildren().addAll(lb, tf, bt);
 350             return hb;
 351         }
 352 
 353         private HBox getSetItemsNullHBox() {
 354             HBox hb = new HBox();
 355 
 356             Button bt = new Button("Set items null");
 357             bt.setId(SET_ITEMS_NULL_BUTTON_ID);
 358             bt.setOnAction(new EventHandler() {
 359                 public void handle(Event t) {
 360                     ((ComboBox) testedComboBox).setItems(null);
 361                 }
 362             });
 363             hb.getChildren().addAll(bt);
 364             return hb;
 365         }
 366 
 367         class TextFieldListCell extends ListCell<String> {
 368 
 369             public TextFieldListCell() {
 370                 setEditable(true);
 371             }
 372 
 373             @Override
 374             public void startEdit() {
 375                 tb.incrementCounter(CUSTOM_CELL_START_EDIT_COUNTER);
 376                 super.startEdit();
 377 


< prev index next >