Search in sources :

Example 1 with SingleSelectBoxItem

use of org.jboss.hal.ballroom.form.SingleSelectBoxItem 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 SingleSelectBoxItem

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

the class JcaPresenter method launchAddThreadPool.

// ------------------------------------------------------ thread pools (for normal and distributed work managers)
/**
 * Used to bring up the dialog to add thread pools for the normal and the distributed work managers.
 * <p>
 * Only one long and one short running thread pool is allowed per (distributed) work manager. This method takes care of
 * showing the right attributes in the dialog. If there are already long and short running thread pools attached to the work
 * manager an error message is shown.
 */
void launchAddThreadPool(AddressTemplate workmanagerTemplate, String workmanager) {
    dispatcher.execute(threadPoolsOperation(workmanagerTemplate, workmanager), (CompositeResult cr) -> {
        boolean lrtPresent = !cr.step(0).get(RESULT).asPropertyList().isEmpty();
        boolean srtPresent = !cr.step(1).get(RESULT).asPropertyList().isEmpty();
        if (lrtPresent && srtPresent) {
            MessageEvent.fire(getEventBus(), Message.error(resources.messages().allThreadPoolsExist()));
        } else {
            FormItem<String> typeItem;
            if (!lrtPresent && !srtPresent) {
                typeItem = new SingleSelectBoxItem(TYPE, resources.constants().type(), asList(Names.LONG_RUNNING, Names.SHORT_RUNNING), false);
                typeItem.setRequired(true);
            } else {
                typeItem = new TextBoxItem(TYPE, resources.constants().type());
                typeItem.setValue(lrtPresent ? Names.SHORT_RUNNING : Names.LONG_RUNNING);
                typeItem.setEnabled(false);
            }
            // for the metadata it doesn't matter whether we use the LRT or SRT template nor
            // whether we use the normal or distributed workmanager version
            Metadata metadata = metadataRegistry.lookup(WORKMANAGER_LRT_TEMPLATE);
            Form<ModelNode> form = new ModelNodeForm.Builder<>(Ids.JCA_THREAD_POOL_ADD, metadata).fromRequestProperties().unboundFormItem(typeItem, 0).include(MAX_THREADS, QUEUE_LENGTH, THREAD_FACTORY).unsorted().build();
            AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(THREAD_POOL), form, (name, modelNode) -> {
                String type = typeItem.getValue();
                AddressTemplate tpTemplate = Names.LONG_RUNNING.equals(type) ? workmanagerTemplate.append(WORKMANAGER_LRT_TEMPLATE.lastName() + EQUALS + workmanager) : workmanagerTemplate.append(WORKMANAGER_SRT_TEMPLATE.lastName() + EQUALS + workmanager);
                ResourceAddress address = tpTemplate.resolve(statementContext, workmanager);
                Operation operation = new Operation.Builder(address, ADD).payload(modelNode).build();
                dispatcher.execute(operation, result -> {
                    MessageEvent.fire(getEventBus(), Message.success(resources.messages().addResourceSuccess(THREAD_POOL, name)));
                    loadThreadPools(workmanagerTemplate, workmanager);
                });
            });
            dialog.show();
        }
    });
}
Also used : AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) AddressTemplate(org.jboss.hal.meta.AddressTemplate) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) 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) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 3 with SingleSelectBoxItem

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

the class ServerActions method copyServer.

