<commit_before>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.jboss.as.console.client.domain.topology;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasRows;
import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.RangeChangeEvent;
import com.google.gwt.view.client.RowCountChangeEvent;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.SuspendableViewImpl;
import org.jboss.as.console.client.domain.model.ServerInstance;
import org.jboss.as.console.client.domain.model.impl.LifecycleOperation;
import org.jboss.as.console.client.shared.viewframework.builder.SimpleLayout;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.ballroom.client.widgets.window.Feedback;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;

import static com.google.gwt.user.client.Event.ONCLICK;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.*;
import static org.jboss.as.console.client.domain.topology.HtmlGenerator.*;

/**
 * @author <NAME>
 * @date 10/09/12
 */
public class TopologyView extends SuspendableViewImpl implements TopologyPresenter.MyView
{
    static final int TABLE_WIDTH = 100; // percent
    static final int SERVER_GROUPS_COLUMN = 15; // percent
    static final int HOSTS_COLUMNS = TABLE_WIDTH - SERVER_GROUPS_COLUMN;
    static final int SERVER_GROUP_COLORS = 5; // must match the '.serverGroupX' css class names

    private int hostIndex = 0; // the index of the current visible host
    private int visibleHosts = TopologyPresenter.VISIBLE_HOSTS_COLUMNS;
    private int hostSize = 0;
    private TopologyPresenter presenter;
    private HTMLPanel root;
    private HostsDisplay display;
    private LifecycleLinkListener lifecycleLinkListener;


    @Override
    public Widget createWidget()
    {
        lifecycleLinkListener = new LifecycleLinkListener();

        ToolStrip topLevelTools = new ToolStrip();
        topLevelTools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_refresh(),
                new ClickHandler()
                {
                    @Override
                    public void onClick(ClickEvent event)
                    {
                        presenter.loadTopology();
                    }
                }));

        SimpleLayout layout = new SimpleLayout()
                .setTopLevelTools(topLevelTools)
                .setTitle("Topology")
                .setHeadline("Hosts, groups and server instances")
                .setDescription("An overview of all hosts, groups and server instances in the domain.");
        root = new HTMLPanel(new HtmlGenerator().root().toSafeHtml().asString());
        display = new HostsDisplay();
        HostsPager pager = new HostsPager();
        pager.setDisplay(display);
        pager.setPageSize(TopologyPresenter.VISIBLE_HOSTS_COLUMNS);
        root.add(pager);
        layout.addContent("domain", root);
        return layout.build();
    }

    @Override
    public void setPresenter(final TopologyPresenter presenter)
    {
        this.presenter = presenter;
    }

    @Override
    public void updateHosts(SortedSet<ServerGroup> groups, final int hostIndex)
    {
        // initialize
        Set<HostInfo> hosts = groups.first().getHosts();
        this.hostSize = hosts.size();
        this.visibleHosts = min(TopologyPresenter.VISIBLE_HOSTS_COLUMNS, hostSize);
        HtmlGenerator hiddenHosts = new HtmlGenerator();
        HtmlGenerator hiddenServers = new HtmlGenerator();
        HtmlGenerator visible = new HtmlGenerator();
        HtmlGenerator columns = new HtmlGenerator();
        assignColors(groups);

        // fill the hidden table
        // first row: hosts
        hiddenHosts.startRow();
        for (HostInfo host : hosts)
        {<commit_msg>Added saftey check<commit_after>/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @author tags. All rights reserved.
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA  02110-1301, USA.
 */
package org.jboss.as.console.client.domain.topology;

import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.dom.client.NodeList;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.HasRows;
import com.google.gwt.view.client.Range;
import com.google.gwt.view.client.RangeChangeEvent;
import com.google.gwt.view.client.RowCountChangeEvent;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.core.SuspendableViewImpl;
import org.jboss.as.console.client.domain.model.ServerInstance;
import org.jboss.as.console.client.domain.model.impl.LifecycleOperation;
import org.jboss.as.console.client.shared.viewframework.builder.SimpleLayout;
import org.jboss.ballroom.client.widgets.tables.DefaultPager;
import org.jboss.ballroom.client.widgets.tools.ToolButton;
import org.jboss.ballroom.client.widgets.tools.ToolStrip;
import org.jboss.ballroom.client.widgets.window.Feedback;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;

import static com.google.gwt.user.client.Event.ONCLICK;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.jboss.as.console.client.domain.model.impl.LifecycleOperation.*;
import static org.jboss.as.console.client.domain.topology.HtmlGenerator.*;

/**
 * @author <NAME>
 * @date 10/09/12
 */
public class TopologyView extends SuspendableViewImpl implements TopologyPresenter.MyView
{
    static final int TABLE_WIDTH = 100; // percent
    static final int SERVER_GROUPS_COLUMN = 15; // percent
    static final int HOSTS_COLUMNS = TABLE_WIDTH - SERVER_GROUPS_COLUMN;
    static final int SERVER_GROUP_COLORS = 5; // must match the '.serverGroupX' css class names

    private int hostIndex = 0; // the index of the current visible host
    private int visibleHosts = TopologyPresenter.VISIBLE_HOSTS_COLUMNS;
    private int hostSize = 0;
    private TopologyPresenter presenter;
    private HTMLPanel root;
    private HostsDisplay display;
    private LifecycleLinkListener lifecycleLinkListener;


    @Override
    public Widget createWidget()
    {
        lifecycleLinkListener = new LifecycleLinkListener();

        ToolStrip topLevelTools = new ToolStrip();
        topLevelTools.addToolButtonRight(new ToolButton(Console.CONSTANTS.common_label_refresh(),
                new ClickHandler()
                {
                    @Override
                    public void onClick(ClickEvent event)
                    {
                        presenter.loadTopology();
                    }
                }));

        SimpleLayout layout = new SimpleLayout()
                .setTopLevelTools(topLevelTools)
                .setTitle("Topology")
                .setHeadline("Hosts, groups and server instances")
                .setDescription("An overview of all hosts, groups and server instances in the domain.");
        root = new HTMLPanel(new HtmlGenerator().root().toSafeHtml().asString());
        display = new HostsDisplay();
        HostsPager pager = new HostsPager();
        pager.setDisplay(display);
        pager.setPageSize(TopologyPresenter.VISIBLE_HOSTS_COLUMNS);
        root.add(pager);
        layout.addContent("domain", root);
        return layout.build();
    }

    @Override
    public void setPresenter(final TopologyPresenter presenter)
    {
        this.presenter = presenter;
    }

    @Override
    public void updateHosts(SortedSet<ServerGroup> groups, final int hostIndex)
    {
        // initialize
        if (groups == null || groups.isEmpty())
        {
            // TODO Add "empty data" html
            return;
        }

        Set<HostInfo> hosts = groups.first().getHosts();
        this.hostSize = hosts.size();
        this.visibleHosts = min(TopologyPresenter.VISIBLE_HOSTS_COLUMNS, hostSize);
        HtmlGenerator hiddenHosts = new HtmlGenerator();
        HtmlGenerator hiddenServers = new HtmlGenerator();
        HtmlGenerator visible = new HtmlGenerator();
        HtmlGenerator columns = new HtmlGenerator();
        assignColors(groups);

        // fill the hidden table
        // first row: hosts
        hiddenHosts.startRow();
        for (HostInfo host : hosts)
        {
{'fraction_non_alphanumeric': 0.09243098842386464, 'fraction_numerical': 0.0058771148708815675, 'mean_word_length': 3.2638572513287776, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '833014', 'n_tokens_mistral': 3264, 'n_tokens_neox': 3136, 'n_words': 834}