Search in sources :

Example 11 with LabelBuilder

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);
        }
    }
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) VariableElement(javax.lang.model.element.VariableElement) Element(org.jdom2.Element) XmlHelper.xmlAsString(org.jboss.hal.processor.mbui.XmlHelper.xmlAsString) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Element(org.jdom2.Element)

Example 12 with LabelBuilder

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);
}
Also used : Provider(javax.inject.Provider) Environment(org.jboss.hal.config.Environment) StatementContext(org.jboss.hal.meta.StatementContext) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) ItemDisplay(org.jboss.hal.core.finder.ItemDisplay) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) HTMLElement(elemental2.dom.HTMLElement) Message(org.jboss.hal.spi.Message) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) Metadata(org.jboss.hal.meta.Metadata) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping) Settings(org.jboss.hal.config.Settings) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog) RemoveAssignments(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveAssignments) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Flow.series(org.jboss.hal.flow.Flow.series) Role(org.jboss.hal.config.Role) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) Elements.small(org.jboss.gwt.elemento.core.Elements.small) CSS.subtitle(org.jboss.hal.resources.CSS.subtitle) ModelNode(org.jboss.hal.dmr.ModelNode) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) AsyncColumn(org.jboss.hal.spi.AsyncColumn) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ColumnAction(org.jboss.hal.core.finder.ColumnAction) ItemAction(org.jboss.hal.core.finder.ItemAction) FlowContext(org.jboss.hal.flow.FlowContext) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) RemoveRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveRoleMapping) FinderColumn(org.jboss.hal.core.finder.FinderColumn) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Comparator.comparing(java.util.Comparator.comparing) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddressTemplates(org.jboss.hal.client.accesscontrol.AddressTemplates) ColumnActionFactory(org.jboss.hal.core.finder.ColumnActionFactory) Requires(org.jboss.hal.spi.Requires) CSS.itemText(org.jboss.hal.resources.CSS.itemText) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Form(org.jboss.hal.ballroom.form.Form) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog)

Example 13 with LabelBuilder

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()))));
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation)

Example 14 with LabelBuilder

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()))));
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation)

Example 15 with LabelBuilder

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);
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) HTMLElement(elemental2.dom.HTMLElement) Metadata(org.jboss.hal.meta.Metadata) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm)

Aggregations

LabelBuilder (org.jboss.hal.ballroom.LabelBuilder)48 ModelNode (org.jboss.hal.dmr.ModelNode)33 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)32 Metadata (org.jboss.hal.meta.Metadata)28 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)26 Operation (org.jboss.hal.dmr.Operation)25 AddResourceDialog (org.jboss.hal.core.mbui.dialog.AddResourceDialog)23 Form (org.jboss.hal.ballroom.form.Form)20 Ids (org.jboss.hal.resources.Ids)17 List (java.util.List)15 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)15 AddressTemplate (org.jboss.hal.meta.AddressTemplate)15 Resources (org.jboss.hal.resources.Resources)15 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)14 EventBus (com.google.web.bindery.event.shared.EventBus)14 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)14 StatementContext (org.jboss.hal.meta.StatementContext)14 Names (org.jboss.hal.resources.Names)14 Inject (javax.inject.Inject)13 NamedNode (org.jboss.hal.dmr.NamedNode)12