Search in sources :

Example 6 with ExportDisplay

use of com.haulmont.cuba.gui.export.ExportDisplay in project cuba by cuba-platform.

the class ControllerDependencyInjector method getInjectedInstance.

protected Object getInjectedInstance(Class<?> type, String name, Class annotationClass, AnnotatedElement element) {
    if (annotationClass == WindowParam.class) {
        // Injecting a parameter
        return params.get(name);
    } else if (Component.class.isAssignableFrom(type)) {
        // Injecting a UI component
        return frame.getComponent(name);
    } else if (Datasource.class.isAssignableFrom(type)) {
        // Injecting a datasource
        return frame.getDsContext().get(name);
    } else if (DsContext.class.isAssignableFrom(type)) {
        // Injecting the DsContext
        return frame.getDsContext();
    } else if (DataSupplier.class.isAssignableFrom(type)) {
        // Injecting the DataSupplier
        return frame.getDsContext().getDataSupplier();
    } else if (FrameContext.class.isAssignableFrom(type)) {
        // Injecting the FrameContext
        return frame.getContext();
    } else if (Action.class.isAssignableFrom(type)) {
        // Injecting an action
        return ComponentsHelper.findAction(name, frame);
    } else if (ExportDisplay.class.isAssignableFrom(type)) {
        // Injecting an ExportDisplay
        return AppConfig.createExportDisplay(frame);
    } else if (ThemeConstants.class.isAssignableFrom(type)) {
        // Injecting a Theme
        ThemeConstantsManager themeManager = (ThemeConstantsManager) applicationContext.getBean(ThemeConstantsManager.NAME);
        return themeManager.getConstants();
    } else if (Config.class.isAssignableFrom(type)) {
        ClientConfiguration configuration = (ClientConfiguration) applicationContext.getBean(Configuration.NAME);
        // noinspection unchecked
        return configuration.getConfigCached((Class<? extends Config>) type);
    } else if (Logger.class == type && element instanceof Field) {
        return LoggerFactory.getLogger(((Field) element).getDeclaringClass());
    } else {
        Object instance;
        // Try to find a Spring bean
        Map<String, ?> beans = applicationContext.getBeansOfType(type, true, true);
        if (!beans.isEmpty()) {
            instance = beans.get(name);
            // If a bean with required name found, return it. Otherwise return first found.
            if (instance != null) {
                return instance;
            } else {
                return beans.values().iterator().next();
            }
        }
        // There are no Spring beans of required type - the last option is Companion
        if (frame instanceof AbstractFrame) {
            instance = ((AbstractFrame) frame).getCompanion();
            if (instance != null && type.isAssignableFrom(instance.getClass())) {
                return instance;
            }
        }
    }
    return null;
}
Also used : DsContext(com.haulmont.cuba.gui.data.DsContext) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) Config(com.haulmont.cuba.core.config.Config) Logger(org.slf4j.Logger) Field(java.lang.reflect.Field) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) ClientConfiguration(com.haulmont.cuba.client.ClientConfiguration)

Aggregations

ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)6 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 ComponentsFactory (com.haulmont.cuba.gui.xml.layout.ComponentsFactory)2 ClientConfiguration (com.haulmont.cuba.client.ClientConfiguration)1 DomainDescriptionService (com.haulmont.cuba.core.app.DomainDescriptionService)1 Config (com.haulmont.cuba.core.config.Config)1 Entity (com.haulmont.cuba.core.entity.Entity)1 JmxInstance (com.haulmont.cuba.core.entity.JmxInstance)1 LogControlException (com.haulmont.cuba.core.sys.logging.LogControlException)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)1 ThemeConstantsManager (com.haulmont.cuba.gui.theme.ThemeConstantsManager)1 LogDataProvider (com.haulmont.cuba.web.export.LogDataProvider)1 WebExportDisplay (com.haulmont.cuba.web.filestorage.WebExportDisplay)1 Field (java.lang.reflect.Field)1 Logger (org.slf4j.Logger)1