List of usage examples for javafx.beans.binding Bindings when
public static When when(final ObservableBooleanValue condition)
From source file:com.properned.application.SystemController.java
public void initialize() { logger.info("Initialize System controller"); localeButton.disableProperty().bind(multiLanguageProperties.isLoadedProperty().not()); saveButton.disableProperty().bind(multiLanguageProperties.isDirtyProperty().not() .or(multiLanguageProperties.isLoadedProperty().not())); Stage primaryStage = Properned.getInstance().getPrimaryStage(); primaryStage.titleProperty()/* ww w . j ava2 s . c om*/ .bind(multiLanguageProperties.baseNameProperty() .concat(Bindings.when(multiLanguageProperties.isLoadedProperty()) .then(new SimpleStringProperty(" (") .concat(multiLanguageProperties.parentDirectoryPathProperty()).concat(")")) .otherwise("")) .concat(Bindings.when(multiLanguageProperties.isDirtyProperty()).then(" *").otherwise(""))); FilteredList<String> filteredList = new FilteredList<>(multiLanguageProperties.getListMessageKey(), new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); SortedList<String> sortedList = new SortedList<>(filteredList, new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); messageKeyList.setItems(sortedList); filterText.textProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { // Filter the list filteredList.setPredicate(new Predicate<String>() { @Override public boolean test(String t) { String filter = filterText.getText(); if (filter == null || filter.equals("")) { return true; } return t.contains(filter); } }); // check the add button disabled status if (isKeyCanBeAdded(newValue)) { addButton.setDisable(false); } else { addButton.setDisable(true); } } }); ChangeListener<String> changeMessageListener = new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { logger.info("Message key selection changed : " + newValue); valueList.setItems(FXCollections.observableArrayList()); valueList.setItems(FXCollections .observableArrayList(multiLanguageProperties.getMapPropertiesByLocale().keySet())); } }; messageKeyList.getSelectionModel().selectedItemProperty().addListener(changeMessageListener); messageKeyList.setCellFactory(c -> new MessageKeyListCell(multiLanguageProperties)); valueList.setCellFactory(c -> new ValueListCell(multiLanguageProperties, messageKeyList)); filterText.setOnKeyReleased(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent event) { if (event.getCode() == KeyCode.DOWN) { messageKeyList.requestFocus(); event.consume(); } else if (event.getCode() == KeyCode.ENTER) { addKey(); event.consume(); } } }); }
From source file:com.wineshop.client.Home.java
@Override public void initialize(URL url, ResourceBundle bundle) { // Setup of the table view vineyards.setSortAdapter(new TableViewSortAdapter<Vineyard>(tableVineyards, Vineyard.class)); vineyards.getFilter().nameProperty().bindBidirectional(fieldSearch.textProperty()); // Setup of the creation/edit form labelFormVineyard.textProperty()//from ww w . j av a2 s . c o m .bind(Bindings.when(vineyard.savedProperty()).then("Edit vineyard").otherwise("Create vineyard")); vineyard.instanceProperty().addListener(new ChangeListener<Vineyard>() { @Override public void changed(ObservableValue<? extends Vineyard> observable, Vineyard oldValue, Vineyard newValue) { if (oldValue != null) { fieldName.textProperty().unbindBidirectional(oldValue.nameProperty()); fieldAddress.textProperty().unbindBidirectional(oldValue.getAddress().addressProperty()); listWines.setItems(null); } if (newValue != null) { fieldName.textProperty().bindBidirectional(newValue.nameProperty()); fieldAddress.textProperty().bindBidirectional(newValue.getAddress().addressProperty()); listWines.setItems(newValue.getWines()); } } }); // Define the cell factory for the list of wines listWines.setCellFactory(new Callback<ListView<Wine>, ListCell<Wine>>() { public ListCell<Wine> call(ListView<Wine> listView) { return new WineListCell(); } }); buttonDelete.visibleProperty().bind(vineyard.savedProperty()); buttonDelete.disableProperty().bind(Bindings.not(identity.ifAllGranted("ROLE_ADMIN"))); buttonSave.disableProperty().bind(Bindings.not(vineyard.dirtyProperty())); buttonCancel.disableProperty() .bind(Bindings.not(Bindings.or(vineyard.savedProperty(), vineyard.dirtyProperty()))); // Link the table selection and the entity instance in the form select(null); tableVineyards.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Vineyard>() { @Override public void changed(ObservableValue<? extends Vineyard> property, Vineyard oldSelection, Vineyard newSelection) { select(newSelection); } }); formVineyard.addEventHandler(ValidationResultEvent.INVALID, new EventHandler<ValidationResultEvent>() { @Override public void handle(ValidationResultEvent event) { ((Node) event.getTarget()).setStyle("-fx-border-color: red"); if (event.getTarget() instanceof TextInputControl && event.getErrorResults() != null && event.getErrorResults().size() > 0) { Tooltip tooltip = new Tooltip(event.getErrorResults().get(0).getMessage()); tooltip.setAutoHide(true); ((TextInputControl) event.getTarget()).setTooltip(tooltip); } } }); formVineyard.addEventHandler(ValidationResultEvent.VALID, new EventHandler<ValidationResultEvent>() { @Override public void handle(ValidationResultEvent event) { ((Node) event.getTarget()).setStyle("-fx-border-color: null"); if (event.getTarget() instanceof TextInputControl) { Tooltip tooltip = ((TextInputControl) event.getTarget()).getTooltip(); if (tooltip != null && tooltip.isActivated()) tooltip.hide(); ((TextInputControl) event.getTarget()).setTooltip(null); } } }); }
From source file:ca.wumbo.doommanager.client.controller.file.DoomFileController.java
@FXML private void initialize() { // Keep the left window the same size when resizing/maximizing. SplitPane.setResizableWithParent(leftBorderPane, false); // Allow selection of multiple cells. entryTreeTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); // Make the cells update accordingly. nameColumn.setCellValueFactory(cellData -> cellData.getValue().getValue().entryProperty()); sizeColumn.setCellValueFactory(cellData -> cellData.getValue().getValue().dataLengthStringProperty()); typeColumn.setCellValueFactory(cellData -> cellData.getValue().getValue().entryTypeProperty()); // Resize the splitter to a reasonable position. // Since we can't use Platform.runlater() to do this, we have to use a listener that removes itself. // Note: The old way it was done was to pass the tabPane's width to the function after this is initialized. InvalidationListener invalidationListener = new InvalidationListener() { @Override//from w w w . j ava2 s. c o m public void invalidated(Observable observable) { setSplitterPosition((int) splitPane.getWidth()); splitPane.widthProperty().removeListener(this); // Remove itself after the size is set. } }; splitPane.widthProperty().addListener(invalidationListener); // Handle item selection. This will clean up our GUI and add/remove panes on the right of the splitter. entryTreeTable.getSelectionModel().selectedItemProperty().addListener((obsValue, oldValue, newValue) -> { updateGUIFromEntrySelection(oldValue, newValue); }); // Support right clicking menus on the rows, source: https://gist.github.com/james-d/7758918 entryTreeTable.setRowFactory(new Callback<TreeTableView<Entry>, TreeTableRow<Entry>>() { @Override public TreeTableRow<Entry> call(TreeTableView<Entry> tableView) { // Create the row to return. TreeTableRow<Entry> row = new TreeTableRow<>(); ContextMenu contextMenu = new ContextMenu(); // Whenever this row gets a new item (or is updated), rebuild the right click menu. row.itemProperty().addListener((observableValue, oldValue, newValue) -> { // TODO - Dynamically generate a new context menu - contextMenu.getItems().add(new MenuItem()); }); // Set context menu on row, but use a binding to make it only show for non-empty rows: row.contextMenuProperty() .bind(Bindings.when(row.emptyProperty()).then((ContextMenu) null).otherwise(contextMenu)); return row; } }); // Instead of assigning graphics to each node, only do it for the cells. // This should help reduce object creation by having it only required for the visible rows. nameColumn.setCellFactory(new Callback<TreeTableColumn<Entry, Entry>, TreeTableCell<Entry, Entry>>() { @Override public TreeTableCell<Entry, Entry> call(TreeTableColumn<Entry, Entry> param) { return new TreeTableCell<Entry, Entry>() { @Override protected void updateItem(Entry item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { setText(item.getName()); Image img = resources.getImage(item.getClass().getSimpleName().toLowerCase()); setGraphic(new ImageView(img)); } else { setText(null); setGraphic(null); } } }; } }); }
From source file:dtv.controller.FXMLMainController.java
public void init(ObservableList<DVBChannel> serviceData, TableView<DVBChannel> table, TableColumn<DVBChannel, Integer> idx, TableColumn<DVBChannel, String> name, TableColumn<DVBChannel, String> type, TableColumn<DVBChannel, String> ppr) { table.setEditable(true);//w w w.j a v a 2s. c o m idx.setCellValueFactory(cellData -> cellData.getValue().idxProperty().asObject()); name.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); name.setEditable(true); type.setCellValueFactory(cellData -> cellData.getValue().typeProperty()); // nid.setCellValueFactory(cellData -> cellData.getValue().nidProperty().asObject()); ppr.setCellValueFactory(cellData -> cellData.getValue().pprProperty()); // newCol.setCellValueFactory(cellData -> cellData.getValue().neewProperty()); // Context menu table.setRowFactory(tableView -> { final TableRow<DVBChannel> row = new TableRow<>(); final ContextMenu rowMenu = new ContextMenu(); final MenuItem removeItem = new MenuItem("Delete"); removeItem.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { final DVBChannel service = row.getItem(); serviceData.removeAll(service); } }); rowMenu.getItems().addAll(removeItem); row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty())).then(rowMenu) .otherwise((ContextMenu) null)); return row; }); ppr.setCellFactory(col -> { final TableCell<DVBChannel, String> cell = new TableCell<>(); cell.textProperty().bind(cell.itemProperty()); cell.itemProperty().addListener((obs, oldValue, newValue) -> { if (newValue != null) { final ContextMenu cellMenu = new ContextMenu(); for (String pref : Utils.prefTab) { final CheckMenuItem prefMenuItem = new CheckMenuItem(pref); if (Utils.isPreferenceOn(cell.getText(), pref)) { prefMenuItem.setSelected(true); } prefMenuItem.selectedProperty().addListener((obs1, old_val, new_val) -> { final String new_ppr; final DVBChannel service = (DVBChannel) cell.getTableRow().getItem(); if (new_val) { new_ppr = Utils.add_ppr(cell.getText(), pref); } else { new_ppr = Utils.remove_ppr(cell.getText(), pref); } service.setPpr(new_ppr); service.setModified(true); }); cellMenu.getItems().add(prefMenuItem); cell.setContextMenu(cellMenu); } } else { cell.setContextMenu(null); } }); return cell; }); // Editable service name name.setCellFactory(p -> new EditingCell()); name.setOnEditCommit(t -> { final DVBChannel service = t.getTableView().getItems().get(t.getTablePosition().getRow()); service.setName(t.getNewValue()); service.setModified(true); }); }
From source file:acmi.l2.clientmod.l2smr.Controller.java
@Override public void initialize(URL url, ResourceBundle resourceBundle) { stageProperty().addListener(observable -> initializeKeyCombinations()); this.l2Path.textProperty().bind( Bindings.when(l2DirProperty().isNotNull()).then(Bindings.convert(l2DirProperty())).otherwise("")); initializeUnr();//w ww . j av a2s . c o m initializeUsx(); this.filterPane.setExpanded(false); this.filterPane.setDisable(true); this.smaPane.setDisable(true); table.itemsProperty().bind(Bindings.createObjectBinding(() -> { if (actors.get() == null) return FXCollections.emptyObservableList(); return FXCollections .observableArrayList( actors.get().stream() .filter(actor -> !rotatable.isSelected() || actor.getRotation() != null) .filter(actor -> !scalable.isSelected() || actor.getScale() != null || actor.getScale3D() != null) .filter(actor -> !rotating.isSelected() || actor.getRotationRate() != null) .filter(actor -> filterStaticMesh.getText() == null || filterStaticMesh.getText().isEmpty() || actor.getStaticMesh().toLowerCase() .contains(filterStaticMesh.getText().toLowerCase())) .filter(actor -> { Double x = getDoubleOrClearTextField(filterX); Double y = getDoubleOrClearTextField(filterY); Double z = getDoubleOrClearTextField(filterZ); Double range = getDoubleOrClearTextField(filterRange); return range == null || range(actor.getLocation(), x, y, z) < range; }).collect(Collectors.toList())); }, actors, filterStaticMesh.textProperty(), filterX.textProperty(), filterY.textProperty(), filterZ.textProperty(), filterRange.textProperty(), rotatable.selectedProperty(), scalable.selectedProperty(), rotating.selectedProperty())); }
From source file:sonicScream.controllers.CategoryTabController.java
public CategoryTabController(Category category) { URL location = getClass().getResource("/sonicScream/views/CategoryTab.fxml"); FXMLLoader loader = new FXMLLoader(location); loader.setRoot(this); loader.setController(this); try {//from w w w .j a v a2 s . c o m loader.load(); } catch (IOException ex) { throw new RuntimeException(ex); } _category = category; this.textProperty().bind(_category.categoryNameProperty()); CategoryTabComboBox.setItems(_category.getCategoryScripts()); //These two bindings handle changing between categories with only a single //script (items) and those with multiple (everything else) SimpleListProperty bindableList = new SimpleListProperty(); bindableList.bind(new SimpleObjectProperty<>(_category.getCategoryScripts())); CategoryTabComboBox.visibleProperty().bind(Bindings.greaterThan(bindableList.sizeProperty(), 1)); selectedScriptNodeProperty().bind(CategoryTabTreeView.getSelectionModel().selectedItemProperty()); selectedScript.bind(CategoryTabComboBox.getSelectionModel().selectedItemProperty()); if (_category.getCategoryScripts() != null && !_category.getCategoryScripts().isEmpty()) { CategoryTabComboBox.valueProperty().set(_category.getCategoryScripts().get(0)); handleComboBoxChanged(null); } SwapDisplayModeButton.textProperty().bind(Bindings.when(displayMode.isEqualTo(CategoryDisplayMode.SIMPLE)) .then("Advanced >>").otherwise("<< Simple")); CategoryTabTreeView.getSelectionModel().selectedItemProperty() .addListener((observable, oldValue, newValue) -> { if (newValue != null) { TreeItem<String> scriptValue = TreeUtils.getRootMinusOne((TreeItem<String>) newValue); TreeItem<String> selectedValue = (TreeItem<String>) newValue; CategoryTabScriptValueLabel.setText(scriptValue.getValue()); selectedScriptNodeIsLeaf.set(selectedValue.isLeaf()); } }); }