Search in sources :

Example 1 with Events

use of com.haulmont.cuba.core.global.Events in project cuba by cuba-platform.

the class ControllerDependencyInjector method injectEventListeners.

protected void injectEventListeners(Frame frame) {
    Class<? extends Frame> clazz = frame.getClass();
    List<Method> eventListenerMethods = getAnnotatedListenerMethods(clazz);
    if (!eventListenerMethods.isEmpty()) {
        Events events = (Events) applicationContext.getBean(Events.NAME);
        List<ApplicationListener> listeners = eventListenerMethods.stream().map(m -> new UiEventListenerMethodAdapter(frame, clazz, m, events)).collect(Collectors.toList());
        ((AbstractFrame) frame).setUiEventListeners(listeners);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) LoadingCache(com.google.common.cache.LoadingCache) Datasource(com.haulmont.cuba.gui.data.Datasource) ClassUtils(org.apache.commons.lang.ClassUtils) Config(com.haulmont.cuba.core.config.Config) LoggerFactory(org.slf4j.LoggerFactory) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) Configuration(com.haulmont.cuba.core.global.Configuration) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Named(javax.inject.Named) Nonnull(javax.annotation.Nonnull) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) DsContext(com.haulmont.cuba.gui.data.DsContext) java.lang.reflect(java.lang.reflect) Logger(org.slf4j.Logger) ClientConfiguration(com.haulmont.cuba.client.ClientConfiguration) ExportDisplay(com.haulmont.cuba.gui.export.ExportDisplay) Resource(javax.annotation.Resource) ThemeConstantsManager(com.haulmont.cuba.gui.theme.ThemeConstantsManager) EventListener(org.springframework.context.event.EventListener) BeansException(org.springframework.beans.BeansException) ApplicationListener(org.springframework.context.ApplicationListener) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) CacheLoader(com.google.common.cache.CacheLoader) Events(com.haulmont.cuba.core.global.Events) UiEventListenerMethodAdapter(com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter) ReflectionUtils(org.springframework.util.ReflectionUtils) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) CacheBuilder(com.google.common.cache.CacheBuilder) DataSupplier(com.haulmont.cuba.gui.data.DataSupplier) ApplicationContextAware(org.springframework.context.ApplicationContextAware) UiEventListenerMethodAdapter(com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter) Events(com.haulmont.cuba.core.global.Events) ApplicationListener(org.springframework.context.ApplicationListener)

Example 2 with Events

use of com.haulmont.cuba.core.global.Events in project cuba by cuba-platform.

the class AbstractAppContextLoader method initAppContext.

protected void initAppContext() {
    String configProperty = AppContext.getProperty(SPRING_CONTEXT_CONFIG);
    if (StringUtils.isBlank(configProperty)) {
        throw new IllegalStateException("Missing " + SPRING_CONTEXT_CONFIG + " application property");
    }
    StrTokenizer tokenizer = new StrTokenizer(configProperty);
    String[] locations = tokenizer.getTokenArray();
    replaceLocationsFromConf(locations);
    ApplicationContext appContext = createApplicationContext(locations);
    AppContext.Internals.setApplicationContext(appContext);
    Events events = AppBeans.get(Events.NAME);
    events.publish(new AppContextInitializedEvent(appContext));
    log.debug("AppContext initialized");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Events(com.haulmont.cuba.core.global.Events) AppContextInitializedEvent(com.haulmont.cuba.core.sys.events.AppContextInitializedEvent) StrTokenizer(org.apache.commons.lang.text.StrTokenizer)

Example 3 with Events

use of com.haulmont.cuba.core.global.Events in project cuba by cuba-platform.

the class AppContext method stopContext.

/**
 * Called by the framework right before the application shutdown.
 */
static void stopContext() {
    if (!started)
        return;
    started = false;
    for (int i = listeners.size() - 1; i >= 0; i--) {
        Listener listener = listeners.get(i);
        listener.applicationStopped();
    }
    Events events = (Events) getApplicationContext().getBean(Events.NAME);
    events.publish(new AppContextStoppedEvent(context));
    if (context != null && context instanceof ConfigurableApplicationContext) {
        ((ConfigurableApplicationContext) context).close();
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Events(com.haulmont.cuba.core.global.Events) AppContextStoppedEvent(com.haulmont.cuba.core.sys.events.AppContextStoppedEvent)

Example 4 with Events

use of com.haulmont.cuba.core.global.Events in project cuba by cuba-platform.

the class UserRemoveAction method afterRemove.

@Override
protected void afterRemove(Set removedItems) {
    super.afterRemove(removedItems);
    Events events = AppBeans.get(Events.NAME);
    for (Object removedItem : removedItems) {
        UserRemovedEvent event = new UserRemovedEvent((User) removedItem);
        events.publish(event);
    }
}
Also used : Events(com.haulmont.cuba.core.global.Events) UserRemovedEvent(com.haulmont.cuba.gui.events.UserRemovedEvent)

Example 5 with Events

use of com.haulmont.cuba.core.global.Events in project cuba by cuba-platform.

the class AppContext method startContext.

static void startContext() {
    if (started)
        return;
    started = true;
    listeners.sort(new OrderComparator());
    for (Listener listener : listeners) {
        listener.applicationStarted();
    }
    Events events = (Events) getApplicationContext().getBean(Events.NAME);
    events.publish(new AppContextStartedEvent(context));
    listenersNotified = true;
}
Also used : Events(com.haulmont.cuba.core.global.Events) AppContextStartedEvent(com.haulmont.cuba.core.sys.events.AppContextStartedEvent) OrderComparator(org.springframework.core.OrderComparator)

Aggregations

Events (com.haulmont.cuba.core.global.Events)5 ApplicationContext (org.springframework.context.ApplicationContext)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableList (com.google.common.collect.ImmutableList)1 ClientConfiguration (com.haulmont.cuba.client.ClientConfiguration)1 Config (com.haulmont.cuba.core.config.Config)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 AppContextInitializedEvent (com.haulmont.cuba.core.sys.events.AppContextInitializedEvent)1 AppContextStartedEvent (com.haulmont.cuba.core.sys.events.AppContextStartedEvent)1 AppContextStoppedEvent (com.haulmont.cuba.core.sys.events.AppContextStoppedEvent)1 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)1 DataSupplier (com.haulmont.cuba.gui.data.DataSupplier)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 DsContext (com.haulmont.cuba.gui.data.DsContext)1 UserRemovedEvent (com.haulmont.cuba.gui.events.UserRemovedEvent)1 UiEventListenerMethodAdapter (com.haulmont.cuba.gui.events.sys.UiEventListenerMethodAdapter)1 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)1 ThemeConstants (com.haulmont.cuba.gui.theme.ThemeConstants)1