<commit_before>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.web;

import com.haulmont.bali.util.ParamsMap;
import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.UserSessionSource;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer;
import com.haulmont.cuba.gui.app.core.dev.LayoutTip;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.mainwindow.UserIndicator;
import com.haulmont.cuba.gui.config.WindowConfig;
import com.haulmont.cuba.gui.config.WindowInfo;
import com.haulmont.cuba.gui.theme.ThemeConstantsRepository;
import com.haulmont.cuba.security.app.UserSessionService;
import com.haulmont.cuba.web.app.UserSettingsTools;
import com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea;
import com.haulmont.cuba.web.toolkit.ui.*;
import com.vaadin.event.LayoutEvents;
import com.vaadin.server.Extension;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.Component;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.vaadin.peter.contextmenu.ContextMenu;

import java.util.*;

/**
 * Standard main application window.
 * <p/>
 * To use a specific implementation override {@link App#createAppWindow(AppUI)} method.
 *
 * @author krivopustov
 * @version $Id$
 */
public class AppWindow extends UIView implements CubaHistoryControl.HistoryBackHandler {

    private static final Log log = LogFactory.getLog(AppWindow.class);

    protected final AppUI ui;

    protected final App app;

    protected final Connection connection;

    protected final WebWindowManager windowManager;

    protected CubaClientManager clientManager;

    protected CubaFileDownloader fileDownloader;

    protected CubaHistoryControl historyControl;

    protected CubaTimer workerTimer;

    protected WebConfig webConfig;

    protected Window.MainWindow mainWindow;

    protected Messages messages = AppBeans.get(Messages.NAME);

