@Override protected Node createUndecoratedEditor() { //TODO: CustomValue should be bound to defaultValue until we disable auto for the first time final HBox container = new HBox(); final TextInputControl textInput = getInputControl(); final CheckBox auto = new CheckBox("Auto"); final boolean useDefaultValue = value.isEmpty().get() || value.get().equals(defaultValue.get()); textInput.disableProperty().bind(auto.selectedProperty()); if (useDefaultValue) { textInput.textProperty().bind(defaultValue); } else { textInput.setText(value.get()); } customValue.bind(textInput.textProperty()); attachListener(textInput.textProperty(), (ov, o, n) -> { if (n == null || n.isEmpty() || n.equalsIgnoreCase(defaultValue.getValue())) { value.setValue(null); } else { value.setValue(n); } }); auto.selectedProperty().setValue(useDefaultValue); attachListener(auto.selectedProperty(), (ov, o, isAuto) -> setTextFieldBehaviour(textInput, isAuto, defaultValue, customValue) ); HBox.setHgrow(textInput, Priority.ALWAYS); HBox.setHgrow(auto, Priority.NEVER); container.getChildren().addAll(auto, textInput); return container; }
@Override protected String computeValue() { return source.get(); } };
@Override protected Node createUndecoratedEditor() { //TODO: CustomValue should be bound to defaultValue until we disable auto for the first time final HBox container = new HBox(); final TextInputControl textInput = getInputControl(); final CheckBox auto = new CheckBox("Auto"); final boolean useDefaultValue = value.isEmpty().get() || value.get().equals(defaultValue.get()); textInput.disableProperty().bind(auto.selectedProperty()); if (useDefaultValue) { textInput.textProperty().bind(defaultValue); } else { textInput.setText(value.get()); } customValue.bind(textInput.textProperty()); attachListener(textInput.textProperty(), (ov, o, n) -> { if (n == null || n.isEmpty() || n.equalsIgnoreCase(defaultValue.getValue())) { value.setValue(null); } else { value.setValue(n); } }); auto.selectedProperty().setValue(useDefaultValue); attachListener(auto.selectedProperty(), (ov, o, isAuto) -> setTextFieldBehaviour(textInput, isAuto, defaultValue, customValue) ); HBox.setHgrow(textInput, Priority.ALWAYS); HBox.setHgrow(auto, Priority.NEVER); container.getChildren().addAll(auto, textInput); return container; }