Search in sources :

Example 1 with Requires

use of org.jboss.hal.spi.Requires in project console by hal.

the class RequiredResourcesProcessor method onProcess.

@Override
protected boolean onProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    for (Element e : roundEnv.getElementsAnnotatedWith(Requires.class)) {
        TypeElement requiredElement = (TypeElement) e;
        Requires requires = requiredElement.getAnnotation(Requires.class);
        // Get the related id. Currently @Requires can be placed at named proxies or (async) columns
        String id = null;
        NameToken token = requiredElement.getAnnotation(NameToken.class);
        if (token != null) {
            id = token.value()[0];
        } else {
            AsyncColumn asyncColumn = requiredElement.getAnnotation(AsyncColumn.class);
            if (asyncColumn != null) {
                id = asyncColumn.value();
            } else {
                Column column = requiredElement.getAnnotation(Column.class);
                if (column != null) {
                    id = column.value();
                }
            }
        }
        // noinspection ConstantConditions
        if (id != null) {
            RequiredInfo requiredInfo = new RequiredInfo(id, requiredElement);
            requiredInfo.addResources(requires.value());
            requiredInfo.setRecursive(requires.recursive());
            if (requiredInfos.containsKey(id)) {
                RequiredInfo other = requiredInfos.get(id);
                if (!requiredInfo.getResources().equals(other.getResources())) {
                    error(requiredElement, "Different required resources for the same id \"%s\". This class conflicts with %s", id, other.source.getQualifiedName());
                }
            }
            requiredInfos.put(id, requiredInfo);
        }
    }
    if (!requiredInfos.isEmpty()) {
        debug("Generating code for required resources registry");
        code(REQUIRED_RESOURCES_TEMPLATE, REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS, context(REQUIRED_RESOURCES_PACKAGE, REQUIRED_RESOURCES_CLASS));
        List<RegistryBinding> bindings = ImmutableList.of(new RegistryBinding(REQUIRED_RESOURCES_PACKAGE + ".RequiredResources", REQUIRED_RESOURCES_PACKAGE + "." + REQUIRED_RESOURCES_CLASS));
        debug("Generating code for registry module");
        code(REGISTRY_MODULE_TEMPLATE, REGISTRY_MODULE_PACKAGE, REGISTRY_MODULE_CLASS, () -> {
            Map<String, Object> context = new HashMap<>();
            context.put(GENERATED_WITH, RequiredResourcesProcessor.class.getName());
            context.put(PACKAGE_NAME, REGISTRY_MODULE_PACKAGE);
            context.put(CLASS_NAME, REGISTRY_MODULE_CLASS);
            context.put("bindings", bindings);
            return context;
        });
        info("Successfully generated required resources registry [%s] and related module [%s].", REQUIRED_RESOURCES_CLASS, REGISTRY_MODULE_CLASS);
        requiredInfos.clear();
    }
    return false;
}
Also used : Requires(org.jboss.hal.spi.Requires) HashMap(java.util.HashMap) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) AsyncColumn(org.jboss.hal.spi.AsyncColumn) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) AsyncColumn(org.jboss.hal.spi.AsyncColumn) Column(org.jboss.hal.spi.Column)

Example 2 with Requires

use of org.jboss.hal.spi.Requires in project console by hal.

the class ClusteringPresenter method showBroadcastOrDiscoveryGroupAddDialog.

