Search in sources :

Example 76 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class RelatedEntitiesSupportImpl method getMetaProperty.

protected MetaProperty getMetaProperty(RelatedEntitiesBuilder builder, MetaClass metaClass) {
    MetaProperty metaProperty = builder.getMetaProperty();
    if (metaProperty != null) {
        return metaProperty;
    }
    String property = builder.getProperty();
    if (!Strings.isNullOrEmpty(property)) {
        return metaClass.getProperty(property);
    }
    throw new IllegalStateException("'metaProperty' or 'property' can't be null");
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 77 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class RelatedEntitiesSupportImpl method buildScreen.

protected Screen buildScreen(RelatedEntitiesBuilder builder) {
    MetaClass metaClass = getMetaClass(builder);
    MetaProperty metaProperty = getMetaProperty(builder, metaClass);
    Screen screen = createScreen(builder, metaClass, metaProperty);
    boolean found = ComponentsHelper.walkComponents(screen.getWindow(), screenComponent -> {
        if (screenComponent instanceof Filter) {
            Filter filter = (Filter) screenComponent;
            DataLoader dataLoader = filter.getDataLoader();
            MetaClass actualMetaClass = dataLoader.getContainer().getEntityMetaClass();
            MetaClass relatedMetaClass = metaProperty.getRange().asClass();
            MetaClass effectiveMetaClass = extendedEntities.getEffectiveMetaClass(relatedMetaClass);
            if (Objects.equals(actualMetaClass, effectiveMetaClass)) {
                Collection selectedEntities = builder.getSelectedEntities() == null ? Collections.emptyList() : builder.getSelectedEntities();
                String configurationName = generateConfigurationName(builder, metaProperty);
                DesignTimeConfiguration configuration = createFilterConfiguration((Filter) screenComponent, configurationName);
                JpqlFilter jpqlFilter = createJpqlFilter(filter.getDataLoader(), metaProperty, metaClass, selectedEntities);
                configuration.getRootLogicalFilterComponent().add(jpqlFilter);
                configuration.setFilterComponentDefaultValue(jpqlFilter.getParameterName(), jpqlFilter.getValue());
                filter.setCurrentConfiguration(configuration);
                return true;
            }
        }
        return false;
    });
    if (!found) {
        screen.addAfterShowListener(event -> {
            ScreenContext screenContext = UiControllerUtils.getScreenContext(event.getSource());
            screenContext.getNotifications().create(Notifications.NotificationType.WARNING).withCaption(messages.getMessage("actions.Related.FilterNotFound")).show();
        });
    }
    return screen;
}
Also used : DataLoader(io.jmix.ui.model.DataLoader) ScreenContext(io.jmix.ui.screen.ScreenContext) MetaClass(io.jmix.core.metamodel.model.MetaClass) JpqlFilter(io.jmix.ui.component.JpqlFilter) Filter(io.jmix.ui.component.Filter) Screen(io.jmix.ui.screen.Screen) JpqlFilter(io.jmix.ui.component.JpqlFilter) DesignTimeConfiguration(io.jmix.ui.component.filter.configuration.DesignTimeConfiguration) Collection(java.util.Collection) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 78 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method createView.

/**
 * Creates a view, loading only necessary properties.
 * Referenced entities will be loaded with a MINIMAL view.
 *
 * @param meta meta class
 * @return View instance
 */
protected View createView(MetaClass meta) {
    View view = new View(meta.getJavaClass(), false);
    for (MetaProperty metaProperty : meta.getProperties()) {
        if (!managedFields.containsKey(metaProperty.getName()) && !managedEmbeddedProperties.contains(metaProperty.getName())) {
            continue;
        }
        switch(metaProperty.getType()) {
            case DATATYPE:
            case ENUM:
                view.addProperty(metaProperty.getName());
                break;
            case EMBEDDED:
                {
                    // build view for embedded property
                    FetchPlan propView = createEmbeddedView(metaProperty.getRange().asClass(), metaProperty.getName());
                    view.addProperty(metaProperty.getName(), propView);
                    break;
                }
            case ASSOCIATION:
            case COMPOSITION:
                FetchPlan propView = viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL);
                // in some cases JPA loads extended entities as instance of base class which leads to ClassCastException
                // loading property lazy prevents this from happening
                view.addProperty(metaProperty.getName(), propView);
                break;
            default:
                throw new IllegalStateException("unknown property type");
        }
    }
    return view;
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty) FetchPlan(io.jmix.core.FetchPlan)

Example 79 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method createEmbeddedView.

protected View createEmbeddedView(MetaClass meta, String fqnPrefix) {
    View view = new View(meta.getJavaClass(), false);
    for (MetaProperty metaProperty : meta.getProperties()) {
        String fqn = fqnPrefix + "." + metaProperty.getName();
        if (!managedFields.containsKey(fqn)) {
            continue;
        }
        switch(metaProperty.getType()) {
            case DATATYPE:
            case ENUM:
                view.addProperty(metaProperty.getName());
                break;
            case EMBEDDED:
                {
                    FetchPlan propView = createEmbeddedView(metaProperty.getRange().asClass(), fqn);
                    view.addProperty(metaProperty.getName(), propView);
                    break;
                }
            case ASSOCIATION:
            case COMPOSITION:
                FetchPlan propView = viewRepository.getView(metaProperty.getRange().asClass(), View.MINIMAL);
                // in some cases JPA loads extended entities as instance of base class which leads to ClassCastException
                // loading property lazy prevents this from happening
                view.addProperty(metaProperty.getName(), propView);
                break;
            default:
                throw new IllegalStateException("unknown property type");
        }
    }
    return view;
}
Also used : MetaProperty(io.jmix.core.metamodel.model.MetaProperty) FetchPlan(io.jmix.core.FetchPlan)

Example 80 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class BulkEditorWindow method createNestedEmbeddedDatasources.

protected void createNestedEmbeddedDatasources(Datasource masterDs, MetaClass metaClass, String fqnPrefix) {
    for (MetaProperty metaProperty : metaClass.getProperties()) {
        if (MetaProperty.Type.ASSOCIATION == metaProperty.getType() || MetaProperty.Type.COMPOSITION == metaProperty.getType() || MetaProperty.Type.EMBEDDED == metaProperty.getType()) {
            String fqn = metaProperty.getName();
            if (StringUtils.isNotEmpty(fqnPrefix)) {
                fqn = fqnPrefix + "." + fqn;
            }
            if (managedEmbeddedProperties.contains(fqn) && metadataTools.isEmbedded(metaProperty)) {
                MetaClass propertyMetaClass = metaProperty.getRange().asClass();
                @SuppressWarnings("unchecked") NestedDatasource<Entity> propertyDs = new EmbeddedDatasourceImpl();
                propertyDs.setup(fqn + "Ds", masterDs, metaProperty.getName());
                propertyDs.setAllowCommit(false);
                createNestedEmbeddedDatasources(propertyDs, propertyMetaClass, fqn);
                datasources.put(fqn, propertyDs);
                dsContext.register(propertyDs);
            }
        }
    }
}
Also used : Entity(io.jmix.core.Entity) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) EmbeddedDatasourceImpl(com.haulmont.cuba.gui.data.impl.EmbeddedDatasourceImpl)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8