Search in sources :

Example 6 with LabelBuilder

use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.

the class OtherSettingsPresenter method addNewItemTemplate.

void addNewItemTemplate(String ldapKeyStore) {
    Metadata metadata = metadataRegistry.lookup(AddressTemplates.LDAP_KEY_STORE_TEMPLATE).forComplexAttribute(NEW_ITEM_TEMPLATE);
    String id = Ids.build(Ids.ELYTRON_LDAP_KEY_STORE, NEW_ITEM_TEMPLATE, Ids.ADD);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).include(NEW_ITEM_PATH, NEW_ITEM_RDN, NEW_ITEM_ATTRIBUTES).customFormItem(NEW_ITEM_ATTRIBUTES, (attributeDescription) -> new MultiValueListItem(NEW_ITEM_ATTRIBUTES)).unsorted().addOnly().build();
    String type = new LabelBuilder().label(NEW_ITEM_TEMPLATE);
    new AddResourceDialog(resources.messages().addResourceTitle(type), form, (name, model) -> ca.add(ldapKeyStore, NEW_ITEM_TEMPLATE, Names.NEW_ITEM_TEMPLATE, AddressTemplates.LDAP_KEY_STORE_TEMPLATE, model, this::reloadLdapKeyStores)).show();
}
Also used : FinishRemove(org.jboss.hal.ballroom.form.Form.FinishRemove) StatementContext(org.jboss.hal.meta.StatementContext) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FinishReset(org.jboss.hal.ballroom.form.Form.FinishReset) RequireAtLeastOneAttributeValidation(org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) CrudOperations(org.jboss.hal.core.CrudOperations) ModelNodeHelper.move(org.jboss.hal.dmr.ModelNodeHelper.move) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) ComplexAttributeOperations(org.jboss.hal.core.ComplexAttributeOperations) FinderPath(org.jboss.hal.core.finder.FinderPath) PathsAutoComplete(org.jboss.hal.core.configuration.PathsAutoComplete) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Finder(org.jboss.hal.core.finder.Finder) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) Requires(org.jboss.hal.spi.Requires) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) AddressTemplates(org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) Consumer(java.util.function.Consumer) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) FormItem(org.jboss.hal.ballroom.form.FormItem) NameTokens(org.jboss.hal.meta.token.NameTokens) MbuiPresenter(org.jboss.hal.core.mbui.MbuiPresenter) Resources(org.jboss.hal.resources.Resources) SuggestCapabilitiesAutoComplete(org.jboss.hal.ballroom.autocomplete.SuggestCapabilitiesAutoComplete) MbuiView(org.jboss.hal.core.mbui.MbuiView) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) Form(org.jboss.hal.ballroom.form.Form) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Metadata(org.jboss.hal.meta.Metadata) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm)

Example 7 with LabelBuilder

use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.

the class OtherSettingsPresenter method addServerSslSniContext.

