Search in sources :

Example 1 with FormItem

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

the class MailSessionPresenter method launchAddServer.

void launchAddServer() {
    SortedSet<String> availableServers = new TreeSet<>(asList(SMTP.toUpperCase(), IMAP.toUpperCase(), POP3.toUpperCase()));
    ResourceAddress selectedSessionAddress = SELECTED_MAIL_SESSION_TEMPLATE.resolve(statementContext);
    Operation serverNamesOp = new Operation.Builder(selectedSessionAddress, READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, SERVER).build();
    dispatcher.execute(serverNamesOp, serversResult -> {
        Set<String> existingServers = serversResult.asList().stream().map(node -> node.asString().toUpperCase()).collect(toSet());
        availableServers.removeAll(existingServers);
        if (availableServers.isEmpty()) {
            MessageEvent.fire(getEventBus(), Message.error(resources.messages().allMailServersExist()));
        } else {
            FormItem<String> serverTypeItem;
            if (availableServers.size() == 1) {
                serverTypeItem = new TextBoxItem(ModelDescriptionConstants.SERVER_TYPE, resources.constants().type());
                serverTypeItem.setValue(availableServers.first());
                serverTypeItem.setEnabled(false);
            } else {
                serverTypeItem = new SingleSelectBoxItem(ModelDescriptionConstants.SERVER_TYPE, resources.constants().type(), new ArrayList<>(availableServers), false);
                serverTypeItem.setRequired(true);
            }
            Metadata metadata = metadataRegistry.lookup(AddressTemplates.SERVER_TEMPLATE);
            Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.MAIL_SERVER_DIALOG, metadata).unboundFormItem(serverTypeItem, 0).include(OUTBOUND_SOCKET_BINDING_REF, USERNAME, PASSWORD, "ssl", "tls").fromRequestProperties().requiredOnly().unsorted().build();
            form.getFormItem(OUTBOUND_SOCKET_BINDING_REF).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, AddressTemplates.SOCKET_BINDING_TEMPLATE));
            AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(Names.SERVER), form, (name, modelNode) -> {
                String serverType = serverTypeItem.getValue().toLowerCase();
                ResourceAddress address = SELECTED_MAIL_SESSION_TEMPLATE.append(SERVER + EQUALS + serverType).resolve(statementContext);
                Operation operation = new Operation.Builder(address, ModelDescriptionConstants.ADD).payload(modelNode).build();
                dispatcher.execute(operation, result -> {
                    MessageEvent.fire(getEventBus(), Message.success(resources.messages().addResourceSuccess(Names.SERVER, serverType)));
                    reload();
                });
            });
            dialog.show();
        }
    });
}
Also used : SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) SortedSet(java.util.SortedSet) StatementContext(org.jboss.hal.meta.StatementContext) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) FinishReset(org.jboss.hal.ballroom.form.Form.FinishReset) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) Nullable(javax.annotation.Nullable) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Collectors.toSet(java.util.stream.Collectors.toSet) Requires(org.jboss.hal.spi.Requires) CrudOperations(org.jboss.hal.core.CrudOperations) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) Operation(org.jboss.hal.dmr.Operation) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Ids(org.jboss.hal.resources.Ids) Set(java.util.Set) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) FinderPath(org.jboss.hal.core.finder.FinderPath) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) AddressTemplates(org.jboss.hal.client.configuration.subsystem.mail.AddressTemplates) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) FormItem(org.jboss.hal.ballroom.form.FormItem) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) SelectionAwareStatementContext(org.jboss.hal.meta.SelectionAwareStatementContext) NameTokens(org.jboss.hal.meta.token.NameTokens) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Resources(org.jboss.hal.resources.Resources) HalView(org.jboss.hal.core.mvp.HalView) Finder(org.jboss.hal.core.finder.Finder) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ArrayList(java.util.ArrayList) Metadata(org.jboss.hal.meta.Metadata) Operation(org.jboss.hal.dmr.Operation) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) TreeSet(java.util.TreeSet) ModelNode(org.jboss.hal.dmr.ModelNode) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete)

Example 2 with FormItem

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

the class ModelNodeFormTest method noRuntime.

@Test
public void noRuntime() throws Exception {
    ModelNodeForm<ModelNode> form = builder("noRuntime", new ResourceDescriptionBuilder().storage(ImmutableMap.of("foo", CONFIGURATION, "bar", RUNTIME))).build();
    Iterable<FormItem> formItems = form.getFormItems();
    Iterator<FormItem> iterator = formItems.iterator();
    assertEquals(1, Iterables.size(formItems));
    assertEquals("foo", iterator.next().getName());
}
Also used : FormItem(org.jboss.hal.ballroom.form.FormItem) ModelNode(org.jboss.hal.dmr.ModelNode) ResourceDescriptionBuilder(org.jboss.hal.core.mbui.ResourceDescriptionBuilder) Test(org.junit.Test)

