Search in sources :

Example 1 with PropertiesItem

use of org.jboss.hal.ballroom.form.PropertiesItem in project console by hal.

the class RemotingView method init.

@PostConstruct
void init() {
    // remote connector
    Metadata connectorMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_TEMPLATE);
    connectorForm = new ModelNodeForm.Builder<NamedNode>(Ids.REMOTING_CONNECTOR_FORM, connectorMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 1).onSave((form, changedValues) -> presenter.saveConnector(form, changedValues)).prepareReset(form -> presenter.resetConnector(form)).build();
    registerAttachable(connectorForm);
    // remote connector security
    Metadata connectorSecurityMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_SECURITY_TEMPLATE);
    connectorSecurityForm = new ModelNodeForm.Builder<>(Ids.REMOTING_CONNECTOR_SECURITY_FORM, connectorSecurityMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).singleton(() -> new Operation.Builder(SELECTED_CONNECTOR_SECURITY_TEMPLATE.resolve(presenter.selectedConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createConnectorSecurity()).onSave((form, changedValues) -> presenter.saveConnectorSecurity(form, changedValues)).prepareReset(form -> presenter.resetConnectorSecurity(form)).prepareRemove(form -> presenter.removeConnectorSecurity(form)).build();
    registerAttachable(connectorSecurityForm);
    // remote connector security policy
    Metadata connectorSecurityPolicyMetadata = mbuiContext.metadataRegistry().lookup(CONNECTOR_SECURITY_POLICY_TEMPLATE);
    connectorSecurityPolicyForm = new ModelNodeForm.Builder<>(Ids.REMOTING_CONNECTOR_SECURITY_POLICY_FORM, connectorSecurityPolicyMetadata).singleton(() -> new Operation.Builder(SELECTED_CONNECTOR_SECURITY_POLICY_TEMPLATE.resolve(presenter.selectedConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createConnectorSecurityPolicy()).onSave((form, changedValues) -> presenter.saveConnectorSecurityPolicy(changedValues)).prepareReset(form -> presenter.resetConnectorSecurityPolicy(form)).prepareRemove(form -> presenter.removeConnectorSecurityPolicy(form)).build();
    registerAttachable(connectorSecurityPolicyForm);
    // remote connector tabs
    Tabs connectorTabs = new Tabs(Ids.REMOTING_CONNECTOR_TAB_CONTAINER);
    connectorTabs.add(Ids.REMOTING_CONNECTOR_TAB, mbuiContext.resources().constants().attributes(), connectorForm.element());
    connectorTabs.add(Ids.REMOTING_CONNECTOR_SECURITY_TAB, Names.SECURITY, connectorSecurityForm.element());
    connectorTabs.add(Ids.REMOTING_CONNECTOR_SECURITY_POLICY_TAB, Names.POLICY, connectorSecurityPolicyForm.element());
    connectorTable.element().parentNode.appendChild(connectorTabs.element());
    // http connector
    Metadata httpConnectorMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_TEMPLATE);
    httpConnectorForm = new ModelNodeForm.Builder<NamedNode>(Ids.REMOTING_HTTP_CONNECTOR_FORM, httpConnectorMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).onSave((form, changedValues) -> presenter.saveHttpConnector(form, changedValues)).prepareReset(form -> presenter.resetHttpConnector(form)).build();
    registerAttachable(httpConnectorForm);
    // http connector security
    Metadata httpConnectorSecurityMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_SECURITY_TEMPLATE);
    httpConnectorSecurityForm = new ModelNodeForm.Builder<>(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_FORM, httpConnectorSecurityMetadata).unboundFormItem(new PropertiesItem(PROPERTY), 2).singleton(() -> new Operation.Builder(SELECTED_HTTP_CONNECTOR_SECURITY_TEMPLATE.resolve(presenter.selectedHttpConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createHttpConnectorSecurity()).onSave((form, changedValues) -> presenter.saveHttpConnectorSecurity(form, changedValues)).prepareReset(form -> presenter.resetHttpConnectorSecurity(form)).prepareRemove(form -> presenter.removeHttpConnectorSecurity(form)).build();
    registerAttachable(httpConnectorSecurityForm);
    // http connector security policy
    Metadata httpConnectorSecurityPolicyMetadata = mbuiContext.metadataRegistry().lookup(HTTP_CONNECTOR_SECURITY_POLICY_TEMPLATE);
    httpConnectorSecurityPolicyForm = new ModelNodeForm.Builder<>(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_POLICY_FORM, httpConnectorSecurityPolicyMetadata).singleton(() -> new Operation.Builder(SELECTED_HTTP_CONNECTOR_SECURITY_POLICY_TEMPLATE.resolve(presenter.selectedHttpConnectorContext), READ_RESOURCE_OPERATION).build(), () -> presenter.createHttpConnectorSecurityPolicy()).onSave((form, changedValues) -> presenter.saveHttpConnectorSecurityPolicy(changedValues)).prepareReset(form -> presenter.resetHttpConnectorSecurityPolicy(form)).prepareRemove(form -> presenter.removeHttpConnectorSecurityPolicy(form)).build();
    registerAttachable(httpConnectorSecurityPolicyForm);
    // http connector tabs
    Tabs httpConnectorTabs = new Tabs(Ids.REMOTING_HTTP_CONNECTOR_TAB_CONTAINER);
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_TAB, mbuiContext.resources().constants().attributes(), httpConnectorForm.element());
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_TAB, Names.SECURITY, httpConnectorSecurityForm.element());
    httpConnectorTabs.add(Ids.REMOTING_HTTP_CONNECTOR_SECURITY_POLICY_TAB, Names.POLICY, httpConnectorSecurityPolicyForm.element());
    httpConnectorTable.element().parentNode.appendChild(httpConnectorTabs.element());
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) MbuiViewImpl(org.jboss.hal.core.mbui.MbuiViewImpl) Tabs(org.jboss.hal.ballroom.Tabs) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) PROPERTY(org.jboss.hal.dmr.ModelDescriptionConstants.PROPERTY) Collectors.toMap(java.util.stream.Collectors.toMap) MbuiElement(org.jboss.hal.spi.MbuiElement) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) Map(java.util.Map) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Nullable(javax.annotation.Nullable) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Table(org.jboss.hal.ballroom.table.Table) Operation(org.jboss.hal.dmr.Operation) AddressTemplates(org.jboss.hal.client.configuration.subsystem.remoting.AddressTemplates) Ids(org.jboss.hal.resources.Ids) VerticalNavigation(org.jboss.hal.ballroom.VerticalNavigation) ModelNodeHelper.failSafeGet(org.jboss.hal.dmr.ModelNodeHelper.failSafeGet) ModelNodeHelper.failSafePropertyList(org.jboss.hal.dmr.ModelNodeHelper.failSafePropertyList) FormItem(org.jboss.hal.ballroom.form.FormItem) PropertiesItem(org.jboss.hal.ballroom.form.PropertiesItem) MbuiContext(org.jboss.hal.core.mbui.MbuiContext) PostConstruct(javax.annotation.PostConstruct) MbuiView(org.jboss.hal.spi.MbuiView) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) PropertiesItem(org.jboss.hal.ballroom.form.PropertiesItem) Metadata(org.jboss.hal.meta.Metadata) NamedNode(org.jboss.hal.dmr.NamedNode) Tabs(org.jboss.hal.ballroom.Tabs) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) PostConstruct(javax.annotation.PostConstruct)

