List of usage examples for javafx.util Callback Callback
Callback
From source file:org.pdfsam.ui.io.PdfVersionCombo.java
public PdfVersionCombo(String ownerModule) { this.ownerModule = ownerModule; Arrays.stream(PdfVersion.values()).filter(v -> v.getVersion() > 2).map(PdfVersionComboItem::new) .forEach(unfilteredItems::add); setCellFactory(new Callback<ListView<PdfVersionComboItem>, ListCell<PdfVersionComboItem>>() { @Override/*from w w w . jav a2s. c o m*/ public ListCell<PdfVersionComboItem> call(ListView<PdfVersionComboItem> p) { ListCell<PdfVersionComboItem> cell = new ListCell<PdfVersionComboItem>() { @Override protected void updateItem(PdfVersionComboItem item, boolean bln) { super.updateItem(item, bln); if (item != null) { setText(item.toString()); if (item.sourceVersion) { setTooltip(new Tooltip( DefaultI18nContext.getInstance().i18n("Same as the input document"))); } } } }; return cell; } }); versionsFilter.requiredProperty().addListener((observable, oldVal, newVal) -> { PdfVersionComboItem selected = getSelectionModel().getSelectedItem(); setItems(unfilteredItems.filtered(t -> t.isHigherOrEqual(newVal.intValue()))); int selecedIndex = getItems().indexOf(selected); if (selecedIndex != -1) { getSelectionModel().select(selecedIndex); } else { getSelectionModel().selectLast(); } }); versionsFilter.addFilter(-1); getSelectionModel().selectLast(); eventStudio().addAnnotatedListeners(this); }
From source file:org.pdfsam.ui.selection.multiple.LoadingStatusColumn.java
@Override public Callback<TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus>, TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus>> cellFactory() { return new Callback<TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus>, TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus>>() { public TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus> call( TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> param) { return new LoadingStatusTableCell(); }// ww w .ja v a 2 s. co m }; }
From source file:org.pdfsam.ui.selection.multiple.PageRangesColumn.java
@Override public Callback<TableColumn<SelectionTableRowData, String>, TableCell<SelectionTableRowData, String>> cellFactory() { return new Callback<TableColumn<SelectionTableRowData, String>, TableCell<SelectionTableRowData, String>>() { @Override//from www .j a v a 2 s.c o m public TableCell<SelectionTableRowData, String> call(TableColumn<SelectionTableRowData, String> param) { return new TooltippedTextFieldTableCell(tooltipMessage); } }; }
From source file:retsys.client.controller.ItemController.java
/** * Initializes the controller class./* ww w. j av a 2 s.c om*/ */ @Override public void initialize(URL url, ResourceBundle rb) { //Begin // TextFields.bindAutoCompletion(name, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Client>>() AutoCompletionBinding<Item> txt_name = TextFields.bindAutoCompletion(name, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Item>>() { @Override public Collection<Item> call(AutoCompletionBinding.ISuggestionRequest param) { List<Item> list = null; HttpHelper helper = new HttpHelper(); try { LovHandler lovHandler = new LovHandler("items", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Item>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Item>>() { }); } catch (IOException ex) { Logger.getLogger(ItemController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Item>() { @Override public String toString(Item object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Item fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); //event handler for setting other Client fields with values from selected Client object //fires after autocompletion txt_name.setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<Item>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<Item> event) { Item item = event.getCompletion(); //fill other item related fields id.setText(splitId(name.getText()) + ""); name.setText(item.getName()); rate.setText(item.getRate() + ""); brand.setText(item.getBrand()); color.setText(item.getColor()); unit.setText(item.getUnit()); size.setText(item.getSize()); billno.setText(item.getBillno()); Site.setText(item.getSite()); remarks.setText(item.getRemarks()); quantity.setText(item.getQuantity() + ""); unit.setText(item.getUnit()); transport_mode.setText(item.getTransportmode()); transport_charges.setText(item.getTransportcharge() + ""); supervisor.setText(item.getSupervisor()); vendor.setText(item.getVendor().getName() + " (ID:" + item.getVendor().getId() + ")"); godown_name.setText(item.getGodownName()); location1.setText(item.getLocation1()); minReorder.setText(item.getMinReorder()); product.setText(item.getProduct().getName() + " (ID:" + item.getProduct().getId() + ")"); discountPercentage.setText(item.getDiscountPercentage() + ""); populateAuditValues(item); } }); //Ends TextFields.bindAutoCompletion(vendor, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Vendor>>() { @Override public Collection<Vendor> call(AutoCompletionBinding.ISuggestionRequest param) { List<Vendor> list = null; try { LovHandler lovHandler = new LovHandler("vendors", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Vendor>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Vendor>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Vendor>() { @Override public String toString(Vendor object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Vendor fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); //Project query TextFields.bindAutoCompletion(Site, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Project>>() { @Override public Collection<Project> call(AutoCompletionBinding.ISuggestionRequest param) { List<Project> list = null; try { LovHandler lovHandler = new LovHandler("projects", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Project>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Project>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Project>() { @Override public String toString(Project object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Project fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); //} // //} // product query TextFields.bindAutoCompletion(product, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Product>>() { @Override public Collection<Product> call(AutoCompletionBinding.ISuggestionRequest param) { List<Product> list = null; try { LovHandler lovHandler = new LovHandler("products", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Product>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Product>>() { }); } catch (IOException ex) { Logger.getLogger(ProductController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Product>() { @Override public String toString(Product object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Product fromString(String string) { throw new UnsupportedOperationException("Not supported yet."); } }); }
From source file:org.pdfsam.ui.selection.multiple.LoadingColumn.java
@Override public Callback<TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus>, TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus>> cellFactory() { return new Callback<TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus>, TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus>>() { public TableCell<SelectionTableRowData, PdfDescriptorLoadingStatus> call( TableColumn<SelectionTableRowData, PdfDescriptorLoadingStatus> param) { return new LoadingStatusCell(); }// w w w . ja va 2 s.co m }; }
From source file:Main.java
@Override public void start(Stage stage) { VBox box = new VBox(); Scene scene = new Scene(box, 200, 200); stage.setScene(scene);//from w w w . ja v a2 s . c om stage.setTitle("ListViewSample"); box.getChildren().addAll(list, label); VBox.setVgrow(list, Priority.ALWAYS); label.setLayoutX(10); label.setLayoutY(115); label.setFont(Font.font("Verdana", 20)); list.setItems(data); list.setCellFactory(new Callback<ListView<String>, ListCell<String>>() { @Override public ListCell<String> call(ListView<String> list) { return new ColorRectCell(); } }); list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> ov, String old_val, String new_val) { label.setText(new_val); label.setTextFill(Color.web(new_val)); } }); stage.show(); }
From source file:Person.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle(""); Group root = new Group(); Scene scene = new Scene(root, 500, 250, Color.WHITE); // create a grid pane GridPane gridpane = new GridPane(); gridpane.setPadding(new Insets(5)); gridpane.setHgap(10);/*from w w w .j av a2 s . c o m*/ gridpane.setVgap(10); ObservableList<Person> leaders = FXCollections.observableArrayList(); leaders.add(new Person("A", "B", "C")); leaders.add(new Person("D", "E", "F")); final ListView<Person> leaderListView = new ListView<Person>(leaders); leaderListView.setPrefWidth(150); leaderListView.setPrefHeight(150); // leaderListView.setCellFactory(new Callback<ListView<Person>, ListCell<Person>>() { public ListCell<Person> call(ListView<Person> param) { final Label leadLbl = new Label(); final Tooltip tooltip = new Tooltip(); final ListCell<Person> cell = new ListCell<Person>() { @Override public void updateItem(Person item, boolean empty) { super.updateItem(item, empty); if (item != null) { leadLbl.setText(item.getAliasName()); setText(item.getFirstName() + " " + item.getLastName()); tooltip.setText(item.getAliasName()); setTooltip(tooltip); } } }; // ListCell return cell; } }); // setCellFactory gridpane.add(leaderListView, 0, 1); leaderListView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Person>() { public void changed(ObservableValue<? extends Person> observable, Person oldValue, Person newValue) { System.out.println("selection changed"); } }); root.getChildren().add(gridpane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("java-buddy.blogspot.com"); tableView.setEditable(true);//from w ww.j a v a2s .c o m Callback<TableColumn, TableCell> cellFactory = new Callback<TableColumn, TableCell>() { @Override public TableCell call(TableColumn p) { return new EditingCell(); } }; btnNew.setOnAction(btnNewHandler); //init table //Un-editable column of "id" TableColumn col_id = new TableColumn("ID"); tableView.getColumns().add(col_id); col_id.setCellValueFactory(new PropertyValueFactory<Record, String>("id")); //Editable columns for (int i = 0; i < Day.length; i++) { TableColumn col = new TableColumn(Day[i]); col.setCellValueFactory(new PropertyValueFactory<Record, String>("value_" + String.valueOf(i))); tableView.getColumns().add(col); col.setCellFactory(cellFactory); } tableView.setItems(data); Group root = new Group(); VBox vBox = new VBox(); vBox.setSpacing(10); vBox.getChildren().addAll(btnNew, tableView); root.getChildren().add(vBox); primaryStage.setScene(new Scene(root, 500, 400)); primaryStage.show(); }
From source file:eu.ggnet.dwoss.receipt.shipment.ShipmentUpdateStage.java
private void init(Shipment s) { okButton.setOnAction((ActionEvent event) -> { shipment = getShipment();/*from ww w .j a va2s . c o m*/ if (isValid()) close(); }); cancelButton.setOnAction((ActionEvent event) -> { close(); }); idField = new TextField(Long.toString(s.getId())); idField.setDisable(true); shipIdField = new TextField(s.getShipmentId()); Callback<ListView<TradeName>, ListCell<TradeName>> cb = new Callback<ListView<TradeName>, ListCell<TradeName>>() { @Override public ListCell<TradeName> call(ListView<TradeName> param) { return new ListCell<TradeName>() { @Override protected void updateItem(TradeName item, boolean empty) { super.updateItem(item, empty); if (item == null || empty) setText("Hersteller whlen..."); else setText(item.getName()); } }; } }; Set<TradeName> contractors = Client.lookup(MandatorSupporter.class).loadContractors().all(); ownerBox = new ComboBox<>(FXCollections.observableArrayList(contractors)); ownerBox.setMaxWidth(MAX_VALUE); ownerBox.setCellFactory(cb); ownerBox.getSelectionModel().selectedItemProperty().addListener( (ObservableValue<? extends TradeName> observable, TradeName oldValue, TradeName newValue) -> { if (newValue == null) return; shipment.setContractor(newValue); manufacturerBox.getSelectionModel().select(newValue.getManufacturer()); }); ObservableList<TradeName> manufacturers = FXCollections.observableArrayList(TradeName.getManufacturers()); manufacturerBox = new ComboBox<>(manufacturers); manufacturerBox.setMaxWidth(MAX_VALUE); manufacturerBox.setCellFactory(cb); SingleSelectionModel<TradeName> sm = ownerBox.getSelectionModel(); if (s.getContractor() == null) sm.selectFirst(); else sm.select(s.getContractor()); if (shipment.getDefaultManufacturer() != null) manufacturerBox.getSelectionModel().select(shipment.getDefaultManufacturer()); statusBox = new ComboBox<>(FXCollections.observableArrayList(Shipment.Status.values())); statusBox.setMaxWidth(MAX_VALUE); statusBox.getSelectionModel().select(s.getStatus() == null ? OPENED : s.getStatus()); GridPane grid = new GridPane(); grid.addRow(1, new Label("ID:"), idField); grid.addRow(2, new Label("Shipment ID:"), shipIdField); grid.addRow(3, new Label("Besitzer:"), ownerBox); grid.addRow(4, new Label("Hersteller:"), manufacturerBox); grid.addRow(5, new Label("Status"), statusBox); grid.setMaxWidth(MAX_VALUE); grid.vgapProperty().set(2.); grid.getColumnConstraints().add(0, new ColumnConstraints(100, 100, Double.MAX_VALUE, Priority.SOMETIMES, HPos.LEFT, false)); grid.getColumnConstraints().add(1, new ColumnConstraints(100, 150, Double.MAX_VALUE, Priority.ALWAYS, HPos.LEFT, true)); HBox hButtonBox = new HBox(okButton, cancelButton); hButtonBox.alignmentProperty().set(Pos.TOP_RIGHT); errorLabel.setWrapText(true); BorderPane rootPane = new BorderPane(grid, errorLabel, null, hButtonBox, null); this.setTitle(s.getId() > 0 ? "Shipment bearbeiten" : "Shipment anlegen"); this.setScene(new Scene(rootPane)); this.setResizable(false); }
From source file:com.loop81.fxcomparer.FXComparerController.java
/** * Initiate the table by setting the correct width of the columns and adding a custom value-factory for the * size column. //from ww w . j a v a2 s .co m */ private void initiateTable() { columnName.prefWidthProperty().bind(compareTable.widthProperty().divide(5).multiply(3)); columnName.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ComparisonEntry, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<ComparisonEntry, String> cell) { return new SimpleStringProperty(cell.getValue().getOriginalEntry().getEntryName()); } }); columnState.prefWidthProperty().bind(compareTable.widthProperty().divide(5)); columnState.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ComparisonEntry, String>, ObservableValue<String>>() { @Override public ObservableValue<String> call(CellDataFeatures<ComparisonEntry, String> cell) { return new SimpleObjectProperty<>(MessageBundle.getString( "result.state." + cell.getValue().getChangeState().toString().toLowerCase())); } }); columnChange.prefWidthProperty().bind(compareTable.widthProperty().divide(5)); columnChange.setCellValueFactory( new Callback<TableColumn.CellDataFeatures<ComparisonEntry, ChangeWrapper>, ObservableValue<ChangeWrapper>>() { @Override public ObservableValue<ChangeWrapper> call( CellDataFeatures<ComparisonEntry, ChangeWrapper> cell) { long sizeChange = cell.getValue().getSizeChange(); if (sizeChange == 0) { return new SimpleObjectProperty<ChangeWrapper>(new ChangeWrapper()); } else if (sizeChange == Long.MIN_VALUE) { return new SimpleObjectProperty<ChangeWrapper>( new ChangeWrapper(MessageBundle.getString("general.not_avalible"), 0)); } else { return new SimpleObjectProperty<ChangeWrapper>( new ChangeWrapper(convertdifferenceToReadableString(sizeChange), sizeChange)); } } }); columnChange.setComparator(new Comparator<ChangeWrapper>() { @Override public int compare(ChangeWrapper wrapper1, ChangeWrapper wrapper2) { return wrapper1.compareTo(wrapper2); } }); }