<commit_before>package org.ovirt.engine.ui.webadmin.plugin;

import java.util.logging.Logger;

import org.ovirt.engine.ui.common.auth.CurrentUser;
import org.ovirt.engine.ui.common.auth.UserLoginChangeEvent;
import org.ovirt.engine.ui.common.auth.UserLoginChangeEvent.UserLoginChangeHandler;
import org.ovirt.engine.ui.common.restapi.RestApiSessionAcquiredEvent;
import org.ovirt.engine.ui.common.restapi.RestApiSessionAcquiredEvent.RestApiSessionAcquiredHandler;
import org.ovirt.engine.ui.webadmin.plugin.PluginManager.PluginInvocationCondition;
import org.ovirt.engine.ui.webadmin.plugin.entity.EntityObject;
import org.ovirt.engine.ui.webadmin.plugin.entity.SystemTreeItemObject;
import org.ovirt.engine.ui.webadmin.plugin.jsni.JsArrayHelper;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ClusterSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ClusterSelectionChangeEvent.ClusterSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DataCenterSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DataCenterSelectionChangeEvent.DataCenterSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DiskSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DiskSelectionChangeEvent.DiskSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.EventSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.EventSelectionChangeEvent.EventSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.HostSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.HostSelectionChangeEvent.HostSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.NetworkSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.NetworkSelectionChangeEvent.NetworkSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.PoolSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.PoolSelectionChangeEvent.PoolSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ProviderSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ProviderSelectionChangeEvent.ProviderSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.QuotaSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.QuotaSelectionChangeEvent.QuotaSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.StorageSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.StorageSelectionChangeEvent.StorageSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.TemplateSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.TemplateSelectionChangeEvent.TemplateSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.UserSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.UserSelectionChangeEvent.UserSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VirtualMachineSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VirtualMachineSelectionChangeEvent.VirtualMachineSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VolumeSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VolumeSelectionChangeEvent.VolumeSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.system.MessageEventData;
import org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent;
import org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent.MessageReceivedHandler;
import org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent.SystemTreeSelectionChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;

/**
 * Handles WebAdmin application events to be consumed by UI plugins.
 * <p>
 * Should be bound as GIN eager singleton, created early on during application startup.
 */
public class PluginEventHandler {

    private static final Logger logger = Logger.getLogger(PluginEventHandler.class.getName());

