<commit_before>/*******************************************************************************
 * Copyright (c) 2012-2015 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME>. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.extension.builder.client.console;

import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SimpleHtmlSanitizer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.builder.dto.BuildTaskDescriptor;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.ide.api.build.BuildContext;
import org.eclipse.che.ide.api.parts.PartStackUIResources;
import org.eclipse.che.ide.api.parts.base.BaseView;
import org.eclipse.che.ide.extension.builder.client.BuilderLocalizationConstant;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * Implements {@link BuilderConsoleView}.
 *
 * @author <NAME>
 */
@Singleton
public class BuilderConsoleViewImpl extends BaseView<BuilderConsoleView.ActionDelegate> implements BuilderConsoleView {

    private static final int MAX_LINE_COUNT = 1000;

    /** Rate (limit per 1 sec.) */
    private static final int LIMIT        = 300;

    /** Period to print all collected messages. */
    private static final int FLUSH_PERIOD = 500;

    private static final String INFO  = "INFO";
    private static final String ERROR = "ERROR";
    private static final String WARN  = "WARNING";
    private static final String MAVEN = "MAVEN";

    private static final String PRE_STYLE = "style='margin:0px;'";

    private static final String INFO_COLOR  = "lightgreen";
    private static final String WARN_COLOR  = "#FFBA00";
    private static final String ERROR_COLOR = "#F62217";
    private static final String MAVEN_COLOR = "#61b7ef";

    private static final String FULL_LOGS_WIDGET_ID = "logs_link";

    private final List<String> buffer;

    private final BuildContext                buildContext;
    private final BuilderLocalizationConstant localizationConstant;
    @UiField
    SimplePanel toolbarPanel;
    @UiField
    ScrollPanel scrollPanel;
    @UiField
    FlowPanel   consoleArea;

    @Inject
    public BuilderConsoleViewImpl(PartStackUIResources resources,
                                  BuilderConsoleViewImplUiBinder uiBinder,
                                  BuildContext buildContext,
                                  BuilderLocalizationConstant localizationConstant) {
        super(resources);

        buffer = new ArrayList<>();
        new Timer() {
            @Override
            public void run() {
                printCollectedMessages();
            }
        }.scheduleRepeating(FLUSH_PERIOD);

        this.buildContext = buildContext;
        this.localizationConstant = localizationConstant;

        setContentWidget(uiBinder.createAndBindUi(this));

        minimizeButton.ensureDebugId("builder-console-minimizeButton");

        // this hack used for adding box shadow effect to toolbar
        toolbarPanel.getElement().getParentElement().getStyle().setOverflow(Overflow.VISIBLE);
        toolbarPanel.getElement().getParentElement().getStyle().setZIndex(1);

        scrollPanel.getElement().setTabIndex(0);
    }

    /** Print all postponed messages in correct order. */
    private void printCollectedMessages() {
        if (buffer.isEmpty()) {
            return;
        }

        int firstMessageNum = 0;
        if (buffer.size() > LIMIT) {
            firstMessageNum = buffer.size() - LIMIT;

            printLine("--------------------------------------------------------------------------------------");
            printLine("-------------------------------- " + firstMessageNum + " MESSAGES MISSED --------------------------------");
            consoleArea.add(getFullLogsWidget(getFullLogsLink()));
            printLine("--------------------------------------------------------------------------------------");
        }

        final ListIterator<String> iterator = buffer.listIterator(firstMessageNum);
        while (iterator.hasNext()) {
            printLine(iterator.next());
        }

        buffer.clear();
    }

    /** {@inheritDoc} */
    @Override
    public AcceptsOneWidget getToolbarPanel() {
        return toolbarPanel;
    }

    /** {@inheritDoc} */
    @Override
    public void print(String message) {
        buffer.add(message);
    }

