@Test public void select() { @SuppressWarnings("unchecked") ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") ComboBoxListCell<String> cell = (ComboBoxListCell<String>) getCellAt(listView, 3); Point2D point = getPoint(listView, 3); RFXListView rfxListView = new RFXListView(listView, null, point, lr); rfxListView.focusGained(rfxListView); cell.startEdit(); cell.updateItem("Option 3", false); cell.commitEdit("Option 3"); rfxListView.focusLost(rfxListView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Option 3", recording.getParameters()[0]); }
@Test public void selectEditable() { @SuppressWarnings("unchecked") ListView<String> listView = (ListView<String>) getPrimaryStage().getScene().getRoot().lookup(".list-view"); LoggingRecorder lr = new LoggingRecorder(); Platform.runLater(() -> { @SuppressWarnings("unchecked") ComboBoxListCell<String> cell = (ComboBoxListCell<String>) getCellAt(listView, 3); cell.setComboBoxEditable(true); Point2D point = getPoint(listView, 3); RFXListView rfxListView = new RFXListView(listView, null, point, lr); rfxListView.focusGained(rfxListView); cell.startEdit(); cell.updateItem("Option 5", false); cell.commitEdit("Option 5"); rfxListView.focusLost(rfxListView); }); List<Recording> recordings = lr.waitAndGetRecordings(1); Recording recording = recordings.get(0); AssertJUnit.assertEquals("recordSelect", recording.getCall()); AssertJUnit.assertEquals("Option 5", recording.getParameters()[0]); }
private ComboBox getEditFactoryComboBoxChoser() { ComboBox<CellsApp.CellType> cb = new ComboBox<CellsApp.CellType>(); cb.getItems().addAll(FXCollections.observableArrayList(CellsApp.CellType.values())); cb.setId(LIST_FACTORY_CHOICE_ID); cb.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<CellsApp.CellType>() { public void changed(ObservableValue<? extends CellsApp.CellType> ov, CellsApp.CellType t, CellsApp.CellType t1) { switch (t1) { case ChoiceBox: testedControl.setCellFactory(ChoiceBoxListCell.forListView(new CellCustomStringConverter(), someValues)); break; case ComboBox: testedControl.setCellFactory(ComboBoxListCell.forListView(new CellCustomStringConverter(), someValues)); break; case TextField: testedControl.setCellFactory(TextFieldListCell.forListView(new CellCustomStringConverter())); break; default: testedControl.setCellFactory(new ListView().getCellFactory()); } } }); return cb; }
public static void reset() { add(Node.class, JavaFXElement.class); add(TextInputControl.class, JavaFXTextInputControlElement.class); add(HTMLEditor.class, JavaFXHTMLEditor.class); add(CheckBox.class, JavaFXCheckBoxElement.class); add(ToggleButton.class, JavaFXToggleButtonElement.class); add(Slider.class, JavaFXSliderElement.class); add(Spinner.class, JavaFXSpinnerElement.class); add(SplitPane.class, JavaFXSplitPaneElement.class); add(ProgressBar.class, JavaFXProgressBarElement.class); add(ChoiceBox.class, JavaFXChoiceBoxElement.class); add(ColorPicker.class, JavaFXColorPickerElement.class); add(ComboBox.class, JavaFXComboBoxElement.class); add(DatePicker.class, JavaFXDatePickerElement.class); add(TabPane.class, JavaFXTabPaneElement.class); add(ListView.class, JavaFXListViewElement.class); add(TreeView.class, JavaFXTreeViewElement.class); add(TableView.class, JavaFXTableViewElement.class); add(TreeTableView.class, JavaFXTreeTableViewElement.class); add(CheckBoxListCell.class, JavaFXCheckBoxListCellElement.class); add(ChoiceBoxListCell.class, JavaFXChoiceBoxListCellElement.class); add(ComboBoxListCell.class, JavaFXComboBoxListCellElemnt.class); add(CheckBoxTreeCell.class, JavaFXCheckBoxTreeCellElement.class); add(ChoiceBoxTreeCell.class, JavaFXChoiceBoxTreeCellElement.class); add(ComboBoxTreeCell.class, JavaFXComboBoxTreeCellElement.class); add(TableCell.class, JavaFXTableViewCellElement.class); add(CheckBoxTableCell.class, JavaFXCheckBoxTableCellElement.class); add(ChoiceBoxTableCell.class, JavaFXChoiceBoxTableCellElement.class); add(ComboBoxTableCell.class, JavaFXComboBoxTableCellElemnt.class); add(TreeTableCell.class, JavaFXTreeTableCellElement.class); add(CheckBoxTreeTableCell.class, JavaFXCheckBoxTreeTableCell.class); add(ChoiceBoxTreeTableCell.class, JavaFXChoiceBoxTreeTableCell.class); add(ComboBoxTreeTableCell.class, JavaFXComboBoxTreeTableCell.class); }
public ComboBoxListViewSample() { ListView<Object> listView = new ListView<>(); listView.getItems().addAll(items); listView.setEditable(true); listView.setCellFactory(ComboBoxListCell.forListView(items)); getChildren().add(listView); }
/** * Create a set of widgets to choose a Projection * @param defProj The default projection, before the user chooses anything * @return the full formatted Region */ protected Region buildProjectionSelector(Procedure projectionSetter) { final Label label = new Label("Projection:"); projectionChooser = new ComboBox<Projection>(FXCollections.observableArrayList(FEATURED_PROJECTIONS)); projectionChooser.getItems().add(Projection.NULL_PROJECTION); projectionChooser.setPrefWidth(COMBOBOX_WIDTH); final Text description = new Text(); description.setWrappingWidth(GUI_WIDTH); projectionChooser.valueProperty().addListener((observable, old, now) -> { projectionChooser.setButtonCell(new ComboBoxListCell<Projection>()); //This makes it properly display values not in the featured list final boolean suppressedListeners = suppressListeners.isSet(); //save this value, because revealParameters()... if (projectionChooser.getValue() == Projection.NULL_PROJECTION) { chooseProjectionFromExpandedList(old); //<aside>NULL_PROJECTION is the "More..." button. It triggers the expanded list</aside> } else { description.setText(projectionChooser.getValue().getDescription()); revealParameters(projectionChooser.getValue()); //...clears suppressListeners. That's fine, if (!suppressedListeners) //because suppressListeners is only needed here for that one case. projectionSetter.execute(); } }); HBox comboRow = new HBox(H_SPACE, label, projectionChooser); comboRow.setAlignment(Pos.CENTER_LEFT); return new VBox(V_SPACE, comboRow, description); }
@Test public void testGetComboBoxListCellAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(ComboBoxListCell.class); assertThat(adjuster, is(instanceOf(ControlAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(Control.class))); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ComboBoxListCell cell = (ComboBoxListCell) getComponent(); return cell.getConverter().toString(cell.getItem()); }
@SuppressWarnings("unchecked") @Override public String _getValue() { @SuppressWarnings("rawtypes") ComboBoxListCell cell = (ComboBoxListCell) node; return cell.getConverter().toString(cell.getItem()); }
public EventManagerRenderer() { getChildren().add(borderPane); borderPane.minWidthProperty().bind(widthProperty()); borderPane.maxWidthProperty().bind(widthProperty()); borderPane.minHeightProperty().bind(heightProperty()); borderPane.maxHeightProperty().bind(heightProperty()); pushButton.setOnAction(e -> { eventTypeToSelectedEvents.get(eventListView.getSelectionModel().getSelectedItem()).forEach(event -> { pushedEvents.add(event); }); }); sendButton.setOnAction(e -> { pushedEvents.forEach(eventManager::queueEvent); eventTypeToEventTableView.values().forEach(t -> t.getSelectionModel().clearSelection()); // eventTypeToSelectedEvents.forEach((k,v) -> v.clear()); pushedEvents.clear(); }); header.getChildren().addAll(pushButton, sendButton); eventListView.setCellFactory((l) -> new ComboBoxListCell<EClass>(new StringConverter<EClass>() { @Override public String toString(EClass object) { return object.getName(); } @Override public EClass fromString(String string) { return null; } })); eventListView.getSelectionModel().selectedItemProperty().addListener((c, o, n) -> { scrollPane.setContent(eventTypeToEventTableView.get(n)); }); final VBox leftPanel = new VBox(); leftPanel.getChildren().addAll(eventListView, pushedEventListView); borderPane.setTop(header); borderPane.setLeft(leftPanel); borderPane.setCenter(scrollPane); scrollPane.setFitToWidth(true); scrollPane.setBorder(Border.EMPTY); scrollPane.minHeightProperty().bind(leftPanel.heightProperty()); scrollPane.maxHeightProperty().bind(leftPanel.heightProperty()); final ListChangeListener<EClass> eventTypesChangeListener = c -> { while (c.next()) { c.getRemoved().stream().forEach(e -> { eventTypeToEventTableView.remove(e); eventTypeToSelectedEvents.remove(e); }); c.getAddedSubList().stream().forEach(e -> { final EventTableView tableView = new EventTableView(e, executedModel, eventManager); eventTypeToEventTableView.put(e, tableView); final List<EventInstance> selectedEvents = new ArrayList<>(); eventTypeToSelectedEvents.put(e, selectedEvents); final ListChangeListener<EventInstance> selectedEventsChangeListener = c1 -> { while (c1.next()) { selectedEvents.removeAll(c1.getRemoved()); selectedEvents.addAll(c1.getAddedSubList()); } }; tableView.getSelectionModel().getSelectedItems().addListener(selectedEventsChangeListener); tableView.refreshEvents(); tableView.minHeightProperty().bind(scrollPane.heightProperty().subtract(2)); }); } }; eventList.addListener(eventTypesChangeListener); }
private HBox createTypeComboBox(Sip descOb) { HBox result = new HBox(10); result.setAlignment(Pos.CENTER_LEFT); // Text field for the OTHER content type TextField otherTextField = new TextField(); otherTextField.textProperty().addListener((obs, old, newValue) -> { descOb.getContentType().setOtherType(newValue); editButton.setText(newValue); }); // Content Type combo box contentType = new ComboBox<>(); List<Pair> contTypeList = new ArrayList<>(); result.getChildren().addAll(contentType); Pair selected = null; for (IPContentType.IPContentTypeEnum ct : IPContentType.IPContentTypeEnum.values()) { IPContentType ipCT = new IPContentType(ct); Pair toAdd = new Pair(ipCT, ipCT.getType()); contTypeList.add(toAdd); if (ipCT.asString().equalsIgnoreCase(descOb.getContentType().asString())) { selected = toAdd; } } // sort the list as strings Collections.sort(contTypeList, (o1, o2) -> o1.toString().compareTo(o2.toString())); contentType.setItems(FXCollections.observableList(contTypeList)); contentType.getSelectionModel().select(selected); editButton.setText(((IPContentType) selected.getKey()).asString()); contentType.valueProperty().addListener((obs, old, newValue) -> { descOb.setContentType((IPContentType) newValue.getKey()); if (old != null || ((IPContentType) newValue.getKey()).getType() != IPContentType.IPContentTypeEnum.MIXED) { editButton.setText(((IPContentType) newValue.getKey()).asString()); } if (((IPContentType) newValue.getKey()).getType() == IPContentType.IPContentTypeEnum.OTHER) { if (!result.getChildren().contains(otherTextField)) { result.getChildren().add(otherTextField); otherTextField.setText(descOb.getContentType().getOtherType()); } } else { if (result.getChildren().contains(otherTextField)) result.getChildren().remove(otherTextField); } }); contentType.getSelectionModel().select(new Pair(descOb.getContentType(), descOb.getContentType().getType())); contentType.setMinWidth(85); contentType.setCellFactory(param -> new ComboBoxListCell<Pair>() { @Override public void updateItem(Pair item, boolean empty) { super.updateItem(item, empty); if (item != null && item.getKey() != null) { String translation = I18n .t(Constants.I18N_INSPECTIONPANE_IP_CONTENT_TYPE_PREFIX + item.getValue().toString()); if (translation == null || "".equals(translation)) translation = item.getValue().toString(); setTooltip(new Tooltip(translation)); } } }); contentType.setTooltip(new Tooltip(I18n.t(Constants.I18N_INSPECTIONPANE_SIP_TYPE_TOOLTIP))); return result; }
public EventManagerRenderer() { getChildren().add(borderPane); borderPane.minWidthProperty().bind(widthProperty()); borderPane.maxWidthProperty().bind(widthProperty()); borderPane.minHeightProperty().bind(heightProperty()); borderPane.maxHeightProperty().bind(heightProperty()); pushButton.setOnAction(e -> { eventTypeToSelectedEvents.get(eventListView.getSelectionModel().getSelectedItem()).forEach(event -> { pushedEvents.add(event); }); }); sendButton.setOnAction(e -> { pushedEvents.forEach(eventManager::sendEvent); pushedEvents.clear(); }); header.getChildren().addAll(pushButton, sendButton); eventListView.setCellFactory((l) -> new ComboBoxListCell<EClass>(new StringConverter<EClass>() { @Override public String toString(EClass object) { return object.getName(); } @Override public EClass fromString(String string) { return null; } })); eventListView.getSelectionModel().selectedItemProperty().addListener((c, o, n) -> { scrollPane.setContent(eventTypeToEventTableView.get(n)); }); final VBox leftPanel = new VBox(); leftPanel.getChildren().addAll(eventListView, pushedEventListView); borderPane.setTop(header); borderPane.setLeft(leftPanel); borderPane.setCenter(scrollPane); scrollPane.setFitToWidth(true); scrollPane.setBorder(Border.EMPTY); scrollPane.minHeightProperty().bind(leftPanel.heightProperty()); scrollPane.maxHeightProperty().bind(leftPanel.heightProperty()); final ListChangeListener<EClass> eventTypesChangeListener = c -> { while (c.next()) { c.getRemoved().stream().forEach(e -> { eventTypeToEventTableView.remove(e); eventTypeToSelectedEvents.remove(e); }); c.getAddedSubList().stream().forEach(e -> { final EventTableView tableView = new EventTableView(e, executedModel, eventManager); eventTypeToEventTableView.put(e, tableView); final List<EObject> selectedEvents = new ArrayList<>(); eventTypeToSelectedEvents.put(e, selectedEvents); final ListChangeListener<EObject> selectedEventsChangeListener = c1 -> { while (c1.next()) { selectedEvents.removeAll(c1.getRemoved()); selectedEvents.addAll(c1.getAddedSubList()); } }; tableView.getSelectionModel().getSelectedItems().addListener(selectedEventsChangeListener); tableView.refreshEvents(); tableView.minHeightProperty().bind(scrollPane.heightProperty().subtract(2)); }); } }; eventList.addListener(eventTypesChangeListener); }