<commit_before>package io.subutai.core.environment.terminal.ui;


import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.base.Strings;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;

import io.subutai.common.mdc.SubutaiExecutors;
import io.subutai.core.environment.api.EnvironmentManager;


/**
 * Environment Terminal
 */
public class TerminalForm extends CustomComponent
{
    protected EnvironmentTree environmentTree;
    protected TextField programTxtFld;
    protected TextField timeoutTxtFld;
    protected TextField workDirTxtFld;
    protected CheckBox daemonChk;

    protected Label indicator;
    protected TextArea commandOutputTxtArea;
    protected AtomicInteger taskCount = new AtomicInteger();
    private ExecutorService executor;


    public TerminalForm( final EnvironmentManager environmentManager, final Date updateDate )
    {
        setSizeFull();


        HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
        horizontalSplit.setSplitPosition( 200, Unit.PIXELS );
        environmentTree = new EnvironmentTree( environmentManager, updateDate );
        horizontalSplit.setFirstComponent( environmentTree );

        GridLayout grid = new GridLayout( 20, 11 );
        grid.setSizeFull();
        grid.setMargin( true );
        grid.setSpacing( true );

        horizontalSplit.setSecondComponent( grid );

        commandOutputTxtArea = new TextArea( "Commands output" );
        commandOutputTxtArea.setSizeFull();
        commandOutputTxtArea.setImmediate( true );
        commandOutputTxtArea.setWordwrap( false );
        commandOutputTxtArea.setId( "env_terminal_output" );
        grid.addComponent( commandOutputTxtArea, 0, 0, 19, 8 );

        HorizontalLayout controls = new HorizontalLayout();
        controls.setSpacing( true );
        Label programLbl = new Label( "Command" );
        programTxtFld = new TextField();
        programTxtFld.setValue( "<PASSWORD>" );
        programTxtFld.setWidth( 300, Unit.PIXELS );
        programTxtFld.setId( "env_terminal_command" );
        controls.addComponent( programLbl );
        controls.addComponent( programTxtFld );
        Label workDirLbl = new Label( "Cwd" );
        workDirTxtFld = new TextField();
        workDirTxtFld.setValue( "/" );
        workDirTxtFld.setId( "env_terminal_workdir" );
        controls.addComponent( workDirLbl );
        controls.addComponent( workDirTxtFld );
        Label timeoutLbl = new Label( "Timeout" );
        timeoutTxtFld = new TextField();
        timeoutTxtFld.setValue( "30" );
        timeoutTxtFld.setWidth( 30, Unit.PIXELS );
        timeoutTxtFld.setId( "env_terminal_timeout" );
        controls.addComponent( timeoutLbl );
        controls.addComponent( timeoutTxtFld );
        Button clearBtn = new Button( "Clear" );
        controls.addComponent( clearBtn );
        final Button sendBtn = new Button( "Send" );
        controls.addComponent( sendBtn );
        daemonChk = new CheckBox( "Daemon" );
        daemonChk.setId( "env_terminal_daemon" );
        controls.addComponent( daemonChk );
        indicator = new Label();
        indicator.setId( "terminal_indicator" );
        indicator.setIcon( new ThemeResource( "img/spinner.gif" ) );
        indicator.setContentMode( ContentMode.HTML );
        indicator.setHeight( 11, Unit.PIXELS );
        indicator.setWidth( 50, Unit.PIXELS );
        indicator.setVisible( false );
        controls.addComponent( indicator );

        grid.addComponent( controls, 0, 9, 19, 9 );

        HorizontalLayout filterControls = new HorizontalLayout();
        filterControls.setSpacing( true );
        Label filterLbl = new Label( "Tag" );
        final TextField filterTxt = new TextField();
        Button filterBtn = new Button( "Filter" );
        filterControls.addComponent( filterLbl );
        filterControls.addComponent( filterTxt );
        filterControls.addComponent( filterBtn );

        filterBtn.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick( final Button.ClickEvent event )
            {
                environmentTree.filterContainerHostsByTag( filterTxt.getValue() );
            }
        } );

        programTxtFld.addShortcutListener( new ShortcutListener( "Shortcut Name", ShortcutAction.KeyCode.ENTER, null )
        {
            @Override
            public void handleAction( Object sender, Object target )
            {
                sendBtn.click();
            }
        } );

        final SendButtonListener sendButtonListener = new SendButtonListener( this );
        sendBtn.addClickListener( sendButtonListener );

        clearBtn.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick( Button.ClickEvent event )
            {
                commandOutputTxtArea.setValue( "" );
            }
        } );

        grid.addComponent( filterControls, 0, 10, 19, 10 );


        setCompositionRoot( horizontalSplit );

        addDetachListener( new DetachListener()
        {
            @Override
            public void detach( final DetachEvent event )
            {
                executor.shutdown();
            }
        } );

        addAttachListener( new AttachListener()
        {
            @Override
            public void attach( final AttachEvent event )
            {
                executor = SubutaiExecutors.newCachedThreadPool();
                sendButtonListener.setExecutor( executor );
            }
        } );
    }


    protected void show( String msg )
    {
        Notification.show( msg );
    }


    protected void addOutput( String output )
    {
        if ( !Strings.isNullOrEmpty( output ) )
        {
            commandOutputTxtArea.setValue( String.format( "%s%s", commandOutputTxtArea.getValue(), output ) );
            commandOutputTxtArea.setCursorPosition( commandOutputTxtArea.getValue().length() - 1 );
        }
    }
}
<commit_msg>Added static ids to terminal UI controls SS-3721<commit_after>package io.subutai.core.environment.terminal.ui;


import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicInteger;

import com.google.common.base.Strings;
import com.vaadin.event.ShortcutAction;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;

