diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-20 09:01:39 +0200 |
---|---|---|
committer | Péter Török <31210544+torok-peter@users.noreply.github.com> | 2017-10-20 10:01:39 +0300 |
commit | 03570cb8740de05568f8045ad13526d9d8382c44 (patch) | |
tree | 199239782405aeca1b73f9c3f4a94efab4e4d1e7 /client/src | |
parent | 0f4702c6d1e03e2522c556487aba74ea01f25837 (diff) | |
download | vaadin-framework-03570cb8740de05568f8045ad13526d9d8382c44.tar.gz vaadin-framework-03570cb8740de05568f8045ad13526d9d8382c44.zip |
Scheduler.ScheduledCommand and RepeatingCommand to be lambda (#10203)
* Scheduler.ScheduledCommand and RepeatingCommand to be lambda
* Restore <table> in javadoc
* Fix docs
Diffstat (limited to 'client/src')
28 files changed, 285 insertions, 476 deletions
diff --git a/client/src/main/java/com/vaadin/client/ApplicationConfiguration.java b/client/src/main/java/com/vaadin/client/ApplicationConfiguration.java index 9c3bc4d2ff..f36a181dd2 100644 --- a/client/src/main/java/com/vaadin/client/ApplicationConfiguration.java +++ b/client/src/main/java/com/vaadin/client/ApplicationConfiguration.java @@ -31,7 +31,6 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.core.client.RunAsyncCallback; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.client.ScriptInjector; import com.google.gwt.dom.client.Element; import com.google.gwt.logging.client.LogConfiguration; @@ -465,21 +464,15 @@ public class ApplicationConfiguration implements EntryPoint { * element into which the application should be rendered. */ public static void startApplication(final String applicationId) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - Profiler.enter("ApplicationConfiguration.startApplication"); - ApplicationConfiguration appConf = getConfigFromDOM( - applicationId); - ApplicationConnection a = GWT - .create(ApplicationConnection.class); - a.init(widgetSet, appConf); - runningApplications.add(a); - Profiler.leave("ApplicationConfiguration.startApplication"); - - a.start(); - } + Scheduler.get().scheduleDeferred(() -> { + Profiler.enter("ApplicationConfiguration.startApplication"); + ApplicationConfiguration appConf = getConfigFromDOM(applicationId); + ApplicationConnection a = GWT.create(ApplicationConnection.class); + a.init(widgetSet, appConf); + runningApplications.add(a); + Profiler.leave("ApplicationConfiguration.startApplication"); + + a.start(); }); } diff --git a/client/src/main/java/com/vaadin/client/VSchedulerImpl.java b/client/src/main/java/com/vaadin/client/VSchedulerImpl.java index 155487d721..2142514735 100644 --- a/client/src/main/java/com/vaadin/client/VSchedulerImpl.java +++ b/client/src/main/java/com/vaadin/client/VSchedulerImpl.java @@ -29,17 +29,10 @@ public class VSchedulerImpl extends SchedulerImpl { public void scheduleDeferred(ScheduledCommand cmd) { deferredCommandTrackers++; super.scheduleDeferred(cmd); - super.scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - deferredCommandTrackers--; - } - }); + super.scheduleDeferred(() -> deferredCommandTrackers--); } public boolean hasWorkQueued() { - boolean hasWorkQueued = (deferredCommandTrackers != 0); - return hasWorkQueued; + return deferredCommandTrackers != 0; } } diff --git a/client/src/main/java/com/vaadin/client/VUIDLBrowser.java b/client/src/main/java/com/vaadin/client/VUIDLBrowser.java index 7068f7c790..eaf0503fa0 100644 --- a/client/src/main/java/com/vaadin/client/VUIDLBrowser.java +++ b/client/src/main/java/com/vaadin/client/VUIDLBrowser.java @@ -20,7 +20,6 @@ import java.util.Set; import com.google.gwt.core.client.JsArray; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style; @@ -319,12 +318,8 @@ public class VUIDLBrowser extends SimpleTree { } if (highlightedPid != null && highlightedPid.equals(uidl.getId())) { getElement().getStyle().setBackgroundColor("#fdd"); - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - getElement().scrollIntoView(); - } - }); + Scheduler.get() + .scheduleDeferred(() -> getElement().scrollIntoView()); } } } diff --git a/client/src/main/java/com/vaadin/client/WidgetUtil.java b/client/src/main/java/com/vaadin/client/WidgetUtil.java index 56f8a1273b..7d54ac7650 100644 --- a/client/src/main/java/com/vaadin/client/WidgetUtil.java +++ b/client/src/main/java/com/vaadin/client/WidgetUtil.java @@ -23,7 +23,6 @@ import java.util.logging.Logger; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.AnchorElement; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; @@ -791,7 +790,7 @@ public class WidgetUtil { com.google.gwt.dom.client.Element el, String p) /*-{ try { - + if (el.currentStyle) { // IE return el.currentStyle[p]; @@ -806,7 +805,7 @@ public class WidgetUtil { } catch (e) { return ""; } - + }-*/; /** @@ -820,7 +819,7 @@ public class WidgetUtil { try { el.focus(); } catch (e) { - + } }-*/; @@ -1151,19 +1150,14 @@ public class WidgetUtil { ((Focusable) targetWidget).focus(); } - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - try { - target.dispatchEvent(createMouseDownEvent); - target.dispatchEvent(createMouseUpEvent); - target.dispatchEvent(createMouseClickEvent); - } catch (Exception e) { - } - + Scheduler.get().scheduleDeferred(() -> { + try { + target.dispatchEvent(createMouseDownEvent); + target.dispatchEvent(createMouseUpEvent); + target.dispatchEvent(createMouseClickEvent); + } catch (Exception e) { } }); - } /** @@ -1176,7 +1170,7 @@ public class WidgetUtil { if ($wnd.document.activeElement) { return $wnd.document.activeElement; } - + return null; }-*/; @@ -1247,11 +1241,11 @@ public class WidgetUtil { /*-{ var top = elem.offsetTop; var height = elem.offsetHeight; - + if (elem.parentNode != elem.offsetParent) { top -= elem.parentNode.offsetTop; } - + var cur = elem.parentNode; while (cur && (cur.nodeType == 1)) { if (top < cur.scrollTop) { @@ -1260,12 +1254,12 @@ public class WidgetUtil { if (top + height > cur.scrollTop + cur.clientHeight) { cur.scrollTop = (top + height) - cur.clientHeight; } - + var offsetTop = cur.offsetTop; if (cur.parentNode != cur.offsetParent) { offsetTop -= cur.parentNode.offsetTop; } - + top += offsetTop - cur.scrollTop; cur = cur.parentNode; } @@ -1714,7 +1708,7 @@ public class WidgetUtil { } var heightWithoutBorder = cloneElement.offsetHeight; parentElement.removeChild(cloneElement); - + return heightWithBorder - heightWithoutBorder; } }-*/; diff --git a/client/src/main/java/com/vaadin/client/communication/DefaultReconnectDialog.java b/client/src/main/java/com/vaadin/client/communication/DefaultReconnectDialog.java index 0f8c1a1dc1..4026796e0d 100644 --- a/client/src/main/java/com/vaadin/client/communication/DefaultReconnectDialog.java +++ b/client/src/main/java/com/vaadin/client/communication/DefaultReconnectDialog.java @@ -16,7 +16,6 @@ package com.vaadin.client.communication; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.BodyElement; import com.google.gwt.dom.client.Document; @@ -113,15 +112,10 @@ public class DefaultReconnectDialog extends VOverlay getElement().getStyle().setVisibility(Visibility.HIDDEN); setStyleName(STYLE_RECONNECTING, true); - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - getElement().getStyle().setVisibility(Visibility.VISIBLE); - setStyleName(STYLE_RECONNECTING, false); - hide(); - - } + Scheduler.get().scheduleDeferred(() -> { + getElement().getStyle().setVisibility(Visibility.VISIBLE); + setStyleName(STYLE_RECONNECTING, false); + hide(); }); } } diff --git a/client/src/main/java/com/vaadin/client/communication/MessageHandler.java b/client/src/main/java/com/vaadin/client/communication/MessageHandler.java index f1354f4a92..6fea01af69 100644 --- a/client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -31,7 +31,6 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArray; import com.google.gwt.core.client.JsArrayString; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.Widget; @@ -574,12 +573,9 @@ public class MessageHandler { ConnectorBundleLoader.get().ensureDeferredBundleLoaded(); if (Profiler.isEnabled()) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - Profiler.logTimings(); - Profiler.reset(); - } + Scheduler.get().scheduleDeferred(() -> { + Profiler.logTimings(); + Profiler.reset(); }); } } diff --git a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java index 1460b978ac..fc66d8a502 100644 --- a/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java +++ b/client/src/main/java/com/vaadin/client/communication/ServerRpcQueue.java @@ -191,16 +191,13 @@ public class ServerRpcQueue { Scheduler.get().scheduleFinally(scheduledFlushCommand); } - private final ScheduledCommand scheduledFlushCommand = new ScheduledCommand() { - @Override - public void execute() { - flushScheduled = false; - if (!isFlushPending()) { - // Somebody else cleared the queue before we had the chance - return; - } - connection.getMessageSender().sendInvocationsToServer(); + private final ScheduledCommand scheduledFlushCommand = () -> { + flushScheduled = false; + if (!isFlushPending()) { + // Somebody else cleared the queue before we had the chance + return; } + connection.getMessageSender().sendInvocationsToServer(); }; /** diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java index b8889591da..973a3df09a 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/DetailsManagerConnector.java @@ -137,22 +137,17 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { private ScheduledCommand createResizeCommand(final int rowIndex, final Element element) { - return new ScheduledCommand() { - - @Override - public void execute() { - // It should not be possible to get here without calculating - // the spacerCellBorderHeights or without having the details - // row open, nor for this command to be triggered while - // layout is running, but it's safer to check anyway. - if (spacerCellBorderHeights != null - && !getLayoutManager().isLayoutRunning() - && getDetailsComponentConnectorId( - rowIndex) != null) { - double height = getLayoutManager().getOuterHeightDouble( - element) + spacerCellBorderHeights; - getWidget().setDetailsHeight(rowIndex, height); - } + return () -> { + // It should not be possible to get here without calculating + // the spacerCellBorderHeights or without having the details + // row open, nor for this command to be triggered while + // layout is running, but it's safer to check anyway. + if (spacerCellBorderHeights != null + && !getLayoutManager().isLayoutRunning() + && getDetailsComponentConnectorId(rowIndex) != null) { + double height = getLayoutManager().getOuterHeightDouble( + element) + spacerCellBorderHeights; + getWidget().setDetailsHeight(rowIndex, height); } }; } diff --git a/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java b/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java index 20de99cef0..dfe9036d1a 100644 --- a/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java +++ b/client/src/main/java/com/vaadin/client/data/AbstractRemoteDataSource.java @@ -206,12 +206,9 @@ public abstract class AbstractRemoteDataSource<T> implements DataSource<T> { private CacheStrategy cacheStrategy = new CacheStrategy.DefaultCacheStrategy(); - private final ScheduledCommand coverageChecker = new ScheduledCommand() { - @Override - public void execute() { - coverageCheckPending = false; - checkCacheCoverage(); - } + private final ScheduledCommand coverageChecker = () -> { + coverageCheckPending = false; + checkCacheCoverage(); }; private Map<Object, Integer> pinnedCounts = new HashMap<>(); diff --git a/client/src/main/java/com/vaadin/client/debug/internal/VDebugWindow.java b/client/src/main/java/com/vaadin/client/debug/internal/VDebugWindow.java index aff8e5d268..7ac67d349a 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/VDebugWindow.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/VDebugWindow.java @@ -21,7 +21,6 @@ import java.util.List; import com.google.gwt.core.client.Duration; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; @@ -706,29 +705,26 @@ public final class VDebugWindow extends VOverlay { * Finalize initialization when all entry points have had the chance to * e.g. register new sections. */ - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - readStoredState(); - - Window.addResizeHandler( - new com.google.gwt.event.logical.shared.ResizeHandler() { + Scheduler.get().scheduleFinally(() -> { + readStoredState(); - Timer t = new Timer() { - @Override - public void run() { - applyPositionAndSize(); - } - }; + Window.addResizeHandler( + new com.google.gwt.event.logical.shared.ResizeHandler() { + Timer t = new Timer() { @Override - public void onResize(ResizeEvent event) { - t.cancel(); - // TODO less - t.schedule(1000); + public void run() { + applyPositionAndSize(); } - }); - } + }; + + @Override + public void onResize(ResizeEvent event) { + t.cancel(); + // TODO less + t.schedule(1000); + } + }); }); } diff --git a/client/src/main/java/com/vaadin/client/ui/FocusableScrollPanel.java b/client/src/main/java/com/vaadin/client/ui/FocusableScrollPanel.java index 9ec6c0ee2f..3b02145b0f 100644 --- a/client/src/main/java/com/vaadin/client/ui/FocusableScrollPanel.java +++ b/client/src/main/java/com/vaadin/client/ui/FocusableScrollPanel.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui; import java.util.List; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Style; @@ -185,22 +184,18 @@ public class FocusableScrollPanel extends SimpleFocusablePanel @Override public void onScroll(ScrollEvent event) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - focusElement.getStyle().setTop(getScrollPosition(), Unit.PX); - focusElement.getStyle().setLeft(getHorizontalScrollPosition(), - Unit.PX); - } + Scheduler.get().scheduleDeferred(() -> { + focusElement.getStyle().setTop(getScrollPosition(), Unit.PX); + focusElement.getStyle().setLeft(getHorizontalScrollPosition(), + Unit.PX); }); } public com.google.gwt.user.client.Element getFocusElement() { if (useFakeFocusElement()) { return focusElement.cast(); - } else { - return getElement(); } + return getElement(); } } diff --git a/client/src/main/java/com/vaadin/client/ui/ImageIcon.java b/client/src/main/java/com/vaadin/client/ui/ImageIcon.java index 7248ff754e..cca477a131 100644 --- a/client/src/main/java/com/vaadin/client/ui/ImageIcon.java +++ b/client/src/main/java/com/vaadin/client/ui/ImageIcon.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.vaadin.client.BrowserInfo; @@ -50,12 +49,8 @@ public class ImageIcon extends Icon { if (BrowserInfo.get().isIE()) { // apply src later for IE, to ensure onload is fired - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - DOM.setElementProperty(getElement(), "src", imageUrl); - } - }); + Scheduler.get().scheduleDeferred(() -> DOM + .setElementProperty(getElement(), "src", imageUrl)); } DOM.setElementProperty(getElement(), "src", imageUrl); diff --git a/client/src/main/java/com/vaadin/client/ui/VComboBox.java b/client/src/main/java/com/vaadin/client/ui/VComboBox.java index b28c5cb518..683f04a942 100644 --- a/client/src/main/java/com/vaadin/client/ui/VComboBox.java +++ b/client/src/main/java/com/vaadin/client/ui/VComboBox.java @@ -26,7 +26,6 @@ import java.util.Set; import com.google.gwt.animation.client.AnimationScheduler; import com.google.gwt.aria.client.Roles; import com.google.gwt.core.client.JavaScriptObject; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; @@ -258,12 +257,12 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, return $entry(function(e) { var deltaX = e.deltaX ? e.deltaX : -0.5*e.wheelDeltaX; var deltaY = e.deltaY ? e.deltaY : -0.5*e.wheelDeltaY; - + // IE8 has only delta y if (isNaN(deltaY)) { deltaY = -0.5*e.wheelDelta; } - + @com.vaadin.client.ui.VComboBox.JsniUtil::moveScrollFromEvent(*)(widget, deltaX, deltaY, e, e.deltaMode); }); }-*/; @@ -1027,20 +1026,15 @@ public class VComboBox extends Composite implements Field, KeyDownHandler, implements SubPartAware, LoadHandler { private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor( - 100, new ScheduledCommand() { - - @Override - public void execute() { - debug("VComboBox.SM: delayedImageLoadExecutioner()"); - if (suggestionPopup.isVisible() - && suggestionPopup.isAttached()) { - setWidth(""); - getElement().getFirstChildElement().getStyle() - .clearWidth(); - suggestionPopup - .setPopupPositionAndShow(suggestionPopup); - } - + 100, () -> { + debug("VComboBox.SM: delayedImageLoadExecutioner()"); + if (suggestionPopup.isVisible() + && suggestionPopup.isAttached()) { + setWidth(""); + getElement().getFirstChildElement().getStyle() + .clearWidth(); + suggestionPopup + .setPopupPositionAndShow(suggestionPopup); } }); diff --git a/client/src/main/java/com/vaadin/client/ui/VContextMenu.java b/client/src/main/java/com/vaadin/client/ui/VContextMenu.java index d9feb6193f..7d2f718566 100644 --- a/client/src/main/java/com/vaadin/client/ui/VContextMenu.java +++ b/client/src/main/java/com/vaadin/client/ui/VContextMenu.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NodeList; import com.google.gwt.dom.client.TableRowElement; @@ -66,12 +65,7 @@ public class VContextMenu extends VOverlay implements SubPartAware { private Element focusedElement; private VLazyExecutor delayedImageLoadExecutioner = new VLazyExecutor(100, - new ScheduledCommand() { - @Override - public void execute() { - imagesLoaded(); - } - }); + () -> imagesLoaded()); /** * This method should be used only by Client object as only one per client diff --git a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java index 0b87139478..607128c43c 100644 --- a/client/src/main/java/com/vaadin/client/ui/VMenuBar.java +++ b/client/src/main/java/com/vaadin/client/ui/VMenuBar.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Queue; import com.google.gwt.core.client.GWT; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Overflow; @@ -107,13 +106,7 @@ public class VMenuBar extends SimpleFocusablePanel public boolean enabled = true; private VLazyExecutor iconLoadedExecutioner = new VLazyExecutor(100, - new ScheduledCommand() { - - @Override - public void execute() { - iLayout(true); - } - }); + () -> iLayout(true)); /** For internal use only. May be removed or replaced in the future. */ public boolean openRootOnHover; diff --git a/client/src/main/java/com/vaadin/client/ui/VPopupView.java b/client/src/main/java/com/vaadin/client/ui/VPopupView.java index 7686703925..8185bb06cd 100644 --- a/client/src/main/java/com/vaadin/client/ui/VPopupView.java +++ b/client/src/main/java/com/vaadin/client/ui/VPopupView.java @@ -21,7 +21,6 @@ import java.util.Iterator; import java.util.Set; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -326,16 +325,13 @@ public class VPopupView extends HTML * could be no shortcutActionHandler set yet. So let's postpone * search of shortcutActionHandler. */ - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - try { - if (shortcutActionHandler == null) { - shortcutActionHandler = findShortcutActionHandler(); - } - } finally { - popupShowInProgress = false; + Scheduler.get().scheduleDeferred(() -> { + try { + if (shortcutActionHandler == null) { + shortcutActionHandler = findShortcutActionHandler(); } + } finally { + popupShowInProgress = false; } }); } diff --git a/client/src/main/java/com/vaadin/client/ui/VSlider.java b/client/src/main/java/com/vaadin/client/ui/VSlider.java index e067613923..22c681d5c2 100644 --- a/client/src/main/java/com/vaadin/client/ui/VSlider.java +++ b/client/src/main/java/com/vaadin/client/ui/VSlider.java @@ -16,7 +16,6 @@ package com.vaadin.client.ui; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.Style.Overflow; @@ -90,15 +89,10 @@ public class VSlider extends SimpleFocusablePanel /* Temporary dragging/animation variables */ private boolean dragging = false; - private VLazyExecutor delayedValueUpdater = new VLazyExecutor(100, - new ScheduledCommand() { - - @Override - public void execute() { - fireValueChanged(); - acceleration = 1; - } - }); + private VLazyExecutor delayedValueUpdater = new VLazyExecutor(100, () -> { + fireValueChanged(); + acceleration = 1; + }); public VSlider() { super(); diff --git a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java index f5e137f6e4..c2cbd626e8 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -563,13 +563,8 @@ public class VTabsheet extends VTabsheetBase getTab(tabsheet.activeTabIndex).recalculateCaptionWidth(); // Scroll the tab into view if it is not already, after layout - Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() { - @Override - public void execute() { - getTabsheet() - .scrollIntoView(getTab(tabsheet.activeTabIndex)); - } - }); + Scheduler.get().scheduleFinally(() -> getTabsheet() + .scrollIntoView(getTab(tabsheet.activeTabIndex))); } public Tab navigateTab(int fromIndex, int toIndex) { diff --git a/client/src/main/java/com/vaadin/client/ui/VUI.java b/client/src/main/java/com/vaadin/client/ui/VUI.java index cf5de33866..8fa0308df4 100644 --- a/client/src/main/java/com/vaadin/client/ui/VUI.java +++ b/client/src/main/java/com/vaadin/client/ui/VUI.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui; import java.util.List; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.HasScrollHandlers; import com.google.gwt.event.dom.client.ScrollEvent; @@ -97,14 +96,7 @@ public class VUI extends SimplePanel implements ResizeHandler, private TouchScrollHandler touchScrollHandler; private VLazyExecutor delayedResizeExecutor = new VLazyExecutor(200, - new ScheduledCommand() { - - @Override - public void execute() { - performSizeCheck(); - } - - }); + () -> performSizeCheck()); private Element storedFocus; diff --git a/client/src/main/java/com/vaadin/client/ui/VUpload.java b/client/src/main/java/com/vaadin/client/ui/VUpload.java index dd4c295492..5d78a68011 100644 --- a/client/src/main/java/com/vaadin/client/ui/VUpload.java +++ b/client/src/main/java/com/vaadin/client/ui/VUpload.java @@ -270,8 +270,10 @@ public class VUpload extends SimplePanel { if (isAttached()) { // no need to call poll() if component is already // detached #8728 - ((UploadConnector) ConnectorMap.get(client).getConnector(VUpload.this)) - .getRpcProxy(UploadServerRpc.class).poll(); + ((UploadConnector) ConnectorMap.get(client) + .getConnector(VUpload.this)) + .getRpcProxy(UploadServerRpc.class) + .poll(); } } @@ -290,40 +292,34 @@ public class VUpload extends SimplePanel { }); } - ScheduledCommand startUploadCmd = new ScheduledCommand() { - - @Override - public void execute() { - element.submit(); - submitted = true; - - disableUpload(); - - /* - * Visit server a moment after upload has started to see possible - * changes from UploadStarted event. Will be cleared on complete. - * - * Must get the id here as the upload can finish before the timer - * expires and in that case nextUploadId has been updated and is - * wrong. - */ - final int thisUploadId = nextUploadId; - t = new Timer() { - @Override - public void run() { - // Only visit the server if the upload has not already - // finished - if (thisUploadId == nextUploadId) { - VConsole.log( - "Visiting server to see if upload started event changed UI."); - client.updateVariable(paintableId, "pollForStart", - thisUploadId, true); - } + ScheduledCommand startUploadCmd = () -> { + element.submit(); + submitted = true; + + disableUpload(); + + /* + * Visit server a moment after upload has started to see possible + * changes from UploadStarted event. Will be cleared on complete. + * + * Must get the id here as the upload can finish before the timer + * expires and in that case nextUploadId has been updated and is wrong. + */ + final int thisUploadId = nextUploadId; + t = new Timer() { + @Override + public void run() { + // Only visit the server if the upload has not already + // finished + if (thisUploadId == nextUploadId) { + VConsole.log( + "Visiting server to see if upload started event changed UI."); + client.updateVariable(paintableId, "pollForStart", + thisUploadId, true); } - }; - t.schedule(800); - } - + } + }; + t.schedule(800); }; /** For internal use only. May be removed or replaced in the future. */ diff --git a/client/src/main/java/com/vaadin/client/ui/VWindow.java b/client/src/main/java/com/vaadin/client/ui/VWindow.java index df2c4b17f3..8ac90386c7 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -28,7 +28,6 @@ import com.google.gwt.aria.client.Id; import com.google.gwt.aria.client.RelevantValue; import com.google.gwt.aria.client.Roles; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; @@ -203,13 +202,7 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, public int bringToFrontSequence = -1; private VLazyExecutor delayedContentsSizeUpdater = new VLazyExecutor(200, - new ScheduledCommand() { - - @Override - public void execute() { - updateContentsSize(); - } - }); + () -> updateContentsSize()); public VWindow() { super(false, false); // no autohide, not modal diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VDragAndDropManager.java b/client/src/main/java/com/vaadin/client/ui/dd/VDragAndDropManager.java index e3b0f11a0d..f1b2e3736a 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VDragAndDropManager.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VDragAndDropManager.java @@ -17,7 +17,6 @@ package com.vaadin.client.ui.dd; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.RepeatingCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.NativeEvent; @@ -372,8 +371,8 @@ public class VDragAndDropManager { int currentY = WidgetUtil .getTouchOrMouseClientY( event.getNativeEvent()); - if (Math.abs( - startX - currentX) > MINIMUM_DISTANCE_TO_START_DRAG + if (Math.abs(startX + - currentX) > MINIMUM_DISTANCE_TO_START_DRAG || Math.abs(startY - currentY) > MINIMUM_DISTANCE_TO_START_DRAG) { ensureDeferredRegistrationCleanup(); @@ -493,18 +492,13 @@ public class VDragAndDropManager { .getTransferable().getDragSource(); final ApplicationConnection client = currentDropHandler .getApplicationConnection(); - Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { - @Override - public boolean execute() { - if (!client.getMessageSender().hasActiveRequest()) { - removeActiveDragSourceStyleName(dragSource); - return false; - } - return true; + Scheduler.get().scheduleFixedDelay(() -> { + if (!client.getMessageSender().hasActiveRequest()) { + removeActiveDragSourceStyleName(dragSource); + return false; } - + return true; }, 30); - } } else { currentDropHandler.dragLeave(currentDrag); @@ -516,9 +510,9 @@ public class VDragAndDropManager { } /* - * Remove class name indicating drag source when server visit is done - * if server visit was not initiated. Otherwise it will be removed once - * the server visit is done. + * Remove class name indicating drag source when server visit is done if + * server visit was not initiated. Otherwise it will be removed once the + * server visit is done. */ if (!sendTransferableToServer && currentDrag != null) { removeActiveDragSourceStyleName( diff --git a/client/src/main/java/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java b/client/src/main/java/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java index e111d4993e..3e8fc0eb8f 100644 --- a/client/src/main/java/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui.orderedlayout; import java.util.List; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.user.client.ui.Widget; @@ -520,12 +519,8 @@ public abstract class AbstractOrderedLayoutConnector // updateExpandedSizes causes fixed size components to temporarily // lose their size. updateExpandCompensation must be delayed until // the browser has a chance to measure them. - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - getWidget().updateExpandCompensation(); - } - }); + Scheduler.get().scheduleFinally( + () -> getWidget().updateExpandCompensation()); } else { getWidget().clearExpand(); } diff --git a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java index 597dca83c2..b502b89135 100644 --- a/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/ui/UIConnector.java @@ -26,7 +26,6 @@ import java.util.Map; import java.util.logging.Logger; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.HeadElement; @@ -186,20 +185,17 @@ public class UIConnector extends AbstractSingleComponentContainerConnector registerRpc(UIClientRpc.class, new UIClientRpc() { @Override public void uiClosed(final boolean sessionExpired) { - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - // Only notify user if we're still running and not eg. - // navigating away (#12298) - if (getConnection().isApplicationRunning()) { - if (sessionExpired) { - getConnection().showSessionExpiredError(null); - } else { - getState().enabled = false; - updateEnabledState(getState().enabled); - } - getConnection().setApplicationRunning(false); + Scheduler.get().scheduleDeferred(() -> { + // Only notify user if we're still running and not eg. + // navigating away (#12298) + if (getConnection().isApplicationRunning()) { + if (sessionExpired) { + getConnection().showSessionExpiredError(null); + } else { + getState().enabled = false; + updateEnabledState(getState().enabled); } + getConnection().setApplicationRunning(false); } }); } @@ -445,12 +441,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector if (firstPaint) { // Queue the initial window size to be sent with the following // request. - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - @Override - public void execute() { - getWidget().sendClientResized(); - } - }); + Scheduler.get() + .scheduleDeferred(() -> getWidget().sendClientResized()); } } diff --git a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java index dc8d30e517..4159ef1078 100644 --- a/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/window/WindowConnector.java @@ -18,7 +18,6 @@ package com.vaadin.client.ui.window; import java.util.logging.Logger; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Node; @@ -403,13 +402,7 @@ public class WindowConnector extends AbstractSingleComponentContainerConnector window.centered = state.centered; // Ensure centering before setting visible (#16486) if (window.centered && getState().windowMode != WindowMode.MAXIMIZED) { - Scheduler.get().scheduleFinally(new ScheduledCommand() { - - @Override - public void execute() { - getWidget().center(); - } - }); + Scheduler.get().scheduleFinally(() -> getWidget().center()); } window.setVisible(true); } diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java index db80553b87..bb1686ae83 100644 --- a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -54,39 +54,34 @@ public abstract class ScrollbarBundle implements DeferredWorker { .isNativelySupported(); private class ScrollEventFirer { - private final ScheduledCommand fireEventCommand = new ScheduledCommand() { - @Override - public void execute() { - - /* - * Some kind of native-scroll-event related asynchronous problem - * occurs here (at least on desktops) where the internal - * bookkeeping isn't up to date with the real scroll position. - * The weird thing is, that happens only once, and if you drag - * scrollbar fast enough. After it has failed once, it never - * fails again. - * - * Theory: the user drags the scrollbar, and this command is - * executed before the browser has a chance to fire a scroll - * event (which normally would correct this situation). This - * would explain why slow scrolling doesn't trigger the problem, - * while fast scrolling does. - * - * To make absolutely sure that we have the latest scroll - * position, let's update the internal value. - * - * This might lead to a slight performance hit (on my computer - * it was never more than 3ms on either of Chrome 38 or Firefox - * 31). It also _slightly_ counteracts the purpose of the - * internal bookkeeping. But since getScrollPos is called 3 - * times (on one direction) per scroll loop, it's still better - * to have take this small penalty than removing it altogether. - */ - updateScrollPosFromDom(); + private final ScheduledCommand fireEventCommand = () -> { + /* + * Some kind of native-scroll-event related asynchronous problem + * occurs here (at least on desktops) where the internal bookkeeping + * isn't up to date with the real scroll position. The weird thing + * is, that happens only once, and if you drag scrollbar fast + * enough. After it has failed once, it never fails again. + * + * Theory: the user drags the scrollbar, and this command is + * executed before the browser has a chance to fire a scroll event + * (which normally would correct this situation). This would explain + * why slow scrolling doesn't trigger the problem, while fast + * scrolling does. + * + * To make absolutely sure that we have the latest scroll position, + * let's update the internal value. + * + * This might lead to a slight performance hit (on my computer it + * was never more than 3ms on either of Chrome 38 or Firefox 31). It + * also _slightly_ counteracts the purpose of the internal + * bookkeeping. But since getScrollPos is called 3 times (on one + * direction) per scroll loop, it's still better to have take this + * small penalty than removing it altogether. + */ + updateScrollPosFromDom(); - getHandlerManager().fireEvent(new ScrollEvent()); - isBeingFired = false; - } + getHandlerManager().fireEvent(new ScrollEvent()); + isBeingFired = false; }; private boolean isBeingFired; diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index de4afcf2e1..a85a16ab63 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -1125,13 +1125,13 @@ public class Escalator extends Widget } /** - * Helper class that helps to implement the WAI-ARIA functionality - * for the Grid and TreeGrid component. + * Helper class that helps to implement the WAI-ARIA functionality for the + * Grid and TreeGrid component. * <p> * The following WAI-ARIA attributes are added through this class: * * <ul> - * <li>aria-rowcount (since 8.2)</li> + * <li>aria-rowcount (since 8.2)</li> * </ul> * * @since 8.2 @@ -1139,8 +1139,8 @@ public class Escalator extends Widget public class AriaGridHelper { /** - * This field contains the total number of rows from the grid - * including rows from thead, tbody and tfoot. + * This field contains the total number of rows from the grid including + * rows from thead, tbody and tfoot. * * @since 8.2 */ @@ -1150,8 +1150,8 @@ public class Escalator extends Widget * Adds the given numberOfRows to allRows and calls * {@link #updateAriaRowCount()}. * - * @param numberOfRows number of rows that were added to the - * grid + * @param numberOfRows + * number of rows that were added to the grid * * @since 8.2 */ @@ -1164,8 +1164,8 @@ public class Escalator extends Widget * Removes the given numberOfRows from allRows and calls * {@link #updateAriaRowCount()}. * - * @param numberOfRows number of rows that were removed from - * the grid + * @param numberOfRows + * number of rows that were removed from the grid * * @since 8.2 */ @@ -1175,9 +1175,9 @@ public class Escalator extends Widget } /** - * Sets the aria-rowcount attribute with the current value - * of {@link AriaGridHelper#allRows} if the grid is attached - * and {@link AriaGridHelper#allRows} > 0. + * Sets the aria-rowcount attribute with the current value of + * {@link AriaGridHelper#allRows} if the grid is attached and + * {@link AriaGridHelper#allRows} > 0. * * @since 8.2 */ @@ -1217,7 +1217,8 @@ public class Escalator extends Widget private boolean initialColumnSizesCalculated = false; - public AbstractRowContainer(final TableSectionElement rowContainerElement) { + public AbstractRowContainer( + final TableSectionElement rowContainerElement) { root = rowContainerElement; } @@ -2027,13 +2028,10 @@ public class Escalator extends Widget } public void autodetectRowHeightLater() { - Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() { - @Override - public void execute() { - if (defaultRowHeightShouldBeAutodetected && isAttached()) { - autodetectRowHeightNow(); - defaultRowHeightShouldBeAutodetected = false; - } + Scheduler.get().scheduleFinally(() -> { + if (defaultRowHeightShouldBeAutodetected && isAttached()) { + autodetectRowHeightNow(); + defaultRowHeightShouldBeAutodetected = false; } }); } @@ -2041,12 +2039,9 @@ public class Escalator extends Widget private void fireRowHeightChangedEventFinally() { if (!rowHeightChangedEventFired) { rowHeightChangedEventFired = true; - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - fireEvent(new RowHeightChangedEvent()); - rowHeightChangedEventFired = false; - } + Scheduler.get().scheduleFinally(() -> { + fireEvent(new RowHeightChangedEvent()); + rowHeightChangedEventFired = false; }); } } @@ -2236,7 +2231,8 @@ public class Escalator extends Widget /** The height of the combined rows in the DOM. Never negative. */ private double heightOfSection = 0; - public AbstractStaticRowContainer(final TableSectionElement headElement) { + public AbstractStaticRowContainer( + final TableSectionElement headElement) { super(headElement); } @@ -5664,7 +5660,8 @@ public class Escalator extends Widget private final AriaGridHelper ariaGridHelper = new AriaGridHelper(); private final HeaderRowContainer header = new HeaderRowContainer(headElem); - private final BodyRowContainerImpl body = new BodyRowContainerImpl(bodyElem); + private final BodyRowContainerImpl body = new BodyRowContainerImpl( + bodyElem); private final FooterRowContainer footer = new FooterRowContainer(footElem); /** @@ -5703,12 +5700,9 @@ public class Escalator extends Widget private double delayToCancelTouchScroll = -1; private boolean layoutIsScheduled = false; - private ScheduledCommand layoutCommand = new ScheduledCommand() { - @Override - public void execute() { - recalculateElementSizes(); - layoutIsScheduled = false; - } + private ScheduledCommand layoutCommand = () -> { + recalculateElementSizes(); + layoutIsScheduled = false; }; private final ElementPositionBookkeeper positions = new ElementPositionBookkeeper(); @@ -5835,13 +5829,9 @@ public class Escalator extends Widget * We either lost or gained a scrollbar. In any case, we * need to change the height, if it's defined by rows. */ - Scheduler.get().scheduleFinally(new ScheduledCommand() { - - @Override - public void execute() { - applyHeightByRows(); - queued = false; - } + Scheduler.get().scheduleFinally(() -> { + applyHeightByRows(); + queued = false; }); } }); @@ -6235,13 +6225,10 @@ public class Escalator extends Widget public void scrollToRow(final int rowIndex, final ScrollDestination destination, final int padding) throws IndexOutOfBoundsException, IllegalArgumentException { - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - validateScrollDestination(destination, padding); - verifyValidRowIndex(rowIndex); - scroller.scrollToRow(rowIndex, destination, padding); - } + Scheduler.get().scheduleFinally(() -> { + validateScrollDestination(destination, padding); + verifyValidRowIndex(rowIndex); + scroller.scrollToRow(rowIndex, destination, padding); }); } @@ -6306,59 +6293,53 @@ public class Escalator extends Widget public void scrollToRowAndSpacer(final int rowIndex, final ScrollDestination destination, final int padding) throws IllegalArgumentException { - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - validateScrollDestination(destination, padding); - if (rowIndex != -1) { - verifyValidRowIndex(rowIndex); - } + Scheduler.get().scheduleFinally(() -> { + validateScrollDestination(destination, padding); + if (rowIndex != -1) { + verifyValidRowIndex(rowIndex); + } - // row range - final Range rowRange; - if (rowIndex != -1) { - int rowTop = (int) Math.floor(body.getRowTop(rowIndex)); - int rowHeight = (int) Math.ceil(body.getDefaultRowHeight()); - rowRange = Range.withLength(rowTop, rowHeight); - } else { - rowRange = Range.withLength(0, 0); - } + // row range + final Range rowRange; + if (rowIndex != -1) { + int rowTop = (int) Math.floor(body.getRowTop(rowIndex)); + int rowHeight = (int) Math.ceil(body.getDefaultRowHeight()); + rowRange = Range.withLength(rowTop, rowHeight); + } else { + rowRange = Range.withLength(0, 0); + } - // get spacer - final SpacerContainer.SpacerImpl spacer = body.spacerContainer - .getSpacer(rowIndex); + // get spacer + final SpacerContainer.SpacerImpl spacer = body.spacerContainer + .getSpacer(rowIndex); - if (rowIndex == -1 && spacer == null) { - throw new IllegalArgumentException( - "Cannot scroll to row index " - + "-1, as there is no spacer open at that index."); - } + if (rowIndex == -1 && spacer == null) { + throw new IllegalArgumentException("Cannot scroll to row index " + + "-1, as there is no spacer open at that index."); + } - // make into target range - final Range targetRange; - if (spacer != null) { - final int spacerTop = (int) Math.floor(spacer.getTop()); - final int spacerHeight = (int) Math - .ceil(spacer.getHeight()); - Range spacerRange = Range.withLength(spacerTop, - spacerHeight); + // make into target range + final Range targetRange; + if (spacer != null) { + final int spacerTop = (int) Math.floor(spacer.getTop()); + final int spacerHeight = (int) Math.ceil(spacer.getHeight()); + Range spacerRange = Range.withLength(spacerTop, spacerHeight); - targetRange = rowRange.combineWith(spacerRange); - } else { - targetRange = rowRange; - } + targetRange = rowRange.combineWith(spacerRange); + } else { + targetRange = rowRange; + } - // get params - int targetStart = targetRange.getStart(); - int targetEnd = targetRange.getEnd(); - double viewportStart = getScrollTop(); - double viewportEnd = viewportStart + body.getHeightOfSection(); + // get params + int targetStart = targetRange.getStart(); + int targetEnd = targetRange.getEnd(); + double viewportStart = getScrollTop(); + double viewportEnd = viewportStart + body.getHeightOfSection(); - double scrollPos = getScrollPos(destination, targetStart, - targetEnd, viewportStart, viewportEnd, padding); + double scrollPos = getScrollPos(destination, targetStart, targetEnd, + viewportStart, viewportEnd, padding); - setScrollTop(scrollPos); - } + setScrollTop(scrollPos); }); } diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index e51d8d57fc..3d3a8b805b 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -948,14 +948,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, * (for example when updating cell values) we only get one actual * refresh in the end. */ - Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() { - - @Override - public void execute() { - if (markAsDirty) { - markAsDirty = false; - getGrid().refreshHeader(); - } + Scheduler.get().scheduleFinally(() -> { + if (markAsDirty) { + markAsDirty = false; + getGrid().refreshHeader(); } }); } @@ -1036,14 +1032,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, * (for example when updating cell values) we only get one actual * refresh in the end. */ - Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() { - - @Override - public void execute() { + Scheduler.get().scheduleFinally(() -> { if (markAsDirty) { markAsDirty = false; getGrid().refreshFooter(); - } } }); } @@ -1677,10 +1669,11 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, if (grid.selectionColumn != null && grid.selectionColumn .getRenderer() instanceof MultiSelectionRenderer) { grid.refreshBody(); - HeaderCell cell = grid.getDefaultHeaderRow().getCell(grid.selectionColumn); + HeaderCell cell = grid.getDefaultHeaderRow() + .getCell(grid.selectionColumn); if (cell.getType() == GridStaticCellType.WIDGET) { // if lazy provider, then no checkbox CheckBox checkBox = (CheckBox) grid.getDefaultHeaderRow() - .getCell(grid.selectionColumn).getWidget(); + .getCell(grid.selectionColumn).getWidget(); checkBox.setEnabled(isEnabled); } } @@ -3866,20 +3859,15 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, final MenuItem item = getSelectedItem(); super.onBrowserEvent(event); Scheduler.get() - .scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - selectItem(item); - focus(); - } + .scheduleDeferred(() -> { + selectItem(item); + focus(); }); } else { super.onBrowserEvent(event); } } - }; KeyDownHandler keyDownHandler = new KeyDownHandler() { @@ -4013,13 +4001,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, super.onAttach(); // make sure the button will get correct height if the button should // be visible when the grid is rendered the first time. - Scheduler.get().scheduleDeferred(new ScheduledCommand() { - - @Override - public void execute() { - setHeightToHeaderCellHeight(); - } - }); + Scheduler.get() + .scheduleDeferred(() -> setHeightToHeaderCellHeight()); } @Override @@ -4068,14 +4051,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, private MenuItem createToggle(final Column<?, T> column) { MenuItem toggle = new MenuItem(createHTML(column), true, - new ScheduledCommand() { - - @Override - public void execute() { - hidingColumn = true; - column.setHidden(!column.isHidden(), true); - hidingColumn = false; - } + () -> { + hidingColumn = true; + column.setHidden(!column.isHidden(), true); + hidingColumn = false; }); toggle.addStyleName("column-hiding-toggle"); columnToHidingToggleMap.put(column, toggle); @@ -6439,7 +6418,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, /** * Request delayed refresh of all body rows. - * + * * @since 8.1 */ public void requestRefreshBody() { @@ -8209,13 +8188,10 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, public HandlerRegistration addDataAvailableHandler( final DataAvailableHandler handler) { // Deferred call to handler with current row range - Scheduler.get().scheduleFinally(new ScheduledCommand() { - @Override - public void execute() { - if (!dataSource.isWaitingForData()) { - handler.onDataAvailable( - new DataAvailableEvent(currentDataAvailable)); - } + Scheduler.get().scheduleFinally(() -> { + if (!dataSource.isWaitingForData()) { + handler.onDataAvailable( + new DataAvailableEvent(currentDataAvailable)); } }); return addHandler(handler, DataAvailableEvent.TYPE); @@ -8910,10 +8886,7 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, /* * Delay calculation to be deferred so Escalator can do it's magic. */ - Scheduler.get().scheduleFinally(new ScheduledCommand() { - - @Override - public void execute() { + Scheduler.get().scheduleFinally(() -> { if (escalator .getInnerWidth() != autoColumnWidthsRecalculator.lastCalculatedInnerWidth) { recalculateColumnWidths(); @@ -8929,7 +8902,6 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, // off-by-one error which occurs when the user scrolls all the // way to the bottom. refreshBody(); - } }); } |