Search in sources :

Example 1 with Sex

use of eu.ggnet.dwoss.customer.ee.entity.Contact.Sex in project dwoss by gg-net.

the class ContactUpdateController 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));
    // get overwriten in accept()
    lastNameTextField.setText("");
    // enable the save and "saveAndClose" button only on filled TextFields
    saveButton.disableProperty().bind(Bindings.createBooleanBinding(() -> lastNameTextField.getText().trim().isEmpty(), lastNameTextField.textProperty()));
    saveAndCloseButton.disableProperty().bind(Bindings.createBooleanBinding(() -> lastNameTextField.getText().trim().isEmpty(), lastNameTextField.textProperty()));
    // fill the UI with default values
    genderBox.setConverter(new StringConverter<Sex>() {

        @Override
        public Sex fromString(String string) {
            throw new UnsupportedOperationException("Invalid operation for Convert a String into a Sex.");
        }

        @Override
        public String toString(Sex myClassinstance) {
            return myClassinstance.getSign();
        }
    });
    genderBox.getItems().addAll(Contact.Sex.values());
    // 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<>("preferred"));
    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);
                }
            }
        };
    });
    // fill the listViews
    addressListView.setItems(addressList);
    communicationTableView.setItems(communicationsList);
    communicationTableView.getColumns().addAll(typeColumn, idColumn, prefColumn);
}
Also used : Locale(java.util.Locale) HBox(javafx.scene.layout.HBox) Sex(eu.ggnet.dwoss.customer.ee.entity.Contact.Sex) Type(eu.ggnet.dwoss.customer.ee.entity.Communication.Type) AlertType(eu.ggnet.saft.core.ui.AlertType) VBox(javafx.scene.layout.VBox)

Aggregations

Type (eu.ggnet.dwoss.customer.ee.entity.Communication.Type)1 Sex (eu.ggnet.dwoss.customer.ee.entity.Contact.Sex)1 AlertType (eu.ggnet.saft.core.ui.AlertType)1 Locale (java.util.Locale)1 HBox (javafx.scene.layout.HBox)1 VBox (javafx.scene.layout.VBox)1