<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.safehaus.subutai.ui.cassandra.manager;


import com.vaadin.data.Property;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.server.Sizeable;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.*;
import org.safehaus.subutai.api.cassandra.Config;
import org.safehaus.subutai.server.ui.component.ConfirmationDialog;
import org.safehaus.subutai.server.ui.component.ProgressWindow;
import org.safehaus.subutai.server.ui.component.TerminalWindow;
import org.safehaus.subutai.shared.protocol.Agent;
import org.safehaus.subutai.shared.protocol.Util;
import org.safehaus.subutai.ui.cassandra.CassandraUI;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;


/**
 * @author dilshat
 */
public class Manager {

	private final Table nodesTable;
	private VerticalLayout contentRoot;
	private ComboBox clusterCombo;
	private HorizontalLayout controlsContent;
	private Config config;


	public Manager() {

		contentRoot = new VerticalLayout();
		contentRoot.setSpacing(true);
		contentRoot.setSizeFull();

		//tables go here
		nodesTable = createTableTemplate("Cluster nodes");

		controlsContent = new HorizontalLayout();
		controlsContent.setSpacing(true);
		controlsContent.setHeight(20, Sizeable.Unit.PERCENTAGE);

		getClusterNameLabel();
		getClusterCombo();
		getRefreshClusterButton();
		getCheckAllButton();
		getStartAllButton();
		getStopAllButton();
		getDestroyClusterButton();

		contentRoot.addComponent(controlsContent);
		contentRoot.addComponent(nodesTable);

	}

	private Table createTableTemplate(String caption) {
		final Table table = new Table(caption);
		table.addContainerProperty("Host", String.class, null);
		table.addContainerProperty("Status", Embedded.class, null);
		table.setHeight(80, Sizeable.Unit.PERCENTAGE);
		table.setWidth(100, Sizeable.Unit.PERCENTAGE);
		table.setPageLength(10);
		table.setSelectable(false);
		table.setImmediate(true);
		table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
			@Override
			public void itemClick(ItemClickEvent event) {
				if (event.isDoubleClick()) {
					String lxcHostname = (String) table.getItem(event.getItemId()).getItemProperty("Host").getValue();
					Agent lxcAgent = CassandraUI.getAgentManager().getAgentByHostname(lxcHostname);
					if (lxcAgent != null) {
						TerminalWindow terminal = new TerminalWindow(Util.wrapAgentToSet(lxcAgent), CassandraUI.getExecutor(), CassandraUI.getCommandRunner(), CassandraUI.getAgentManager());
						contentRoot.getUI().addWindow(terminal.getWindow());
					} else {
						show("Agent is not connected");
					}
				}
			}
		});
		return table;
	}

	private void getClusterNameLabel() {
		Label clusterNameLabel = new Label("Select the cluster");
		controlsContent.addComponent(clusterNameLabel);
		controlsContent.setComponentAlignment(clusterNameLabel, Alignment.MIDDLE_CENTER);
	}

	private void getClusterCombo() {
		clusterCombo = new ComboBox();
		clusterCombo.setImmediate(true);
		clusterCombo.setTextInputAllowed(false);
		clusterCombo.setWidth(200, Sizeable.Unit.PIXELS);
		clusterCombo.addValueChangeListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(Property.ValueChangeEvent event) {
				config = (Config) event.getProperty().getValue();
				refreshUI();
			}
		});
		controlsContent.addComponent(clusterCombo);
	}

	private void getRefreshClusterButton() {
		Button refreshClustersBtn = new Button("Refresh clusters");
		refreshClustersBtn.addStyleName("default");
		refreshClustersBtn.addClickListener(new Button.ClickListener() {
			@Override
			public void buttonClick(Button.ClickEvent clickEvent) {
				refreshClustersInfo();
			}
		});
		controlsContent.addComponent(refreshClustersBtn);
	}<commit_msg>-m SUBUTAI-865 Cassandra UI Styling interface<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.safehaus.subutai.ui.cassandra.manager;


