diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-11-01 10:36:47 +0100 |
---|---|---|
committer | Pekka Maanpää <pekkamaa@vaadin.com> | 2017-11-01 11:36:47 +0200 |
commit | 3763f3f94cbcb0b5035ba547accf123b5c50ed3d (patch) | |
tree | 762058cc800575af022601d39fcdd3326a6dd078 /client | |
parent | 04905e1e2eb81770d813abda6a516254e541443d (diff) | |
download | vaadin-framework-3763f3f94cbcb0b5035ba547accf123b5c50ed3d.tar.gz vaadin-framework-3763f3f94cbcb0b5035ba547accf123b5c50ed3d.zip |
Use lambda expressions. (#10268)
Diffstat (limited to 'client')
36 files changed, 396 insertions, 646 deletions
diff --git a/client/src/main/java/com/vaadin/client/ApplicationConnection.java b/client/src/main/java/com/vaadin/client/ApplicationConnection.java index 3cd2590311..718941916b 100644 --- a/client/src/main/java/com/vaadin/client/ApplicationConnection.java +++ b/client/src/main/java/com/vaadin/client/ApplicationConnection.java @@ -460,12 +460,8 @@ public class ApplicationConnection implements HasHandlers { // correct place in the DOM if (!tooltipInitialized) { tooltipInitialized = true; - ApplicationConfiguration.runWhenDependenciesLoaded(new Command() { - @Override - public void execute() { - getVTooltip().initializeAssistiveTooltips(); - } - }); + ApplicationConfiguration.runWhenDependenciesLoaded( + () -> getVTooltip().initializeAssistiveTooltips()); } } diff --git a/client/src/main/java/com/vaadin/client/Profiler.java b/client/src/main/java/com/vaadin/client/Profiler.java index e9e75a6922..d1ba1443a6 100644 --- a/client/src/main/java/com/vaadin/client/Profiler.java +++ b/client/src/main/java/com/vaadin/client/Profiler.java @@ -19,7 +19,6 @@ package com.vaadin.client; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -538,12 +537,8 @@ public class Profiler { rootNode.sumUpTotals(totals); List<Node> totalList = new ArrayList<>(totals.values()); - Collections.sort(totalList, new Comparator<Node>() { - @Override - public int compare(Node o1, Node o2) { - return (int) (o2.getTimeSpent() - o1.getTimeSpent()); - } - }); + Collections.sort(totalList, + (o1, o2) -> (int) (o2.getTimeSpent() - o1.getTimeSpent())); if (getConsumer() != null) { getConsumer().addProfilerData(stack.getFirst(), totalList); diff --git a/client/src/main/java/com/vaadin/client/WidgetUtil.java b/client/src/main/java/com/vaadin/client/WidgetUtil.java index 3841592704..09ef5a3c6a 100644 --- a/client/src/main/java/com/vaadin/client/WidgetUtil.java +++ b/client/src/main/java/com/vaadin/client/WidgetUtil.java @@ -37,7 +37,6 @@ import com.google.gwt.dom.client.Touch; import com.google.gwt.event.dom.client.KeyEvent; import com.google.gwt.regexp.shared.MatchResult; import com.google.gwt.regexp.shared.RegExp; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.EventListener; @@ -425,14 +424,8 @@ public class WidgetUtil { * with overflow auto */ public static void runWebkitOverflowAutoFixDeferred(final Element elem) { - Scheduler.get().scheduleDeferred(new Command() { - - @Override - public void execute() { - WidgetUtil.runWebkitOverflowAutoFix(elem); - } - }); - + Scheduler.get().scheduleDeferred( + () -> WidgetUtil.runWebkitOverflowAutoFix(elem)); } /** @@ -464,60 +457,54 @@ public class WidgetUtil { final int scrollleft = elem.getScrollLeft(); elem.getStyle().setProperty("overflow", "hidden"); - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - // Dough, Safari scroll auto means actually just a moped - elem.getStyle().setProperty("overflow", originalOverflow); - if (!originalOverflowX.isEmpty()) { - elem.getStyle().setProperty("overflowX", - originalOverflowX); - } - if (!originalOverflowY.isEmpty()) { - elem.getStyle().setProperty("overflowY", - originalOverflowY); - } + Scheduler.get().scheduleDeferred(() -> { + // Dough, Safari scroll auto means actually just a moped + elem.getStyle().setProperty("overflow", originalOverflow); + if (!originalOverflowX.isEmpty()) { + elem.getStyle().setProperty("overflowX", originalOverflowX); + } + if (!originalOverflowY.isEmpty()) { + elem.getStyle().setProperty("overflowY", originalOverflowY); + } - if (scrolltop > 0 || elem.getScrollTop() > 0) { - int scrollvalue = scrolltop; - if (scrollvalue == 0) { - // mysterious are the ways of webkits scrollbar - // handling. In some cases webkit reports bad (0) - // scrolltop before hiding the element temporary, - // sometimes after. - scrollvalue = elem.getScrollTop(); - } - // fix another bug where scrollbar remains in wrong - // position - elem.setScrollTop(scrollvalue - 1); - elem.setScrollTop(scrollvalue); + if (scrolltop > 0 || elem.getScrollTop() > 0) { + int scrollvalue = scrolltop; + if (scrollvalue == 0) { + // mysterious are the ways of webkits scrollbar + // handling. In some cases webkit reports bad (0) + // scrolltop before hiding the element temporary, + // sometimes after. + scrollvalue = elem.getScrollTop(); } + // fix another bug where scrollbar remains in wrong + // position + elem.setScrollTop(scrollvalue - 1); + elem.setScrollTop(scrollvalue); + } - // fix for #6940 : Table horizontal scroll sometimes not - // updated when collapsing/expanding columns - // Also appeared in Safari 5.1 with webkit 534 (#7667) - if ((BrowserInfo.get().isChrome() || (BrowserInfo.get() - .isSafariOrIOS() - && BrowserInfo.get().getWebkitVersion() >= 534)) - && (scrollleft > 0 || elem.getScrollLeft() > 0)) { - int scrollvalue = scrollleft; - - if (scrollvalue == 0) { - // mysterious are the ways of webkits scrollbar - // handling. In some cases webkit may report a bad - // (0) scrollleft before hiding the element - // temporary, sometimes after. - scrollvalue = elem.getScrollLeft(); - } - // fix another bug where scrollbar remains in wrong - // position - elem.setScrollLeft(scrollvalue - 1); - elem.setScrollLeft(scrollvalue); + // fix for #6940 : Table horizontal scroll sometimes not + // updated when collapsing/expanding columns + // Also appeared in Safari 5.1 with webkit 534 (#7667) + if ((BrowserInfo.get().isChrome() + || (BrowserInfo.get().isSafariOrIOS() + && BrowserInfo.get().getWebkitVersion() >= 534)) + && (scrollleft > 0 || elem.getScrollLeft() > 0)) { + int scrollvalue = scrollleft; + + if (scrollvalue == 0) { + // mysterious are the ways of webkits scrollbar + // handling. In some cases webkit may report a bad + // (0) scrollleft before hiding the element + // temporary, sometimes after. + scrollvalue = elem.getScrollLeft(); } + // fix another bug where scrollbar remains in wrong + // position + elem.setScrollLeft(scrollvalue - 1); + elem.setScrollLeft(scrollvalue); } }); } - } public static void alert(String string) { diff --git a/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java b/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java index 4e7cbef43f..1a65fd8d8d 100644 --- a/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java +++ b/client/src/main/java/com/vaadin/client/communication/AtmospherePushConnection.java @@ -156,10 +156,7 @@ public class AtmospherePushConnection implements PushConnection { return; } - disconnect(new Command() { - @Override - public void execute() { - } + disconnect(() -> { }); }); config = createConfig(); @@ -182,17 +179,8 @@ public class AtmospherePushConnection implements PushConnection { url = ApplicationConstants.APP_PROTOCOL_PREFIX + ApplicationConstants.PUSH_PATH; } - runWhenAtmosphereLoaded(new Command() { - @Override - public void execute() { - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - connect(); - } - }); - } - }); + runWhenAtmosphereLoaded( + () -> Scheduler.get().scheduleDeferred(() -> connect())); } private void connect() { 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 6fea01af69..50f98bf5f7 100644 --- a/client/src/main/java/com/vaadin/client/communication/MessageHandler.java +++ b/client/src/main/java/com/vaadin/client/communication/MessageHandler.java @@ -247,12 +247,7 @@ public class MessageHandler { .getApplicationState() == ApplicationState.INITIALIZING) { // Application is starting up for the first time connection.setApplicationRunning(true); - connection.executeWhenCSSLoaded(new Command() { - @Override - public void execute() { - handleJSON(json); - } - }); + connection.executeWhenCSSLoaded(() -> handleJSON(json)); } else { getLogger().warning( "Ignored received message because application has already been stopped"); diff --git a/client/src/main/java/com/vaadin/client/communication/MessageSender.java b/client/src/main/java/com/vaadin/client/communication/MessageSender.java index 07855902fb..735668bd5a 100644 --- a/client/src/main/java/com/vaadin/client/communication/MessageSender.java +++ b/client/src/main/java/com/vaadin/client/communication/MessageSender.java @@ -19,7 +19,6 @@ import java.util.logging.Logger; import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.user.client.Command; import com.vaadin.client.ApplicationConfiguration; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ApplicationConnection.RequestStartingEvent; @@ -199,26 +198,23 @@ public class MessageSender { push = GWT.create(PushConnection.class); push.init(connection, pushState); } else if (!enabled && push != null && push.isActive()) { - push.disconnect(new Command() { - @Override - public void execute() { - push = null; - /* - * If push has been enabled again while we were waiting for - * the old connection to disconnect, now is the right time - * to open a new connection - */ - if (pushState.mode.isEnabled()) { - setPushEnabled(true); - } - - /* - * Send anything that was enqueued while we waited for the - * connection to close - */ - if (getServerRpcQueue().isFlushPending()) { - getServerRpcQueue().flush(); - } + push.disconnect(() -> { + push = null; + /* + * If push has been enabled again while we were waiting for the + * old connection to disconnect, now is the right time to open a + * new connection + */ + if (pushState.mode.isEnabled()) { + setPushEnabled(true); + } + + /* + * Send anything that was enqueued while we waited for the + * connection to close + */ + if (getServerRpcQueue().isFlushPending()) { + getServerRpcQueue().flush(); } }); } @@ -250,21 +246,18 @@ public class MessageSender { } // deferring to avoid flickering - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - if (!connection.isApplicationRunning() || !(hasActiveRequest() - || getServerRpcQueue().isFlushPending())) { - getLoadingIndicator().hide(); - - // If on Liferay and session expiration management is in - // use, extend session duration on each request. - // Doing it here rather than before the request to improve - // responsiveness. - // Postponed until the end of the next request if other - // requests still pending. - extendLiferaySession(); - } + Scheduler.get().scheduleDeferred(() -> { + if (!connection.isApplicationRunning() || !(hasActiveRequest() + || getServerRpcQueue().isFlushPending())) { + getLoadingIndicator().hide(); + + // If on Liferay and session expiration management is in + // use, extend session duration on each request. + // Doing it here rather than before the request to improve + // responsiveness. + // Postponed until the end of the next request if other + // requests still pending. + extendLiferaySession(); } }); connection.fireEvent(new ResponseHandlingEndedEvent(connection)); diff --git a/client/src/main/java/com/vaadin/client/communication/XhrConnection.java b/client/src/main/java/com/vaadin/client/communication/XhrConnection.java index 859b3c3024..cc15c00cc2 100644 --- a/client/src/main/java/com/vaadin/client/communication/XhrConnection.java +++ b/client/src/main/java/com/vaadin/client/communication/XhrConnection.java @@ -24,8 +24,6 @@ import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; -import com.google.gwt.user.client.Window.ClosingEvent; -import com.google.gwt.user.client.Window.ClosingHandler; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ApplicationConnection.CommunicationHandler; import com.vaadin.client.ApplicationConnection.RequestStartingEvent; @@ -63,12 +61,8 @@ public class XhrConnection { private boolean webkitMaybeIgnoringRequests = false; public XhrConnection() { - Window.addWindowClosingHandler(new ClosingHandler() { - @Override - public void onWindowClosing(ClosingEvent event) { - webkitMaybeIgnoringRequests = true; - } - }); + Window.addWindowClosingHandler( + event -> webkitMaybeIgnoringRequests = true); } /** diff --git a/client/src/main/java/com/vaadin/client/debug/internal/TestBenchSection.java b/client/src/main/java/com/vaadin/client/debug/internal/TestBenchSection.java index 172bfcdeef..62ae9c458a 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/TestBenchSection.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/TestBenchSection.java @@ -26,7 +26,6 @@ import com.google.gwt.event.dom.client.MouseOverEvent; import com.google.gwt.event.dom.client.MouseOverHandler; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Event.NativePreviewEvent; import com.google.gwt.user.client.Event.NativePreviewHandler; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.FlowPanel; @@ -193,60 +192,54 @@ public class TestBenchSection implements Section { content.add(w); } - private final NativePreviewHandler highlightModeHandler = new NativePreviewHandler() { - - @Override - public void onPreviewNativeEvent(NativePreviewEvent event) { - - if (event.getTypeInt() == Event.ONKEYDOWN && event.getNativeEvent() - .getKeyCode() == KeyCodes.KEY_ESCAPE) { - stopFind(); - Highlight.hideAll(); + private final NativePreviewHandler highlightModeHandler = event -> { + if (event.getTypeInt() == Event.ONKEYDOWN + && event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ESCAPE) { + stopFind(); + Highlight.hideAll(); + return; + } + if (event.getTypeInt() == Event.ONMOUSEMOVE + || event.getTypeInt() == Event.ONCLICK) { + Element eventTarget = WidgetUtil.getElementFromPoint( + event.getNativeEvent().getClientX(), + event.getNativeEvent().getClientY()); + if (VDebugWindow.get().getElement().isOrHasChild(eventTarget)) { + if (isFindMode() && event.getTypeInt() == Event.ONCLICK) { + stopFind(); + event.cancel(); + } return; } - if (event.getTypeInt() == Event.ONMOUSEMOVE - || event.getTypeInt() == Event.ONCLICK) { - Element eventTarget = WidgetUtil.getElementFromPoint( - event.getNativeEvent().getClientX(), - event.getNativeEvent().getClientY()); - if (VDebugWindow.get().getElement().isOrHasChild(eventTarget)) { - if (isFindMode() && event.getTypeInt() == Event.ONCLICK) { - stopFind(); - event.cancel(); - } - return; - } - // make sure that not finding the highlight element only - Highlight.hideAll(); - - eventTarget = WidgetUtil.getElementFromPoint( - event.getNativeEvent().getClientX(), - event.getNativeEvent().getClientY()); - ComponentConnector connector = findConnector(eventTarget); - - if (event.getTypeInt() == Event.ONMOUSEMOVE) { - if (connector != null) { - Highlight.showOnly(connector); - event.cancel(); - event.consume(); - event.getNativeEvent().stopPropagation(); - return; - } - } else if (event.getTypeInt() == Event.ONCLICK) { + // make sure that not finding the highlight element only + Highlight.hideAll(); + + eventTarget = WidgetUtil.getElementFromPoint( + event.getNativeEvent().getClientX(), + event.getNativeEvent().getClientY()); + ComponentConnector connector = findConnector(eventTarget); + + if (event.getTypeInt() == Event.ONMOUSEMOVE) { + if (connector != null) { + Highlight.showOnly(connector); event.cancel(); event.consume(); event.getNativeEvent().stopPropagation(); - if (connector != null) { - Highlight.showOnly(connector); - pickSelector(connector, eventTarget); - return; - } + return; + } + } else if (event.getTypeInt() == Event.ONCLICK) { + event.cancel(); + event.consume(); + event.getNativeEvent().stopPropagation(); + if (connector != null) { + Highlight.showOnly(connector); + pickSelector(connector, eventTarget); + return; } } - event.cancel(); } - + event.cancel(); }; private ComponentConnector findConnector(Element element) { 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 ad93e15092..70d4f7a154 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 @@ -27,7 +27,6 @@ import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Cursor; import com.google.gwt.dom.client.Style.Overflow; -import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.MouseDownEvent; import com.google.gwt.event.dom.client.MouseDownHandler; @@ -520,12 +519,9 @@ public final class VDebugWindow extends VOverlay { */ public void addSection(final Section section) { Button b = section.getTabButton(); - b.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - activateSection(section); - writeStoredState(); - } + b.addClickHandler(event -> { + activateSection(section); + writeStoredState(); }); b.setStylePrimaryName(STYLENAME_TAB); tabs.add(b); @@ -792,17 +788,14 @@ public final class VDebugWindow extends VOverlay { FlowPanel size = new FlowPanel(); content.add(size); - final ClickHandler sizeHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - for (int i = 0; i < sizes.length; i++) { - Button b = sizes[i]; - if (b == event.getSource()) { - setSize(i); - } + final ClickHandler sizeHandler = event -> { + for (int i = 0; i < sizes.length; i++) { + Button b = sizes[i]; + if (b == event.getSource()) { + setSize(i); } - hide(); } + hide(); }; for (int i = 0; i < sizes.length; i++) { Button b = sizes[i]; @@ -813,17 +806,14 @@ public final class VDebugWindow extends VOverlay { FlowPanel mode = new FlowPanel(); content.add(mode); - final ClickHandler modeHandler = new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - for (int i = 0; i < modes.length; i++) { - Button b = modes[i]; - if (b == event.getSource()) { - setDevMode(i); - } + final ClickHandler modeHandler = event -> { + for (int i = 0; i < modes.length; i++) { + Button b = modes[i]; + if (b == event.getSource()) { + setDevMode(i); } - hide(); } + hide(); }; modes[getDevMode()].setActive(true); for (Button b : modes) { @@ -833,13 +823,10 @@ public final class VDebugWindow extends VOverlay { Button reset = new DebugButton(Icon.RESET, "Restore defaults.", " Reset"); - reset.addClickHandler(new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - resetStoredState(); - readStoredState(); - hide(); - } + reset.addClickHandler(event -> { + resetStoredState(); + readStoredState(); + hide(); }); content.add(reset); } diff --git a/client/src/main/java/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java b/client/src/main/java/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java index 4381caddd0..05f7bf9c30 100644 --- a/client/src/main/java/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java +++ b/client/src/main/java/com/vaadin/client/extensions/javascriptmanager/JavaScriptManagerConnector.java @@ -38,12 +38,7 @@ public class JavaScriptManagerConnector extends AbstractExtensionConnector { @Override protected void init() { - registerRpc(ExecuteJavaScriptRpc.class, new ExecuteJavaScriptRpc() { - @Override - public void executeJavaScript(String script) { - eval(script); - } - }); + registerRpc(ExecuteJavaScriptRpc.class, script -> eval(script)); } @Override diff --git a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java index 133d195f48..02bfa95e14 100644 --- a/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/ShortcutActionHandler.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import com.google.gwt.core.client.Scheduler; import com.google.gwt.dom.client.Element; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.HasWidgets; @@ -136,15 +135,12 @@ public class ShortcutActionHandler { */ client.flushActiveConnector(); - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - if (finalTarget != null) { - client.updateVariable(paintableId, "actiontarget", - finalTarget, false); - } - client.updateVariable(paintableId, "action", a.getKey(), true); + Scheduler.get().scheduleDeferred(() -> { + if (finalTarget != null) { + client.updateVariable(paintableId, "actiontarget", finalTarget, + false); } + client.updateVariable(paintableId, "action", a.getKey(), true); }); } 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 e6aabd1af1..bf159f17f0 100644 --- a/client/src/main/java/com/vaadin/client/ui/VContextMenu.java +++ b/client/src/main/java/com/vaadin/client/ui/VContextMenu.java @@ -43,7 +43,6 @@ import com.google.gwt.event.dom.client.LoadHandler; import com.google.gwt.event.logical.shared.CloseEvent; import com.google.gwt.event.logical.shared.CloseHandler; import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.MenuBar; @@ -137,45 +136,38 @@ public class VContextMenu extends VOverlay implements SubPartAware { // reset height (if it has been previously set explicitly) setHeight(""); - setPopupPositionAndShow(new PositionCallback() { - @Override - public void setPosition(int offsetWidth, int offsetHeight) { - // mac FF gets bad width due GWT popups overflow hacks, - // re-determine width - offsetWidth = menu.getOffsetWidth(); - int left = VContextMenu.this.left; - int top = VContextMenu.this.top; - if (offsetWidth + left > Window.getClientWidth()) { - left = left - offsetWidth; - if (left < 0) { - left = 0; - } - } - if (offsetHeight + top > Window.getClientHeight()) { - top = Math.max(0, Window.getClientHeight() - offsetHeight); - } - if (top == 0) { - setHeight(Window.getClientHeight() + "px"); + setPopupPositionAndShow((offsetWidth, offsetHeight) -> { + // mac FF gets bad width due GWT popups overflow hacks, + // re-determine width + offsetWidth = menu.getOffsetWidth(); + int menuLeft = VContextMenu.this.left; + int menuTop = VContextMenu.this.top; + if (offsetWidth + menuLeft > Window.getClientWidth()) { + menuLeft = menuLeft - offsetWidth; + if (menuLeft < 0) { + menuLeft = 0; } - setPopupPosition(left, top); - - /* - * Move keyboard focus to menu, deferring the focus setting so - * the focus is certainly moved to the menu in all browser after - * the positioning has been done. - */ - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - // Focus the menu. - menu.setFocus(true); - - // Unselect previously selected items - menu.selectItem(null); - } - }); - } + if (offsetHeight + menuTop > Window.getClientHeight()) { + menuTop = Math.max(0, Window.getClientHeight() - offsetHeight); + } + if (menuTop == 0) { + setHeight(Window.getClientHeight() + "px"); + } + setPopupPosition(menuLeft, menuTop); + + /* + * Move keyboard focus to menu, deferring the focus setting so the + * focus is certainly moved to the menu in all browser after the + * positioning has been done. + */ + Scheduler.get().scheduleDeferred(() -> { + // Focus the menu. + menu.setFocus(true); + + // Unselect previously selected items + menu.selectItem(null); + }); }); } diff --git a/client/src/main/java/com/vaadin/client/ui/VCustomField.java b/client/src/main/java/com/vaadin/client/ui/VCustomField.java index 2d5039fcd8..11ecfd88b0 100644 --- a/client/src/main/java/com/vaadin/client/ui/VCustomField.java +++ b/client/src/main/java/com/vaadin/client/ui/VCustomField.java @@ -47,13 +47,7 @@ public class VCustomField extends VCustomComponent implements Focusable { */ public void setFocusDelegate( final com.google.gwt.user.client.ui.Focusable focusDelegate) { - this.focusDelegate = new Focusable() { - @Override - public void focus() { - focusDelegate.setFocus(true); - } - }; - + this.focusDelegate = () -> focusDelegate.setFocus(true); } } diff --git a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java index 43c455f386..3c088236c6 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java +++ b/client/src/main/java/com/vaadin/client/ui/VDragAndDropWrapper.java @@ -28,7 +28,6 @@ import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.dom.client.MouseDownEvent; import com.google.gwt.event.dom.client.MouseUpEvent; import com.google.gwt.event.dom.client.TouchStartEvent; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; @@ -46,7 +45,6 @@ import com.vaadin.client.ValueMap; import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.dd.DDUtil; import com.vaadin.client.ui.dd.VAbstractDropHandler; -import com.vaadin.client.ui.dd.VAcceptCallback; import com.vaadin.client.ui.dd.VDragAndDropManager; import com.vaadin.client.ui.dd.VDragEvent; import com.vaadin.client.ui.dd.VDropHandler; @@ -223,30 +221,23 @@ public class VDragAndDropWrapper extends VCustomComponent /** For internal use only. May be removed or replaced in the future. */ public void startNextUpload() { - Scheduler.get().scheduleDeferred(new Command() { - - @Override - public void execute() { - if (!uploading) { - if (!fileIds.isEmpty()) { - - uploading = true; - final Integer fileId = fileIds.remove(0); - VHtml5File file = files.remove(0); - final String receiverUrl = client.translateVaadinUri( - fileIdToReceiver.remove(fileId.toString())); - ExtendedXHR extendedXHR = (ExtendedXHR) ExtendedXHR - .create(); - extendedXHR - .setOnReadyStateChange(readyStateChangeHandler); - extendedXHR.open("POST", receiverUrl); - extendedXHR.postFile(file); - } + Scheduler.get().scheduleDeferred(() -> { + if (!uploading) { + if (!fileIds.isEmpty()) { + + uploading = true; + final Integer fileId = fileIds.remove(0); + VHtml5File file = files.remove(0); + final String receiverUrl = client.translateVaadinUri( + fileIdToReceiver.remove(fileId.toString())); + ExtendedXHR extendedXHR = (ExtendedXHR) ExtendedXHR + .create(); + extendedXHR.setOnReadyStateChange(readyStateChangeHandler); + extendedXHR.open("POST", receiverUrl); + extendedXHR.postFile(file); } - } }); - } public boolean html5DragStart(VHtml5DragEvent event) { @@ -511,13 +502,7 @@ public class VDragAndDropWrapper extends VCustomComponent boolean detailsChanged = updateDropDetails(drag); if (detailsChanged) { currentlyValid = false; - validate(new VAcceptCallback() { - - @Override - public void accepted(VDragEvent event) { - dragAccepted(drag); - } - }, drag); + validate(event -> dragAccepted(drag), drag); } } diff --git a/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java b/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java index a4d8147f81..2c655c40cf 100644 --- a/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java +++ b/client/src/main/java/com/vaadin/client/ui/VRichTextArea.java @@ -259,12 +259,9 @@ public class VRichTextArea extends Composite implements Field, KeyPressHandler, @Override public void onKeyPress(KeyPressEvent event) { if (maxLength >= 0) { - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - if (rta.getHTML().length() > maxLength) { - rta.setHTML(rta.getHTML().substring(0, maxLength)); - } + Scheduler.get().scheduleDeferred(() -> { + if (rta.getHTML().length() > maxLength) { + rta.setHTML(rta.getHTML().substring(0, maxLength)); } }); } 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 ec4167f9fa..fe4950bfdb 100644 --- a/client/src/main/java/com/vaadin/client/ui/VSlider.java +++ b/client/src/main/java/com/vaadin/client/ui/VSlider.java @@ -231,12 +231,9 @@ public class VSlider extends SimpleFocusablePanel if (!isVertical()) { // Draw handle with a delay to allow base to gain maximum width - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - buildHandle(); - setValue(value, false); - } + Scheduler.get().scheduleDeferred(() -> { + buildHandle(); + setValue(value, false); }); } else { buildHandle(); 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 e7da389113..e3e55f97ef 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -1347,15 +1347,9 @@ public class VTabsheet extends VTabsheetBase */ final Style style = scroller.getStyle(); style.setProperty("whiteSpace", "normal"); - Scheduler.get().scheduleDeferred(new Command() { - - @Override - public void execute() { - style.setProperty("whiteSpace", ""); - } - }); + Scheduler.get().scheduleDeferred( + () -> style.setProperty("whiteSpace", "")); } - } /** For internal use only. May be removed or replaced in the future. */ 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 11e9c24a14..a808f76a7e 100644 --- a/client/src/main/java/com/vaadin/client/ui/VUpload.java +++ b/client/src/main/java/com/vaadin/client/ui/VUpload.java @@ -23,7 +23,6 @@ import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.FormElement; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.FileUpload; @@ -253,35 +252,32 @@ public class VUpload extends SimplePanel { */ private void onSubmitComplete() { /* Needs to be run dereferred to avoid various browser issues. */ - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - if (submitted) { - if (client != null) { - if (t != null) { - t.cancel(); - } - VConsole.log("VUpload:Submit complete"); - if (isAttached()) { - // no need to call poll() if component is already - // detached #8728 - ((UploadConnector) ConnectorMap.get(client) - .getConnector(VUpload.this)) - .getRpcProxy(UploadServerRpc.class) - .poll(); - } + Scheduler.get().scheduleDeferred(() -> { + if (submitted) { + if (client != null) { + if (t != null) { + t.cancel(); + } + VConsole.log("VUpload:Submit complete"); + if (isAttached()) { + // no need to call poll() if component is already + // detached #8728 + ((UploadConnector) ConnectorMap.get(client) + .getConnector(VUpload.this)) + .getRpcProxy(UploadServerRpc.class) + .poll(); } + } - rebuildPanel(); + rebuildPanel(); - submitted = false; - enableUpload(); - if (!isAttached()) { - /* - * Upload is complete when upload is already abandoned. - */ - cleanTargetFrame(); - } + submitted = false; + enableUpload(); + if (!isAttached()) { + /* + * Upload is complete when upload is already abandoned. + */ + cleanTargetFrame(); } } }); 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 6b32278734..e7618ed59b 100644 --- a/client/src/main/java/com/vaadin/client/ui/VWindow.java +++ b/client/src/main/java/com/vaadin/client/ui/VWindow.java @@ -21,7 +21,6 @@ import static com.vaadin.client.WidgetUtil.isFocusedElementEditable; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.List; import com.google.gwt.aria.client.Id; @@ -45,7 +44,6 @@ import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Event.NativePreviewHandler; @@ -522,13 +520,9 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, public static void deferOrdering() { if (!orderingDefered) { orderingDefered = true; - Scheduler.get().scheduleFinally(new Command() { - - @Override - public void execute() { - doServerSideOrdering(); - VNotification.bringNotificationsToFront(); - } + Scheduler.get().scheduleFinally(() -> { + doServerSideOrdering(); + VNotification.bringNotificationsToFront(); }); } } @@ -536,26 +530,24 @@ public class VWindow extends VOverlay implements ShortcutActionHandlerOwner, private static void doServerSideOrdering() { orderingDefered = false; VWindow[] array = windowOrder.toArray(new VWindow[windowOrder.size()]); - Arrays.sort(array, new Comparator<VWindow>() { - - @Override - public int compare(VWindow o1, VWindow o2) { - /* - * Order by modality, then by bringtofront sequence. - */ - - if (o1.vaadinModality && !o2.vaadinModality) { - return 1; - } else if (!o1.vaadinModality && o2.vaadinModality) { - return -1; - } else if (o1.bringToFrontSequence > o2.bringToFrontSequence) { - return 1; - } else if (o1.bringToFrontSequence < o2.bringToFrontSequence) { - return -1; - } else { - return 0; - } + Arrays.sort(array, (o1, o2) -> { + + /* + * Order by modality, then by bringtofront sequence. + */ + if (o1.vaadinModality && !o2.vaadinModality) { + return 1; + } + if (!o1.vaadinModality && o2.vaadinModality) { + return -1; + } + if (o1.bringToFrontSequence > o2.bringToFrontSequence) { + return 1; + } + if (o1.bringToFrontSequence < o2.bringToFrontSequence) { + return -1; } + return 0; }); for (VWindow w : array) { if (w.bringToFrontSequence != -1 || w.vaadinModality) { diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java b/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java index 89d33881ff..f7903e615e 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAbstractDropHandler.java @@ -96,12 +96,7 @@ public abstract class VAbstractDropHandler implements VDropHandler { */ @Override public void dragEnter(final VDragEvent drag) { - validate(new VAcceptCallback() { - @Override - public void accepted(VDragEvent event) { - dragAccepted(drag); - } - }, drag); + validate(event -> dragAccepted(drag), drag); } /** @@ -116,12 +111,8 @@ public abstract class VAbstractDropHandler implements VDropHandler { protected abstract void dragAccepted(VDragEvent drag); protected void validate(final VAcceptCallback cb, final VDragEvent event) { - Command checkCriteria = new Command() { - @Override - public void execute() { - acceptCriteria.accept(event, criterioUIDL, cb); - } - }; + Command checkCriteria = () -> acceptCriteria.accept(event, criterioUIDL, + cb); VDragAndDropManager.get().executeWhenReady(checkCriteria); } @@ -139,15 +130,10 @@ public abstract class VAbstractDropHandler implements VDropHandler { return true; } else { validated = false; - acceptCriteria.accept(drag, criterioUIDL, new VAcceptCallback() { - @Override - public void accepted(VDragEvent event) { - validated = true; - } - }); + acceptCriteria.accept(drag, criterioUIDL, + event -> validated = true); return validated; } - } /** diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java index f1fe4fb409..956b10c8d8 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VAcceptCriterion.java @@ -39,12 +39,9 @@ public abstract class VAcceptCriterion { public void accept(final VDragEvent drag, UIDL configuration, final VAcceptCallback callback) { if (needsServerSideCheck(drag, configuration)) { - VDragEventServerCallback acceptCallback = new VDragEventServerCallback() { - @Override - public void handleResponse(boolean accepted, UIDL response) { - if (accepted) { - callback.accepted(drag); - } + VDragEventServerCallback acceptCallback = (accepted, response) -> { + if (accepted) { + callback.accepted(drag); } }; VDragAndDropManager.get().visitServer(acceptCallback); @@ -54,7 +51,6 @@ public abstract class VAcceptCriterion { callback.accepted(drag); } } - } protected abstract boolean accept(VDragEvent drag, UIDL configuration); diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java b/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java index 40817c5d32..16f9420adf 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VLazyInitItemIdentifiers.java @@ -47,20 +47,16 @@ public class VLazyInitItemIdentifiers extends VAcceptCriterion { } } else { - VDragEventServerCallback acceptCallback = new VDragEventServerCallback() { - - @Override - public void handleResponse(boolean accepted, UIDL response) { - hashSet = new HashSet<>(); - String[] stringArrayAttribute = response - .getStringArrayAttribute("allowedIds"); - for (String attribute : stringArrayAttribute) { - hashSet.add(attribute); - } - loaded = true; - if (accepted) { - callback.accepted(drag); - } + VDragEventServerCallback acceptCallback = (accepted, response) -> { + hashSet = new HashSet<>(); + String[] stringArrayAttribute = response + .getStringArrayAttribute("allowedIds"); + for (String attribute : stringArrayAttribute) { + hashSet.add(attribute); + } + loaded = true; + if (accepted) { + callback.accepted(drag); } }; diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VNot.java b/client/src/main/java/com/vaadin/client/ui/dd/VNot.java index ffa0b25aff..d919541b8e 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VNot.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VNot.java @@ -46,12 +46,7 @@ public final class VNot extends VAcceptCriterion { b1 = false; - VAcceptCallback accept1cb = new VAcceptCallback() { - @Override - public void accepted(VDragEvent event) { - b1 = true; - } - }; + VAcceptCallback accept1cb = event -> b1 = true; crit1.accept(drag, configuration.getChildUIDL(0), accept1cb); if (!b1) { diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java b/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java index 69bb013e5c..24a8ae0f58 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VServerAccept.java @@ -32,12 +32,9 @@ public final class VServerAccept extends VAcceptCriterion { public void accept(final VDragEvent drag, UIDL configuration, final VAcceptCallback callback) { - VDragEventServerCallback acceptCallback = new VDragEventServerCallback() { - @Override - public void handleResponse(boolean accepted, UIDL response) { - if (accepted) { - callback.accepted(drag); - } + VDragEventServerCallback acceptCallback = (accepted, response) -> { + if (accepted) { + callback.accepted(drag); } }; VDragAndDropManager.get().visitServer(acceptCallback); diff --git a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java index 4b9f9a1bd5..802d4a7396 100644 --- a/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/menubar/MenuBarConnector.java @@ -123,12 +123,7 @@ public class MenuBarConnector extends AbstractComponentConnector if (itemHasCommand || itemIsCheckable) { // Construct a command that fires onMenuClick(int) with the // item's id-number - cmd = new Command() { - @Override - public void execute() { - widget.hostReference.onMenuClick(itemId); - } - }; + cmd = () -> widget.hostReference.onMenuClick(itemId); } } diff --git a/client/src/main/java/com/vaadin/client/ui/tabsheet/TabsheetConnector.java b/client/src/main/java/com/vaadin/client/ui/tabsheet/TabsheetConnector.java index 1c2841fd20..bc3c412f09 100644 --- a/client/src/main/java/com/vaadin/client/ui/tabsheet/TabsheetConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/tabsheet/TabsheetConnector.java @@ -34,21 +34,18 @@ public class TabsheetConnector extends TabsheetBaseConnector implements SimpleManagedLayout, MayScrollChildren { public TabsheetConnector() { - registerRpc(TabsheetClientRpc.class, new TabsheetClientRpc() { - @Override - public void revertToSharedStateSelection() { - for (int i = 0; i < getState().tabs.size(); ++i) { - final String key = getState().tabs.get(i).key; - final boolean selected = key.equals(getState().selected); - if (selected) { - getWidget().waitingForResponse = false; - getWidget().setActiveTabIndex(i); - getWidget().selectTab(i); - break; - } + registerRpc(TabsheetClientRpc.class, () -> { + for (int i = 0; i < getState().tabs.size(); ++i) { + final String key = getState().tabs.get(i).key; + final boolean selected = key.equals(getState().selected); + if (selected) { + getWidget().waitingForResponse = false; + getWidget().setActiveTabIndex(i); + getWidget().selectTab(i); + break; } - renderContent(); } + renderContent(); }); } 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 835c924d47..ad7a192d14 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 @@ -39,7 +39,6 @@ import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.event.dom.client.ScrollEvent; import com.google.gwt.event.dom.client.ScrollHandler; import com.google.gwt.event.shared.HandlerRegistration; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; import com.google.gwt.user.client.History; @@ -172,23 +171,20 @@ public class UIConnector extends AbstractSingleComponentContainerConnector getWidget().getElement().setScrollLeft(scrollLeft); } }); - registerRpc(UIClientRpc.class, new UIClientRpc() { - @Override - public void uiClosed(final boolean sessionExpired) { - Scheduler.get().scheduleDeferred(() -> { - // Only notify user if we're still running and not e.g. - // navigating away (#12298) - if (getConnection().isApplicationRunning()) { - if (sessionExpired) { - getConnection().showSessionExpiredError(null); - } else { - getState().enabled = false; - updateEnabledState(getState().enabled); - } - getConnection().setApplicationRunning(false); + registerRpc(UIClientRpc.class, sessionExpired -> { + Scheduler.get().scheduleDeferred(() -> { + // Only notify user if we're still running and not e.g. + // navigating away (#12298) + if (getConnection().isApplicationRunning()) { + if (sessionExpired) { + getConnection().showSessionExpiredError(null); + } else { + getState().enabled = false; + updateEnabledState(getState().enabled); } - }); - } + getConnection().setApplicationRunning(false); + } + }); }); registerRpc(DebugWindowClientRpc.class, new DebugWindowClientRpc() { @@ -297,12 +293,7 @@ public class UIConnector extends AbstractSingleComponentContainerConnector // source will be opened to this browser window, but we may have // to finish rendering this window in case this is a download // (and window stays open). - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - VUI.goTo(url); - } - }); + Scheduler.get().scheduleDeferred(() -> VUI.goTo(url)); } else if ("_self".equals(target)) { // This window is closing (for sure). Only other opens are // relevant in this change. See #3558, #2144 @@ -365,38 +356,34 @@ public class UIConnector extends AbstractSingleComponentContainerConnector if (uidl.hasAttribute("focused")) { // set focused component when render phase is finished - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - ComponentConnector connector = (ComponentConnector) uidl - .getPaintableAttribute("focused", getConnection()); - - if (connector == null) { - // Do not try to focus invisible components which not - // present in UIDL - return; - } + Scheduler.get().scheduleDeferred(() -> { + ComponentConnector connector = (ComponentConnector) uidl + .getPaintableAttribute("focused", getConnection()); + + if (connector == null) { + // Do not try to focus invisible components which not + // present in UIDL + return; + } - final Widget toBeFocused = connector.getWidget(); - /* - * Two types of Widgets can be focused, either implementing - * GWT Focusable of a thinner Vaadin specific Focusable - * interface. - */ - if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { - final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; - toBeFocusedWidget.setFocus(true); - } else if (toBeFocused instanceof Focusable) { - ((Focusable) toBeFocused).focus(); - } else { - getLogger().severe( - "Server is trying to set focus to the widget of connector " - + Util.getConnectorString(connector) - + " but it is not focusable. The widget should implement either " - + com.google.gwt.user.client.ui.Focusable.class - .getName() - + " or " + Focusable.class.getName()); - } + final Widget toBeFocused = connector.getWidget(); + /* + * Two types of Widgets can be focused, either implementing GWT + * Focusable of a thinner Vaadin specific Focusable interface. + */ + if (toBeFocused instanceof com.google.gwt.user.client.ui.Focusable) { + final com.google.gwt.user.client.ui.Focusable toBeFocusedWidget = (com.google.gwt.user.client.ui.Focusable) toBeFocused; + toBeFocusedWidget.setFocus(true); + } else if (toBeFocused instanceof Focusable) { + ((Focusable) toBeFocused).focus(); + } else { + getLogger().severe( + "Server is trying to set focus to the widget of connector " + + Util.getConnectorString(connector) + + " but it is not focusable. The widget should implement either " + + com.google.gwt.user.client.ui.Focusable.class + .getName() + + " or " + Focusable.class.getName()); } }); } @@ -757,12 +744,8 @@ public class UIConnector extends AbstractSingleComponentContainerConnector return; } - Scheduler.get().scheduleDeferred(new Command() { - @Override - public void execute() { - componentConnector.getWidget().getElement().scrollIntoView(); - } - }); + Scheduler.get().scheduleDeferred(() -> componentConnector.getWidget() + .getElement().scrollIntoView()); } @Override diff --git a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java index 92945427f5..49aeae6a39 100644 --- a/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/upload/UploadConnector.java @@ -34,12 +34,7 @@ public class UploadConnector extends AbstractComponentConnector implements Paintable { public UploadConnector() { - registerRpc(UploadClientRpc.class, new UploadClientRpc() { - @Override - public void submitUpload() { - getWidget().submit(); - } - }); + registerRpc(UploadClientRpc.class, () -> getWidget().submit()); } @Override diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java b/client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java index 996741ddc5..4ab1676af2 100644 --- a/client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java +++ b/client/src/main/java/com/vaadin/client/widget/escalator/FlyweightRow.java @@ -240,13 +240,9 @@ public class FlyweightRow implements Row { assertSetup(); assert offset >= 0 && offset + numberOfCells <= cells .size() : "Invalid range of cells"; - return new Iterable<FlyweightCell>() { - @Override - public Iterator<FlyweightCell> iterator() { - return CellIterator.attached( + return () -> CellIterator + .attached( cells.subList(offset, offset + numberOfCells)); - } - }; } /** @@ -269,13 +265,9 @@ public class FlyweightRow implements Row { assertSetup(); assert offset >= 0 && offset + numberOfCells <= cells .size() : "Invalid range of cells"; - return new Iterable<FlyweightCell>() { - @Override - public Iterator<FlyweightCell> iterator() { - return CellIterator.unattached( + return () -> CellIterator + .unattached( cells.subList(offset, offset + numberOfCells)); - } - }; } /** diff --git a/client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java b/client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java index 6ff77a2c88..db9af545fc 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/AutoScroller.java @@ -380,39 +380,6 @@ public class AutoScroller { } } - /** - * This handler makes sure that pointer movements are handled. - * <p> - * Essentially, a native preview handler is registered (so that selection - * gestures can happen outside of the selection column). The handler itself - * makes sure that it's detached when the pointer is "lifted". - */ - private final NativePreviewHandler scrollPreviewHandler = new NativePreviewHandler() { - @Override - public void onPreviewNativeEvent(final NativePreviewEvent event) { - if (autoScroller == null) { - stop(); - return; - } - - final NativeEvent nativeEvent = event.getNativeEvent(); - int pageY = 0; - int pageX = 0; - switch (event.getTypeInt()) { - case Event.ONMOUSEMOVE: - case Event.ONTOUCHMOVE: - pageY = WidgetUtil.getTouchOrMouseClientY(nativeEvent); - pageX = WidgetUtil.getTouchOrMouseClientX(nativeEvent); - autoScroller.updatePointerCoords(pageX, pageY); - break; - case Event.ONMOUSEUP: - case Event.ONTOUCHEND: - case Event.ONTOUCHCANCEL: - stop(); - break; - } - } - }; /** The registration info for {@link #scrollPreviewHandler} */ private HandlerRegistration handlerRegistration; @@ -442,6 +409,37 @@ public class AutoScroller { private AutoScrollerCallback callback; /** + * This handler makes sure that pointer movements are handled. + * <p> + * Essentially, a native preview handler is registered (so that selection + * gestures can happen outside of the selection column). The handler itself + * makes sure that it's detached when the pointer is "lifted". + */ + private final NativePreviewHandler scrollPreviewHandler = event -> { + if (autoScroller == null) { + stop(); + return; + } + + final NativeEvent nativeEvent = event.getNativeEvent(); + int pageY = 0; + int pageX = 0; + switch (event.getTypeInt()) { + case Event.ONMOUSEMOVE: + case Event.ONTOUCHMOVE: + pageY = WidgetUtil.getTouchOrMouseClientY(nativeEvent); + pageX = WidgetUtil.getTouchOrMouseClientX(nativeEvent); + autoScroller.updatePointerCoords(pageX, pageY); + break; + case Event.ONMOUSEUP: + case Event.ONTOUCHEND: + case Event.ONTOUCHCANCEL: + stop(); + break; + } + }; + + /** * Creates a new instance for scrolling the given grid. * * @param grid diff --git a/client/src/main/java/com/vaadin/client/widget/grid/DetailsGenerator.java b/client/src/main/java/com/vaadin/client/widget/grid/DetailsGenerator.java index 23e2c5aee5..c5f483ca96 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/DetailsGenerator.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/DetailsGenerator.java @@ -26,12 +26,7 @@ import com.google.gwt.user.client.ui.Widget; public interface DetailsGenerator { /** A details generator that provides no details. */ - public static final DetailsGenerator NULL = new DetailsGenerator() { - @Override - public Widget getDetails(int rowIndex) { - return null; - } - }; + public static final DetailsGenerator NULL = rowIndex -> null; /** * This method is called for whenever a new details row needs to be diff --git a/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java b/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java index d5f3e24528..fe95399e7c 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/datasources/ListSorter.java @@ -133,45 +133,36 @@ public class ListSorter<T> { "Grid " + grid + " data source is not a ListDataSource!"); } - ((ListDataSource<T>) ds).sort(new Comparator<T>() { - - @Override - @SuppressWarnings({ "rawtypes", "unchecked" }) - public int compare(T a, T b) { - - for (SortOrder o : order) { - - Grid.Column column = o.getColumn(); - Comparator cmp = ListSorter.this.comparators.get(column); - int result = 0; - Object valueA = column.getValue(a); - Object valueB = column.getValue(b); - if (cmp != null) { - result = cmp.compare(valueA, valueB); - } else { - if (!(valueA instanceof Comparable)) { - throw new IllegalStateException("Column " + column - + " has no assigned comparator and value " - + valueA + " isn't naturally comparable"); - } - result = ((Comparable) valueA).compareTo(valueB); - } - - if (result != 0) { - return o.getDirection() == SortDirection.ASCENDING - ? result - : -result; + ((ListDataSource<T>) ds).sort((a, b) -> { + for (SortOrder o : order) { + Grid.Column column = o.getColumn(); + Comparator cmp = comparators.get(column); + int result = 0; + Object valueA = column.getValue(a); + Object valueB = column.getValue(b); + if (cmp != null) { + result = cmp.compare(valueA, valueB); + } else { + if (!(valueA instanceof Comparable)) { + throw new IllegalStateException("Column " + column + + " has no assigned comparator and value " + + valueA + " isn't naturally comparable"); } + result = ((Comparable) valueA).compareTo(valueB); } - if (!order.isEmpty()) { - return order.get(0) - .getDirection() == SortDirection.ASCENDING - ? a.hashCode() - b.hashCode() - : b.hashCode() - a.hashCode(); + if (result != 0) { + return o.getDirection() == SortDirection.ASCENDING ? result + : -result; } - return a.hashCode() - b.hashCode(); } + + if (!order.isEmpty()) { + return order.get(0).getDirection() == SortDirection.ASCENDING + ? a.hashCode() - b.hashCode() + : b.hashCode() - a.hashCode(); + } + return a.hashCode() - b.hashCode(); }); } } diff --git a/client/src/main/java/com/vaadin/client/widget/grid/selection/SpaceSelectHandler.java b/client/src/main/java/com/vaadin/client/widget/grid/selection/SpaceSelectHandler.java index b8a1ae4e5b..59c78b313d 100644 --- a/client/src/main/java/com/vaadin/client/widget/grid/selection/SpaceSelectHandler.java +++ b/client/src/main/java/com/vaadin/client/widget/grid/selection/SpaceSelectHandler.java @@ -17,12 +17,8 @@ package com.vaadin.client.widget.grid.selection; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.shared.HandlerRegistration; -import com.vaadin.client.widget.grid.DataAvailableEvent; -import com.vaadin.client.widget.grid.DataAvailableHandler; import com.vaadin.client.widget.grid.events.BodyKeyDownHandler; -import com.vaadin.client.widget.grid.events.BodyKeyUpHandler; import com.vaadin.client.widget.grid.events.GridKeyDownEvent; -import com.vaadin.client.widget.grid.events.GridKeyUpEvent; import com.vaadin.client.widgets.Grid; import com.vaadin.shared.ui.grid.ScrollDestination; @@ -60,17 +56,12 @@ public class SpaceSelectHandler<T> { } scrollHandler = grid - .addDataAvailableHandler(new DataAvailableHandler() { - - @Override - public void onDataAvailable( - DataAvailableEvent dataAvailableEvent) { - if (dataAvailableEvent.getAvailableRows() - .contains(rowIndex)) { - setSelected(grid, rowIndex); - scrollHandler.removeHandler(); - scrollHandler = null; - } + .addDataAvailableHandler(dataAvailableEvent -> { + if (dataAvailableEvent.getAvailableRows() + .contains(rowIndex)) { + setSelected(grid, rowIndex); + scrollHandler.removeHandler(); + scrollHandler = null; } }); grid.scrollToRow(rowIndex, ScrollDestination.ANY); @@ -104,13 +95,9 @@ public class SpaceSelectHandler<T> { this.grid = grid; spaceDownHandler = grid .addBodyKeyDownHandler(new SpaceKeyDownHandler()); - spaceUpHandler = grid.addBodyKeyUpHandler(new BodyKeyUpHandler() { - - @Override - public void onKeyUp(GridKeyUpEvent event) { - if (event.getNativeKeyCode() == KeyCodes.KEY_SPACE) { - spaceDown = false; - } + spaceUpHandler = grid.addBodyKeyUpHandler(event -> { + if (event.getNativeKeyCode() == KeyCodes.KEY_SPACE) { + spaceDown = false; } }); } 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 f53ea4fdd8..f54cecad6d 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -5868,12 +5868,9 @@ public class Escalator extends Widget private void setupScrollbars(final Element root) { - ScrollHandler scrollHandler = new ScrollHandler() { - @Override - public void onScroll(ScrollEvent event) { - scroller.onScroll(); - fireEvent(new ScrollEvent()); - } + ScrollHandler scrollHandler = event -> { + scroller.onScroll(); + fireEvent(new ScrollEvent()); }; int scrollbarThickness = WidgetUtil.getNativeScrollbarSize(); diff --git a/client/src/main/java/com/vaadin/client/widgets/Overlay.java b/client/src/main/java/com/vaadin/client/widgets/Overlay.java index 1ec7456f93..965924c376 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Overlay.java +++ b/client/src/main/java/com/vaadin/client/widgets/Overlay.java @@ -238,12 +238,7 @@ public class Overlay extends PopupPanel { if (left < 0) { // Would move left of screen, shrink to fit in window setOuterWidthThroughWidget(windowRight - windowLeft); - runOnClose.add(new Command() { - @Override - public void execute() { - getWidget().setWidth(""); - } - }); + runOnClose.add(() -> getWidget().setWidth("")); left = 0; } } @@ -259,12 +254,7 @@ public class Overlay extends PopupPanel { if (top < 0) { // Would move above screen, shrink to fit in window setOuterHeightThroughWidget(windowBottom - windowTop); - runOnClose.add(new Command() { - @Override - public void execute() { - getWidget().setHeight(""); - } - }); + runOnClose.add(() -> getWidget().setHeight("")); top = 0; } } diff --git a/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java b/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java index 7d9bf530ce..93a5be4de0 100644 --- a/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java +++ b/client/src/test/java/com/vaadin/client/ui/grid/ListDataSourceTest.java @@ -19,7 +19,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; -import java.util.Comparator; import org.easymock.EasyMock; import org.junit.Test; @@ -178,12 +177,7 @@ public class ListDataSourceTest { // TODO Should be simplified to sort(). No point in providing these // trivial comparators. - ds.sort(new Comparator<Integer>() { - @Override - public int compare(Integer o1, Integer o2) { - return o1.compareTo(o2); - } - }); + ds.sort((o1, o2) -> o1.compareTo(o2)); assertTrue(Arrays.equals(ds.asList().toArray(), new Integer[] { 1, 2, 3, 3, 4 })); |