Skip to content

Commit

Permalink
Added wrapper around error node in LoadingPane.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemmermann committed Dec 12, 2024
1 parent a6fcb7e commit 40d2c86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
23 changes: 16 additions & 7 deletions gemsfx/src/main/java/com/dlsc/gemsfx/LoadingPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.application.Platform;
import javafx.beans.DefaultProperty;
import javafx.beans.InvalidationListener;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.LongProperty;
import javafx.beans.property.ObjectProperty;
Expand Down Expand Up @@ -85,7 +86,6 @@ public LoadingPane() {
Label errorLabel = new Label();
errorLabel.getStyleClass().add("error-label");
errorLabel.setGraphic(icon);
errorLabel.visibleProperty().bind(committedStatus.isEqualTo(Status.ERROR));
errorLabel.textProperty().bind(errorProperty());

setErrorNode(errorLabel);
Expand Down Expand Up @@ -117,7 +117,9 @@ public LoadingPane() {
}
});

progressIndicator.addListener(it -> updateView());
InvalidationListener updateViewListener = it -> updateView();
progressIndicator.addListener(updateViewListener);
errorNodeProperty().addListener(updateViewListener);
updateView();

updatePseudoClass(null, committedStatus.get());
Expand All @@ -134,6 +136,11 @@ public LoadingPane(Node node) {
setContent(node);
}

@Override
public String getUserAgentStylesheet() {
return Objects.requireNonNull(LoadingPane.class.getResource("loading-pane.css")).toExternalForm();
}

private void updateView() {
ProgressIndicator indicator = getProgressIndicator();

Expand Down Expand Up @@ -162,19 +169,21 @@ private void updateView() {

if (newNode != null) {
newNode.visibleProperty().bind(committedStatus.isEqualTo(Status.OK));
getChildren().setAll(newNode, indicatorWrapper, getErrorNode());
getChildren().setAll(newNode, indicatorWrapper, wrapErrorNode(getErrorNode()));
} else {
getChildren().setAll(indicatorWrapper, getErrorNode());
getChildren().setAll(indicatorWrapper, wrapErrorNode(getErrorNode()));
}
});

committedStatus.addListener((obs, oldStatus, newStatus) -> updatePseudoClass(oldStatus, newStatus));
sizeProperty().addListener((obs, oldSize, newSize) -> updatePseudoClass(oldSize, newSize));
}

@Override
public String getUserAgentStylesheet() {
return Objects.requireNonNull(LoadingPane.class.getResource("loading-pane.css")).toExternalForm();
private Node wrapErrorNode(Node errorNode) {
StackPane errorWrapper = new StackPane(errorNode);
errorWrapper.getStyleClass().add("error-pane");
errorWrapper.visibleProperty().bind(committedStatus.isEqualTo(Status.ERROR));
return errorWrapper;
}

private final ObjectProperty<Node> errorNode = new SimpleObjectProperty<>(this, "errorNode");
Expand Down
4 changes: 2 additions & 2 deletions gemsfx/src/main/resources/com/dlsc/gemsfx/loading-pane.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.loading-pane {
}

.loading-pane > .error-label {
.loading-pane > .error-pane > .error-label {
-fx-text-fill: red;
-fx-alignment: center;
-fx-content-display: top;
-fx-wrap-text: true;
-fx-text-alignment: center;
}

.loading-pane > .error-label .icon {
.loading-pane > .error-pane > .error-label .icon {
-size: 1.5em;
-fx-min-width: -size;
-fx-min-height: -size;
Expand Down

0 comments on commit 40d2c86

Please sign in to comment.