package org.safehaus.subutai.core.env.ui.forms;


import org.safehaus.subutai.common.peer.ContainerHost;

import com.google.common.base.Strings;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.Notification;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;


public class TagsWindow extends Window
{

    private final ContainerHost containerHost;


    public TagsWindow( final ContainerHost containerHost )
    {
        this.containerHost = containerHost;

        setCaption( "Tags" );
        setWidth( "600px" );
        setHeight( "400px" );
        setModal( true );
        setClosable( true );


        VerticalLayout content = new VerticalLayout();
        content.setSpacing( true );
        content.setMargin( true );
        content.setStyleName( "default" );
        content.setSizeFull();


        final ListSelect tagsSelect = new ListSelect( "Tags", containerHost.getTags() );
        //        tagsSelect.setReadOnly( true );
        tagsSelect.setRows( 5 );
        tagsSelect.setWidth( "100px" );
        tagsSelect.setMultiSelect( false );

        content.addComponent( tagsSelect );

        final TextField newTagTxt = new TextField( "New tag" );

        content.addComponent( newTagTxt );

        Button addNewTagBtn = new Button( "Add" );

        addNewTagBtn.addClickListener( new Button.ClickListener()
        {
            @Override
            public void buttonClick( final Button.ClickEvent event )
            {

                if ( !Strings.isNullOrEmpty( newTagTxt.getValue() ) )
                {
                    containerHost.addTag( newTagTxt.getValue().trim() );
                    tagsSelect.setContainerDataSource( new IndexedContainer( containerHost.getTags() ) );
                }
                else
                {
                    Notification.show( "Please, enter valid tag" );
                }
            }
        } );

        content.addComponent( addNewTagBtn );

        setContent( content );
    }
}

@@ -209,24 +209,91 @@
 .ui.Button;%0A
+import com.vaadin.ui.HorizontalLayout;%0Aimport com.vaadin.ui.Label;%0A
 import com.v
@@ -1090,18 +1090,8 @@
  );%0A
-        //
     
@@ -1112,21 +1112,34 @@
 .set
-ReadOnly( tru
+NullSelectionAllowed( fals
 e );
@@ -1314,55 +1314,182 @@
     
-final TextField newTagTxt
+HorizontalLayout controls = new HorizontalLayout();%0A        controls.setSpacing( true );%0A%0A        content.addComponent( controls );%0A%0A%0A        Label tagLbl
  = new 
-TextFi
+Lab
 el
-d
 ( %22
-New
+Enter
  tag
@@ -1498,35 +1498,36 @@
 );%0A%0A        cont
-ent
+rols
 .addComponent( n
@@ -1525,20 +1525,110 @@
 ponent( 
-newT
+tagLbl );%0A%0A        final TextField tagTxt = new TextField();%0A%0A        controls.addComponent( t
 agTxt );
@@ -1643,27 +1643,24 @@
   Button add
-New
 TagBtn = new
@@ -1685,27 +1685,24 @@
 %0A        add
-New
 TagBtn.addCl
@@ -1902,20 +1902,17 @@
 rEmpty( 
-newT
+t
 agTxt.ge
@@ -1988,34 +1988,748 @@
 ag( 
-newTagTxt.getValue().trim(
+tagTxt.getValue().trim() );%0A                    tagsSelect.setContainerDataSource( new IndexedContainer( containerHost.getTags() ) );%0A                %7D%0A                else%0A                %7B%0A                    Notification.show( %22Please, enter valid tag%22 );%0A                %7D%0A            %7D%0A        %7D );%0A%0A        controls.addComponent( addTagBtn );%0A%0A        Button removeTagBtn = new Button( %22Remove%22 );%0A%0A        removeTagBtn.addClickListener( new Button.ClickListener()%0A        %7B%0A            @Override%0A            public void buttonClick( final Button.ClickEvent event )%0A            %7B%0A                if ( tagsSelect.getValue() != null )%0A                %7B%0A                    containerHost.removeTag( String.valueOf( tagsSelect.getValue() 
 ) );
@@ -3010,35 +3010,36 @@
 );%0A%0A        cont
-ent
+rols
 .addComponent( a
@@ -3041,14 +3041,14 @@
 nt( 
-addNew
+remove
 TagB

Fix container tags