Search in sources :

Example 1 with EmptyState

use of org.jboss.hal.ballroom.EmptyState 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 2 with EmptyState

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

the class SecurityManagerView method createPermissionUI.

private void createPermissionUI(Permission permission) {
    Metadata metadata = metadataRegistry.lookup(DEPLOYMENT_PERMISSIONS_TEMPLATE).forComplexAttribute(permission.resource);
    Constraint constraint = Constraint.writable(DEPLOYMENT_PERMISSIONS_TEMPLATE, permission.resource);
    EmptyState emptyState = new EmptyState.Builder(Ids.DEPLOYMENT_PERMISSIONS_EMPTY, Names.DEPLOYMENT_PERMISSIONS).description(resources.messages().noDeploymentPermissions()).primaryAction(resources.constants().add(), () -> presenter.addDeploymentPermissions(), constraint).build();
    emptyState.element().classList.add(marginTopLarge);
    emptyStates.put(permission, emptyState);
    Table<ModelNode> table = new ModelNodeTable.Builder<>(Ids.build(permission.baseId, Ids.TABLE), metadata).button(resources.constants().add(), t -> presenter.addPermission(permission), constraint).button(resources.constants().remove(), t -> presenter.removePermission(permission, t.selectedRow().get(HAL_INDEX).asInt()), Scope.SELECTED, constraint).column(CLASS).build();
    tables.put(permission, table);
    registerAttachable(table);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.build(permission.baseId, Ids.FORM), metadata).onSave((f, changedValues) -> presenter.savePermission(permission, f.getModel().get(HAL_INDEX).asInt(), changedValues)).build();
    forms.put(permission, form);
    registerAttachable(form);
    HTMLElement masterDetail;
    HTMLElement section = section().add(emptyState).add(masterDetail = div().add(h(1).textContent(permission.type)).add(p().textContent(metadata.getDescription().getDescription())).add(table).add(form).element()).element();
    masterDetails.put(permission, masterDetail);
    navigation.addPrimary(Ids.build(permission.baseId, Ids.ITEM), permission.type, permission.icon, section);
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Elements.div(org.jboss.gwt.elemento.core.Elements.div) DEPLOYMENT_PERMISSIONS_TEMPLATE(org.jboss.hal.client.configuration.subsystem.securitymanager.AddressTemplates.DEPLOYMENT_PERMISSIONS_TEMPLATE) Constraint(org.jboss.hal.meta.security.Constraint) HAL_INDEX(org.jboss.hal.dmr.ModelDescriptionConstants.HAL_INDEX) ModelNodeTable(org.jboss.hal.core.mbui.table.ModelNodeTable) HashMap(java.util.HashMap) LayoutBuilder.column(org.jboss.hal.ballroom.LayoutBuilder.column) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Elements.section(org.jboss.gwt.elemento.core.Elements.section) Elements.p(org.jboss.gwt.elemento.core.Elements.p) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) EmptyState(org.jboss.hal.ballroom.EmptyState) HalViewImpl(org.jboss.hal.core.mvp.HalViewImpl) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Elements.h(org.jboss.gwt.elemento.core.Elements.h) CLASS(org.jboss.hal.dmr.ModelDescriptionConstants.CLASS) Table(org.jboss.hal.ballroom.table.Table) LayoutBuilder.row(org.jboss.hal.ballroom.LayoutBuilder.row) Ids(org.jboss.hal.resources.Ids) CSS.marginTopLarge(org.jboss.hal.resources.CSS.marginTopLarge) VerticalNavigation(org.jboss.hal.ballroom.VerticalNavigation) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) Resources(org.jboss.hal.resources.Resources) Elements(org.jboss.gwt.elemento.core.Elements) Form(org.jboss.hal.ballroom.form.Form) Scope(org.jboss.hal.ballroom.table.Scope) EmptyState(org.jboss.hal.ballroom.EmptyState) HTMLElement(elemental2.dom.HTMLElement) Constraint(org.jboss.hal.meta.security.Constraint) Metadata(org.jboss.hal.meta.Metadata) ModelNode(org.jboss.hal.dmr.ModelNode)

Aggregations

Inject (javax.inject.Inject)2 EmptyState (org.jboss.hal.ballroom.EmptyState)2 Form (org.jboss.hal.ballroom.form.Form)2 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)2 ModelNode (org.jboss.hal.dmr.ModelNode)2 Metadata (org.jboss.hal.meta.Metadata)2 Constraint (org.jboss.hal.meta.security.Constraint)2 Ids (org.jboss.hal.resources.Ids)2 Names (org.jboss.hal.resources.Names)2 Resources (org.jboss.hal.resources.Resources)2 Strings (com.google.common.base.Strings)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 DomGlobal.setTimeout (elemental2.dom.DomGlobal.setTimeout)1 HTMLElement (elemental2.dom.HTMLElement)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Elements (org.jboss.gwt.elemento.core.Elements)1 Elements.div (org.jboss.gwt.elemento.core.Elements.div)1