    public AppWindow(AppUI ui) {
        log.trace("Creating " + this);

        this.ui = ui;
        this.app = ui.getApp();
        this.connection = app.getConnection();
        this.windowManager = createWindowManager();

        Configuration configuration = AppBeans.get(Configuration.NAME);
        webConfig = configuration.getConfig(WebConfig.class);

        setSizeFull();

        initInternalComponents();

        ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
        if (clientConfig.getLayoutAnalyzerEnabled()) {
            final ContextMenu contextMenu = new ContextMenu();
            contextMenu.setOpenAutomatically(true);
            ContextMenu.ContextMenuItem analyzeLayout = contextMenu.addItem(messages.getMainMessage("actions.analyzeLayout"));
            analyzeLayout.addItemClickListener(new ContextMenu.ContextMenuItemClickListener() {
                @Override
                public void contextMenuItemClicked(ContextMenu.ContextMenuItemClickEvent event) {
                    Window window = getMainWindow();
                    if (window != null) {
                        LayoutAnalyzer analyzer = new LayoutAnalyzer();
                        List<LayoutTip> tipsList = analyzer.analyze(window);

                        if (tipsList.isEmpty()) {
                            window.showNotification("No layout problems found", IFrame.NotificationType.HUMANIZED);
                        } else {
                            window.openWindow("layoutAnalyzer", WindowManager.OpenType.DIALOG, ParamsMap.of("tipsList", tipsList));
                        }
                    }
                }
            });
            contextMenu.setAsContextMenuOf(this);

            addLayoutClickListener(new LayoutEvents.LayoutClickListener() {
                @Override
                public void layoutClick(LayoutEvents.LayoutClickEvent event) {
                    if (event.getButton() == MouseEventDetails.MouseButton.RIGHT) {
                        Component targetComponent = event.getClickedComponent();

                        if (targetComponent != null) {
                            if (getMainWindow().getWorkArea() != null) {
                                WebAppWorkArea workArea = (WebAppWorkArea) getMainWindow().getWorkArea();
                                CubaTabSheet tabbedWindowContainer = workArea.getTabbedWindowContainer();
                                VerticalLayout singleWindowContainer = workArea.getSingleWindowContainer();

                                Component parent = targetComponent.getParent();
                                while (parent != null) {
                                    if (parent == tabbedWindowContainer
                                            || parent == singleWindowContainer) {
                                        return;
                                    }
                                    parent = parent.getParent();
                                }
                            }

                            contextMenu.open(event.getClientX(), event.getClientY());
                        }<commit_msg>Analyze layout for main window #PL-5548<commit_after>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.web;

import com.haulmont.bali.util.ParamsMap;
import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Configuration;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.UserSessionSource;
import com.haulmont.cuba.gui.WindowManager;
import com.haulmont.cuba.gui.app.core.dev.LayoutAnalyzer;
import com.haulmont.cuba.gui.app.core.dev.LayoutTip;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.Window;
import com.haulmont.cuba.gui.components.mainwindow.UserIndicator;
import com.haulmont.cuba.gui.config.WindowConfig;
import com.haulmont.cuba.gui.config.WindowInfo;
import com.haulmont.cuba.gui.theme.ThemeConstantsRepository;
import com.haulmont.cuba.security.app.UserSessionService;
import com.haulmont.cuba.web.app.UserSettingsTools;
import com.haulmont.cuba.web.gui.components.mainwindow.WebAppWorkArea;
import com.haulmont.cuba.web.toolkit.ui.*;
import com.vaadin.event.LayoutEvents;
import com.vaadin.server.Extension;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.ui.Component;
import com.vaadin.ui.Notification;
import com.vaadin.ui.VerticalLayout;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.vaadin.peter.contextmenu.ContextMenu;

import java.util.*;

/**
 * Standard main application window.
 * <p/>
 * To use a specific implementation override {@link App#createAppWindow(AppUI)} method.
 *
 * @author krivopustov
 * @version $Id$
 */
public class AppWindow extends UIView implements CubaHistoryControl.HistoryBackHandler {

    private static final Log log = LogFactory.getLog(AppWindow.class);

    protected final AppUI ui;

    protected final App app;

    protected final Connection connection;

    protected final WebWindowManager windowManager;

    protected CubaClientManager clientManager;

    protected CubaFileDownloader fileDownloader;

    protected CubaHistoryControl historyControl;

    protected CubaTimer workerTimer;

    protected WebConfig webConfig;

    protected Window.MainWindow mainWindow;

    protected Messages messages = AppBeans.get(Messages.NAME);

    public AppWindow(AppUI ui) {
        log.trace("Creating " + this);

        this.ui = ui;
        this.app = ui.getApp();
        this.connection = app.getConnection();
        this.windowManager = createWindowManager();

        Configuration configuration = AppBeans.get(Configuration.NAME);
        webConfig = configuration.getConfig(WebConfig.class);

        setSizeFull();

        initInternalComponents();

        ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);
        if (clientConfig.getLayoutAnalyzerEnabled()) {
            final ContextMenu contextMenu = new ContextMenu();
            contextMenu.setOpenAutomatically(true);
            ContextMenu.ContextMenuItem analyzeLayout = contextMenu.addItem(messages.getMainMessage("actions.analyzeLayout"));
            analyzeLayout.addItemClickListener(new ContextMenu.ContextMenuItemClickListener() {
                @Override
                public void contextMenuItemClicked(ContextMenu.ContextMenuItemClickEvent event) {
                    Window window = getMainWindow();
                    if (window != null) {
                        LayoutAnalyzer analyzer = new LayoutAnalyzer();
                        List<LayoutTip> tipsList = analyzer.analyze(window);

                        if (tipsList.isEmpty()) {
                            window.showNotification("No layout problems found", IFrame.NotificationType.HUMANIZED);
                        } else {
                            window.openWindow("layoutAnalyzer", WindowManager.OpenType.DIALOG, ParamsMap.of("tipsList", tipsList));
                        }
                    }
                }
            });
            contextMenu.setAsContextMenuOf(this);

            addLayoutClickListener(new LayoutEvents.LayoutClickListener() {
                @Override
                public void layoutClick(LayoutEvents.LayoutClickEvent event) {
                    if (event.getButton() == MouseEventDetails.MouseButton.RIGHT) {
                        Component targetComponent = event.getClickedComponent();

                        if (targetComponent != null) {
                            if (getMainWindow().getWorkArea() != null) {
                                WebAppWorkArea workArea = (WebAppWorkArea) getMainWindow().getWorkArea();
                                CubaTabSheet tabbedWindowContainer = workArea.getTabbedWindowContainer();
                                VerticalLayout singleWindowContainer = workArea.getSingleWindowContainer();

                                Component parent = targetComponent;
                                while (parent != null) {
                                    if (parent == tabbedWindowContainer
                                            || parent == singleWindowContainer) {
                                        return;
                                    }
                                    parent = parent.getParent();
                                }
                            }

                            contextMenu.open(event.getClientX(), event.getClientY());
                        }
{'fraction_non_alphanumeric': 0.08867924528301886, 'fraction_numerical': 0.0017969451931716084, 'mean_word_length': 2.338632273545291, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3828914', 'n_tokens_mistral': 2864, 'n_tokens_neox': 2692, 'n_words': 523}