// -------------------------------------------- server ssl sni context
void addServerSslSniContext() {
    Metadata metadata = metadataRegistry.lookup(AddressTemplates.SERVER_SSL_SNI_CONTEXT_TEMPLATE);
    String id = Ids.build(Ids.ELYTRON_SERVER_SSL_SNI_CONTEXT, Ids.ADD);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(new NameItem(), 0).unsorted().addOnly().build();
    // "host-context-map" is not required in r-r-d for "add" operation
    // but the resource fails to add without this parameter, see https://issues.jboss.org/browse/WFCORE-4223
    form.getFormItem("host-context-map").setRequired(true);
    String type = new LabelBuilder().label(SERVER_SSL_SNI_CONTEXT);
    new AddResourceDialog(resources.messages().addResourceTitle(type), form, (name, model) -> {
        crud.add(type, name, AddressTemplates.SERVER_SSL_SNI_CONTEXT_TEMPLATE, model, (name1, address) -> reload(SERVER_SSL_SNI_CONTEXT, nodes -> getView().updateResourceElement(SERVER_SSL_SNI_CONTEXT, nodes)));
    }).show();
}
Also used : AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) FinishRemove(org.jboss.hal.ballroom.form.Form.FinishRemove) StatementContext(org.jboss.hal.meta.StatementContext) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) FinishReset(org.jboss.hal.ballroom.form.Form.FinishReset) RequireAtLeastOneAttributeValidation(org.jboss.hal.core.mbui.form.RequireAtLeastOneAttributeValidation) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) CrudOperations(org.jboss.hal.core.CrudOperations) ModelNodeHelper.move(org.jboss.hal.dmr.ModelNodeHelper.move) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) ComplexAttributeOperations(org.jboss.hal.core.ComplexAttributeOperations) FinderPath(org.jboss.hal.core.finder.FinderPath) PathsAutoComplete(org.jboss.hal.core.configuration.PathsAutoComplete) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Finder(org.jboss.hal.core.finder.Finder) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) Requires(org.jboss.hal.spi.Requires) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) AddressTemplates(org.jboss.hal.client.configuration.subsystem.elytron.AddressTemplates) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) Consumer(java.util.function.Consumer) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) FormItem(org.jboss.hal.ballroom.form.FormItem) NameTokens(org.jboss.hal.meta.token.NameTokens) MbuiPresenter(org.jboss.hal.core.mbui.MbuiPresenter) Resources(org.jboss.hal.resources.Resources) SuggestCapabilitiesAutoComplete(org.jboss.hal.ballroom.autocomplete.SuggestCapabilitiesAutoComplete) MbuiView(org.jboss.hal.core.mbui.MbuiView) NamedNode(org.jboss.hal.dmr.NamedNode) Collections(java.util.Collections) 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 8 with LabelBuilder

use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.

the class RealmsPresenter method resetKeyMapper.

void resetKeyMapper(String jdbcRealm, int pqIndex, String keyMapper, Form<ModelNode> form) {
    String type = new LabelBuilder().label(keyMapper);
    Metadata metadata = metadataRegistry.lookup(JDBC_REALM_TEMPLATE).forComplexAttribute(PRINCIPAL_QUERY).forComplexAttribute(keyMapper);
    ca.reset(jdbcRealm, keyMapperAttribute(pqIndex, keyMapper), type, JDBC_REALM_TEMPLATE, metadata, form, new Form.FinishReset<ModelNode>(form) {

        @Override
        public void afterReset(Form<ModelNode> form) {
            reloadJdbcRealms();
        }
    });
}
Also used : ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Form(org.jboss.hal.ballroom.form.Form) Metadata(org.jboss.hal.meta.Metadata) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 9 with LabelBuilder

use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.

the class CredentialReference method form.

/**
 * Creates a form for the {@code credential-reference} complex attribute of a resource. The form is setup as a singleton
 * form to add, save, reset and remove the complex attribute.
 *
 * @param baseId base ID used for the generated form and add resource dialog
 * @param metadata the metadata of the resource which contains the {@code credential-reference} attribute
 * @param crName the name of the credential-reference complex attribute
 * @param alternativeName the name of the alternative attribute
 * @param alternativeValue the value of the alternative attribute
 * @param address the fully qualified address of the resource used for the CRUD actions
 * @param callback the callback executed after the {@code credential-reference} attributes has been added, saved, reset or
 *        removed
 */