import com.vaadin.data.Property;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.server.Sizeable;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.*;
import org.safehaus.subutai.api.cassandra.Config;
import org.safehaus.subutai.server.ui.component.ConfirmationDialog;
import org.safehaus.subutai.server.ui.component.ProgressWindow;
import org.safehaus.subutai.server.ui.component.TerminalWindow;
import org.safehaus.subutai.shared.protocol.Agent;
import org.safehaus.subutai.shared.protocol.Util;
import org.safehaus.subutai.ui.cassandra.CassandraUI;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.UUID;


/**
 * @author dilshat
 */
public class Manager {

	private final Table nodesTable;
	private GridLayout contentRoot;
	private ComboBox clusterCombo;
	private HorizontalLayout controlsContent;
	private Config config;


	public Manager() {

		contentRoot = new GridLayout();
		contentRoot.setSpacing(true);
		contentRoot.setSizeFull();
		contentRoot.setRows(5);
		contentRoot.setColumns(1);

		//tables go here
		nodesTable = createTableTemplate("Cluster nodes");

		controlsContent = new HorizontalLayout();
		controlsContent.setSpacing(true);

		getClusterNameLabel();
		getClusterCombo();
		getRefreshClusterButton();
		getCheckAllButton();
		getStartAllButton();
		getStopAllButton();
		getDestroyClusterButton();

		contentRoot.addComponent(controlsContent, 0, 0, 0, 1);
		contentRoot.addComponent(nodesTable, 0, 1, 0, 4);

	}

	private Table createTableTemplate(String caption) {
		final Table table = new Table(caption);
		table.addContainerProperty("Host", String.class, null);
		table.addContainerProperty("Status", Embedded.class, null);
		table.setPageLength(10);
		table.setSelectable(false);
		table.setImmediate(true);
		table.addItemClickListener(new ItemClickEvent.ItemClickListener() {
			@Override
			public void itemClick(ItemClickEvent event) {
				if (event.isDoubleClick()) {
					String lxcHostname = (String) table.getItem(event.getItemId()).getItemProperty("Host").getValue();
					Agent lxcAgent = CassandraUI.getAgentManager().getAgentByHostname(lxcHostname);
					if (lxcAgent != null) {
						TerminalWindow terminal = new TerminalWindow(Util.wrapAgentToSet(lxcAgent), CassandraUI.getExecutor(), CassandraUI.getCommandRunner(), CassandraUI.getAgentManager());
						contentRoot.getUI().addWindow(terminal.getWindow());
					} else {
						show("Agent is not connected");
					}
				}
			}
		});
		return table;
	}

	private void getClusterNameLabel() {
		Label clusterNameLabel = new Label("Select the cluster");
		controlsContent.addComponent(clusterNameLabel);
	}

	private void getClusterCombo() {
		clusterCombo = new ComboBox();
		clusterCombo.setImmediate(true);
		clusterCombo.setTextInputAllowed(false);
		clusterCombo.setWidth(200, Sizeable.Unit.PIXELS);
		clusterCombo.addValueChangeListener(new Property.ValueChangeListener() {
			@Override
			public void valueChange(Property.ValueChangeEvent event) {
				config = (Config) event.getProperty().getValue();
				refreshUI();
			}
		});
		controlsContent.addComponent(clusterCombo);
	}

	private void getRefreshClusterButton() {
		Button refreshClustersBtn = new Button("Refresh clusters");
		refreshClustersBtn.addStyleName("default");
		refreshClustersBtn.addClickListener(new Button.ClickListener() {
			@Override
			public void buttonClick(Button.ClickEvent clickEvent) {
				refreshClustersInfo();
			}
		});
		controlsContent.addComponent(refreshClustersBtn);
	}
{'fraction_non_alphanumeric': 0.11063993831919815, 'fraction_numerical': 0.0038550501156515036, 'mean_word_length': 5.3847415914684165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5402085', 'n_tokens_mistral': 2556, 'n_tokens_neox': 2285, 'n_words': 443}