Skip to content

Commit

Permalink
Add clearText property to customize "Clear" hyperlink text
Browse files Browse the repository at this point in the history
Introduced a `clearText` property to allow customization of the "Clear" hyperlink text in ChipsViewContainer. The text now dynamically binds to this property, providing greater flexibility for UI configuration.
  • Loading branch information
dlemmermann committed Feb 13, 2025
1 parent 6d3f5d9 commit a08d3dc
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion gemsfx/src/main/java/com/dlsc/gemsfx/ChipsViewContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.Hyperlink;
Expand Down Expand Up @@ -59,6 +61,8 @@ public final void setChips(ObservableList<ChipView<?>> chips) {
this.chips.set(chips);
}

// clearing callback

public final ObjectProperty<Runnable> onClear = new SimpleObjectProperty<>(this, "onClear");

public final Runnable getOnClear() {
Expand All @@ -68,6 +72,8 @@ public final Runnable getOnClear() {
/**
* A callback that will be invoked when the user clicks on the "clear" hyperlink.
*
* @see #clearTextProperty()
*
* @return the "on clear" callback
*/
public final ObjectProperty<Runnable> onClearProperty() {
Expand All @@ -78,13 +84,36 @@ public final void setOnClear(Runnable onClear) {
this.onClear.set(onClear);
}

// clear hyperlink text

private final StringProperty clearText = new SimpleStringProperty(this, "clearText", "Clear");

public final String getClearText() {
return clearText.get();
}

/**
* A property storing the text for the hyperlink that is being used to clear the view.
*
* @see #onClearProperty()
* @return the text property used for the text of the hyperlink used to clear the view
*/
public final StringProperty clearTextProperty() {
return clearText;
}

public final void setClearText(String clearText) {
this.clearText.set(clearText);
}

private void updateChips() {
getChildren().clear();

getChips().forEach(c -> getChildren().add(c));

if (!getChildren().isEmpty()) {
Hyperlink clear = new Hyperlink("Clear");
Hyperlink clear = new Hyperlink();
clear.textProperty().bind(clearTextProperty());
clear.visibleProperty().bind(onClear.isNotNull());
clear.managedProperty().bind(onClear.isNotNull());
clear.setOnAction(e -> getOnClear().run());
Expand Down

0 comments on commit a08d3dc

Please sign in to comment.