// ------------------------------------------------------ server operations
public void copyServer(Server server, Callback callback) {
    Operation operation = new Operation.Builder(ResourceAddress.root(), READ_CHILDREN_NAMES_OPERATION).param(CHILD_TYPE, HOST).build();
    dispatcher.execute(operation, result -> {
        List<String> hosts = new ArrayList<>();
        result.asList().forEach(m -> hosts.add(m.asString()));
        // get the first host only to retrieve the r-r-d for server-config
        // as /host=*/server-config=*:read-operation-description(name=add) does not work
        AddressTemplate template = AddressTemplate.of("/host=" + hosts.get(0) + "/server-config=*");
        metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

            @Override
            public void onMetadata(Metadata metadata) {
                String id = Ids.build(SERVER_GROUP, statementContext.selectedServerGroup(), SERVER, FORM);
                SingleSelectBoxItem hostFormItem = new SingleSelectBoxItem(HOST, Names.HOST, hosts, false);
                hostFormItem.setRequired(true);
                NameItem nameItem = new NameItem();
                ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).fromRequestProperties().unboundFormItem(nameItem, 0).unboundFormItem(hostFormItem, 1, resources.messages().addServerHostHelp()).exclude(AUTO_START, SOCKET_BINDING_DEFAULT_INTERFACE, SOCKET_BINDING_GROUP, UPDATE_AUTO_START_WITH_SERVER_STATUS).build();
                AddResourceDialog dialog = new AddResourceDialog(resources.messages().copyServerTitle(), form, (resource, payload) -> {
                    // read server-config recursively to retrieve nested resources
                    ModelNode serverConfigModel = new ModelNode();
                    serverConfigModel.get(HOST).set(server.getHost());
                    serverConfigModel.get(SERVER_CONFIG).set(server.getName());
                    ResourceAddress serverAddress = new ResourceAddress(serverConfigModel);
                    Operation opReadServer = new Operation.Builder(serverAddress, READ_RESOURCE_OPERATION).param(RECURSIVE, true).build();
                    dispatcher.execute(opReadServer, new Consumer<ModelNode>() {

                        @Override
                        public void accept(ModelNode newServerModel) {
                            String newServerName = nameItem.getValue();
                            // set the chosen group in the model
                            newServerModel.get(GROUP).set(payload.get(GROUP).asString());
                            if (payload.hasDefined(SOCKET_BINDING_PORT_OFFSET)) {
                                newServerModel.get(SOCKET_BINDING_PORT_OFFSET).set(payload.get(SOCKET_BINDING_PORT_OFFSET).asLong());
                            }
                            newServerModel.get(NAME).set(newServerName);
                            ModelNode newServerModelAddress = new ModelNode();
                            newServerModelAddress.get(HOST).set(hostFormItem.getValue());
                            newServerModelAddress.get(SERVER_CONFIG).set(newServerName);
                            Operation opAddServer = new Operation.Builder(new ResourceAddress(newServerModelAddress), ADD).payload(newServerModel).build();
                            Composite comp = new Composite();
                            comp.add(opAddServer);
                            // create operation for each nested resource of the source server
                            createOperation(comp, JVM, newServerModel, newServerModelAddress);
                            createOperation(comp, INTERFACE, newServerModel, newServerModelAddress);
                            createOperation(comp, PATH, newServerModel, newServerModelAddress);
                            createOperation(comp, SYSTEM_PROPERTY, newServerModel, newServerModelAddress);
                            createOperation(comp, SSL, newServerModel, newServerModelAddress);
                            dispatcher.execute(comp, (CompositeResult result) -> {
                                MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(Names.SERVER, newServerName)));
                                callback.execute();
                            }, (operation1, failure) -> {
                                MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, failure)));
                                callback.execute();
                            }, (operation1, exception) -> {
                                MessageEvent.fire(eventBus, Message.error(resources.messages().addResourceError(newServerName, exception.getMessage())));
                                callback.execute();
                            });
                        }

                        private void createOperation(Composite composite, String resource, ModelNode model, ModelNode baseAddress) {
                            if (model.hasDefined(resource)) {
                                List<Property> props = model.get(resource).asPropertyList();
                                props.forEach(p -> {
                                    String propname = p.getName();
                                    ModelNode _address = baseAddress.clone();
                                    _address.get(resource).set(propname);
                                    Operation operation = new Operation.Builder(new ResourceAddress(_address), ADD).payload(p.getValue()).build();
                                    composite.add(operation);
                                });
                            }
                        }
                    });
                });
                dialog.show();
            }
        });
    });
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Dialog(org.jboss.hal.ballroom.dialog.Dialog) DISABLED(org.jboss.hal.core.runtime.server.ServerConfigStatus.DISABLED) Provider(javax.inject.Provider) Elements.a(org.jboss.gwt.elemento.core.Elements.a) TimeoutHandler.repeatUntilTimeout(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatUntilTimeout) STOPPED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STOPPED) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) ManagementModel(org.jboss.hal.meta.ManagementModel) Icons(org.jboss.hal.resources.Icons) ModelNodeHelper.asEnumValue(org.jboss.hal.dmr.ModelNodeHelper.asEnumValue) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) OnError(org.jboss.hal.dmr.dispatch.Dispatcher.OnError) Elements.p(org.jboss.gwt.elemento.core.Elements.p) STARTED(org.jboss.hal.core.runtime.server.ServerConfigStatus.STARTED) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) SuspendState(org.jboss.hal.core.runtime.SuspendState) Message(org.jboss.hal.spi.Message) Timeouts(org.jboss.hal.core.runtime.Timeouts) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) EnumSet(java.util.EnumSet) CSS.marginLeft5(org.jboss.hal.resources.CSS.marginLeft5) Predicate(java.util.function.Predicate) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) FORM(org.jboss.hal.resources.Ids.FORM) ReadSocketBinding(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBinding) List(java.util.List) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) Callback(org.jboss.hal.spi.Callback) Action(org.jboss.hal.core.runtime.Action) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) Core(org.jboss.hal.core.Core) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) Subscription(rx.Subscription) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) DomGlobal.setTimeout(elemental2.dom.DomGlobal.setTimeout) ModelNode(org.jboss.hal.dmr.ModelNode) Alert(org.jboss.hal.ballroom.Alert) MessageEvent(org.jboss.hal.spi.MessageEvent) SHORT_TIMEOUT(org.jboss.hal.resources.UIConstants.SHORT_TIMEOUT) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ModelNodeHelper.getOrDefault(org.jboss.hal.dmr.ModelNodeHelper.getOrDefault) HashMap(java.util.HashMap) RUNNING(org.jboss.hal.core.runtime.RunningState.RUNNING) Result(org.jboss.hal.core.runtime.Result) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) ArrayList(java.util.ArrayList) OnFail(org.jboss.hal.dmr.dispatch.Dispatcher.OnFail) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) Strings(com.google.common.base.Strings) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) TimeoutHandler.repeatOperationUntil(org.jboss.hal.dmr.dispatch.TimeoutHandler.repeatOperationUntil) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) ReadSocketBindingGroup(org.jboss.hal.core.runtime.server.ServerUrlTasks.ReadSocketBindingGroup) BlockingDialog(org.jboss.hal.ballroom.dialog.BlockingDialog) Logger(org.slf4j.Logger) CompositeResult(org.jboss.hal.dmr.CompositeResult) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) EventBus(com.google.web.bindery.event.shared.EventBus) CSS.pfIcon(org.jboss.hal.resources.CSS.pfIcon) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) CompletableSubscriber(rx.CompletableSubscriber) Consumer(java.util.function.Consumer) Composite(org.jboss.hal.dmr.Composite) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Resources(org.jboss.hal.resources.Resources) SUSPENDED(org.jboss.hal.core.runtime.SuspendState.SUSPENDED) RunningState(org.jboss.hal.core.runtime.RunningState) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) URL_KEY(org.jboss.hal.core.runtime.server.ServerUrlTasks.URL_KEY) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) Composite(org.jboss.hal.dmr.Composite) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CompositeResult(org.jboss.hal.dmr.CompositeResult) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) ArrayList(java.util.ArrayList) Metadata(org.jboss.hal.meta.Metadata) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) Operation(org.jboss.hal.dmr.Operation) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Consumer(java.util.function.Consumer) ModelNode(org.jboss.hal.dmr.ModelNode) Property(org.jboss.hal.dmr.Property)

