Search in sources :

Example 11 with FormItem

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

the class ModelNodeMapping method populateFormItems.

@Override
@SuppressWarnings("unchecked")
public void populateFormItems(T model, Form<T> form) {
    String id = id(form);
    for (FormItem formItem : form.getBoundFormItems()) {
        formItem.clearError();
        String name = formItem.getName();
        if (model.hasDefined(name)) {
            ModelNode attributeDescription = findAttribute(name);
            if (attributeDescription == null) {
                logger.error("{}: Unable to populate form item '{}': No attribute description found in\n{}", id, name, attributeDescriptions);
                continue;
            }
            ModelNode value = model.get(name);
            ModelType valueType = value.getType();
            if (valueType == EXPRESSION) {
                if (formItem.supportsExpressions()) {
                    formItem.setExpressionValue(value.asString());
                    formItem.setUndefined(false);
                } else {
                    logger.error("{}: Unable to populate form item '{}': Value is an expression, but form item does not support expressions", id, name);
                    continue;
                }
            } else if (formItem instanceof ModelNodeItem) {
                formItem.setValue(value);
            } else {
                populateFormItem(id, name, attributeDescription, value, formItem);
            }
            formItem.setUndefined(false);
        } else {
            formItem.clearValue();
            formItem.setUndefined(true);
        }
    }
}
Also used : FormItem(org.jboss.hal.ballroom.form.FormItem) ModelType(org.jboss.hal.dmr.ModelType) ModelNodeItem(org.jboss.hal.ballroom.form.ModelNodeItem) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 12 with FormItem

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

the class DriverStep method assignFromJdbcDriverOrTemplate.

@SuppressWarnings("unchecked")
private void assignFromJdbcDriverOrTemplate(String driverName, String propName) {
    FormItem formItem = form.getFormItem(propName);
    if (formItem != null) {
        JdbcDriver driver = driversByName.get(driverName);
        DataSourceTemplate template = this.wizard().getContext().template;
        if (driver != null && driver.hasDefined(propName) && !driver.get(propName).asString().isEmpty()) {
            // assign the value inside the driver
            formItem.setModified(true);
            formItem.setValue(driver.get(propName).asString());
        } else if (template != null && template.getDriver() != null && template.getDriver().hasDefined(propName) && !template.getDriver().get(propName).asString().isEmpty()) {
            // assign the value in the template
            formItem.setModified(true);
            formItem.setValue(this.wizard().getContext().template.getDriver().get(propName).asString());
        }
    // let the current value at it is now
    }
}
Also used : JdbcDriver(org.jboss.hal.core.datasource.JdbcDriver) FormItem(org.jboss.hal.ballroom.form.FormItem) DataSourceTemplate(org.jboss.hal.client.configuration.subsystem.datasource.DataSourceTemplate)

Example 13 with FormItem

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

the class OtherSettingsPresenter method addCredentialStore.