public Form<ModelNode> form(String baseId, Metadata metadata, String crName, String alternativeName, Supplier<String> alternativeValue, Supplier<ResourceAddress> address, Callback callback) {
    String credentialReferenceName = crName == null ? CREDENTIAL_REFERENCE : crName;
    Metadata crMetadata = metadata.forComplexAttribute(credentialReferenceName);
    EmptyState.Builder emptyStateBuilder = new EmptyState.Builder(Ids.build(baseId, credentialReferenceName, Ids.FORM, Ids.EMPTY), resources.constants().noResource());
    if (crMetadata.getSecurityContext().isWritable()) {
        emptyStateBuilder.primaryAction(resources.constants().add(), () -> {
            if (alternativeName != null && alternativeValue != null && !Strings.isNullOrEmpty(alternativeValue.get())) {
                String alternativeLabel = new LabelBuilder().label(alternativeName);
                DialogFactory.showConfirmation(resources.messages().addResourceTitle(Names.CREDENTIAL_REFERENCE), resources.messages().credentialReferenceAddConfirmation(alternativeLabel), () -> setTimeout(o -> addCredentialReference(baseId, crMetadata, credentialReferenceName, alternativeName, address, callback), SHORT_TIMEOUT));
            } else {
                addCredentialReference(baseId, crMetadata, credentialReferenceName, null, address, callback);
            }
        }, Constraint.executable(metadata.getTemplate(), ADD)).description(resources.messages().noResource());
    } else {
        emptyStateBuilder.description(resources.constants().restricted());
    }
    EmptyState noCredentialReference = emptyStateBuilder.build();
    ModelNodeForm.Builder<ModelNode> formBuilder = new ModelNodeForm.Builder<>(Ids.build(baseId, credentialReferenceName, Ids.FORM), crMetadata).include(STORE, ALIAS, CLEAR_TEXT, TYPE).unsorted().singleton(() -> {
        ResourceAddress fqAddress = address.get();
        Operation operation = null;
        if (fqAddress != null && crMetadata.getSecurityContext().isReadable()) {
            operation = new Operation.Builder(address.get(), READ_ATTRIBUTE_OPERATION).param(NAME, credentialReferenceName).build();
        }
        return operation;
    }, noCredentialReference).onSave(((f, changedValues) -> {
        ResourceAddress fqa = address.get();
        if (fqa != null) {
            if (changedValues.isEmpty()) {
                MessageEvent.fire(eventBus, Message.warning(resources.messages().noChanges()));
                callback.execute();
            } else {
                ca.save(credentialReferenceName, Names.CREDENTIAL_REFERENCE, fqa, f.getModel(), callback);
            }
        } else {
            MessageEvent.fire(eventBus, Message.error(resources.messages().credentialReferenceAddressError()));
        }
    }));
    // some credential-reference attributes are nillable=false, so only nillable=true may be removed
    if (crMetadata.getDescription().get(NILLABLE).asBoolean()) {
        formBuilder.prepareRemove(f -> {
            ResourceAddress fqAddress = address.get();
            if (fqAddress != null) {
                ca.remove(credentialReferenceName, Names.CREDENTIAL_REFERENCE, fqAddress, new Form.FinishRemove<ModelNode>(f) {

                    @Override
                    public void afterRemove(Form<ModelNode> form) {
                        callback.execute();
                    }
                });
            } else {
                MessageEvent.fire(eventBus, Message.error(resources.messages().credentialReferenceAddressError()));
            }
        });
    }
    Form<ModelNode> form = formBuilder.build();
    form.addFormValidation(new CrFormValidation(alternativeName, alternativeValue, resources));
    form.addFormValidation(new CrFormValuesValidation(resources));
    return form;
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Constraint(org.jboss.hal.meta.security.Constraint) MessageEvent(org.jboss.hal.spi.MessageEvent) SHORT_TIMEOUT(org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Supplier(java.util.function.Supplier) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FormValidation(org.jboss.hal.ballroom.form.FormValidation) Strings(com.google.common.base.Strings) Message(org.jboss.hal.spi.Message) EmptyState(org.jboss.hal.ballroom.EmptyState) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) ComplexAttributeOperations(org.jboss.hal.core.ComplexAttributeOperations) EventBus(com.google.web.bindery.event.shared.EventBus) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Composite(org.jboss.hal.dmr.Composite) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) FormItem(org.jboss.hal.ballroom.form.FormItem) Callback(org.jboss.hal.spi.Callback) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) Form(org.jboss.hal.ballroom.form.Form) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) EmptyState(org.jboss.hal.ballroom.EmptyState) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Form(org.jboss.hal.ballroom.form.Form) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 10 with LabelBuilder

use of org.jboss.hal.ballroom.LabelBuilder in project console by hal.

the class FormProcessor method process.

