Search in sources :

Example 1 with BeanLocatorAware

use of com.haulmont.cuba.core.sys.BeanLocatorAware in project cuba by cuba-platform.

the class ExceptionHandlers method createByConfiguration.

/**
 * Create all Web handlers defined by <code>ExceptionHandlersConfiguration</code> beans in spring.xml and
 * GUI handlers defined as Spring-beans.
 */
public void createByConfiguration() {
    removeAll();
    // Web handlers
    Map<String, ExceptionHandlersConfiguration> map = beanLocator.getAll(ExceptionHandlersConfiguration.class);
    // Project-level handlers must run before platform-level
    List<ExceptionHandlersConfiguration> configurations = new ArrayList<>(map.values());
    Collections.reverse(configurations);
    for (ExceptionHandlersConfiguration conf : configurations) {
        for (Class aClass : conf.getHandlerClasses()) {
            try {
                ExceptionHandler handler = ReflectionHelper.<ExceptionHandler>newInstance(aClass);
                if (handler instanceof BeanLocatorAware) {
                    ((BeanLocatorAware) handler).setBeanLocator(beanLocator);
                }
                addHandler(handler);
            } catch (NoSuchMethodException e) {
                log.error("Unable to instantiate {}", aClass, e);
            }
        }
    }
    // GUI handlers
    Map<String, UiExceptionHandler> handlerMap = beanLocator.getAll(UiExceptionHandler.class);
    List<UiExceptionHandler> handlers = new ArrayList<>(handlerMap.values());
    handlers.sort(new OrderComparator());
    for (UiExceptionHandler handler : handlers) {
        addHandler(handler);
    }
}
Also used : ArrayList(java.util.ArrayList) UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) OrderComparator(org.springframework.core.OrderComparator) UiExceptionHandler(com.haulmont.cuba.gui.exception.UiExceptionHandler) BeanLocatorAware(com.haulmont.cuba.core.sys.BeanLocatorAware)

Example 2 with BeanLocatorAware

use of com.haulmont.cuba.core.sys.BeanLocatorAware in project cuba by cuba-platform.

the class ValueBinder method bind.

public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
    if (valueSource instanceof BeanLocatorAware) {
        ((BeanLocatorAware) valueSource).setBeanLocator(beanLocator);
    }
    ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
    if (component instanceof Component.Editable) {
        ((Component.Editable) component).setEditable(!valueSource.isReadOnly());
    }
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
        if (component instanceof Field) {
            initRequired((Field) component, metaPropertyPath);
            initBeanValidator((Field<?>) component, metaPropertyPath);
        }
        if (entityValueSource.isDataModelSecurityEnabled()) {
            if (component instanceof Component.Editable) {
                MetaClass metaClass = entityValueSource.getEntityMetaClass();
                boolean permittedIfEmbedded = true;
                if (entityValueSource instanceof ContainerValueSource) {
                    InstanceContainer container = ((ContainerValueSource) entityValueSource).getContainer();
                    if (container instanceof Nested && metadataTools.isEmbeddable(metaClass)) {
                        String embeddedProperty = ((Nested) container).getProperty();
                        MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
                        permittedIfEmbedded = security.isEntityAttrUpdatePermitted(masterMetaClass, embeddedProperty);
                    }
                    if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
                        for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
                            if (metadataTools.isEmbedded(property) && !security.isEntityAttrUpdatePermitted(property.getDomain(), property.getName())) {
                                permittedIfEmbedded = false;
                                break;
                            }
                        }
                    }
                }
                if (!security.isEntityAttrUpdatePermitted(metaPropertyPath) || !permittedIfEmbedded) {
                    ((Component.Editable) component).setEditable(false);
                }
            }
            if (!security.isEntityAttrReadPermitted(metaPropertyPath)) {
                component.setVisible(false);
            }
        }
    }
    binding.bind();
    return binding;
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) Nested(com.haulmont.cuba.gui.model.Nested) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) Field(com.haulmont.cuba.gui.components.Field) MetaClass(com.haulmont.chile.core.model.MetaClass) BeanLocatorAware(com.haulmont.cuba.core.sys.BeanLocatorAware) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

BeanLocatorAware (com.haulmont.cuba.core.sys.BeanLocatorAware)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 Field (com.haulmont.cuba.gui.components.Field)1 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)1 UiExceptionHandler (com.haulmont.cuba.gui.exception.UiExceptionHandler)1 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)1 Nested (com.haulmont.cuba.gui.model.Nested)1 ArrayList (java.util.ArrayList)1 OrderComparator (org.springframework.core.OrderComparator)1