fix(account): Authlib-Injector server may be unknown when in CreateAcountPane tab mode.
This commit is contained in:
@@ -362,6 +362,7 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
|||||||
|
|
||||||
private final AccountFactory<?> factory;
|
private final AccountFactory<?> factory;
|
||||||
private @Nullable AuthlibInjectorServer server;
|
private @Nullable AuthlibInjectorServer server;
|
||||||
|
private @Nullable JFXComboBox<AuthlibInjectorServer> cboServers;
|
||||||
private @Nullable JFXTextField txtUsername;
|
private @Nullable JFXTextField txtUsername;
|
||||||
private @Nullable JFXPasswordField txtPassword;
|
private @Nullable JFXPasswordField txtPassword;
|
||||||
private @Nullable JFXTextField txtUUID;
|
private @Nullable JFXTextField txtUUID;
|
||||||
@@ -404,10 +405,46 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
|||||||
add(boxServers, 1, rowIndex);
|
add(boxServers, 1, rowIndex);
|
||||||
|
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
} else if (factory instanceof AuthlibInjectorAccountFactory) {
|
||||||
|
Label lblServers = new Label(i18n("account.injector.server"));
|
||||||
|
setHalignment(lblServers, HPos.LEFT);
|
||||||
|
add(lblServers, 0, rowIndex);
|
||||||
|
|
||||||
if (factory instanceof AuthlibInjectorAccountFactory) {
|
cboServers = new JFXComboBox<>();
|
||||||
throw new IllegalArgumentException("Use BoundAuthlibInjectorAccountFactory instead");
|
cboServers.setCellFactory(jfxListCellFactory(server -> new TwoLineListItem(server.getName(), server.getUrl())));
|
||||||
|
cboServers.setConverter(stringConverter(AuthlibInjectorServer::getName));
|
||||||
|
bindContent(cboServers.getItems(), config().getAuthlibInjectorServers());
|
||||||
|
cboServers.getItems().addListener(onInvalidating(
|
||||||
|
() -> Platform.runLater( // the selection will not be updated as expected if we call it immediately
|
||||||
|
cboServers.getSelectionModel()::selectFirst)));
|
||||||
|
cboServers.getSelectionModel().selectFirst();
|
||||||
|
cboServers.setPromptText(i18n("account.injector.empty"));
|
||||||
|
BooleanBinding noServers = createBooleanBinding(cboServers.getItems()::isEmpty, cboServers.getItems());
|
||||||
|
classPropertyFor(cboServers, "jfx-combo-box-warning").bind(noServers);
|
||||||
|
classPropertyFor(cboServers, "jfx-combo-box").bind(noServers.not());
|
||||||
|
HBox.setHgrow(cboServers, Priority.ALWAYS);
|
||||||
|
HBox.setMargin(cboServers, new Insets(0, 10, 0, 0));
|
||||||
|
cboServers.setMaxWidth(Double.MAX_VALUE);
|
||||||
|
|
||||||
|
HBox linksContainer = new HBox();
|
||||||
|
linksContainer.setAlignment(Pos.CENTER);
|
||||||
|
onChangeAndOperate(cboServers.valueProperty(), server -> {
|
||||||
|
this.server = server;
|
||||||
|
linksContainer.getChildren().setAll(createHyperlinks(server));
|
||||||
|
});
|
||||||
|
linksContainer.setMinWidth(USE_PREF_SIZE);
|
||||||
|
|
||||||
|
JFXButton btnAddServer = new JFXButton();
|
||||||
|
btnAddServer.setGraphic(SVG.plus(Theme.blackFillBinding(), 20, 20));
|
||||||
|
btnAddServer.getStyleClass().add("toggle-icon4");
|
||||||
|
btnAddServer.setOnAction(e -> {
|
||||||
|
Controllers.dialog(new AddAuthlibInjectorServerPane());
|
||||||
|
});
|
||||||
|
|
||||||
|
HBox boxServers = new HBox(cboServers, linksContainer, btnAddServer);
|
||||||
|
add(boxServers, 1, rowIndex);
|
||||||
|
|
||||||
|
rowIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (factory.getLoginType().requiresUsername) {
|
if (factory.getLoginType().requiresUsername) {
|
||||||
@@ -511,6 +548,8 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
|||||||
|
|
||||||
valid = new BooleanBinding() {
|
valid = new BooleanBinding() {
|
||||||
{
|
{
|
||||||
|
if (cboServers != null)
|
||||||
|
bind(cboServers.valueProperty());
|
||||||
if (txtUsername != null)
|
if (txtUsername != null)
|
||||||
bind(txtUsername.textProperty());
|
bind(txtUsername.textProperty());
|
||||||
if (txtPassword != null)
|
if (txtPassword != null)
|
||||||
@@ -521,6 +560,8 @@ public class CreateAccountPane extends JFXDialogLayout implements DialogAware {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean computeValue() {
|
protected boolean computeValue() {
|
||||||
|
if (cboServers != null && cboServers.getValue() == null)
|
||||||
|
return false;
|
||||||
if (txtUsername != null && !txtUsername.validate())
|
if (txtUsername != null && !txtUsername.validate())
|
||||||
return false;
|
return false;
|
||||||
if (txtPassword != null && !txtPassword.validate())
|
if (txtPassword != null && !txtPassword.validate())
|
||||||
|
|||||||
Reference in New Issue
Block a user