]> source.dussan.org Git - vaadin-framework.git/commitdiff
Adds mouse wheel scrolling to VFilterSelect #4518
authorJohn Alhroos <john.ahlroos@itmill.com>
Thu, 11 Aug 2011 12:36:02 +0000 (12:36 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Thu, 11 Aug 2011 12:36:02 +0000 (12:36 +0000)
svn changeset:20301/svn branch:6.7

src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java

index 68d5e40326aa1bd3930eab65dabb3400bc1e4655..108a68f73f64036d8207f39eb82a1c14de698403 100644 (file)
@@ -32,6 +32,7 @@ import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.Composite;
 import com.google.gwt.user.client.ui.FlowPanel;
@@ -175,7 +176,7 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             DOM.appendChild(root, down);
             DOM.appendChild(root, status);
             DOM.setElementProperty(status, "className", CLASSNAME + "-status");
-            DOM.sinkEvents(root, Event.ONMOUSEDOWN);
+            DOM.sinkEvents(root, Event.ONMOUSEDOWN | Event.ONMOUSEWHEEL);
             addCloseHandler(this);
         }
 
@@ -317,6 +318,38 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             }
         }
 
+        /*
+         * Timer for scrolling pages up or down.
+         */
+        private LazyPageScroller lazyPageScroller = new LazyPageScroller();
+        private class LazyPageScroller extends Timer {
+            private int pagesToScroll = 0;
+
+            @Override
+            public void run() {
+               if(pagesToScroll != 0){
+                          filterOptions(currentPage + pagesToScroll, lastFilter);
+                   pagesToScroll = 0;
+               }             
+            }
+
+            public void scrollUp() {             
+               if(currentPage - pagesToScroll >= 0){
+                        pagesToScroll--;
+                     cancel();
+                     schedule(100);
+               }               
+            }
+
+            public void scrollDown() {      
+               if(totalMatches > (currentPage + pagesToScroll +1)*pageLength){
+                        pagesToScroll++;
+                     cancel();
+                     schedule(100);
+               }               
+            }
+        }
+        
         /*
          * (non-Javadoc)
          * 
@@ -329,9 +362,16 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             if (event.getTypeInt() == Event.ONCLICK) {
                 final Element target = DOM.eventGetTarget(event);
                 if (target == up || target == DOM.getChild(up, 0)) {
-                    filterOptions(currentPage - 1, lastFilter);
+                       lazyPageScroller.scrollUp();
                 } else if (target == down || target == DOM.getChild(down, 0)) {
-                    filterOptions(currentPage + 1, lastFilter);
+                       lazyPageScroller.scrollDown();                    
+                }
+            } else if (event.getTypeInt() == Event.ONMOUSEWHEEL) {                
+                int velocity = event.getMouseWheelVelocityY();
+                if (velocity > 0) {                
+                       lazyPageScroller.scrollDown();                  
+                } else {
+                        lazyPageScroller.scrollUp();                   
                 }
             }