/*
 * Copyright 2014 Corpuslinguistic working group Humboldt University Berlin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package annis.gui.admin;

import annis.gui.admin.view.CorpusListView;
import annis.service.objects.AnnisCorpus;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ChameleonTheme;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Thomas Krause <krauseto@hu-berlin.de>
 */
public class CorpusAdminPanel extends Panel
  implements CorpusListView
{

  private final List<CorpusListView.Listener> listeners = new LinkedList<>();

  private final BeanContainer<String, AnnisCorpus> corpusContainer = new BeanContainer<>(
    AnnisCorpus.class);

  public CorpusAdminPanel()
  {
    corpusContainer.setBeanIdProperty("name");

    final Table tblCorpora = new Table();
    tblCorpora.setContainerDataSource(corpusContainer);
    tblCorpora.setSizeFull();
    tblCorpora.setSelectable(true);
    tblCorpora.setMultiSelect(true);
    tblCorpora.addStyleName(ChameleonTheme.TABLE_STRIPED);
    tblCorpora.addStyleName("grey-selection");
    
    tblCorpora.
      setVisibleColumns("name", "textCount", "tokenCount", "sourcePath");
    tblCorpora.setColumnHeaders("Name", "Texts", "Tokens", "Source path");

    Button btDelete = new Button("Delete selected");
    btDelete.addClickListener(new Button.ClickListener()
    {

      @Override
      public void buttonClick(Button.ClickEvent event)
      {
        Set<String> selection = (Set<String>) tblCorpora.getValue();
        if (selection != null)
        {
          
          for (CorpusListView.Listener l : listeners)
          {
            l.deleteCorpora(selection);
          }
        }
      }
    });

    VerticalLayout layout = new VerticalLayout(btDelete, tblCorpora);
    layout.setSizeFull();
    layout.setExpandRatio(tblCorpora, 1.0f);
    layout.setSpacing(true);
    layout.setMargin(new MarginInfo(true, false, false, false));
    
    layout.setComponentAlignment(btDelete, Alignment.MIDDLE_CENTER);
    
    setContent(layout);
    setSizeFull();
  }

  @Override
  public void addListener(CorpusListView.Listener listener)
  {
    listeners.add(listener);
  }

  @Override
  public void setAvailableCorpora(Collection<AnnisCorpus> corpora)
  {
    corpusContainer.removeAllItems();
    corpusContainer.addAll(corpora);
  }

}

@@ -913,21 +913,20 @@
 adin.ui.
-Panel
+Grid
 ;%0Aimport
@@ -940,21 +940,21 @@
 adin.ui.
-Table
+Panel
 ;%0Aimport
@@ -988,52 +988,8 @@
 ut;%0A
-import com.vaadin.ui.themes.ChameleonTheme;%0A
 impo
@@ -1086,16 +1086,42 @@
 til.Set;
+%0Aimport java.util.TreeSet;
 %0A%0A/**%0A *
@@ -1537,77 +1537,35 @@
 nal 
-Table tblC
+Grid c
 orpora
+Grid
  = new 
-Table();%0A    tblCorpora.setContainerDataSource
+Grid
 (cor
@@ -1579,34 +1579,35 @@
 ainer);%0A    
-tblC
+c
 orpora
+Grid
 .setSizeFull
@@ -1610,34 +1610,35 @@
 Full();%0A    
-tblC
+c
 orpora
+Grid
 .setSelectab
@@ -1639,262 +1639,259 @@
 lect
-able(true);%0A    tblCorpora.setMultiSelect(true
+ionMode(Grid.SelectionMode.MULTI
 );%0A    
-tblC
+c
 orpora
-.addStyleName(ChameleonTheme.TABLE_STRIPED
+Grid.setColumns(%22name%22, %22textCount%22, %22tokenCount%22, %22sourcePath%22
 );%0A
+%0A
     
-tblC
+c
 orpora
-.addStyleName(%22grey-selection%22);%0A    %0A    tblCorpora.%0A      setVisible
+Grid.getColumn(%22textCount%22).setHeaderCaption(%22Texts%22);%0A    corporaGrid.get
 Column
-s
 (%22
-name%22, %22textCount%22, %22tokenCount%22, %22sourcePath
+tokenCount%22).setHeaderCaption(%22Tokens
 %22);%0A    
 tblC
@@ -1890,28 +1890,29 @@
     
-tblC
+c
 orpora
-.s
+Grid.g
 etColumn
 Head
@@ -1911,51 +1911,48 @@
 lumn
-Headers(%22Name%22, %22Texts%22, %22Tokens%22, 
+(%22sourcePath%22).setHeaderCaption(
 %22Source 
 path
@@ -1947,17 +1947,17 @@
 %22Source 
-p
+P
 ath%22);%0A%0A
@@ -2188,44 +2188,89 @@
 n = 
-(Set%3CString%3E) tblCorpora.getValue();
+new TreeSet%3C%3E();%0A        for (Object o : corporaGrid.getSelectedRows())%0A        %7B
 %0A   
@@ -2278,12 +2278,10 @@
     
-if (
+  
 sele
@@ -2289,27 +2289,118 @@
 tion
- != null)%0A        %7B
+.add((String) o);%0A        %7D%0A        corporaGrid.getSelectionModel().reset();%0A        if (!selection.isEmpty())
 %0A   
@@ -2404,18 +2404,18 @@
         
-  
+%7B%0A
 %0A       
@@ -2609,26 +2609,27 @@
 Delete, 
-tblC
+c
 orpora
+Grid
 );%0A    l
@@ -2679,18 +2679,19 @@
 tio(
-tblC
+c
 orpora
+Grid
 , 1.
@@ -2789,20 +2789,16 @@
 alse));%0A
-    
 %0A    lay
@@ -2859,20 +2859,16 @@
 ENTER);%0A
-    
 %0A    set

use grid in corpus list