Search in sources :

Example 26 with LabelBuilder

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;
    }
}
Also used : ArrayList(java.util.ArrayList) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder)

Example 27 with LabelBuilder

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();
}
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) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) AddRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddRoleMapping) Task(org.jboss.hal.flow.Task) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ArrayList(java.util.ArrayList) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) AddScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.AddScopedRole) Role(org.jboss.hal.config.Role) RemoveScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.RemoveScopedRole) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) CheckRoleMapping(org.jboss.hal.client.accesscontrol.AccessControlTasks.CheckRoleMapping)

Example 28 with LabelBuilder

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());
}
Also used : ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FileItem(org.jboss.hal.ballroom.form.FileItem) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) Dialog(org.jboss.hal.ballroom.dialog.Dialog) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 29 with LabelBuilder

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();
}
Also used : AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) StatementContext(org.jboss.hal.meta.StatementContext) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Requires(org.jboss.hal.spi.Requires) CrudOperations(org.jboss.hal.core.CrudOperations) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Ids(org.jboss.hal.resources.Ids) AddressTemplates(org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) ComplexAttributeOperations(org.jboss.hal.core.ComplexAttributeOperations) EventBus(com.google.web.bindery.event.shared.EventBus) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) FinderPath(org.jboss.hal.core.finder.FinderPath) Consumer(java.util.function.Consumer) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) NameTokens(org.jboss.hal.meta.token.NameTokens) MbuiPresenter(org.jboss.hal.core.mbui.MbuiPresenter) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Resources(org.jboss.hal.resources.Resources) MbuiView(org.jboss.hal.core.mbui.MbuiView) Finder(org.jboss.hal.core.finder.Finder) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 30 with LabelBuilder

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);
}
Also used : SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder)

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