void showBroadcastOrDiscoveryGroupAddDialog(ServerSubResource ssr, Consumer<ModelNodeForm.Builder<ModelNode>> formBuilderAugmenter, Consumer<Form<ModelNode>> formAugmenter) {
    Metadata metadata = metadataRegistry.lookup(ssr.template);
    NameItem nameItem = new NameItem();
    ModelNodeForm.Builder<ModelNode> formBuilder = new ModelNodeForm.Builder<>(Ids.build(ssr.baseId, Ids.ADD), metadata).unboundFormItem(nameItem, 0).fromRequestProperties().include(JGROUPS_CLUSTER, SOCKET_BINDING).unsorted();
    formBuilderAugmenter.accept(formBuilder);
    Form<ModelNode> form = formBuilder.build();
    formAugmenter.accept(form);
    // validation that requires one of jgroups-cluster and socket-binding to be configured
    FormValidation<ModelNode> jgroupsOrSocketValidation = new FormValidation<ModelNode>() {

        @Override
        public ValidationResult validate(Form<ModelNode> form) {
            if (form.getFormItem(JGROUPS_CLUSTER).isEmpty() && form.getFormItem(SOCKET_BINDING).isEmpty()) {
                return ValidationResult.invalid(resources.messages().jgroupsClusterOrSocketBindingMustBeSet());
            }
            return ValidationResult.OK;
        }
    };
    form.getFormItem(SOCKET_BINDING).registerSuggestHandler(new ReadChildrenAutoComplete(dispatcher, statementContext, SOCKET_BINDING_TEMPLATE));
    form.addFormValidation(jgroupsOrSocketValidation);
    new AddResourceDialog(resources.messages().addResourceTitle(ssr.type), form, (name, model) -> {
        name = nameItem.getValue();
        ResourceAddress address = SELECTED_SERVER_TEMPLATE.append(ssr.resource + "=" + name).resolve(statementContext);
        crud.add(ssr.type, name, address, model, (n, a) -> reload());
    }).show();
}
Also used : AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) SupportsExpertMode(org.jboss.hal.core.mvp.SupportsExpertMode) ModelNode(org.jboss.hal.dmr.ModelNode) StatementContext(org.jboss.hal.meta.StatementContext) ProxyPlace(com.gwtplatform.mvp.client.proxy.ProxyPlace) AddResourceDialog(org.jboss.hal.core.mbui.dialog.AddResourceDialog) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Inject(javax.inject.Inject) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) FormValidation(org.jboss.hal.ballroom.form.FormValidation) AddressTemplate(org.jboss.hal.meta.AddressTemplate) Arrays.asList(java.util.Arrays.asList) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) Metadata(org.jboss.hal.meta.Metadata) Names(org.jboss.hal.resources.Names) ModelNodeHelper.asNamedNodes(org.jboss.hal.dmr.ModelNodeHelper.asNamedNodes) Requires(org.jboss.hal.spi.Requires) CrudOperations(org.jboss.hal.core.CrudOperations) ProxyCodeSplit(com.gwtplatform.mvp.client.annotations.ProxyCodeSplit) AddressTemplates(org.jboss.hal.client.configuration.subsystem.messaging.AddressTemplates) NameToken(com.gwtplatform.mvp.client.annotations.NameToken) Ids(org.jboss.hal.resources.Ids) FinderPathFactory(org.jboss.hal.core.finder.FinderPathFactory) EventBus(com.google.web.bindery.event.shared.EventBus) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete) FinderPath(org.jboss.hal.core.finder.FinderPath) Consumer(java.util.function.Consumer) List(java.util.List) Dispatcher(org.jboss.hal.dmr.dispatch.Dispatcher) MetadataRegistry(org.jboss.hal.meta.MetadataRegistry) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) ModelDescriptionConstants(org.jboss.hal.dmr.ModelDescriptionConstants) MbuiView(org.jboss.hal.core.mbui.MbuiView) Finder(org.jboss.hal.core.finder.Finder) ValidationResult(org.jboss.hal.ballroom.form.ValidationResult) NamedNode(org.jboss.hal.dmr.NamedNode) Form(org.jboss.hal.ballroom.form.Form) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) Form(org.jboss.hal.ballroom.form.Form) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) Metadata(org.jboss.hal.meta.Metadata) ModelNodeForm(org.jboss.hal.core.mbui.form.ModelNodeForm) NameItem(org.jboss.hal.core.mbui.dialog.NameItem) FormValidation(org.jboss.hal.ballroom.form.FormValidation) ModelNode(org.jboss.hal.dmr.ModelNode) ReadChildrenAutoComplete(org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete)

Aggregations

NameToken (com.gwtplatform.mvp.client.annotations.NameToken)2 Requires (org.jboss.hal.spi.Requires)2 EventBus (com.google.web.bindery.event.shared.EventBus)1 ProxyCodeSplit (com.gwtplatform.mvp.client.annotations.ProxyCodeSplit)1 ProxyPlace (com.gwtplatform.mvp.client.proxy.ProxyPlace)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Inject (javax.inject.Inject)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 ReadChildrenAutoComplete (org.jboss.hal.ballroom.autocomplete.ReadChildrenAutoComplete)1 Form (org.jboss.hal.ballroom.form.Form)1 FormValidation (org.jboss.hal.ballroom.form.FormValidation)1 ValidationResult (org.jboss.hal.ballroom.form.ValidationResult)1 AddressTemplates (org.jboss.hal.client.configuration.subsystem.messaging.AddressTemplates)1 CrudOperations (org.jboss.hal.core.CrudOperations)1 Finder (org.jboss.hal.core.finder.Finder)1 FinderPath (org.jboss.hal.core.finder.FinderPath)1