@Override
public void process(VariableElement field, Element element, String selector, MbuiViewContext context) {
    String title = element.getAttributeValue(XmlTags.TITLE);
    boolean autoSave = Boolean.parseBoolean(element.getAttributeValue(XmlTags.AUTO_SAVE));
    String addHandler = element.getAttributeValue(XmlTags.ADD_HANDLER);
    boolean reset = Boolean.parseBoolean(element.getAttributeValue(XmlTags.RESET));
    boolean includeRuntime = Boolean.parseBoolean(element.getAttributeValue(XmlTags.INCLUDE_RUNTIME));
    boolean singleton = XmlTags.SINGLETON_FORM.equalsIgnoreCase(element.getName());
    String onSave = element.getAttributeValue(XmlTags.ON_SAVE);
    String prepareReset = element.getAttributeValue(XmlTags.PREPARE_RESET);
    String nameResolver = element.getAttributeValue(XmlTags.NAME_RESOLVER);
    MetadataInfo metadata = findMetadata(field, element, context);
    AddressTemplate template = AddressTemplate.of(metadata.getTemplate());
    if (autoSave && !Strings.isNullOrEmpty(onSave)) {
        processor.error(field, "Please choose either auto-save or on-save not both.");
    } else if (autoSave) {
        if (title == null) {
            title = new LabelBuilder().label(template.lastName());
        }
        if (nameResolver != null && !ExpressionParser.isExpression(nameResolver)) {
            processor.error(field, "Name resolver in form#%s has to be an expression.", selector);
        }
        if ("*".equals(template.lastValue()) && nameResolver == null) {
            processor.error(field, "Auto save is enabled for form#%s and related metadata address ends in \"*\", " + "but no name resolver is is provided.", selector);
        }
    } else if (!Strings.isNullOrEmpty(onSave)) {
        if (!ExpressionParser.isExpression(onSave)) {
            processor.error(field, "on-save handler in form#%s has to be an expression.", selector);
        }
    }
    FormInfo formInfo = new FormInfo(field.getSimpleName().toString(), selector, getTypeParameter(field), metadata, title, addHandler, autoSave, onSave, reset, prepareReset, nameResolver, includeRuntime, singleton);
    context.addFormInfo(formInfo);
    org.jdom2.Element attributesContainer = element.getChild(XmlTags.ATTRIBUTES);
    if (attributesContainer != null) {
        List<Element> groupElements = attributesContainer.getChildren(XmlTags.GROUP);
        if (groupElements.isEmpty()) {
            processAttributes(field, attributesContainer).forEach(formInfo::addAttribute);
        } else {
            Map<String, Element> excludes = new HashMap<>();
            Map<String, FormInfo.Group> groupsById = new HashMap<>();
            // round one: process groups
            for (Element groupElement : groupElements) {
                String id = groupElement.getAttributeValue(XmlTags.ID);
                String name = groupElement.getAttributeValue(XmlTags.NAME);
                String groupTitle = groupElement.getAttributeValue(XmlTags.TITLE);
                FormInfo.Group group = new FormInfo.Group(id, name, groupTitle);
                groupElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> group.addAttribute(processAttribute(field, attributeElement)));
                formInfo.addGroup(group);
                if (id != null) {
                    groupsById.put(id, group);
                }
                Element excludeElement = groupElement.getChild(XmlTags.EXCLUDE);
                if (id != null && excludeElement != null) {
                    excludes.put(id, excludeElement);
                }
            }
            // round two: process group excludes (which might reference other groups)
            excludes.forEach((id, excludeElement) -> {
                FormInfo.Group group = groupsById.get(id);
                if (group != null) {
                    excludeElement.getChildren(XmlTags.ATTRIBUTE).forEach(attributeElement -> {
                        String name = attributeElement.getAttributeValue(XmlTags.NAME);
                        if (name != null) {
                            group.exclude(name);
                        }
                    });
                    excludeElement.getChildren(XmlTags.GROUP).forEach(groupElement -> {
                        String excludedGroupId = groupElement.getAttributeValue(XmlTags.ID);
                        if (excludedGroupId != null && groupsById.get(excludedGroupId) != null) {
                            FormInfo.Group excludedGroup = groupsById.get(excludedGroupId);
                            group.exclude(excludedGroup);
                        }
                    });
                }
            });
        }
    }
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) HashMap(java.util.HashMap) VariableElement(javax.lang.model.element.VariableElement) Element(org.jdom2.Element) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Element(org.jdom2.Element)

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