Example 4 with SingleSelectBoxItem

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

the class RoleColumn method editScopedRole.

private void editScopedRole(Role role, String type, AddressTemplate template, AddressTemplate typeaheadTemplate, String formId, String scopeAttribute) {
    Metadata metadata = metadataRegistry.lookup(template);
    Form<ModelNode> form = new ModelNodeForm.Builder<>(formId, metadata).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;
    }).unboundFormItem(new SwitchItem(INCLUDE_ALL, new LabelBuilder().label(INCLUDE_ALL)), 2, resources.messages().includeAllHelpText()).build();
    form.getFormItem(scopeAttribute).setRequired(true);
    form.getFormItem(scopeAttribute).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, typeaheadTemplate));
    form.getFormItem(INCLUDE_ALL).setValue(role.isIncludeAll());
    form.attach();
    ModelNode modelNode = new ModelNode();
    modelNode.get(BASE_ROLE).set(role.getBaseRole().getName());
    role.getScope().forEach(scope -> modelNode.get(scopeAttribute).add(scope));
    new ModifyResourceDialog(resources.messages().modifyResourceTitle(type), form, (frm, changedValues) -> {
        boolean includeAll = frm.<Boolean>getFormItem(INCLUDE_ALL).getValue();
        boolean includeAllChanged = includeAll != role.isIncludeAll();
        List<Task<FlowContext>> tasks = new ArrayList<>();
        if (!changedValues.isEmpty()) {
            tasks.add(new ModifyScopedRole(dispatcher, role, changedValues, metadata));
        }
        if (includeAllChanged) {
            tasks.add(new ModifyIncludeAll(dispatcher, role, 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().modifyResourceSuccess(type, role.getName())));
                accessControl.reload(() -> {
                    refresh(role.getId());
                    eventBus.fireEvent(new RolesChangedEvent());
                });
            }
        });
    }).show(modelNode);
}
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) SingleSelectBoxItem(org.jboss.hal.ballroom.form.SingleSelectBoxItem) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ModifyScopedRole(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyScopedRole) FlowContext(org.jboss.hal.flow.FlowContext) RolesChangedEvent(org.jboss.hal.config.RolesChangedEvent) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ModifyIncludeAll(org.jboss.hal.client.accesscontrol.AccessControlTasks.ModifyIncludeAll) ModelNode(org.jboss.hal.dmr.ModelNode) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) SwitchItem(org.jboss.hal.ballroom.form.SwitchItem) ModifyResourceDialog(org.jboss.hal.core.mbui.dialog.ModifyResourceDialog)