// -------------------------------------------- Credential Store
void addCredentialStore() {
    Metadata metadata = metadataRegistry.lookup(CREDENTIAL_STORE_TEMPLATE);
    SafeHtml typeHelp = SafeHtmlUtils.fromString(metadata.getDescription().get(ATTRIBUTES).get(TYPE).get(DESCRIPTION).asString());
    Metadata crMetadata = metadata.forComplexAttribute(CREDENTIAL_REFERENCE, true);
    crMetadata.copyComplexAttributeAttributes(asList(STORE, ALIAS, TYPE, CLEAR_TEXT), metadata);
    TextBoxItem typeItem = new TextBoxItem("type-", resources.constants().type());
    String id = Ids.build(Ids.ELYTRON_CREDENTIAL_STORE, Ids.ADD);
    NameItem nameItem = new NameItem();
    ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).addOnly().unboundFormItem(nameItem, 0).include(CREATE, PATH, RELATIVE_TO, STORE, ALIAS, TYPE, CLEAR_TEXT).unboundFormItem(typeItem, 3, typeHelp).unsorted().build();
    form.getFormItem(RELATIVE_TO).registerSuggestHandler(new PathsAutoComplete());
    form.addFormValidation(new RequireAtLeastOneAttributeValidation<>(asList(STORE, CLEAR_TEXT), resources));
    form.addFormValidation(form1 -> {
        ValidationResult result = ValidationResult.OK;
        String typeValue = typeItem.getValue();
        FormItem<String> locationAttr = form1.getFormItem(PATH);
        boolean invalidLocation = locationAttr.isEmpty() && (typeItem.isEmpty() || Collections.binarySearch(FILE_BASED_CS, typeValue) > -1);
        if (invalidLocation) {
            form1.getFormItem(PATH).showError(resources.constants().requiredField());
            result = ValidationResult.invalid(resources.messages().pathRequired());
        }
        return result;
    });
    new AddResourceDialog(resources.messages().addResourceTitle(Names.CREDENTIAL_STORE), form, (name, model) -> {
        if (model != null) {
            move(model, STORE, CREDENTIAL_REFERENCE + "/" + STORE);
            move(model, ALIAS, CREDENTIAL_REFERENCE + "/" + ALIAS);
            move(model, TYPE, CREDENTIAL_REFERENCE + "/" + TYPE);
            move(model, CLEAR_TEXT, CREDENTIAL_REFERENCE + "/" + CLEAR_TEXT);
        }
        if (!typeItem.isEmpty()) {
            model.get(TYPE).set(typeItem.getValue());
        }
        ResourceAddress address = CREDENTIAL_STORE_TEMPLATE.resolve(statementContext, nameItem.getValue());
        crud.add(Names.CREDENTIAL_STORE, name, address, model, (n, a) -> reload(CREDENTIAL_STORE, nodes -> getView().updateResourceElement(CREDENTIAL_STORE, 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) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) PathsAutoComplete(org.jboss.hal.core.configuration.PathsAutoComplete) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Metadata(org.jboss.hal.meta.Metadata) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) TextBoxItem(org.jboss.hal.ballroom.form.TextBoxItem) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 14 with FormItem

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

the class JmsQueuePresenter method changePriority.

void changePriority(List<JmsMessage> messages) {
    if (messages.isEmpty()) {
        noMessagesSelected();
    } else {
        Metadata metadata = metadataRegistry.lookup(MESSAGING_CORE_QUEUE_TEMPLATE);
        Form<ModelNode> form = new OperationFormBuilder<>(Ids.JMS_MESSAGE_CHANGE_PRIORITY_FORM, metadata, CHANGE_MESSAGE_PRIORITY).build();
        Dialog dialog = new Dialog.Builder(resources.constants().changePriority()).add(form.element()).cancel().primary(resources.constants().ok(), () -> {
            boolean valid = form.save();
            if (valid) {
                Operation operation;
                int priority = form.getModel().get(NEW_PRIORITY).asInt();
                if (messages.size() == 1) {
                    operation = new Operation.Builder(queueAddress(), CHANGE_MESSAGE_PRIORITY).param(MESSAGE_ID, messages.get(0).getMessageId()).param(NEW_PRIORITY, priority).build();
                } else {
                    operation = new Operation.Builder(queueAddress(), CHANGE_MESSAGES_PRIORITY).param(FILTER, filter(messages)).param(NEW_PRIORITY, priority).build();
                }
                dispatcher.execute(operation, result -> {
                    reload();
                    MessageEvent.fire(getEventBus(), Message.success(resources.messages().changePrioritySuccess(priority)));
                });
            }
            return valid;
        }).build();
        dialog.registerAttachable(form);
        dialog.show();
        ModelNode model = new ModelNode();
        form.edit(model);
        FormItem<Number> messageId = form.getFormItem(MESSAGE_ID);
        messageId.setValue(42L);
        Elements.setVisible(messageId.element(Form.State.EDITING), false);
        FormItem<Number> priorityItem = form.getFormItem(NEW_PRIORITY);
        if (messages.size() == 1) {
            priorityItem.setValue(messages.get(0).get(JMS_PRIORITY).asLong());
        }
        priorityItem.setFocus(true);
    }
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Collections.emptyList(java.util.Collections.emptyList) FinderPath(org.jboss.hal.core.finder.FinderPath) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) HashMap(java.util.HashMap) FlowContext(org.jboss.hal.flow.FlowContext) Inject(javax.inject.Inject) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplates(org.jboss.hal.client.runtime.subsystem.messaging.AddressTemplates) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) Logger(org.slf4j.Logger) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) ModelNodeHelper.failSafeBoolean(org.jboss.hal.dmr.ModelNodeHelper.failSafeBoolean) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) FormItem(org.jboss.hal.ballroom.form.FormItem) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Type(org.jboss.hal.client.runtime.subsystem.messaging.Destination.Type) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) Dialog(org.jboss.hal.ballroom.dialog.Dialog) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Metadata(org.jboss.hal.meta.Metadata) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode)

