Search in sources :

Example 1 with Prices

use of eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices in project dwoss by gg-net.

the class MyDoubleStringConverter method accept.

@Override
public void accept(Product product) {
    this.pfx.setId(product.getId());
    this.pfx.setOptLock(product.getOptLock());
    this.pfx.setName(product.getName());
    this.pfx.setDescription(product.getDescription());
    this.pfx.setGtin(product.getGtin());
    this.pfx.setImageId(product.getImageId());
    this.pfx.setPartNo(product.getPartNo());
    if (product.getEol() == null) {
        pfx.setEol(null);
    } else {
        this.pfx.setEol(product.getEol().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
    }
    this.pfx.setTradeName(product.getTradeName());
    if (product.getSalesChannel() != null) {
        this.pfx.setSalesChannel(product.getSalesChannel());
    } else {
        this.pfx.setSalesChannel(SalesChannel.UNKNOWN);
    }
    this.pfx.setProductGroup(product.getGroup());
    // product.getAdditionalPartNos().forEach((t, u) -> this.pfx.getAdditionalPartNos().add(new AdditionalPartNo(t, u)));
    this.pfx.getAdditionalPartNos().addAll(product.getAdditionalPartNos().entrySet().stream().map(e -> new AdditionalPartNo(e.getKey(), e.getValue())).collect(Collectors.toList()));
    product.getPrices().forEach((PriceType pT, Double price) -> {
        Prices pr = new Prices();
        pr.setPrice(price);
        pr.setPriceType(pT);
        this.pfx.getPrices().add(pr);
    });
}
Also used : Prices(eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices) AdditionalPartNo(eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.AdditionalPartNo) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)

Example 2 with Prices

use of eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices in project dwoss by gg-net.

the class MyDoubleStringConverter method handlePriceTableSubmitButtonAction.

@FXML
private void handlePriceTableSubmitButtonAction(ActionEvent event) {
    String s = priceTableTextField.getText();
    final PriceType selectedPriceType = priceTableComboBox.getValue();
    if (priceTable.getItems().stream().map(Prices::getPriceType).anyMatch((t) -> t == selectedPriceType)) {
        Ui.exec(() -> {
            Ui.build(priceTableSubmitButton).alert().title("Fehler!").message("Hinzufügen des Preistyps nicht möglich").nl("Der Preistyp ist bereits gesetzt.").show(AlertType.ERROR);
        });
        return;
    }
    if (priceTableComboBox.getSelectionModel().isEmpty()) {
        Ui.exec(() -> {
            Ui.build(priceTableSubmitButton).alert().title("Fehler!").message("Hinzufügen des Preistyps nicht möglich").nl("Kein Preistyp ausgewählt.").show(AlertType.ERROR);
        });
        return;
    }
    Pattern pattern = Pattern.compile("[-+]?[0-9]*(\\.|,)?[0-9]+([eE][-+]?[0-9]+)?");
    Matcher m = pattern.matcher(s);
    if (!m.matches()) {
        Ui.exec(() -> {
            Ui.build(priceTableSubmitButton).alert().title("Fehler!").message("Hinzufügen des Preistyps nicht möglich").nl("Die Preisangabe entspricht keiner gültigen Zahl").show(AlertType.ERROR);
        });
        return;
    }
    s = s.replace(",", ".");
    Prices p = new Prices();
    p.setPriceType(priceTableComboBox.getValue());
    p.setPrice(Double.valueOf(s));
    pfx.getPrices().add(p);
}
Also used : Pattern(java.util.regex.Pattern) Prices(eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices) Matcher(java.util.regex.Matcher) PriceType(eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType) FXML(javafx.fxml.FXML)

Example 3 with Prices

use of eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices in project dwoss by gg-net.

the class MyDoubleStringConverter method initialize.

/**
 * Initializes the controller class.
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    fillTableComboBoxes();
    additionalPartNoTable.setItems(pfx.getAdditionalPartNos());
    priceTable.setItems(pfx.getPrices());
    additionalPartNoTable.setEditable(true);
    priceTable.setEditable(true);
    tradeNameColumn.setCellValueFactory(new PropertyValueFactory<>("contractor"));
    partNoColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    partNoColumn.setCellValueFactory(new PropertyValueFactory<>("partNo"));
    partNoColumn.setOnEditCommit(new EventHandler<TableColumn.CellEditEvent<AdditionalPartNo, String>>() {

        @Override
        public void handle(TableColumn.CellEditEvent<AdditionalPartNo, String> e) {
            ((AdditionalPartNo) e.getTableView().getItems().get(e.getTablePosition().getRow())).setPartNo(e.getNewValue());
        }
    });
    partNoColumn.setEditable(true);
    priceTypeColumn.setCellValueFactory(new PropertyValueFactory<>("priceType"));
    priceDoubleColumn.setCellValueFactory(new PropertyValueFactory<>("price"));
    // see CustomTableCell documentation
    // this is necessary if we want an editable Double Column representing a FXProperty
    // priceDoubleColumn.setCellFactory(CustomTableCell.forTableColumn(new DoubleStringConverter()));
    priceDoubleColumn.setEditable(true);
    priceDoubleColumn.setCellFactory(TextFieldTableCell.<Prices, Double>forTableColumn(new MyDoubleStringConverter()));
    priceDoubleColumn.setOnEditCommit(event -> {
        final Double value = event.getNewValue() != null ? event.getNewValue() : event.getOldValue();
        ((Prices) event.getTableView().getItems().get(event.getTablePosition().getRow())).setPrice(value);
        event.getTableView().refresh();
    });
    pfx.nameProperty().bindBidirectional(nameTextArea.textProperty());
    pfx.descriptionProperty().bindBidirectional(descriptionTextArea.textProperty());
    pfx.partNoProperty().bindBidirectional(partNoTextField.textProperty());
    pfx.eolProperty().bindBidirectional(eolDatePicker.valueProperty());
    imageIdTextField.textProperty().bindBidirectional(pfx.imageIdProperty(), new NumberStringConverter());
    gtinTextField.textProperty().bindBidirectional(pfx.gtinProperty(), new NumberStringConverter());
    pfx.tradeNameProperty().bindBidirectional(tradeNameComboBox.valueProperty());
    pfx.productGroupProperty().bindBidirectional(productGroupComboBox.valueProperty());
    pfx.salesChannelProperty().bindBidirectional(salesChannelComboBox.valueProperty());
    // Defaults
    pfx.setProductGroup(ProductGroup.values()[0]);
    pfx.setSalesChannel(SalesChannel.UNKNOWN);
    pfx.setTradeName(TradeName.values()[0]);
}
Also used : Prices(eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices) NumberStringConverter(javafx.util.converter.NumberStringConverter) AdditionalPartNo(eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.AdditionalPartNo)

Aggregations

Prices (eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.Prices)3 PriceType (eu.ggnet.dwoss.uniqueunit.ee.entity.PriceType)2 AdditionalPartNo (eu.ggnet.dwoss.uniqueunit.ui.product.ProductFx.AdditionalPartNo)2 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 FXML (javafx.fxml.FXML)1 NumberStringConverter (javafx.util.converter.NumberStringConverter)1