Search in sources :

Example 1 with DashboardEvent

use of io.jmix.dashboardsui.event.DashboardEvent in project jmix by jmix-framework.

the class DashboardImpl method dashboardEventListener.

@SuppressWarnings("unchecked")
@EventListener
public void dashboardEventListener(DashboardEvent dashboardEvent) throws InvocationTargetException, IllegalAccessException {
    refreshWidgets(dashboardEvent);
    if (dashboardViewAssistant == null) {
        return;
    }
    Class eventClass = dashboardEvent.getClass();
    Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(dashboardViewAssistant.getClass());
    List<Method> eventListenerMethods = Arrays.stream(methods).filter(m -> m.getAnnotation(EventListener.class) != null).filter(m -> m.getParameterCount() == 1).collect(Collectors.toList());
    for (Method method : eventListenerMethods) {
        java.lang.reflect.Parameter[] parameters = method.getParameters();
        java.lang.reflect.Parameter parameter = parameters[0];
        Class methodEventTypeArg = parameter.getType();
        if (methodEventTypeArg.isAssignableFrom(eventClass)) {
            method.invoke(dashboardViewAssistant, dashboardEvent);
        }
    }
}
Also used : ScreenFragment(io.jmix.ui.screen.ScreenFragment) PersistentDashboard(io.jmix.dashboards.entity.PersistentDashboard) Dashboard(io.jmix.dashboardsui.component.Dashboard) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ParamsMap(io.jmix.core.common.util.ParamsMap) StringUtils(org.apache.commons.lang3.StringUtils) Messages(io.jmix.core.Messages) DashboardEvent(io.jmix.dashboardsui.event.DashboardEvent) io.jmix.ui(io.jmix.ui) Method(java.lang.reflect.Method) Resource(org.springframework.core.io.Resource) DataManager(io.jmix.core.DataManager) UiEventListenerMethodAdapter(io.jmix.ui.sys.event.UiEventListenerMethodAdapter) ResourceLoader(org.springframework.core.io.ResourceLoader) DataUnit(io.jmix.ui.component.data.DataUnit) LookupWidget(io.jmix.dashboardsui.widget.LookupWidget) UiControllerReflectionInspector(io.jmix.ui.sys.UiControllerReflectionInspector) EventListener(org.springframework.context.event.EventListener) ApplicationListener(org.springframework.context.ApplicationListener) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOUtils(org.apache.commons.io.IOUtils) CanvasLayout(io.jmix.dashboardsui.component.CanvasLayout) Timer(io.jmix.ui.component.Timer) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) io.jmix.ui.component(io.jmix.ui.component) CODE(io.jmix.dashboardsui.screen.dashboard.view.DashboardViewScreen.CODE) AccessConstraintsHelper(io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper) java.util(java.util) DashboardUpdatedEvent(io.jmix.dashboardsui.event.DashboardUpdatedEvent) Widget(io.jmix.dashboards.model.Widget) Function(java.util.function.Function) DASHBOARD(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment.DASHBOARD) Parameter(io.jmix.dashboards.model.parameter.Parameter) UiEventsMulticaster(io.jmix.ui.sys.event.UiEventsMulticaster) RefreshableWidget(io.jmix.dashboardsui.widget.RefreshableWidget) MapScreenOptions(io.jmix.ui.screen.MapScreenOptions) Nullable(javax.annotation.Nullable) MapUtils(org.apache.commons.collections4.MapUtils) Logger(org.slf4j.Logger) DashboardException(io.jmix.dashboardsui.DashboardException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Metadata(io.jmix.core.Metadata) JsonConverter(io.jmix.dashboards.converter.JsonConverter) ItemsSelectedEvent(io.jmix.dashboardsui.event.ItemsSelectedEvent) ParameterTransformer(io.jmix.dashboardsui.transformation.ParameterTransformer) DashboardModel(io.jmix.dashboards.model.DashboardModel) ReflectionUtils(org.springframework.util.ReflectionUtils) BeanFactory(org.springframework.beans.factory.BeanFactory) CanvasFragment(io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment) DashboardViewAssistant(io.jmix.dashboardsui.dashboard.assistant.DashboardViewAssistant) Parameter(io.jmix.dashboards.model.parameter.Parameter) Method(java.lang.reflect.Method) EventListener(org.springframework.context.event.EventListener)

Aggregations

DataManager (io.jmix.core.DataManager)1 Messages (io.jmix.core.Messages)1 Metadata (io.jmix.core.Metadata)1 ParamsMap (io.jmix.core.common.util.ParamsMap)1 JsonConverter (io.jmix.dashboards.converter.JsonConverter)1 PersistentDashboard (io.jmix.dashboards.entity.PersistentDashboard)1 DashboardModel (io.jmix.dashboards.model.DashboardModel)1 Widget (io.jmix.dashboards.model.Widget)1 Parameter (io.jmix.dashboards.model.parameter.Parameter)1 DashboardException (io.jmix.dashboardsui.DashboardException)1 CanvasLayout (io.jmix.dashboardsui.component.CanvasLayout)1 Dashboard (io.jmix.dashboardsui.component.Dashboard)1 DashboardViewAssistant (io.jmix.dashboardsui.dashboard.assistant.DashboardViewAssistant)1 AccessConstraintsHelper (io.jmix.dashboardsui.dashboard.tools.AccessConstraintsHelper)1 DashboardEvent (io.jmix.dashboardsui.event.DashboardEvent)1 DashboardUpdatedEvent (io.jmix.dashboardsui.event.DashboardUpdatedEvent)1 ItemsSelectedEvent (io.jmix.dashboardsui.event.ItemsSelectedEvent)1 CanvasFragment (io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment)1 DASHBOARD (io.jmix.dashboardsui.screen.dashboard.editor.canvas.CanvasFragment.DASHBOARD)1 CODE (io.jmix.dashboardsui.screen.dashboard.view.DashboardViewScreen.CODE)1