use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class DataTableProcessor method process.
@Override
public void process(VariableElement field, Element element, String selector, MbuiViewContext context) {
MetadataInfo metadata = findMetadata(field, element, context);
AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
String title = element.getAttributeValue(XmlTags.TITLE);
if (title == null) {
title = new LabelBuilder().label(template.lastName());
}
DataTableInfo tableInfo = new DataTableInfo(field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title);
context.addDataTableInfo(tableInfo);
// actions
org.jdom2.Element actionsContainer = element.getChild(XmlTags.ACTIONS);
if (actionsContainer != null) {
for (org.jdom2.Element actionElement : actionsContainer.getChildren(XmlTags.ACTION)) {
String handler = actionElement.getAttributeValue(XmlTags.HANDLER);
String handlerRef = actionElement.getAttributeValue(XmlTags.HANDLER_REF);
String actionTitle = actionElement.getAttributeValue(XmlTags.TITLE);
String scope = actionElement.getAttributeValue(XmlTags.SCOPE);
String constraint = actionElement.getAttributeValue(XmlTags.CONSTRAINT);
String nameResolver = actionElement.getAttributeValue(XmlTags.NAME_RESOLVER);
Element attributesContainer = actionElement.getChild(XmlTags.ATTRIBUTES);
if (handler != null && handlerRef != null) {
processor.error(field, "Multiple handlers specified for table#%s. Please specify only one of \"handler\" or \"handler-ref\".", selector);
}
if (handler != null) {
if (!ExpressionParser.isExpression(handler)) {
processor.error(field, "Invalid handler \"%s\" in data-table#%s: handler has to be an expression.", handler, selector);
}
if (actionTitle == null) {
processor.error(field, "Invalid handler \"%s\" in data-table#%s: Title is mandatory.", handler, selector);
}
}
if (handlerRef != null && HandlerRef.referenceFor(handlerRef) == null) {
String knownHandlerRefs = Stream.of(HandlerRef.values()).map(HandlerRef::getRef).collect(joining(", "));
processor.error(field, "Unknown handler-ref \"%s\" in data-table#%s: Please choose one of %s.", handlerRef, selector, knownHandlerRefs);
}
if (!HandlerRef.ADD_RESOURCE.getRef().equals(handlerRef) && attributesContainer != null) {
processor.warning(field, "Attributes specified for handler-ref \"%s\" in data-table#%s: " + "Attributes are only processed for \"%s\".", handlerRef, selector, HandlerRef.ADD_RESOURCE.name());
}
if (nameResolver != null && !ExpressionParser.isExpression(nameResolver)) {
processor.error(field, "Name resolver in data-table#%s has to be an expression.", selector);
}
if (HandlerRef.REMOVE_RESOURCE.getRef().equals(handlerRef) && "*".equals(template.lastValue()) && nameResolver == null) {
processor.error(field, "\"%s\" handler-ref specified for data-table#%s and related metadata address ends in \"*\", " + "but no name resolver is is provided.", HandlerRef.REMOVE_RESOURCE.getRef(), selector);
}
if (scope != null && !XmlTags.SELECTED.equals(scope)) {
processor.error(field, "Unknown scope \"%s\" in handler-ref \"%s\" in data-table#%s: Only \"selected\" is supported.", scope, handlerRef, selector);
}
if (constraint != null) {
if (ADD.equals(constraint)) {
constraint = Constraint.executable(AddressTemplate.of(metadata.getTemplate()), ADD).data();
} else if (REMOVE.equals(constraint)) {
constraint = Constraint.executable(AddressTemplate.of(metadata.getTemplate()), REMOVE).data();
}
}
DataTableInfo.Action action = new DataTableInfo.Action(handlerRef != null ? handlerRef : handler, actionTitle, scope, constraint, nameResolver);
tableInfo.addAction(action);
if (attributesContainer != null) {
processAttributes(field, attributesContainer).forEach(action::addAttribute);
}
}
}
// columns
org.jdom2.Element columnsContainer = element.getChild(XmlTags.COLUMNS);
if (columnsContainer != null) {
for (org.jdom2.Element columnElement : columnsContainer.getChildren(XmlTags.COLUMN)) {
String name = columnElement.getAttributeValue(XmlTags.NAME);
String value = columnElement.getAttributeValue(XmlTags.VALUE);
if (name == null) {
processor.error(field, "Invalid column \"%s\" in data-table#%s: name is mandatory.", xmlAsString(columnElement), selector);
}
if (value != null) {
if (!ExpressionParser.isExpression(value)) {
processor.error(field, "Invalid column \"%s\" in data-table#%s: value has to be an expression.", xmlAsString(columnElement), selector);
}
}
DataTableInfo.Column column = new DataTableInfo.Column(name, value);
tableInfo.addColumn(column);
}
}
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class RoleColumn method editScopedRole.
private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
Metadata metadata = metadataRegistry.lookup(template);
Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).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;
}).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
form.getFormItem(scopeAttribute).setRequired(true);
form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
form.attach();
ModelNode modelNode = new ModelNode();
modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
boolean includeAllChanged = includeAll != role.isIncludeAll();
List<Task<FlowContext>> tasks = new ArrayList<>();
if (!changedValues.isEmpty()) {
tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
}
if (includeAllChanged) {
tasks.add(new ModifyIncludeAll(dispatcher, role, 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().modifyResourceSuccess(type, role.getName())));
accessControl.reload(() -> {
refresh(role.getId());
eventBus.fireEvent(new RolesChangedEvent());
});
}
});
}).show(modelNode);
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class StoresPresenter method readAliases.
// ----------------- common methods
void readAliases(AddressTemplate template, String resource, Consumer<List<ModelNode>> viewCallback) {
ResourceAddress address = template.resolve(statementContext, resource);
Operation operation = new Operation.Builder(address, READ_ALIASES_OPERATION).build();
LabelBuilder labelBuilder = new LabelBuilder();
String resourceName = labelBuilder.label(template.lastName()) + SPACE + resource;
dispatcher.execute(operation, result -> {
if (result.isDefined()) {
viewCallback.accept(result.asList());
} else {
viewCallback.accept(Collections.emptyList());
}
}, (operation1, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resourceName, failure))), (operation1, exception) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasesError(resourceName, exception.getMessage()))));
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class StoresPresenter method readAlias.
void readAlias(Metadata metadata, String name, String alias, Consumer<ModelNode> viewCallback) {
AddressTemplate template = metadata.getTemplate();
LabelBuilder labelBuilder = new LabelBuilder();
String resource = labelBuilder.label(template.lastName()) + SPACE + name;
ResourceAddress address = template.resolve(statementContext, name);
Operation addOp = new Operation.Builder(address, READ_ALIAS).param(ALIAS, alias).build();
dispatcher.execute(addOp, viewCallback, (operation, failure) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasError(alias, resource, failure))), (operation, ex) -> MessageEvent.fire(getEventBus(), Message.error(resources.messages().readAliasError(alias, resource, ex.getMessage()))));
}
use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.
the class ConfigurePasswordStep method onShow.
@Override
protected void onShow(PasswordContext context) {
AddressTemplate template = metadata.getTemplate();
Metadata passwordMetadata = metadata.forOperation(SET_PASSWORD).forComplexAttribute(context.type.name);
LabelBuilder labelBuilder = new LabelBuilder();
header.textContent = labelBuilder.label(context.type.name);
description.textContent = passwordMetadata.getDescription().getDescription();
String id = Ids.build(template.lastName(), SET_PASSWORD, FORM);
ModelNodeForm.Builder<ModelNode> builder = new ModelNodeForm.Builder<>(id, passwordMetadata).onSave((form1, changedValues) -> this.changedValues = changedValues);
passwordMetadata.getDescription().getAttributes(ATTRIBUTES).forEach(attr -> {
if (ModelType.BYTES.equals(attr.getValue().get(TYPE).asType())) {
builder.customFormItem(attr.getName(), desc -> {
TextBoxItem saltItem = new TextBoxItem(attr.getName(), labelBuilder.label(attr.getName()));
saltItem.setRequired(desc.getValue().get(REQUIRED).asBoolean());
saltItem.addValidationHandler(value -> {
ValidationResult result = ValidationResult.OK;
// accordingly to the :set-password operation, the salt must be exactly 16 bytes
if (value.length() != 16) {
result = ValidationResult.invalid(resources.messages().invalidLength());
}
return result;
});
return saltItem;
});
}
});
form = builder.build();
HTMLElement formElement = form.element();
form.attach();
form.edit(new ModelNode());
// as the form is dynamically added to the section, we must remove the previous form element
if (section.childElementCount > 2) {
section.removeChild(section.lastChild);
}
section.appendChild(formElement);
}
Aggregations