Example 3 with FormItem

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

the class ConfigurationStep method onNext.

@Override
protected boolean onNext(final EnableSSLContext context) {
    boolean valid = form.save();
    if (valid) {
        // set default values, as metadata comes from an artifical resource description (ssl-mgmt-wizard.dmr)
        description.getAttributes(ATTRIBUTES).forEach(p -> {
            FormItem formItem = getFormItem(p.getName());
            if (p.getValue().hasDefined(DEFAULT) && formItem != null && formItem.isEmpty()) {
                model.get(p.getName()).set(p.getValue().get(DEFAULT));
            }
        });
        context.model = model;
    }
    return valid;
}
Also used : FormItem(org.jboss.hal.ballroom.form.FormItem)

Example 4 with FormItem

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

the class ModelNodeMapping method persistModel.

@Override
@SuppressWarnings("unchecked")
public void persistModel(String id, T model, Iterable<FormItem> formItems) {
    for (FormItem formItem : formItems) {
        String name = formItem.getName();
        if (formItem.isModified()) {
            ModelNode attributeDescription = findAttribute(name);
            if (attributeDescription == null) {
                logger.error("{}: Unable to persist attribute '{}': No attribute description found in\n{}", id, name, attributeDescriptions);
                continue;
            }
            if (formItem instanceof ModelNodeItem) {
                if (formItem.getValue() == null) {
                    failSafeRemove(model, name);
                } else {
                    model.get(name).set(((ModelNodeItem) formItem).getValue());
                }
            } else {
                if (formItem.isExpressionValue()) {
                    model.get(name).setExpression(formItem.getExpressionValue());
                } else {
                    ModelType type = attributeDescription.get(TYPE).asType();
                    Object value = formItem.getValue();
                    switch(type) {
                        case BOOLEAN:
                            Boolean booleanValue = (Boolean) value;
                            if (booleanValue == null) {
                                failSafeRemove(model, name);
                            } else {
                                model.get(name).set(booleanValue);
                            }
                            break;
                        case BIG_INTEGER:
                        case INT:
                        case LONG:
                            Long longValue = (Long) value;
                            if (longValue == null) {
                                failSafeRemove(model, name);
                            } else {
                                if (type == BIG_INTEGER) {
                                    model.get(name).set(BigInteger.valueOf(longValue));
                                } else if (type == INT) {
                                    model.get(name).set(longValue.intValue());
                                } else {
                                    model.get(name).set(longValue);
                                }
                            }
                            break;
                        case DOUBLE:
                            Double doubleValue = (Double) value;
                            if (doubleValue == null) {
                                failSafeRemove(model, name);
                            } else {
                                model.get(name).set(doubleValue);
                            }
                            break;
                        case LIST:
                            List<String> list = (List<String>) value;
                            if (list == null || list.isEmpty()) {
                                failSafeRemove(model, name);
                            } else {
                                ModelNode listNode = new ModelNode();
                                for (String s : list) {
                                    listNode.add(s);
                                }
                                model.get(name).set(listNode);
                            }
                            break;
                        case OBJECT:
                            boolean stringValueType = attributeDescription.get(VALUE_TYPE).getType().equals(ModelType.TYPE) && attributeDescription.get(VALUE_TYPE).asType().equals(ModelType.STRING);
                            if (stringValueType) {
                                Map<String, String> map = (Map<String, String>) value;
                                if (map == null || map.isEmpty()) {
                                    failSafeRemove(model, name);
                                } else {
                                    ModelNode mapNode = new ModelNode();
                                    for (Map.Entry<String, String> entry : map.entrySet()) {
                                        mapNode.get(entry.getKey()).set(entry.getValue());
                                    }
                                    model.get(name).set(mapNode);
                                }
                            }
                            break;
                        case STRING:
                            String stringValue = value == null ? null : String.valueOf(value);
                            if (Strings.isNullOrEmpty(stringValue)) {
                                failSafeRemove(model, name);
                            } else {
                                model.get(name).set(stringValue);
                            }
                            break;
                        // unsupported types
                        case BIG_DECIMAL:
                        case BYTES:
                        case EXPRESSION:
                        case PROPERTY:
                        case TYPE:
                        case UNDEFINED:
                            logger.warn("{}: persisting form field '{}' to type '{}' not implemented", id, name, type);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}
Also used : FormItem(org.jboss.hal.ballroom.form.FormItem) ModelType(org.jboss.hal.dmr.ModelType) ModelNodeItem(org.jboss.hal.ballroom.form.ModelNodeItem) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ModelNode(org.jboss.hal.dmr.ModelNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with FormItem

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

the class FilterView method updateHostRefs.

@SuppressWarnings("ConstantConditions")
private void updateHostRefs(final Table<NamedNode> table, final Form<NamedNode> form) {
    FormItem<String> formItem = form.getFormItem(HOSTS);
    if (formItem != null) {
        if (table.hasSelection()) {
            ResourceAddress filterRefAddress = HOST_TEMPLATE.append(FILTER_REF + "=" + table.selectedRow().getName()).resolve(mbuiContext.statementContext());
            Operation filterRefOp = new Operation.Builder(filterRefAddress, READ_RESOURCE_OPERATION).build();
            ResourceAddress locationFilterRefAddress = HOST_TEMPLATE.append(LOCATION + "=*").append(FILTER_REF + "=" + table.selectedRow().getName()).resolve(mbuiContext.statementContext());
            Operation locationFilterRefOp = new Operation.Builder(locationFilterRefAddress, READ_RESOURCE_OPERATION).build();
            mbuiContext.dispatcher().execute(new Composite(filterRefOp, locationFilterRefOp), (CompositeResult result) -> {
                SortedSet<String> hosts = new TreeSet<>();
                result.step(0).get(RESULT).asList().stream().map(node -> {
                    ResourceAddress adr = new ResourceAddress(node.get(ADDRESS));
                    ResourceAddress host = adr.getParent();
                    ResourceAddress server = host.getParent();
                    return server.lastValue() + "/" + host.lastValue();
                }).forEach(hosts::add);
                result.step(1).get(RESULT).asList().stream().map(node -> {
                    ResourceAddress adr = new ResourceAddress(node.get(ADDRESS));
                    ResourceAddress host = adr.getParent().getParent();
                    ResourceAddress server = host.getParent();
                    return server.lastValue() + "/" + host.lastValue();
                }).forEach(hosts::add);
                formItem.setValue(String.join(", ", hosts));
            }, (op1, failure) -> formItem.clearValue());
        } else {
            formItem.clearValue();
        }
    }
}
Also used : ModelNode(org.jboss.hal.dmr.ModelNode) Arrays(java.util.Arrays) SortedSet(java.util.SortedSet) MbuiViewImpl(org.jboss.hal.core.mbui.MbuiViewImpl) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) TreeSet(java.util.TreeSet) StaticAutoComplete(org.jboss.hal.ballroom.autocomplete.StaticAutoComplete) MbuiElement(org.jboss.hal.spi.MbuiElement) ResponseHeader(org.jboss.hal.dmr.dispatch.ResponseHeader) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) HOST_TEMPLATE(org.jboss.hal.client.configuration.subsystem.undertow.AddressTemplates.HOST_TEMPLATE) CompositeResult(org.jboss.hal.dmr.CompositeResult) Table(org.jboss.hal.ballroom.table.Table) Operation(org.jboss.hal.dmr.Operation) VerticalNavigation(org.jboss.hal.ballroom.VerticalNavigation) Composite(org.jboss.hal.dmr.Composite) ModelNodeHelper.failSafePropertyList(org.jboss.hal.dmr.ModelNodeHelper.failSafePropertyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FormItem(org.jboss.hal.ballroom.form.FormItem) MbuiContext(org.jboss.hal.core.mbui.MbuiContext) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) PostConstruct(javax.annotation.PostConstruct) MbuiView(org.jboss.hal.spi.MbuiView) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) TreeSet(java.util.TreeSet) Operation(org.jboss.hal.dmr.Operation)

Aggregations

FormItem (org.jboss.hal.ballroom.form.FormItem)16 ModelNode (org.jboss.hal.dmr.ModelNode)12 Form (org.jboss.hal.ballroom.form.Form)9 Map (java.util.Map)7 List (java.util.List)6 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)6 Operation (org.jboss.hal.dmr.Operation)6 Collectors.toList (java.util.stream.Collectors.toList)5 NamedNode (org.jboss.hal.dmr.NamedNode)5 ResourceAddress (org.jboss.hal.dmr.ResourceAddress)5 EventBus (com.google.web.bindery.event.shared.EventBus)4 NameToken (com.gwtplatform.mvp.client.annotations.NameToken)4 ProxyCodeSplit (com.gwtplatform.mvp.client.annotations.ProxyCodeSplit)4 ProxyPlace (com.gwtplatform.mvp.client.proxy.ProxyPlace)4 HashMap (java.util.HashMap)4 Inject (javax.inject.Inject)4 Finder (org.jboss.hal.core.finder.Finder)4 FinderPath (org.jboss.hal.core.finder.FinderPath)4 FinderPathFactory (org.jboss.hal.core.finder.FinderPathFactory)4 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)4