use of com.vaadin.ui.CustomField in project unity by unity-idm.
the class EditOAuthClientSubView method buildHeaderSection.
private FormLayoutWithFixedCaptionWidth buildHeaderSection() {
FormLayoutWithFixedCaptionWidth header = new FormLayoutWithFixedCaptionWidth();
header.setMargin(true);
TextField name = new TextField();
name.setCaption(msg.getMessage("EditOAuthClientSubView.name"));
binder.forField(name).withValidator((v, c) -> {
if (v != null && !v.isEmpty() && v.length() < 2) {
return ValidationResult.error(msg.getMessage("toShortValue"));
}
return ValidationResult.ok();
}).bind("name");
header.addComponent(name);
ComboBox<String> type = new ComboBox<>();
type.setCaption(msg.getMessage("EditOAuthClientSubView.type"));
type.setItems(Stream.of(ClientType.values()).map(f -> f.toString()).collect(Collectors.toList()));
type.setEmptySelectionAllowed(false);
binder.forField(type).bind("type");
header.addComponent(type);
TextFieldWithGenerator id = new TextFieldWithGenerator();
id.setCaption(msg.getMessage("EditOAuthClientSubView.id"));
id.setReadOnly(editMode);
id.setWidth(30, Unit.EM);
binder.forField(id).asRequired(msg.getMessage("fieldRequired")).withValidator((v, c) -> {
if (v != null && allClientsIds.contains(v)) {
return ValidationResult.error(msg.getMessage("EditOAuthClientSubView.invalidClientId"));
}
return ValidationResult.ok();
}).bind("id");
header.addComponent(id);
CustomField<String> secret;
if (!editMode) {
secret = new TextFieldWithGenerator();
secret.setCaption(msg.getMessage("EditOAuthClientSubView.secret"));
secret.setWidth(30, Unit.EM);
binder.forField(secret).withValidator((v, c) -> {
if ((v == null || v.isEmpty()) && ClientType.CONFIDENTIAL.toString().equals(type.getValue())) {
return ValidationResult.error(msg.getMessage("fieldRequired"));
}
return ValidationResult.ok();
}).bind("secret");
header.addComponent(secret);
} else {
TextFieldWithChangeConfirmation<TextFieldWithGenerator> secretWithChangeConfirmation = new TextFieldWithChangeConfirmation<>(msg, new TextFieldWithGenerator());
secretWithChangeConfirmation.setCaption(msg.getMessage("EditOAuthClientSubView.secret"));
secretWithChangeConfirmation.setWidth(30, Unit.EM);
binder.forField(secretWithChangeConfirmation).withValidator((v, c) -> {
if (secretWithChangeConfirmation.isEditMode()) {
return ValidationResult.error(msg.getMessage("fieldRequired"));
}
return ValidationResult.ok();
}).bind("secret");
header.addComponent(secretWithChangeConfirmation);
secret = secretWithChangeConfirmation;
}
type.addValueChangeListener(e -> {
secret.setEnabled(ClientType.CONFIDENTIAL.toString().equals(e.getValue()));
if (!secret.isEnabled())
secret.setValue("");
});
ChipsWithDropdown<String> allowedFlows = new ChipsWithDropdown<>();
allowedFlows.setCaption(msg.getMessage("EditOAuthClientSubView.allowedFlows"));
allowedFlows.setItems(Stream.of(GrantFlow.values()).map(f -> f.toString()).collect(Collectors.toList()));
binder.forField(allowedFlows).withValidator((v, c) -> {
if (v == null || v.isEmpty()) {
return ValidationResult.error(msg.getMessage("fieldRequired"));
}
return ValidationResult.ok();
}).bind("flows");
header.addComponent(allowedFlows);
ChipsWithTextfield redirectURIs = new ChipsWithTextfield(msg);
redirectURIs.setWidth(FieldSizeConstans.LINK_FIELD_WIDTH, FieldSizeConstans.LINK_FIELD_WIDTH_UNIT);
redirectURIs.setCaption(msg.getMessage("EditOAuthClientSubView.authorizedRedirectURIs"));
binder.forField(redirectURIs).withValidator((v, c) -> {
if (v == null || v.size() == 0) {
return ValidationResult.error(msg.getMessage("fieldRequired"));
}
return ValidationResult.ok();
}).bind("redirectURIs");
header.addComponent(redirectURIs);
Set<String> definedScopes = scopesSupplier.get();
ChipsWithDropdown<String> allowedScopes = new ChipsWithDropdown<>();
allowedScopes.setCaption(msg.getMessage("EditOAuthClientSubView.allowedScopes"));
allowedScopes.setItems(definedScopes);
allowedScopes.setSkipRemoveInvalidSelections(true);
binder.forField(allowedScopes).withValidator((v, c) -> {
if (v != null && !v.isEmpty() && !definedScopes.containsAll(v)) {
return ValidationResult.error(msg.getMessage("EditOAuthClientSubView.invalidAllowedScopes"));
}
return ValidationResult.ok();
}).bind("scopes");
CheckBox allowAllScopes = new CheckBox(msg.getMessage("EditOAuthClientSubView.allowAllScopes"));
binder.forField(allowAllScopes).bind("allowAnyScopes");
allowAllScopes.addValueChangeListener(v -> allowedScopes.setEnabled(!v.getValue()));
header.addComponent(allowAllScopes);
header.addComponent(allowedScopes);
return header;
}
Aggregations