Example 2 with PropertiesItem

use of org.jboss.hal.ballroom.form.PropertiesItem in project console by hal.

the class DefaultFormItemProvider method createFrom.

@Override
public FormItem<?> createFrom(Property property) {
    FormItem<?> formItem = null;
    String name = property.getName();
    String label = labelBuilder.label(property);
    ModelNode attributeDescription = property.getValue();
    // don't use 'required' here!
    boolean required = attributeDescription.hasDefined(NILLABLE) && !attributeDescription.get(NILLABLE).asBoolean();
    boolean expressionAllowed = attributeDescription.hasDefined(EXPRESSIONS_ALLOWED) && attributeDescription.get(EXPRESSIONS_ALLOWED).asBoolean();
    boolean readOnly = attributeDescription.hasDefined(ACCESS_TYPE) && (READ_ONLY.equals(attributeDescription.get(ACCESS_TYPE).asString()) || METRIC.equals(attributeDescription.get(ACCESS_TYPE).asString()));
    String unit = attributeDescription.hasDefined(UNIT) ? attributeDescription.get(UNIT).asString() : null;
    Deprecation deprecation = attributeDescription.hasDefined(DEPRECATED) ? new Deprecation(attributeDescription.get(DEPRECATED)) : null;
    if (attributeDescription.hasDefined(TYPE)) {
        ModelType type = attributeDescription.get(TYPE).asType();
        ModelType valueType = (attributeDescription.has(VALUE_TYPE) && attributeDescription.get(VALUE_TYPE).getType() != ModelType.OBJECT) ? ModelType.valueOf(attributeDescription.get(VALUE_TYPE).asString()) : null;
        switch(type) {
            case BOOLEAN:
                {
                    SwitchItem switchItem = new SwitchItem(name, label);
                    if (attributeDescription.hasDefined(DEFAULT)) {
                        switchItem.assignDefaultValue(attributeDescription.get(DEFAULT).asBoolean());
                    }
                    formItem = switchItem;
                    break;
                }
            case BIG_INTEGER:
            case INT:
            case LONG:
                {
                    long min, max;
                    if (type == ModelType.INT) {
                        min = attributeDescription.get(MIN).asLong(Integer.MIN_VALUE);
                        max = attributeDescription.get(MAX).asLong(Integer.MAX_VALUE);
                    } else {
                        min = attributeDescription.get(MIN).asLong(MIN_SAFE_LONG);
                        max = attributeDescription.get(MAX).asLong(MAX_SAFE_LONG);
                    }
                    NumberItem numberItem = new NumberItem(name, label, unit, min, max);
                    if (attributeDescription.hasDefined(DEFAULT)) {
                        long defaultValue = attributeDescription.get(DEFAULT).asLong();
                        numberItem.assignDefaultValue(defaultValue);
                    }
                    formItem = numberItem;
                    break;
                }
            case DOUBLE:
                {
                    long min = attributeDescription.get(MIN).asLong(MIN_SAFE_LONG);
                    long max = attributeDescription.get(MAX).asLong(MAX_SAFE_LONG);
                    NumberDoubleItem numberItem = new NumberDoubleItem(name, label, unit, min, max);
                    if (attributeDescription.hasDefined(DEFAULT)) {
                        double defaultValue = attributeDescription.get(DEFAULT).asDouble();
                        numberItem.assignDefaultValue(defaultValue);
                    }
                    formItem = numberItem;
                    break;
                }
            case LIST:
                {
                    if (valueType != null && ModelType.STRING == valueType) {
                        List<String> allowedValues = stringValues(attributeDescription, ALLOWED);
                        if (!allowedValues.isEmpty()) {
                            MultiSelectBoxItem multiSelectBoxItem = new MultiSelectBoxItem(name, label, allowedValues);
                            if (attributeDescription.hasDefined(DEFAULT)) {
                                List<String> defaultValues = stringValues(attributeDescription, DEFAULT);
                                if (!defaultValues.isEmpty()) {
                                    multiSelectBoxItem.assignDefaultValue(defaultValues);
                                }
                            }
                            formItem = multiSelectBoxItem;
                        } else {
                            ListItem listItem = new ListItem(name, label);
                            if (attributeDescription.hasDefined(DEFAULT)) {
                                List<String> defaultValues = stringValues(attributeDescription, DEFAULT);
                                if (!defaultValues.isEmpty()) {
                                    listItem.assignDefaultValue(defaultValues);
                                }
                            }
                            formItem = listItem;
                            checkCapabilityReference(attributeDescription, formItem);
                        }
                    } else if (isSimpleTuple(attributeDescription)) {
                        // process OBJECT type attribute if all of its subattributes are simple types
                        formItem = new TuplesListItem(name, label, metadata.forComplexAttribute(property.getName()));
                    } else {
                        logger.warn("Unsupported model type {} for attribute {} in metadata {}. Unable to create a form item. Attribute will be skipped.", type.name(), property.getName(), metadata.getTemplate());
                        break;
                    }
                    break;
                }
            case OBJECT:
                {
                    if (valueType != null && ModelType.STRING == valueType) {
                        PropertiesItem propertiesItem = new PropertiesItem(name, label);
                        List<Property> properties = ModelNodeHelper.getOrDefault(attributeDescription, DEFAULT, () -> attributeDescription.get(DEFAULT).asPropertyList(), emptyList());
                        if (!properties.isEmpty()) {
                            Map<String, String> defaultValues = new HashMap<>();
                            for (Property p : properties) {
                                defaultValues.put(p.getName(), p.getValue().asString());
                            }
                            propertiesItem.assignDefaultValue(defaultValues);
                        }
                        formItem = propertiesItem;
                    }
                    break;
                }
            case STRING:
                {
                    List<String> allowedValues = stringValues(attributeDescription, ALLOWED);
                    if (allowedValues.isEmpty()) {
                        FormItem<String> textBoxItem = new TextBoxItem(name, label, null);
                        boolean sensitive = failSafeGet(attributeDescription, ACCESS_CONSTRAINTS + "/" + SENSITIVE).isDefined();
                        if (PASSWORD.equals(name) || sensitive) {
                            textBoxItem.mask();
                        }
                        if (attributeDescription.hasDefined(DEFAULT)) {
                            textBoxItem.assignDefaultValue(attributeDescription.get(DEFAULT).asString());
                        }
                        formItem = textBoxItem;
                        checkCapabilityReference(attributeDescription, formItem);
                    } else {
                        SingleSelectBoxItem singleSelectBoxItem = new SingleSelectBoxItem(name, label, allowedValues, !required);
                        if (attributeDescription.hasDefined(DEFAULT)) {
                            singleSelectBoxItem.assignDefaultValue(attributeDescription.get(DEFAULT).asString());
                        }
                        formItem = singleSelectBoxItem;
                    }
                    break;
                }
            // unsupported types
            case BIG_DECIMAL:
            case BYTES:
            case EXPRESSION:
            case PROPERTY:
            case TYPE:
            case UNDEFINED:
                logger.warn("Unsupported model type {} for attribute {} in metadata {}. Unable to create a form item. Attribute will be skipped.", type.name(), property.getName(), metadata.getTemplate());
                break;
            default:
                break;
        }
        if (formItem != null) {
            formItem.setRequired(required);
            formItem.setDeprecated(deprecation);
            if (formItem.supportsExpressions()) {
                formItem.setExpressionAllowed(expressionAllowed);
                formItem.addResolveExpressionHandler(event -> {
                    // resend as application event
                    Core.INSTANCE.eventBus().fireEvent(event);
                });
            }
            if (readOnly) {
                formItem.setEnabled(false);
                // if the attribute is read-only and required, the form validation prevents to save the form
                // remove the required constraint to allow the save operation.
                formItem.setRequired(false);
            }
        }
    }
    return formItem;
}
Also used : TuplesListItem(org.jboss.hal.core.ui.TuplesListItem) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) FormItem(org.jboss.hal.ballroom.form.FormItem) NumberItem(org.jboss.hal.ballroom.form.NumberItem) MultiSelectBoxItem(org.jboss.hal.ballroom.form.MultiSelectBoxItem) PropertiesItem(org.jboss.hal.ballroom.form.PropertiesItem) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) Deprecation(org.jboss.hal.dmr.Deprecation) ModelType(org.jboss.hal.dmr.ModelType) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NumberDoubleItem(org.jboss.hal.ballroom.form.NumberDoubleItem) ListItem(org.jboss.hal.ballroom.form.ListItem) TuplesListItem(org.jboss.hal.core.ui.TuplesListItem) ModelNode(org.jboss.hal.dmr.ModelNode) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.jboss.hal.dmr.Property) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem)

Aggregations

Map (java.util.Map)2 FormItem (org.jboss.hal.ballroom.form.FormItem)2 PropertiesItem (org.jboss.hal.ballroom.form.PropertiesItem)2 ModelNode (org.jboss.hal.dmr.ModelNode)2 Property (org.jboss.hal.dmr.Property)2 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Nullable (javax.annotation.Nullable)1 PostConstruct (javax.annotation.PostConstruct)1 Tabs (org.jboss.hal.ballroom.Tabs)1 VerticalNavigation (org.jboss.hal.ballroom.VerticalNavigation)1 Form (org.jboss.hal.ballroom.form.Form)1 ListItem (org.jboss.hal.ballroom.form.ListItem)1 MultiSelectBoxItem (org.jboss.hal.ballroom.form.MultiSelectBoxItem)1 NumberDoubleItem (org.jboss.hal.ballroom.form.NumberDoubleItem)1 NumberItem (org.jboss.hal.ballroom.form.NumberItem)1 SingleSelectBoxItem (org.jboss.hal.ballroom.form.SingleSelectBoxItem)1