Search in sources :

Example 1 with STRING

use of org.jboss.hal.dmr.ModelDescriptionConstants.STRING in project console by hal.

the class ModelBrowser method add.

void add(Node<Context> parent, List<String> children) {
    if (parent.data.hasSingletons()) {
        if (parent.data.getSingletons().size() == children.size()) {
            MessageEvent.fire(eventBus, Message.warning(resources.messages().allSingletonsExist()));
        } else if (parent.data.getSingletons().size() - children.size() == 1) {
            // no need to show a wizard - find the missing singleton
            HashSet<String> singletons = Sets.newHashSet(parent.data.getSingletons());
            singletons.removeAll(children);
            String singleton = singletons.iterator().next();
            ResourceAddress singletonAddress = parent.data.getAddress().getParent().add(parent.text, singleton);
            AddressTemplate template = asGenericTemplate(parent, singletonAddress);
            String id = Ids.build(parent.id, "singleton", Ids.ADD);
            crud.addSingleton(id, singleton, template, address -> refresh(parent));
        } else {
            // open wizard to choose the singleton
            Wizard<SingletonContext, SingletonState> wizard = new Wizard.Builder<SingletonContext, SingletonState>(resources.messages().addResourceTitle(parent.text), new SingletonContext(parent, children)).addStep(CHOOSE, new ChooseSingletonStep(parent, children, resources)).addStep(CREATE, new CreateSingletonStep(parent, metadataProcessor, progress, eventBus, resources)).onBack((context, currentState) -> currentState == CREATE ? CHOOSE : null).onNext((context, currentState) -> currentState == CHOOSE ? CREATE : null).onFinish((wzrd, context) -> {
                Operation.Builder builder = new Operation.Builder(fqAddress(parent, context.singleton), ADD);
                if (context.modelNode != null) {
                    builder.payload(context.modelNode);
                }
                dispatcher.execute(builder.build(), result -> {
                    MessageEvent.fire(eventBus, Message.success(resources.messages().addResourceSuccess(parent.text, context.singleton)));
                    refresh(parent);
                });
            }).build();
            wizard.show();
        }
    } else {
        AddressTemplate template = asGenericTemplate(parent, parent.data.getAddress());
        metadataProcessor.lookup(template, progress.get(), new SuccessfulMetadataCallback(eventBus, resources) {

            @Override
            public void onMetadata(Metadata metadata) {
                flattenDescription(metadata.getDescription().get(OPERATIONS).get(ADD).get(REQUEST_PROPERTIES));
                String title = new LabelBuilder().label(parent.text);
                NameItem nameItem = new NameItem();
                String id = Ids.build(parent.id, "add");
                ModelNodeForm<ModelNode> form = new ModelNodeForm.Builder<>(id, metadata).unboundFormItem(nameItem, 0).fromRequestProperties().panelForOptionalAttributes().build();
                AddResourceDialog dialog = new AddResourceDialog(resources.messages().addResourceTitle(title), form, (name1, model) -> {
                    unflattenModel(model);
                    crud.add(title, nameItem.getValue(), fqAddress(parent, nameItem.getValue()), model, (n, a) -> refresh(parent));
                });
                dialog.show();
            }
        });
    }
}
Also used : AddressTemplate(org.jboss.hal.meta.AddressTemplate) IsElement(org.jboss.gwt.elemento.core.IsElement) Provider(javax.inject.Provider) Elements.a(org.jboss.gwt.elemento.core.Elements.a) Environment(org.jboss.hal.config.Environment) CHOOSE(org.jboss.hal.core.modelbrowser.SingletonState.CHOOSE) VALUE_TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE_TYPE) LoggerFactory(org.slf4j.LoggerFactory) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) Node(org.jboss.hal.ballroom.tree.Node) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) CSS.modelBrowserButtons(org.jboss.hal.resources.CSS.modelBrowserButtons) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) FinishReset(org.jboss.hal.ballroom.form.Form.FinishReset) SERVER_GROUP(org.jboss.hal.dmr.ModelDescriptionConstants.SERVER_GROUP) READ_RESOURCE_OPERATION(org.jboss.hal.dmr.ModelDescriptionConstants.READ_RESOURCE_OPERATION) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) CrudOperations(org.jboss.hal.core.CrudOperations) Collections.emptyList(java.util.Collections.emptyList) LayoutBuilder.row(org.jboss.hal.ballroom.LayoutBuilder.row) MARGIN_BIG(org.jboss.hal.ballroom.Skeleton.MARGIN_BIG) CSS(org.jboss.hal.resources.CSS) Skeleton.applicationOffset(org.jboss.hal.ballroom.Skeleton.applicationOffset) EventType.click(org.jboss.gwt.elemento.core.EventType.click) STRING(org.jboss.hal.dmr.ModelDescriptionConstants.STRING) CSS.btnGroup(org.jboss.hal.resources.CSS.btnGroup) Sets(com.google.common.collect.Sets) Tree(org.jboss.hal.ballroom.tree.Tree) List(java.util.List) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) MetadataProcessor(org.jboss.hal.meta.processing.MetadataProcessor) CSS.tmTagRemove(org.jboss.hal.resources.CSS.tmTagRemove) Flow.series(org.jboss.hal.flow.Flow.series) Footer(org.jboss.hal.spi.Footer) CSS.tagManagerContainer(org.jboss.hal.resources.CSS.tagManagerContainer) ModelNodeHelper(org.jboss.hal.dmr.ModelNodeHelper) PROFILE(org.jboss.hal.dmr.ModelDescriptionConstants.PROFILE) CSS.fontAwesome(org.jboss.hal.resources.CSS.fontAwesome) MARGIN_SMALL(org.jboss.hal.ballroom.Skeleton.MARGIN_SMALL) ModelNode(org.jboss.hal.dmr.ModelNode) Completable(rx.Completable) Elements.div(org.jboss.gwt.elemento.core.Elements.div) TYPE(org.jboss.hal.dmr.ModelDescriptionConstants.TYPE) SELECTED_GROUP(org.jboss.hal.meta.StatementContext.Expression.SELECTED_GROUP) MessageEvent(org.jboss.hal.spi.MessageEvent) SuccessfulMetadataCallback(org.jboss.hal.meta.processing.SuccessfulMetadataCallback) ADD(org.jboss.hal.dmr.ModelDescriptionConstants.ADD) CSS.btnDefault(org.jboss.hal.resources.CSS.btnDefault) LayoutBuilder.column(org.jboss.hal.ballroom.LayoutBuilder.column) CSS.tmTag(org.jboss.hal.resources.CSS.tmTag) CSS.clickable(org.jboss.hal.resources.CSS.clickable) Stack(java.util.Stack) FlowContext(org.jboss.hal.flow.FlowContext) Outcome(org.jboss.hal.flow.Outcome) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Property(org.jboss.hal.dmr.Property) OPERATIONS(org.jboss.hal.dmr.ModelDescriptionConstants.OPERATIONS) Task(org.jboss.hal.flow.Task) Progress(org.jboss.hal.flow.Progress) AddressTemplate(org.jboss.hal.meta.AddressTemplate) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) REQUEST_PROPERTIES(org.jboss.hal.dmr.ModelDescriptionConstants.REQUEST_PROPERTIES) CSS.modelBrowserContent(org.jboss.hal.resources.CSS.modelBrowserContent) Elements.button(org.jboss.gwt.elemento.core.Elements.button) CSS.tagManagerTag(org.jboss.hal.resources.CSS.tagManagerTag) Logger(org.slf4j.Logger) Operation(org.jboss.hal.dmr.Operation) CREATE(org.jboss.hal.core.modelbrowser.SingletonState.CREATE) Ids(org.jboss.hal.resources.Ids) OBJECT(org.jboss.hal.dmr.ModelDescriptionConstants.OBJECT) Wizard(org.jboss.hal.ballroom.wizard.Wizard) EventBus(com.google.web.bindery.event.shared.EventBus) MODEL_BROWSER_ROOT(org.jboss.hal.resources.Ids.MODEL_BROWSER_ROOT) CSS.btn(org.jboss.hal.resources.CSS.btn) SelectionContext(org.jboss.hal.ballroom.tree.SelectionContext) CSS.vh(org.jboss.hal.resources.CSS.vh) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) Collectors.toList(java.util.stream.Collectors.toList) Resources(org.jboss.hal.resources.Resources) SELECTED_PROFILE(org.jboss.hal.meta.StatementContext.Expression.SELECTED_PROFILE) HTMLButtonElement(elemental2.dom.HTMLButtonElement) Collections(java.util.Collections) Elements.span(org.jboss.gwt.elemento.core.Elements.span) Elements(org.jboss.gwt.elemento.core.Elements) Form(org.jboss.hal.ballroom.form.Form) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) 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) LabelBuilder(org.jboss.hal.ballroom.LabelBuilder) Wizard(org.jboss.hal.ballroom.wizard.Wizard) HashSet(java.util.HashSet)

Aggregations

Sets (com.google.common.collect.Sets)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 EventBus (com.google.web.bindery.event.shared.EventBus)1 HTMLButtonElement (elemental2.dom.HTMLButtonElement)1 HTMLElement (elemental2.dom.HTMLElement)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Stack (java.util.Stack)1 Collectors.toList (java.util.stream.Collectors.toList)1 Inject (javax.inject.Inject)1 Provider (javax.inject.Provider)1 Elements (org.jboss.gwt.elemento.core.Elements)1 Elements.a (org.jboss.gwt.elemento.core.Elements.a)1 Elements.button (org.jboss.gwt.elemento.core.Elements.button)1 Elements.div (org.jboss.gwt.elemento.core.Elements.div)1 Elements.span (org.jboss.gwt.elemento.core.Elements.span)1