use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class RequireAtLeastOneAttributeValidation method validate.
@Override
public ValidationResult validate(Form<T> form) {
LabelBuilder labelBuilder = new LabelBuilder();
List<String> nonEmptyItems = requiresAtLeast.stream().map(form::getFormItem).filter(formItem -> formItem != null && !formItem.isEmpty()).map(FormItem::getName).collect(toList());
if (nonEmptyItems.isEmpty()) {
// retrieve the label item, instead the attribute name, for the cases when a complex attribute is in use
List<String> attributesLabels = new ArrayList<>();
requiresAtLeast.forEach(requiredAttribute -> {
FormItem<Object> formItem = form.getFormItem(requiredAttribute);
attributesLabels.add(formItem.getLabel());
});
// show an error on each related form item
requiresAtLeast.forEach(requiredAttribute -> {
FormItem<Object> formItem = form.getFormItem(requiredAttribute);
if (formItem.isEmpty()) {
formItem.showError(resources.messages().exactlyOneAlternativeError(labelBuilder.enumeration(attributesLabels, resources.constants().or())));
}
});
// return overall result
return ValidationResult.invalid(resources.messages().atLeastOneIsRequired(labelBuilder.enumeration(attributesLabels, resources.constants().or())));
} else {
return ValidationResult.OK;
}
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class RoleColumn method addScopedRole.
// ------------------------------------------------------ add roles
@SuppressWarnings("ConstantConditions")
private void addScopedRole(Role.Type type, String typeName, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).addOnly().unboundFormItem(new NameItem(), 0).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 3, resources.messages().includeAllHelpText()).include(BASE_ROLE, scopeAttribute).customFormItem(BASE_ROLE, attributeDescription -> {
SingleSelectBoxItem item = new SingleSelectBoxItem(BASE_ROLE, new LabelBuilder().label(BASE_ROLE), standardRoleNames, false);
item.setRequired(true);
return item;
}).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.attach();
AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(typeName), form, (name, model) -> {
List<Task<FlowContext>> tasks = new ArrayList<>();
tasks.add(new AddScopedRole(dispatcher, type, name, model));
Boolean includeAll = form.<Boolean>getFormItem(INCLUDE_ALL).getValue();
Role transientRole = new Role(name, null, type, null);
// We only need the role name in the functions,
// so it's ok to setup a transient role w/o the other attributes.
tasks.add(new CheckRoleMapping(dispatcher, transientRole));
tasks.add(new AddRoleMapping(dispatcher, transientRole, status -> status == 404));
if (includeAll != null && includeAll) {
tasks.add(new ModifyIncludeAll(dispatcher, transientRole, includeAll));
}
series(new FlowContext(progress.get()), tasks).subscribe(new SuccessfulOutcome<FlowContext>(eventBus, resources) {
@Override
public void onSuccess(FlowContext context) {
MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(typeName, name)));
accessControl.reload(() -> {
refresh(Ids.role(name));
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
});
dialog.getForm().<String>getFormItem(NAME).addValidationHandler(createUniqueValidation());
dialog.show();
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class BrowseContentElement method uploadContent.
private void uploadContent() {
LabelBuilder labelBuilder = new LabelBuilder();
TextBoxItem targetPathItem = new TextBoxItem(TARGET_PATH);
targetPathItem.setRequired(true);
FileItem fileItem = new FileItem(FILE, labelBuilder.label(FILE));
fileItem.addValueChangeHandler(event -> targetPathItem.setValue(appendFilename(targetPathItem.getValue(), event.getValue().name)));
TextBoxItem urlItem = new TextBoxItem(URL, labelBuilder.label(URL));
urlItem.addValueChangeHandler(event -> targetPathItem.setValue(appendFilename(targetPathItem.getValue(), filename(event.getValue()))));
Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.CONTENT_NEW, Metadata.empty()).unboundFormItem(fileItem).unboundFormItem(urlItem).unboundFormItem(targetPathItem).addOnly().build();
form.addFormValidation(f -> {
if (fileItem.isEmpty() && urlItem.isEmpty()) {
return ValidationResult.invalid(resources.messages().uploadContentInvalid());
}
return ValidationResult.OK;
});
form.setSaveCallback((f, model) -> {
String path = targetPathItem.getValue();
ResourceAddress address = new ResourceAddress().add(DEPLOYMENT, content.getName());
ModelNode contentNode = new ModelNode();
if (fileItem.isEmpty()) {
contentNode.get(URL).set(urlItem.getValue());
} else {
contentNode.get(INPUT_STREAM_INDEX).set(0);
}
contentNode.get(TARGET_PATH).set(path);
Operation operation = new Operation.Builder(address, ADD_CONTENT).param(CONTENT, new ModelNode().add(contentNode)).build();
Single<ModelNode> single = fileItem.isEmpty() ? dispatcher.execute(operation) : dispatcher.upload(fileItem.getValue(), operation);
single.toCompletable().andThen(browseContent()).andThen(awaitTreeReady()).subscribe(() -> {
MessageEvent.fire(eventBus, Message.success(resources.messages().newContentSuccess(content.getName(), path)));
tree.selectNode(NODE_ID.apply(path));
});
});
Dialog dialog = new Dialog.Builder(resources.constants().uploadContent()).add(p().innerHtml(resources.messages().uploadContentDescription()).element()).add(form.element()).primary(resources.constants().upload(), form::save).size(Dialog.Size.MEDIUM).cancel().build();
dialog.registerAttachable(form);
targetPathItem.setValue(selectedPath());
dialog.show();
form.edit(new ModelNode());
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class MapperDecoderPresenter method addMappedRoleMapper.
// -------------------------------------------- Mapped Role Mapper
void addMappedRoleMapper() {
Metadata metadata = metadataRegistry.lookup(MAPPED_ROLE_MAPPER_TEMPLATE);
String id = Ids.build(Ids.ELYTRON_MAPPED_ROLE_MAPPER, Ids.ADD);
Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(new NameItem(), 0).customFormItem(ROLE_MAP, desc -> new RoleMapListItem(ROLE_MAP, new LabelBuilder().label(ROLE_MAP))).addOnly().build();
String title = new LabelBuilder().label(MAPPED_ROLE_MAPPER);
new AddResourceDialog(title, form, (name, payload) -> {
// :add(role-map=[role1 => [role2,role3],role2 => [mane,m2n3]])
crud.add(title, name, MAPPED_ROLE_MAPPER_TEMPLATE, payload, (name1, address) -> reload());
}).show();
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class HeadersElement method saveHeader.
private void saveHeader(int pathIndex, int index, String header, Metadata metadata, Map<String, Object> changedValues) {
LabelBuilder labelBuilder = new LabelBuilder();
String type = labelBuilder.label(HEADER);
SafeHtml successMessage = resources.messages().modifyResourceSuccess(type, header);
presenter.saveHeader(pathIndex, index, header, metadata, changedValues, successMessage);
}
Aggregations