import io.subutai.common.mdc.SubutaiExecutors;
import io.subutai.core.environment.api.EnvironmentManager;


/**
 * Environment Terminal
 */
public class TerminalForm extends CustomComponent
{
    protected EnvironmentTree environmentTree;
    protected TextField programTxtFld;
    protected TextField timeoutTxtFld;
    protected TextField workDirTxtFld;
    protected CheckBox daemonChk;

    protected Label indicator;
    protected TextArea commandOutputTxtArea;
    protected AtomicInteger taskCount = new AtomicInteger();
    private ExecutorService executor;


    public TerminalForm( final EnvironmentManager environmentManager, final Date updateDate )
    {
        setSizeFull();


        HorizontalSplitPanel horizontalSplit = new HorizontalSplitPanel();
        horizontalSplit.setSplitPosition( 200, Unit.PIXELS );
        environmentTree = new EnvironmentTree( environmentManager, updateDate );
        horizontalSplit.setFirstComponent( environmentTree );

        GridLayout grid = new GridLayout( 20, 11 );
        grid.setSizeFull();
        grid.setMargin( true );
        grid.setSpacing( true );

        horizontalSplit.setSecondComponent( grid );

        commandOutputTxtArea = new TextArea( "Commands output" );
        commandOutputTxtArea.setSizeFull();
        commandOutputTxtArea.setImmediate( true );
        commandOutputTxtArea.setWordwrap( false );
        commandOutputTxtArea.setId( "env_terminal_output" );
        grid.addComponent( commandOutputTxtArea, 0, 0, 19, 8 );

        HorizontalLayout controls = new HorizontalLayout();
        controls.setSpacing( true );
        Label programLbl = new Label( "Command" );
        programTxtFld = new TextField();
        programTxtFld.setValue( "<PASSWORD>" );
        programTxtFld.setWidth( 300, Unit.PIXELS );
        programTxtFld.setId( "env_terminal_command" );
        controls.addComponent( programLbl );
        controls.addComponent( programTxtFld );
        Label workDirLbl = new Label( "Cwd" );
        workDirTxtFld = new TextField();
        workDirTxtFld.setValue( "/" );
        workDirTxtFld.setId( "env_terminal_workdir" );
        controls.addComponent( workDirLbl );
        controls.addComponent( workDirTxtFld );
        Label timeoutLbl = new Label( "Timeout" );
        timeoutTxtFld = new TextField();
        timeoutTxtFld.setValue( "30" );
        timeoutTxtFld.setWidth( 30, Unit.PIXELS );
        timeoutTxtFld.setId( "env_terminal_timeout" );
        controls.addComponent( timeoutLbl );
        controls.addComponent( timeoutTxtFld );
        Button clearBtn = new Button( "Clear" );
        controls.addComponent( clearBtn );
        final Button sendBtn = new Button( "Send" );
        controls.addComponent( sendBtn );
        daemonChk = new CheckBox( "Daemon" );
        daemonChk.setId( "env_terminal_daemon" );
        controls.addComponent( daemonChk );
        indicator = new Label();
        indicator.setId( "env_terminal_indicator" );
        indicator.setIcon( new ThemeResource( "img/spinner.gif" ) );
        indicator.setContentMode( ContentMode.HTML );
        indicator.setHeight( 11, Unit.PIXELS );
        indicator.setWidth( 50, Unit.PIXELS );
        indicator.setVisible( false );
        controls.addComponent( indicator );

        grid.addComponent( controls, 0, 9, 19, 9 );

        HorizontalLayout filterControls = new HorizontalLayout();
        filterControls.setSpacing( true );
        Label filterLbl = new Label( "Tag" );
        final TextField filterTxt = new TextField();
        Button filterBtn = new Button( "Filter" );
        filterControls.addComponent( filterLbl );
        filterControls.addComponent( filterTxt );
        filterControls.addComponent( filterBtn );

        filterBtn.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick( final Button.ClickEvent event )
            {
                environmentTree.filterContainerHostsByTag( filterTxt.getValue() );
            }
        } );

        programTxtFld.addShortcutListener( new ShortcutListener( "Shortcut Name", ShortcutAction.KeyCode.ENTER, null )
        {
            @Override
            public void handleAction( Object sender, Object target )
            {
                sendBtn.click();
            }
        } );

        final SendButtonListener sendButtonListener = new SendButtonListener( this );
        sendBtn.addClickListener( sendButtonListener );

        clearBtn.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick( Button.ClickEvent event )
            {
                commandOutputTxtArea.setValue( "" );
            }
        } );

        grid.addComponent( filterControls, 0, 10, 19, 10 );


        setCompositionRoot( horizontalSplit );

        addDetachListener( new DetachListener()
        {
            @Override
            public void detach( final DetachEvent event )
            {
                executor.shutdown();
            }
        } );

        addAttachListener( new AttachListener()
        {
            @Override
            public void attach( final AttachEvent event )
            {
                executor = SubutaiExecutors.newCachedThreadPool();
                sendButtonListener.setExecutor( executor );
            }
        } );
    }


    protected void show( String msg )
    {
        Notification.show( msg );
    }


    protected void addOutput( String output )
    {
        if ( !Strings.isNullOrEmpty( output ) )
        {
            commandOutputTxtArea.setValue( String.format( "%s%s", commandOutputTxtArea.getValue(), output ) );
            commandOutputTxtArea.setCursorPosition( commandOutputTxtArea.getValue().length() - 1 );
        }
    }
}

{'fraction_non_alphanumeric': 0.09231357552581262, 'fraction_numerical': 0.005812619502868069, 'mean_word_length': 2.6171507607192255, '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': '7327856', 'n_tokens_mistral': 3689, 'n_tokens_neox': 3512, 'n_words': 747}