    /** {@inheritDoc} */
    @Override
    public void printFF(char ch) {
        if (consoleArea.getWidgetCount() > 0) {
            final Widget firstWidget = consoleArea.getWidget(0);
            if (!firstWidget.getElement().getId().equals(FULL_LOGS_WIDGET_ID)) {
                consoleArea.insert(getFullLogsWidget(getFullLogsLink()), 0);
            }
        }
<commit_msg>IDEX-2426: builder console is scrolling down automatically<commit_after>/*******************************************************************************
 * Copyright (c) 2012-2015 <NAME>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   <NAME>. - initial API and implementation
 *******************************************************************************/
package org.eclipse.che.ide.extension.builder.client.console;

import com.google.gwt.dom.client.Style;
import com.google.gwt.dom.client.Style.Overflow;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.safehtml.shared.SimpleHtmlSanitizer;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.ui.AcceptsOneWidget;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.InlineHTML;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.builder.dto.BuildTaskDescriptor;
import org.eclipse.che.api.core.rest.shared.dto.Link;
import org.eclipse.che.ide.api.build.BuildContext;
import org.eclipse.che.ide.api.parts.PartStackUIResources;
import org.eclipse.che.ide.api.parts.base.BaseView;
import org.eclipse.che.ide.extension.builder.client.BuilderLocalizationConstant;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

/**
 * Implements {@link BuilderConsoleView}.
 *
 * @author <NAME>
 */
@Singleton
public class BuilderConsoleViewImpl extends BaseView<BuilderConsoleView.ActionDelegate> implements BuilderConsoleView {

    private static final int MAX_LINE_COUNT = 1000;

    /** Rate (limit per 1 sec.) */
    private static final int LIMIT = 300;

    /** Period to print all collected messages. */
    private static final int FLUSH_PERIOD = 500;

    private static final String INFO  = "INFO";
    private static final String ERROR = "ERROR";
    private static final String WARN  = "WARNING";
    private static final String MAVEN = "MAVEN";

    private static final String PRE_STYLE = "style='margin:0px;'";

    private static final String INFO_COLOR  = "lightgreen";
    private static final String WARN_COLOR  = "#FFBA00";
    private static final String ERROR_COLOR = "#F62217";
    private static final String MAVEN_COLOR = "#61b7ef";

    private static final String FULL_LOGS_WIDGET_ID = "logs_link";

    private final List<String> buffer;

    private final BuildContext                buildContext;
    private final BuilderLocalizationConstant localizationConstant;
    @UiField
    SimplePanel toolbarPanel;
    @UiField
    ScrollPanel scrollPanel;
    @UiField
    FlowPanel   consoleArea;

    @Inject
    public BuilderConsoleViewImpl(PartStackUIResources resources,
                                  BuilderConsoleViewImplUiBinder uiBinder,
                                  BuildContext buildContext,
                                  BuilderLocalizationConstant localizationConstant) {
        super(resources);

        buffer = new ArrayList<>();
        new Timer() {
            @Override
            public void run() {
                printCollectedMessages();
            }
        }.scheduleRepeating(FLUSH_PERIOD);

        this.buildContext = buildContext;
        this.localizationConstant = localizationConstant;

        setContentWidget(uiBinder.createAndBindUi(this));

        minimizeButton.ensureDebugId("builder-console-minimizeButton");

        // this hack used for adding box shadow effect to toolbar
        toolbarPanel.getElement().getParentElement().getStyle().setOverflow(Overflow.VISIBLE);
        toolbarPanel.getElement().getParentElement().getStyle().setZIndex(1);

        scrollPanel.getElement().setTabIndex(0);
    }

    /** Print all postponed messages in correct order. */
    private void printCollectedMessages() {
        if (buffer.isEmpty()) {
            return;
        }

        int firstMessageNum = 0;
        if (buffer.size() > LIMIT) {
            firstMessageNum = buffer.size() - LIMIT;

            printLine("--------------------------------------------------------------------------------------");
            printLine("-------------------------------- " + firstMessageNum + " MESSAGES MISSED --------------------------------");
            consoleArea.add(getFullLogsWidget(getFullLogsLink()));
            printLine("--------------------------------------------------------------------------------------");
        }

        final ListIterator<String> iterator = buffer.listIterator(firstMessageNum);
        while (iterator.hasNext()) {
            printLine(iterator.next());
        }

        buffer.clear();

        scrollBottom();
    }

    /** {@inheritDoc} */
    @Override
    public AcceptsOneWidget getToolbarPanel() {
        return toolbarPanel;
    }

    /** {@inheritDoc} */
    @Override
    public void print(String message) {
        buffer.add(message);
    }

    /** {@inheritDoc} */
    @Override
    public void printFF(char ch) {
        if (consoleArea.getWidgetCount() > 0) {
            final Widget firstWidget = consoleArea.getWidget(0);
            if (!firstWidget.getElement().getId().equals(FULL_LOGS_WIDGET_ID)) {
                consoleArea.insert(getFullLogsWidget(getFullLogsLink()), 0);
            }
        }

{'fraction_non_alphanumeric': 0.16429473684210527, 'fraction_numerical': 0.007073684210526316, 'mean_word_length': 2.684765746199193, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6750052', 'n_tokens_mistral': 3238, 'n_tokens_neox': 3091, 'n_words': 677}