Fill health start fail screen with information

This commit is contained in:
Armin Schrenk
2021-07-13 16:55:21 +02:00
parent 102ab93dbd
commit 21946ae6aa
3 changed files with 96 additions and 9 deletions
@@ -8,6 +8,8 @@ public enum FontAwesome5Icon {
ARROW_UP("\uF062"), //
BAN("\uF05E"), //
BUG("\uF188"), //
CARET_DOWN("\uF0D7"), //
CARET_RIGHT("\uF0Da"), //
CHECK("\uF00C"), //
CLOCK("\uF017"), //
COG("\uF013"), //
@@ -1,18 +1,24 @@
package org.cryptomator.ui.health;
import com.google.common.base.Preconditions;
import com.tobiasdiez.easybind.EasyBind;
import org.cryptomator.cryptofs.VaultConfigLoadException;
import org.cryptomator.ui.common.FxController;
import org.cryptomator.ui.controls.FontAwesome5Icon;
import javax.inject.Inject;
import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue;
import javafx.fxml.FXML;
import javafx.scene.control.TitledPane;
import javafx.stage.Stage;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
@HealthCheckScoped
public class StartFailController implements FxController {
@@ -22,10 +28,25 @@ public class StartFailController implements FxController {
Preconditions.checkNotNull(configLoadResult.error());
this.window = window;
this.loadError = new SimpleObjectProperty<>(configLoadResult.error());
this.localizedErrorMessage = new SimpleStringProperty(configLoadResult.error().getLocalizedMessage());
this.typeParseException = Bindings.createBooleanBinding(() -> loadError.get() instanceof VaultConfigLoadException);
this.typeIOException = typeParseException.not();
this.localizedErrorMessage = EasyBind.map(loadError, Throwable::getLocalizedMessage);
this.parseException = Bindings.createBooleanBinding(() -> loadError.get() instanceof VaultConfigLoadException);
this.ioException = parseException.not();
this.stackTrace = EasyBind.map(loadError, this::createPrintableStacktrace);
this.moreInfoIcon = new SimpleObjectProperty<>(FontAwesome5Icon.CARET_RIGHT);
}
public void initialize() {
moreInfoPane.expandedProperty().addListener(this::setMoreInfoIcon);
}
private void setMoreInfoIcon(ObservableValue<? extends Boolean> observable, boolean wasExpanded, boolean willExpand) {
moreInfoIcon.set(willExpand ? FontAwesome5Icon.CARET_DOWN : FontAwesome5Icon.CARET_RIGHT);
}
private String createPrintableStacktrace(Throwable t) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(baos));
return baos.toString(StandardCharsets.UTF_8);
}
@FXML
@@ -33,10 +54,55 @@ public class StartFailController implements FxController {
window.close();
}
public Binding<String> stackTraceProperty() {
return stackTrace;
}
public String getStackTrace() {
return stackTrace.getValue();
}
public Binding<String> localizedErrorMessageProperty() {
return localizedErrorMessage;
}
public String getLocalizedErrorMessage() {
return localizedErrorMessage.getValue();
}
public BooleanBinding parseExceptionProperty() {
return parseException;
}
public boolean isParseException() {
return parseException.getValue();
}
public BooleanBinding ioExceptionProperty() {
return ioException;
}
public boolean isIoException() {
return ioException.getValue();
}
public ObjectProperty<FontAwesome5Icon> moreInfoIconProperty() {
return moreInfoIcon;
}
public FontAwesome5Icon getMoreInfoIcon() {
return moreInfoIcon.getValue();
}
private final Stage window;
private final ObjectProperty<Throwable> loadError;
private final StringProperty localizedErrorMessage;
private final BooleanBinding typeIOException;
private final BooleanBinding typeParseException;
private final Binding<String> stackTrace;
private final Binding<String> localizedErrorMessage;
private final BooleanBinding ioException;
private final BooleanBinding parseException;
private final ObjectProperty<FontAwesome5Icon> moreInfoIcon;
/* FXML */
public TitledPane moreInfoPane;
}
+20 -1
View File
@@ -2,14 +2,33 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextArea?>
<?import javafx.geometry.Insets?>
<?import org.cryptomator.ui.controls.FormattedLabel?>
<?import javafx.scene.control.TitledPane?>
<?import org.cryptomator.ui.controls.FontAwesome5IconView?>
<?import javafx.scene.layout.Region?>
<VBox xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="org.cryptomator.ui.health.StartFailController"
prefWidth="600"
prefHeight="400"
spacing="12">
<padding>
<Insets topRightBottomLeft="12"/>
</padding>
<Label text="TODO: Error on loading" />
<FormattedLabel format="TODO: Error reading file: %s" arg1="${controller.localizedErrorMessage}" visible="${controller.ioException}" managed="${controller.ioException}"/>
<Label text="TODO: Malformed vault config" visible="${controller.parseException}" managed="${controller.parseException}"/>
<TitledPane fx:id="moreInfoPane" text="More Info" expanded="false" contentDisplay="LEFT">
<graphic>
<FontAwesome5IconView glyph="${controller.moreInfoIcon}"/>
</graphic>
<content>
<TextArea VBox.vgrow="ALWAYS" text="${controller.stackTrace}" prefRowCount="20" editable="false" />
</content>
</TitledPane>
<Region VBox.vgrow="ALWAYS"/>
<ButtonBar buttonMinWidth="120" buttonOrder="+CX">
<buttons>
<Button text="%generic.button.close" ButtonBar.buttonData="CANCEL_CLOSE" cancelButton="true" onAction="#close"/>