ref #7246 ReloadableLazyComboBox performance improvement
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 9 Feb 2018 09:25:27 +0000 (10:25 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 9 Feb 2018 09:25:27 +0000 (10:25 +0100)
src/main/java/eu/etaxonomy/vaadin/component/ReloadableLazyComboBox.java

index 66f6c72281e41fda3278306212f4eaffd5d7c4d5..8ab5591979247f29f9083521707faae8446d3bb6 100644 (file)
@@ -17,11 +17,13 @@ import com.vaadin.ui.AbstractField;
 import com.vaadin.ui.AbstractSelect;
 import com.vaadin.ui.ComboBox;
 
-public class ReloadableLazyComboBox<T> extends LazyComboBox<T> implements ReloadableSelect, EntitySupport<T>{
+public class ReloadableLazyComboBox<T> extends LazyComboBox<T> implements ReloadableSelect, EntitySupport<T> {
 
 
     private static final long serialVersionUID = -4833661351090992884L;
 
+//    boolean originalScrollToSelect;
+
     static Field lazySelectInternalValueField;
     static Field internalSelectField;
     static {
@@ -44,10 +46,6 @@ public class ReloadableLazyComboBox<T> extends LazyComboBox<T> implements Reload
      */
     public ReloadableLazyComboBox(Class<T> itemType) {
         super(itemType);
-        // in the LazyComboBox.initList() scrollToSelectedItem is set to false for better performance
-        // but this breaks the refresh, so we need to set it true
-        // (temporarily setting it true in reload() does not work)
-        ((ComboBox)getSelect()).setScrollToSelectedItem(true);
     }
 
     /**
@@ -55,10 +53,16 @@ public class ReloadableLazyComboBox<T> extends LazyComboBox<T> implements Reload
      */
     @Override
     public void reload() {
+        // in the LazyComboBox.initList() scrollToSelectedItem is set to false for better performance
+        // but this breaks the refresh, so we need to set it now so that it can
+        // affect the next component repaint which is triggered in refresh()
+        ComboBox comboBox = (ComboBox)getSelect();
+        comboBox.setScrollToSelectedItem(true);
         refresh(); // reload from persistence
-        discard(); // reload from data source
+        discard(); // reload from property data source
     }
 
+
     /**
      * This method allows updating the value even if the equals check done
      * in {@link com.vaadin.ui.AbstractField#setValue(Object)} would return true.
@@ -118,4 +122,5 @@ public class ReloadableLazyComboBox<T> extends LazyComboBox<T> implements Reload
         }
     }
 
+
 }
\ No newline at end of file