Search in sources :

Example 1 with IntegerStringConverter

use of javafx.util.converter.IntegerStringConverter in project dwoss by gg-net.

the class CompanyUpdateController method initialize.

/**
 * Initializes the controller class.
 *
 * @param url
 * @param rb
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    // button behavior
    delAddressButton.disableProperty().bind(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0));
    delComButton.disableProperty().bind(communicationTableView.getSelectionModel().selectedIndexProperty().lessThan(0));
    delContactButton.disableProperty().bind(contactListView.getSelectionModel().selectedIndexProperty().lessThan(0));
    // get overwriten in accept()
    companyNameTextField.setText("");
    addressListView.setItems(addressList);
    // enable the save and "saveAndClose" button only on filled TextFields
    saveButton.disableProperty().bind(Bindings.createBooleanBinding(() -> companyNameTextField.getText().trim().isEmpty(), companyNameTextField.textProperty()).or(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0)));
    saveAndCloseButton.disableProperty().bind(Bindings.createBooleanBinding(() -> companyNameTextField.getText().trim().isEmpty(), companyNameTextField.textProperty()).or(addressListView.getSelectionModel().selectedIndexProperty().lessThan(0)));
    // Address HORIZONTAL CellFactory
    addressListView.setCellFactory((ListView<Address> p) -> {
        ListCell<Address> cell = new ListCell<Address>() {

            @Override
            protected void updateItem(Address item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                    setText("");
                } else {
                    VBox anschriftbox = new VBox();
                    Label street = new Label(item.getStreet());
                    Label zipCode = new Label(item.getZipCode());
                    Label city = new Label(item.getCity());
                    HBox postBox = new HBox();
                    postBox.getChildren().addAll(zipCode, city);
                    postBox.setSpacing(2.0);
                    Label country = new Label(new Locale("", item.getIsoCountry()).getDisplayCountry());
                    anschriftbox.getChildren().addAll(street, postBox, country);
                    anschriftbox.setSpacing(2.0);
                    setText(null);
                    setGraphic(anschriftbox);
                }
            }
        };
        return cell;
    });
    addressListView.setOrientation(Orientation.HORIZONTAL);
    // adding a CellFactory for every Colum
    typeColumn.setCellValueFactory(new PropertyValueFactory<>("type"));
    typeColumn.setCellFactory(column -> {
        return new TableCell<Communication, Type>() {

            @Override
            protected void updateItem(Type item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setText(null);
                } else {
                    setText(item.name());
                    setStyle("-fx-font-weight: bold");
                }
            }
        };
    });
    idColumn.setCellValueFactory(new PropertyValueFactory<>("identifier"));
    idColumn.setCellFactory(column -> {
        return new TableCell<Communication, String>() {

            @Override
            protected void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setText(null);
                } else {
                    setText(item);
                    setStyle("");
                }
            }
        };
    });
    prefColumn.setCellValueFactory(new PropertyValueFactory<>("prefered"));
    prefColumn.setCellFactory(column -> {
        return new TableCell<Communication, Boolean>() {

            @Override
            protected void updateItem(Boolean item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setText(null);
                    setGraphic(null);
                } else {
                    HBox checkHBox = new HBox();
                    RadioButton prefRadioButton = new RadioButton();
                    prefRadioButton.setSelected(item);
                    prefRadioButton.setToggleGroup(prefGroup);
                    checkHBox.getChildren().add(prefRadioButton);
                    checkHBox.setAlignment(Pos.CENTER);
                    setText("");
                    setGraphic(checkHBox);
                }
            }
        };
    });
    // Contact CellFactory
    contactListView.setCellFactory((ListView<Contact> p) -> {
        ListCell<Contact> cell = new ListCell<Contact>() {

            @Override
            protected void updateItem(Contact item, boolean empty) {
                super.updateItem(item, empty);
                if (item == null || empty) {
                    setGraphic(null);
                    setText("");
                } else {
                    String anrede = "";
                    if (item.getSex() == Sex.FEMALE) {
                        anrede = "Frau ";
                    }
                    if (item.getSex() == Sex.MALE) {
                        anrede = "Herr ";
                    }
                    setText(anrede + item.toFullName());
                }
            }
        };
        return cell;
    });
    // force the ledger field to be numeric only, becuase the ledger get saved as an int
    ledgerTextField.textFormatterProperty().set(new TextFormatter<>(new IntegerStringConverter(), 0, change -> {
        String newText = change.getControlNewText();
        if (Pattern.compile("-?((\\d*))").matcher(newText).matches()) {
            return change;
        } else {
            return null;
        }
    }));
}
Also used : Locale(java.util.Locale) Pos(javafx.geometry.Pos) Initializable(javafx.fxml.Initializable) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) javafx.scene.control(javafx.scene.control) URL(java.net.URL) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) Ui(eu.ggnet.saft.Ui) Bindings(javafx.beans.binding.Bindings) AlertType(eu.ggnet.saft.core.ui.AlertType) ResourceBundle(java.util.ResourceBundle) Locale(java.util.Locale) WINDOW_MODAL(javafx.stage.Modality.WINDOW_MODAL) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) Orientation(javafx.geometry.Orientation) HBox(javafx.scene.layout.HBox) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) eu.ggnet.dwoss.customer.ee.entity(eu.ggnet.dwoss.customer.ee.entity) eu.ggnet.saft.api.ui(eu.ggnet.saft.api.ui) Consumer(java.util.function.Consumer) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Pattern(java.util.regex.Pattern) ObservableList(javafx.collections.ObservableList) HBox(javafx.scene.layout.HBox) IntegerStringConverter(javafx.util.converter.IntegerStringConverter) AlertType(eu.ggnet.saft.core.ui.AlertType) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) VBox(javafx.scene.layout.VBox)

Example 2 with IntegerStringConverter

use of javafx.util.converter.IntegerStringConverter in project certmgr by hdecarne.

the class CertOptionsController method setupStage.

@Override
protected void setupStage(Stage stage) {
    stage.getIcons().addAll(PlatformHelper.stageIcons(Images.NEWCERT32, Images.NEWCERT16));
    stage.setTitle(CertOptionsI18N.formatSTR_STAGE_TITLE());
    this.ctlAliasInput.textProperty().addListener((p, o, n) -> onAliasChanged(o, n));
    this.ctlKeyAlgOption.valueProperty().addListener((p, o, n) -> onKeyAlgChanged(n));
    this.ctlKeySizeOption.setConverter(new IntegerStringConverter());
    this.ctlGeneratorOption.valueProperty().addListener((p, o, n) -> onGeneratorChanged(n));
    this.ctlIssuerInput.valueProperty().addListener((p, o, n) -> onIssuerChanged(n));
    this.cmdAddBasicConstraints.disableProperty().bind(this.basicConstraintsExtension.isNotNull());
    this.cmdAddKeyUsage.disableProperty().bind(this.keyUsageExtension.isNotNull());
    this.cmdAddExtendedKeyUsage.disableProperty().bind(this.extendedKeyUsageExtension.isNotNull());
    this.cmdAddSubjectAlternativeName.disableProperty().bind(this.subjectAlternativeExtension.isNotNull());
    this.cmdAddCRLDistributionPoints.disableProperty().bind(this.crlDistributionPointsExtension.isNotNull());
    this.cmdEditExtension.disableProperty().bind(this.ctlExtensionData.getSelectionModel().selectedItemProperty().isNull());
    this.cmdDeleteExtension.disableProperty().bind(this.ctlExtensionData.getSelectionModel().selectedItemProperty().isNull());
    this.ctlExtensionDataCritical.setCellFactory(CheckBoxTableCell.forTableColumn(this.ctlExtensionDataCritical));
    this.ctlExtensionDataCritical.setCellValueFactory(new PropertyValueFactory<>("critical"));
    this.ctlExtensionDataName.setCellValueFactory(new PropertyValueFactory<>("name"));
    this.ctlExtensionDataValue.setCellValueFactory(new PropertyValueFactory<>("value"));
}
Also used : IntegerStringConverter(javafx.util.converter.IntegerStringConverter)

Example 3 with IntegerStringConverter

use of javafx.util.converter.IntegerStringConverter in project certmgr by hdecarne.

the class StorePreferencesController method setupDialog.

@Override
protected void setupDialog(Dialog<UserCertStore> dialog) {
    dialog.setTitle(StorePreferencesI18N.formatSTR_STAGE_TITLE());
    this.ctlDefKeyAlgOption.valueProperty().addListener((p, o, n) -> onDefKeyAlgChanged(n));
    this.ctlDefKeySizeOption.setConverter(new IntegerStringConverter());
    addButtonEventFilter(ButtonType.APPLY, this::onApply);
}
Also used : IntegerStringConverter(javafx.util.converter.IntegerStringConverter)

Aggregations

IntegerStringConverter (javafx.util.converter.IntegerStringConverter)3 eu.ggnet.dwoss.customer.ee.entity (eu.ggnet.dwoss.customer.ee.entity)1 Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 Sex (eu.ggnet.dwoss.customer.ee.entity.Contact.Sex)1 Ui (eu.ggnet.saft.Ui)1 eu.ggnet.saft.api.ui (eu.ggnet.saft.api.ui)1 AlertType (eu.ggnet.saft.core.ui.AlertType)1 URL (java.net.URL)1 Locale (java.util.Locale)1 ResourceBundle (java.util.ResourceBundle)1 Consumer (java.util.function.Consumer)1 Pattern (java.util.regex.Pattern)1 Platform (javafx.application.Platform)1 Bindings (javafx.beans.binding.Bindings)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 FXML (javafx.fxml.FXML)1 Initializable (javafx.fxml.Initializable)1 Orientation (javafx.geometry.Orientation)1 Pos (javafx.geometry.Pos)1