/*
 * 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.controlpanel;

import com.vaadin.ui.Table;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * A customized extension of the default Vaadin {@link Table}.
 * @author Thomas Krause <krauseto@hu-berlin.de>
 */
public class CorpusListTable extends Table
{
  
  public static final String PAGELENGTH_CHANGED_IN_CLIENT_ID = "pageLengthChangedInClient";

  private final List<PageLengthChangedInClientListener> pageLengthListeners = new ArrayList<>();
  
  public void addPageLengthChangedInClientListener(PageLengthChangedInClientListener listener)
  {
    this.pageLengthListeners.add(listener);
  }
  
  public void removePageLengthChangedInClientListener(PageLengthChangedInClientListener listener)
  {
    this.pageLengthListeners.remove(listener);
  }
  

  @Override
  public void changeVariables(Object source, Map<String, Object> variables)
  {
    int originalPageLength = getPageLength();
    
    super.changeVariables(source, variables);
    
    int newPageLength = getPageLength();
    if(newPageLength != originalPageLength)
    {
      // pagelength changed
      for(PageLengthChangedInClientListener listener : pageLengthListeners)
      {
        listener.pageLengthChangedInClient(newPageLength);
      }
    }
  }
  
  public interface PageLengthChangedInClientListener
  {
    void pageLengthChangedInClient(int newPageLength);
  }

}

@@ -697,16 +697,41 @@
 .Table;%0A
+import com.vaadin.ui.UI;%0A
 import j
@@ -863,16 +863,19 @@
 Table%7D.%0A
+ *%0A
  * @auth
@@ -964,18 +964,16 @@
 Table%0A%7B%0A
-  
 %0A  publi
@@ -1155,18 +1155,16 @@
 st%3C%3E();%0A
-  
 %0A  publi
@@ -1199,32 +1199,37 @@
 nClientListener(
+%0A    
 PageLengthChange
@@ -1304,26 +1304,24 @@
 tener);%0A  %7D%0A
-  
 %0A  public vo
@@ -1363,16 +1363,21 @@
 istener(
+%0A    
 PageLeng
@@ -1466,19 +1466,16 @@
 er);%0A  %7D
-%0A  
 %0A%0A  @Ove
@@ -1606,20 +1606,16 @@
 ngth();%0A
-    
 %0A    sup
@@ -1657,16 +1657,18 @@
 s);%0A
-    
 %0A   
+ final
  int
@@ -1707,16 +1707,17 @@
 ;%0A    if
+ 
 (newPage
@@ -1762,39 +1762,123 @@
     
-// pagelength changed
+UI.getCurrent().access(new Runnable()%0A      %7B%0A%0A        @Override%0A        public void run()%0A        %7B
 %0A      
+    
 for
+ 
 (Pag
@@ -1942,24 +1942,28 @@
 ners)%0A      
+    
 %7B%0A        li
@@ -1960,16 +1960,20 @@
         
+ 
+   
 listener
@@ -2021,17 +2021,41 @@
 ;%0A      
-%7D
+    %7D%0A        %7D%0A      %7D);
 %0A    %7D%0A 
@@ -2057,18 +2057,16 @@
   %7D%0A  %7D%0A
-  
 %0A  publi
@@ -2111,24 +2111,25 @@
 istener%0A  %7B%0A
+%0A
     void pag

put event handler code into UI.getCurrent().access wrapper