    @Inject
    public PluginEventHandler(EventBus eventBus, final PluginManager manager, final CurrentUser user) {
        // User login and logout
        eventBus.addHandler(UserLoginChangeEvent.getType(), new UserLoginChangeHandler() {
            @Override
            public void onUserLoginChange(UserLoginChangeEvent event) {
                if (user.isLoggedIn()) {
                    manager.invokePluginsNowOrLater("UserLogin", //$NON-NLS-1$
                            JsArrayHelper.createStringArray(user.getFullUserName(), user.getUserId()));
                } else {
                    manager.invokePluginsNowOrLater("UserLogout", null); //$NON-NLS-1$
                }
            }
        });

        // Engine REST API session management
        eventBus.addHandler(RestApiSessionAcquiredEvent.getType(), new RestApiSessionAcquiredHandler() {
            @Override
            public void onRestApiSessionAcquired(RestApiSessionAcquiredEvent event) {
                manager.invokePluginsNowOrLater("RestApiSessionAcquired", //$NON-NLS-1$
                        JsArrayHelper.createStringArray(event.getSessionId()));
            }
        });

        // Standard main tab item selection change<commit_msg>webadmin: Issue warning upon RestApiSessionAcquired event<commit_after>package org.ovirt.engine.ui.webadmin.plugin;

import java.util.logging.Logger;

import org.ovirt.engine.ui.common.auth.CurrentUser;
import org.ovirt.engine.ui.common.auth.UserLoginChangeEvent;
import org.ovirt.engine.ui.common.auth.UserLoginChangeEvent.UserLoginChangeHandler;
import org.ovirt.engine.ui.common.restapi.RestApiSessionAcquiredEvent;
import org.ovirt.engine.ui.common.restapi.RestApiSessionAcquiredEvent.RestApiSessionAcquiredHandler;
import org.ovirt.engine.ui.webadmin.plugin.PluginManager.PluginInvocationCondition;
import org.ovirt.engine.ui.webadmin.plugin.entity.EntityObject;
import org.ovirt.engine.ui.webadmin.plugin.entity.SystemTreeItemObject;
import org.ovirt.engine.ui.webadmin.plugin.jsni.JsArrayHelper;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ClusterSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ClusterSelectionChangeEvent.ClusterSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DataCenterSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DataCenterSelectionChangeEvent.DataCenterSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DiskSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.DiskSelectionChangeEvent.DiskSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.EventSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.EventSelectionChangeEvent.EventSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.HostSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.HostSelectionChangeEvent.HostSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.NetworkSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.NetworkSelectionChangeEvent.NetworkSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.PoolSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.PoolSelectionChangeEvent.PoolSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ProviderSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.ProviderSelectionChangeEvent.ProviderSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.QuotaSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.QuotaSelectionChangeEvent.QuotaSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.StorageSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.StorageSelectionChangeEvent.StorageSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.TemplateSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.TemplateSelectionChangeEvent.TemplateSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.UserSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.UserSelectionChangeEvent.UserSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VirtualMachineSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VirtualMachineSelectionChangeEvent.VirtualMachineSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VolumeSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.section.main.presenter.tab.VolumeSelectionChangeEvent.VolumeSelectionChangeHandler;
import org.ovirt.engine.ui.webadmin.system.MessageEventData;
import org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent;
import org.ovirt.engine.ui.webadmin.system.MessageReceivedEvent.MessageReceivedHandler;
import org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent;
import org.ovirt.engine.ui.webadmin.uicommon.model.SystemTreeSelectionChangeEvent.SystemTreeSelectionChangeHandler;

import com.google.gwt.event.shared.EventBus;
import com.google.inject.Inject;

/**
 * Handles WebAdmin application events to be consumed by UI plugins.
 * <p>
 * Should be bound as GIN eager singleton, created early on during application startup.
 */
public class PluginEventHandler {

    private static final Logger logger = Logger.getLogger(PluginEventHandler.class.getName());

    @Inject
    public PluginEventHandler(EventBus eventBus, final PluginManager manager, final CurrentUser user) {
        // User login and logout
        eventBus.addHandler(UserLoginChangeEvent.getType(), new UserLoginChangeHandler() {
            @Override
            public void onUserLoginChange(UserLoginChangeEvent event) {
                if (user.isLoggedIn()) {
                    manager.invokePluginsNowOrLater("UserLogin", //$NON-NLS-1$
                            JsArrayHelper.createStringArray(user.getFullUserName(), user.getUserId()));
                } else {
                    manager.invokePluginsNowOrLater("UserLogout", null); //$NON-NLS-1$
                }
            }
        });

        // Engine REST API session management
        eventBus.addHandler(RestApiSessionAcquiredEvent.getType(), new RestApiSessionAcquiredHandler() {
            @Override
            public void onRestApiSessionAcquired(RestApiSessionAcquiredEvent event) {
                logger.warning("In future versions, RestApiSessionAcquired event will be replaced " + //$NON-NLS-1$
                        "with API to create authenticated requests for Engine services"); //$NON-NLS-1$
                manager.invokePluginsNowOrLater("RestApiSessionAcquired", //$NON-NLS-1$
                        JsArrayHelper.createStringArray(event.getSessionId()));
            }
        });

        // Standard main tab item selection change
{'fraction_non_alphanumeric': 0.09674679351057504, 'fraction_numerical': 0.0006795209377388941, 'mean_word_length': 5.129099427381572, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7255679', 'n_tokens_mistral': 3355, 'n_tokens_neox': 3307, 'n_words': 381}