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;
}
Aggregations