use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class HeadersElement method addHeader.
private void addHeader(Metadata metadata) {
LabelBuilder labelBuilder = new LabelBuilder();
String type = labelBuilder.label(HEADER);
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(Ids.CONSTANT_HEADERS_HEADER, Ids.ADD), metadata).addOnly().include(NAME).include(VALUE).build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(type), form, (name, model) -> {
if (model != null) {
SafeHtml message = resources.messages().addSuccess(type, model.get(NAME).asString(), labelBuilder.label(HEADERS));
presenter.addHeader(pathIndex, model, message);
}
});
dialog.show();
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class ServerPresenter method disableSsl.
void disableSsl(String httpsListener) {
AddressTemplate httpsTemplate = SERVER_TEMPLATE.append(HTTPS_LISTENER + EQ_WILDCARD);
Metadata metadata = metadataRegistry.lookup(httpsTemplate);
SafeHtml description = resources.messages().disableSSLUndertowQuestion(httpsListener);
String label = new LabelBuilder().label(SECURITY_REALM);
TextBoxItem securityRealmItem = new TextBoxItem(SECURITY_REALM, label);
securityRealmItem.setRequired(true);
SafeHtml securityRealmDescription = SafeHtmlUtils.fromTrustedString(metadata.getDescription().get(ATTRIBUTES).get(SECURITY_REALM).get(DESCRIPTION).asString());
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(SECURITY_REALM, Ids.FORM), Metadata.empty()).unboundFormItem(securityRealmItem, 0, securityRealmDescription).build();
HTMLElement content = div().add(p().innerHtml(description)).add(form.element()).element();
Dialog dialog = new Dialog.Builder(resources.constants().disableSSL()).size(Dialog.Size.MEDIUM).primary(resources.constants().yes(), () -> {
boolean valid = form.save();
// if the form contains validation error, don't close the dialog
if (valid) {
ResourceAddress httpsAddress = httpsTemplate.resolve(statementContext, serverName, httpsListener);
Operation undefineSslCtx = new Operation.Builder(httpsAddress, UNDEFINE_ATTRIBUTE_OPERATION).param(NAME, SSL_CONTEXT).build();
Operation writeSecurityRealm = new Operation.Builder(httpsAddress, WRITE_ATTRIBUTE_OPERATION).param(NAME, SECURITY_REALM).param(VALUE, securityRealmItem.getValue()).build();
Composite composite = new Composite();
composite.add(undefineSslCtx);
composite.add(writeSecurityRealm);
dispatcher.execute(composite, (CompositeResult result) -> {
MessageEvent.fire(getEventBus(), Message.success(resources.messages().disableSSLUndertowSuccess(httpsListener)));
reload();
}, (operation, failure) -> {
MessageEvent.fire(getEventBus(), Message.error(resources.messages().disableSSLUndertowError(httpsListener, failure)));
}, (operation, exception) -> {
SafeHtml message = resources.messages().disableSSLUndertowError(httpsListener, exception.getMessage());
MessageEvent.fire(getEventBus(), Message.error(message));
});
}
return valid;
}).secondary(resources.constants().no(), () -> true).closeIcon(true).closeOnEsc(true).add(content).build();
dialog.registerAttachable(form);
dialog.show();
ModelNode model = new ModelNode().setEmptyObject();
form.edit(model);
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class ModelBrowser method add.
void add(Node<Context> parent, List<String> children) {
if (parent.data.hasSingletons()) {
if (parent.data.getSingletons().size() == children.size()) {
MessageEvent.fire(eventBus, Message.warning(resources.messages().allSingletonsExist()));
} else if (parent.data.getSingletons().size() - children.size() == 1) {
// no need to show a wizard - find the missing singleton
HashSet<String> singletons = Sets.newHashSet(parent.data.getSingletons());
singletons.removeAll(children);
String singleton = singletons.iterator().next();
ResourceAddress singletonAddress = parent.data.getAddress().getParent().add(parent.text, singleton);
AddressTemplate template = asGenericTemplate(parent, singletonAddress);
String id = Ids.build(parent.id, "singleton", Ids.ADD);
crud.addSingleton(id, singleton, template, address -> refresh(parent));
} else {
// open wizard to choose the singleton
Wizard<SingletonContext, SingletonState> wizard = new Wizard.Builder<SingletonContext, SingletonState>(resources.messages().addResourceTitle(parent.text), new SingletonContext(parent, children)).addStep(CHOOSE, new ChooseSingletonStep(parent, children, resources)).addStep(CREATE, new CreateSingletonStep(parent, metadataProcessor, progress, eventBus, resources)).onBack((context, currentState) -> currentState == CREATE ? CHOOSE : null).onNext((context, currentState) -> currentState == CHOOSE ? CREATE : null).onFinish((wzrd, context) -> {
Operation.Builder builder = new Operation.Builder(fqAddress(parent, context.singleton), ADD);
if (context.modelNode != null) {
builder.payload(context.modelNode);
}
dispatcher.execute(builder.build(), result -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(parent.text, context.singleton)));
refresh(parent);
});
}).build();
wizard.show();
}
} else {
AddressTemplate template = asGenericTemplate(parent, parent.data.getAddress());
metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {
@Override
public void onMetadata(Metadata metadata) {
flattenDescription(metadata.getDescription().get(OPERATIONS).get(ADD).get(REQUEST_PROPERTIES));
String title = new LabelBuilder().label(parent.text);
NameItem nameItem = new NameItem();
String id = Ids.build(parent.id, "add");
ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).fromRequestProperties().panelForOptionalAttributes().build();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(title), form, (name1, model) -> {
unflattenModel(model);
crud.add(title, nameItem.getValue(), fqAddress(parent, nameItem.getValue()), model, (n, a) -> refresh(parent));
});
dialog.show();
}
});
}
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class ExactlyOneAlternativeValidation method validate.
@Override
public ValidationResult validate(final Form<T> form) {
LabelBuilder labelBuilder = new LabelBuilder();
Set<String> emptyItems = requiredAlternatives.stream().filter(name -> {
FormItem formItem = form.getFormItem(name);
boolean empty = formItem != null && formItem.isEmpty();
// there is a special case for SwitchItem of Boolean type, the SwitchItem.isEmpty() tests if the value is
// null, but for this validation case we must ensure the value is set to false to allow the validation
// to work
boolean switchItemFalse = false;
if (formItem != null && formItem.getClass().equals(SwitchItem.class)) {
Object value = formItem.getValue();
switchItemFalse = value != null && !Boolean.parseBoolean(value.toString());
}
return empty || switchItemFalse;
}).collect(toSet());
if (requiredAlternatives.size() == emptyItems.size()) {
// show an error on each related form item
requiredAlternatives.forEach(alternative -> {
FormItem<Object> formItem = form.getFormItem(alternative);
if (formItem.isEmpty()) {
formItem.showError(messages.exactlyOneAlternativeError(labelBuilder.enumeration(requiredAlternatives, constants.or())));
}
});
// return overall result
return ValidationResult.invalid(messages.exactlyOneAlternativesError(labelBuilder.enumeration(requiredAlternatives, constants.or())));
} else {
return ValidationResult.OK;
}
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class NotMoreThanOneAlternativeValidation method validate.
@Override
public ValidationResult validate(Form<T> form) {
LabelBuilder labelBuilder = new LabelBuilder();
List<String> nonEmptyItems = alternatives.stream().map(form::getFormItem).filter(formItem -> formItem != null && !this.form.isEmptyOrDefault(formItem)).map(FormItem::getName).collect(toList());
if (nonEmptyItems.size() > 1) {
// show an error on each related form item
alternatives.forEach(alternative -> {
TreeSet<String> otherAlternatives = new TreeSet<>(nonEmptyItems);
otherAlternatives.remove(alternative);
FormItem<Object> formItem = form.getFormItem(alternative);
if (!this.form.isEmptyOrDefault(formItem)) {
formItem.showError(messages.notMoreThanOneAlternativeError(labelBuilder.enumeration(otherAlternatives, constants.and())));
}
});
// return overall result
return ValidationResult.invalid(messages.notMoreThanOneAlternativesError(labelBuilder.enumeration(alternatives, constants.or())));
} else {
return ValidationResult.OK;
}
}
Aggregations