Example 15 with FormItem

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

the class JmsQueuePresenter method move.

void move(List<JmsMessage> messages) {
    if (messages.isEmpty()) {
        noMessagesSelected();
    } else {
        Metadata metadata = metadataRegistry.lookup(MESSAGING_CORE_QUEUE_TEMPLATE);
        Form<ModelNode> form = new OperationFormBuilder<>(Ids.JMS_MESSAGE_MOVE_FORM, metadata, MOVE_MESSAGE).build();
        Dialog dialog = new Dialog.Builder(resources.constants().move()).add(form.element()).cancel().primary(resources.constants().ok(), () -> {
            boolean valid = form.save();
            if (valid) {
                Operation operation;
                String destination = form.getModel().get(OTHER_QUEUE_NAME).asString();
                boolean rejectDuplicates = failSafeBoolean(form.getModel(), REJECT_DUPLICATES);
                if (messages.size() == 1) {
                    operation = new Operation.Builder(queueAddress(), MOVE_MESSAGE).param(MESSAGE_ID, messages.get(0).getMessageId()).param(OTHER_QUEUE_NAME, destination).param(REJECT_DUPLICATES, rejectDuplicates).build();
                } else {
                    operation = new Operation.Builder(queueAddress(), MOVE_MESSAGES).param(FILTER, filter(messages)).param(OTHER_QUEUE_NAME, destination).param(REJECT_DUPLICATES, rejectDuplicates).build();
                }
                dispatcher.execute(operation, result -> {
                    reload();
                    MessageEvent.fire(getEventBus(), Message.success(resources.messages().moveMessageSuccess(destination)));
                });
            }
            return valid;
        }).build();
        dialog.registerAttachable(form);
        dialog.show();
        ModelNode model = new ModelNode();
        form.edit(model);
        FormItem<Number> messageId = form.getFormItem(MESSAGE_ID);
        messageId.setValue(42L);
        Elements.setVisible(messageId.element(Form.State.EDITING), false);
        form.getFormItem(OTHER_QUEUE_NAME).setFocus(true);
    }
}
Also used : Dialog(org.jboss.hal.ballroom.dialog.Dialog) Provider(javax.inject.Provider) StatementContext(org.jboss.hal.meta.StatementContext) LoggerFactory(org.slf4j.LoggerFactory) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HasPresenter(org.jboss.hal.core.mvp.HasPresenter) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Collections.emptyList(java.util.Collections.emptyList) FinderPath(org.jboss.hal.core.finder.FinderPath) Collectors.joining(java.util.stream.Collectors.joining) List(java.util.List) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) HalView(org.jboss.hal.core.mvp.HalView) Flow.series(org.jboss.hal.flow.Flow.series) Finder(org.jboss.hal.core.finder.Finder) Footer(org.jboss.hal.spi.Footer) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) MessageEvent(org.jboss.hal.spi.MessageEvent) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) SuccessfulOutcome(org.jboss.hal.core.SuccessfulOutcome) HashMap(java.util.HashMap) FlowContext(org.jboss.hal.flow.FlowContext) Inject(javax.inject.Inject) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplates(org.jboss.hal.client.runtime.subsystem.messaging.AddressTemplates) ApplicationFinderPresenter(org.jboss.hal.core.mvp.ApplicationFinderPresenter) Requires(org.jboss.hal.spi.Requires) Logger(org.slf4j.Logger) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) ModelNodeHelper.failSafeBoolean(org.jboss.hal.dmr.ModelNodeHelper.failSafeBoolean) Operation(org.jboss.hal.dmr.Operation) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DialogFactory(org.jboss.hal.ballroom.dialog.DialogFactory) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) FormItem(org.jboss.hal.ballroom.form.FormItem) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) Type(org.jboss.hal.client.runtime.subsystem.messaging.Destination.Type) Elements(org.jboss.gwt.elemento.core.Elements) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Form(org.jboss.hal.ballroom.form.Form) Dialog(org.jboss.hal.ballroom.dialog.Dialog) OperationFormBuilder(org.jboss.hal.core.mbui.form.OperationFormBuilder) Metadata(org.jboss.hal.meta.Metadata) Operation(org.jboss.hal.dmr.Operation) ModelNode(org.jboss.hal.dmr.ModelNode)

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