Example 5 with SingleSelectBoxItem

use of org.jboss.hal.ballroom.form.SingleSelectBoxItem 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

SingleSelectBoxItem (org.jboss.hal.ballroom.form.SingleSelectBoxItem)8 ModelNode (org.jboss.hal.dmr.ModelNode)8 Metadata (org.jboss.hal.meta.Metadata)7 List (java.util.List)6 Inject (javax.inject.Inject)6 AddResourceDialog (org.jboss.hal.core.mbui.dialog.AddResourceDialog)6 ModelNodeForm (org.jboss.hal.core.mbui.form.ModelNodeForm)6 ModelDescriptionConstants (org.jboss.hal.dmr.ModelDescriptionConstants)6 Ids (org.jboss.hal.resources.Ids)6 EventBus (com.google.web.bindery.event.shared.EventBus)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Form (org.jboss.hal.ballroom.form.Form)5 TextBoxItem (org.jboss.hal.ballroom.form.TextBoxItem)5 Dispatcher (org.jboss.hal.dmr.dispatch.Dispatcher)5 AddressTemplate (org.jboss.hal.meta.AddressTemplate)5 StatementContext (org.jboss.hal.meta.StatementContext)5 HTMLElement (elemental2.dom.HTMLElement)4 Collectors.toList (java.util.stream.Collectors.toList)4 Provider (javax.inject.Provider)4