use of org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation in project console by hal.
the class ResetServerDialog method reset.
void reset(String messagingServer) {
LabelBuilder labelBuilder = new LabelBuilder();
String l1 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTERS);
Property p1 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTERS);
if (p1 != null && p1.getValue().hasDefined(DESCRIPTION)) {
l1 = p1.getValue().get(DESCRIPTION).asString();
l1 = Strings.sanitize(l1);
}
String l2 = labelBuilder.label(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
Property p2 = metadata.getDescription().findOperation(RESET_ALL_MESSAGE_COUNTER_HISTORIES);
if (p2 != null && p2.getValue().hasDefined(DESCRIPTION)) {
l2 = p2.getValue().get(DESCRIPTION).asString();
l2 = Strings.sanitize(l2);
}
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.RESET_MESSAGE_COUNTERS, Metadata.empty()).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTERS, l1)).unboundFormItem(new SwitchItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES, l2)).onSave((f, changedValues) -> column.resetServer(messagingServer, !f.getFormItem(RESET_ALL_MESSAGE_COUNTERS).isEmpty(), !f.getFormItem(RESET_ALL_MESSAGE_COUNTER_HISTORIES).isEmpty())).build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(RESET_ALL_MESSAGE_COUNTERS, RESET_ALL_MESSAGE_COUNTER_HISTORIES), resources));
// Make the long labels more readable
stream(form.element().querySelectorAll("." + halFormLabel + ", ." + halFormInput)).filter(htmlElements()).map(asHtmlElement()).forEach(element -> element.style.width = WidthUnionType.of("50%"));
Dialog dialog = new Dialog.Builder(resources.constants().reset()).add(form.element()).primary(resources.constants().reset(), form::save).size(Size.MEDIUM).closeIcon(true).closeOnEsc(true).cancel().build();
dialog.registerAttachable(form);
form.edit(new ModelNode());
dialog.show();
}
use of org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation in project console by hal.
the class OtherSettingsPresenter method addKeyManager.
// ------------------------------------------------------ key manager
void addKeyManager() {
Metadata metadata = metadataRegistry.lookup(KEY_MANAGER_TEMPLATE);
Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, TYPE, CLEAR_TEXT), metadata);
String id = Ids.build(Ids.ELYTRON_KEY_MANAGER, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(STORE, ALIAS, TYPE, CLEAR_TEXT).unsorted().build();
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
new AddResourceDialog(resources.messages().addResourceTitle(Names.KEY_MANAGER), form, (name, model) -> {
if (model != null) {
move(model, STORE, CREDENTIAL_REFERENCE + "/" + STORE);
move(model, ALIAS, CREDENTIAL_REFERENCE + "/" + ALIAS);
move(model, TYPE, CREDENTIAL_REFERENCE + "/" + TYPE);
move(model, CLEAR_TEXT, CREDENTIAL_REFERENCE + "/" + CLEAR_TEXT);
}
ResourceAddress address = KEY_MANAGER_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.KEY_MANAGER, name, address, model, (n, a) -> reload(KEY_MANAGER, nodes -> getView().updateResourceElement(KEY_MANAGER, nodes)));
}).show();
}
use of org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation in project console by hal.
the class OtherSettingsPresenter method addCredentialStore.
// -------------------------------------------- Credential Store
void addCredentialStore() {
Metadata metadata = metadataRegistry.lookup(CREDENTIAL_STORE_TEMPLATE);
SafeHtml typeHelp = SafeHtmlUtils.fromString(metadata.getDescription().get(ATTRIBUTES).get(TYPE).get(DESCRIPTION).asString());
Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, TYPE, CLEAR_TEXT), metadata);
TextBoxItem typeItem = new TextBoxItem("type-", resources.constants().type());
String id = Ids.build(Ids.ELYTRON_CREDENTIAL_STORE, Ids.ADD);
NameItem nameItem = new NameItem();
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(CREATE, PATH, RELATIVE_TO, STORE, ALIAS, TYPE, CLEAR_TEXT).unboundFormItem(typeItem, 3, typeHelp).unsorted().build();
form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
form.addFormValidation(form1 -> {
ValidationResult result = ValidationResult.OK;
String typeValue = typeItem.getValue();
FormItem<String> locationAttr = form1.getFormItem(PATH);
boolean invalidLocation = locationAttr.isEmpty() && (typeItem.isEmpty() || Collections.binarySearch(FILE_BASED_CS, typeValue) > -1);
if (invalidLocation) {
form1.getFormItem(PATH).showError(resources.constants().requiredField());
result = ValidationResult.invalid(resources.messages().pathRequired());
}
return result;
});
new AddResourceDialog(resources.messages().addResourceTitle(Names.CREDENTIAL_STORE), form, (name, model) -> {
if (model != null) {
move(model, STORE, CREDENTIAL_REFERENCE + "/" + STORE);
move(model, ALIAS, CREDENTIAL_REFERENCE + "/" + ALIAS);
move(model, TYPE, CREDENTIAL_REFERENCE + "/" + TYPE);
move(model, CLEAR_TEXT, CREDENTIAL_REFERENCE + "/" + CLEAR_TEXT);
}
if (!typeItem.isEmpty()) {
model.get(TYPE).set(typeItem.getValue());
}
ResourceAddress address = CREDENTIAL_STORE_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.CREDENTIAL_STORE, name, address, model, (n, a) -> reload(CREDENTIAL_STORE, nodes -> getView().updateResourceElement(CREDENTIAL_STORE, nodes)));
}).show();
}
use of org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation in project console by hal.
the class OtherSettingsPresenter method addKeyStore.
// ------------------------------------------------------ key store
void addKeyStore() {
Metadata metadata = metadataRegistry.lookup(KEY_STORE_TEMPLATE);
Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, CLEAR_TEXT), metadata);
String id = Ids.build(Ids.ELYTRON_KEY_STORE, Ids.ADD);
NameItem nameItem = new NameItem();
// there is a special handling for "type" attribute, as this attribute name exists in key-store and
// credential-reference complex attribute. We must create an unbound form item for credential-reference-type
String crType = "credential-reference-type";
String crTypeLabel = new LabelBuilder().label(crType);
TextBoxItem crTypeItem = new TextBoxItem(crType, crTypeLabel);
SafeHtml crTypeItemHelp = SafeHtmlUtils.fromString(metadata.getDescription().get(ATTRIBUTES).get(CREDENTIAL_REFERENCE).get(VALUE_TYPE).get(TYPE).get(DESCRIPTION).asString());
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(TYPE, PATH, RELATIVE_TO, STORE, ALIAS, CLEAR_TEXT).unboundFormItem(crTypeItem, 7, crTypeItemHelp).unsorted().build();
form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
new AddResourceDialog(resources.messages().addResourceTitle(Names.KEY_STORE), form, (name, model) -> {
if (model != null) {
move(model, STORE, CREDENTIAL_REFERENCE + "/" + STORE);
move(model, ALIAS, CREDENTIAL_REFERENCE + "/" + ALIAS);
move(model, CLEAR_TEXT, CREDENTIAL_REFERENCE + "/" + CLEAR_TEXT);
if (!crTypeItem.isEmpty()) {
model.get(CREDENTIAL_REFERENCE).get(TYPE).set(crTypeItem.getValue());
}
}
ResourceAddress address = KEY_STORE_TEMPLATE.resolve(statementContext, nameItem.getValue());
crud.add(Names.KEY_STORE, name, address, model, (n, a) -> reload(KEY_STORE, nodes -> getView().updateResourceElement(KEY_STORE, nodes)));
}).show();
}
Aggregations