diff options
author | Ahmed Ashour <asashour@yahoo.com> | 2017-10-26 21:19:41 +0200 |
---|---|---|
committer | Pekka Maanpää <pekkamaa@vaadin.com> | 2017-10-26 22:19:41 +0300 |
commit | 01c93a6aef27ef562267d7966c6386ecaa6c1f6b (patch) | |
tree | 438810691e69e7751710917c251c2ba677c969d4 /client | |
parent | 10bd7544fd22dccd7e8e32cb236eb50f102892d3 (diff) | |
download | vaadin-framework-01c93a6aef27ef562267d7966c6386ecaa6c1f6b.tar.gz vaadin-framework-01c93a6aef27ef562267d7966c6386ecaa6c1f6b.zip |
Use lambda with Listeners (#10222)
Also use "event" as the name for events
Diffstat (limited to 'client')
21 files changed, 181 insertions, 276 deletions
diff --git a/client/src/main/java/com/vaadin/client/DependencyLoader.java b/client/src/main/java/com/vaadin/client/DependencyLoader.java index b388bfc00b..8faedfab39 100644 --- a/client/src/main/java/com/vaadin/client/DependencyLoader.java +++ b/client/src/main/java/com/vaadin/client/DependencyLoader.java @@ -56,7 +56,6 @@ public class DependencyLoader { // The show must go on onLoad(event); } - }; /** diff --git a/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java b/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java index 0fb88389d6..40cc6a5d28 100644 --- a/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java +++ b/client/src/main/java/com/vaadin/client/JavaScriptConnectorHelper.java @@ -32,7 +32,6 @@ import com.vaadin.client.communication.JavaScriptMethodInvocation; import com.vaadin.client.communication.ServerRpcQueue; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.JavaScriptConnectorState; import com.vaadin.shared.communication.MethodInvocation; @@ -261,13 +260,8 @@ public class JavaScriptConnectorHelper { if (listener == null) { LayoutManager layoutManager = LayoutManager .get(connector.getConnection()); - listener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - invokeElementResizeCallback(e.getElement(), - callbackFunction); - } - }; + listener = event -> invokeElementResizeCallback(event.getElement(), + callbackFunction); layoutManager.addElementResizeListener(element, listener); elementListeners.put(callbackFunction, listener); } diff --git a/client/src/main/java/com/vaadin/client/SuperDevMode.java b/client/src/main/java/com/vaadin/client/SuperDevMode.java index 981bb4ab1b..850fabac63 100644 --- a/client/src/main/java/com/vaadin/client/SuperDevMode.java +++ b/client/src/main/java/com/vaadin/client/SuperDevMode.java @@ -25,8 +25,6 @@ import com.google.gwt.storage.client.Storage; import com.google.gwt.user.client.Window.Location; import com.google.gwt.user.client.rpc.AsyncCallback; import com.vaadin.client.ui.VNotification; -import com.vaadin.client.ui.VNotification.EventListener; -import com.vaadin.client.ui.VNotification.HideEvent; /** * Class that enables SuperDevMode using a ?superdevmode parameter in the url. @@ -99,13 +97,9 @@ public class SuperDevMode { private void failed() { VNotification n = new VNotification(); - n.addEventListener(new EventListener() { - - @Override - public void notificationHidden(HideEvent event) { - recompileWidgetsetAndStartInDevMode(serverUrl); - } - }); + n.addEventListener( + event -> recompileWidgetsetAndStartInDevMode( + serverUrl)); n.show("Recompilation failed.<br/>" + "Make sure CodeServer is running, " + "check its output and click to retry", 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 973a3df09a..177056c0e3 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 @@ -29,7 +29,6 @@ import com.vaadin.client.ServerConnector; import com.vaadin.client.WidgetUtil; import com.vaadin.client.data.DataChangeHandler; import com.vaadin.client.extensions.AbstractExtensionConnector; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.client.widget.grid.HeightAwareDetailsGenerator; import com.vaadin.client.widgets.Grid; @@ -58,14 +57,10 @@ public class DetailsManagerConnector extends AbstractExtensionConnector { private Registration dataChangeRegistration; private final Map<Element, ScheduledCommand> elementToResizeCommand = new HashMap<Element, Scheduler.ScheduledCommand>(); - private final ElementResizeListener detailsRowResizeListener = new ElementResizeListener() { - - @Override - public void onElementResize(ElementResizeEvent e) { - if (elementToResizeCommand.containsKey(e.getElement())) { - Scheduler.get().scheduleFinally( - elementToResizeCommand.get(e.getElement())); - } + private final ElementResizeListener detailsRowResizeListener = event -> { + if (elementToResizeCommand.containsKey(event.getElement())) { + Scheduler.get().scheduleFinally( + elementToResizeCommand.get(event.getElement())); } }; diff --git a/client/src/main/java/com/vaadin/client/debug/internal/HierarchySection.java b/client/src/main/java/com/vaadin/client/debug/internal/HierarchySection.java index 1412df88fc..326eff5bbd 100644 --- a/client/src/main/java/com/vaadin/client/debug/internal/HierarchySection.java +++ b/client/src/main/java/com/vaadin/client/debug/internal/HierarchySection.java @@ -178,19 +178,11 @@ public class HierarchySection implements Section { } }); - hierarchyPanel.addListener(new SelectConnectorListener() { - @Override - public void select(ServerConnector connector, Element element) { - printState(connector, true); - } - }); + hierarchyPanel.addListener( + (connector, element) -> printState(connector, true)); - analyzeLayoutsPanel.addListener(new SelectConnectorListener() { - @Override - public void select(ServerConnector connector, Element element) { - printState(connector, true); - } - }); + analyzeLayoutsPanel.addListener( + (connector, element) -> printState(connector, true)); content.setStylePrimaryName(VDebugWindow.STYLENAME + "-hierarchy"); diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractDateFieldCalendar.java b/client/src/main/java/com/vaadin/client/ui/VAbstractDateFieldCalendar.java index a5e4733644..420ad8c88f 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractDateFieldCalendar.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractDateFieldCalendar.java @@ -16,8 +16,6 @@ package com.vaadin.client.ui; -import com.google.gwt.event.dom.client.DomEvent; -import com.vaadin.client.ui.VAbstractCalendarPanel.FocusOutListener; import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; /** @@ -46,12 +44,9 @@ public abstract class VAbstractDateFieldCalendar<PANEL extends VAbstractCalendar } }); - calendarPanel.setFocusOutListener(new FocusOutListener() { - @Override - public boolean onFocusOut(DomEvent<?> event) { - updateValueFromPanel(); - return false; - } + calendarPanel.setFocusOutListener(event -> { + updateValueFromPanel(); + return false; }); } diff --git a/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java b/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java index 70ada4d70e..0ca3693286 100644 --- a/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java +++ b/client/src/main/java/com/vaadin/client/ui/VAbstractPopupCalendar.java @@ -24,7 +24,6 @@ import com.google.gwt.aria.client.Roles; import com.google.gwt.dom.client.Element; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.DomEvent; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.MouseOutEvent; import com.google.gwt.event.dom.client.MouseOutHandler; @@ -47,7 +46,6 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.BrowserInfo; import com.vaadin.client.ComputedStyle; import com.vaadin.client.VConsole; -import com.vaadin.client.ui.VAbstractCalendarPanel.FocusOutListener; import com.vaadin.client.ui.VAbstractCalendarPanel.SubmitListener; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.shared.ui.datefield.TextualDateFieldState; @@ -141,13 +139,10 @@ public abstract class VAbstractPopupCalendar<PANEL extends VAbstractCalendarPane calendar = calendarPanel; calendar.setParentField(this); - calendar.setFocusOutListener(new FocusOutListener() { - @Override - public boolean onFocusOut(DomEvent<?> event) { - event.preventDefault(); - closeCalendarPanel(); - return true; - } + calendar.setFocusOutListener(event -> { + event.preventDefault(); + closeCalendarPanel(); + return true; }); // FIXME: Problem is, that the element with the provided id does not diff --git a/client/src/main/java/com/vaadin/client/ui/VDateField.java b/client/src/main/java/com/vaadin/client/ui/VDateField.java index 0db91149ae..b4780955f9 100644 --- a/client/src/main/java/com/vaadin/client/ui/VDateField.java +++ b/client/src/main/java/com/vaadin/client/ui/VDateField.java @@ -270,7 +270,8 @@ public abstract class VDateField<R extends Enum<R>> extends FlowPanel public void sendBufferedValues() { rpc.update(bufferedDateString, bufferedResolutions.entrySet().stream().collect(Collectors - .toMap(e -> e.getKey().name(), e -> e.getValue()))); + .toMap(e -> e.getKey().name(), + e -> e.getValue()))); bufferedDateString = null; bufferedResolutions.clear(); } diff --git a/client/src/main/java/com/vaadin/client/ui/VNotification.java b/client/src/main/java/com/vaadin/client/ui/VNotification.java index 37255ff4bb..494dc8b228 100644 --- a/client/src/main/java/com/vaadin/client/ui/VNotification.java +++ b/client/src/main/java/com/vaadin/client/ui/VNotification.java @@ -23,7 +23,6 @@ import java.util.List; import com.google.gwt.aria.client.Roles; import com.google.gwt.core.client.GWT; import com.google.gwt.dom.client.Element; -import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; @@ -34,7 +33,6 @@ import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.AnimationUtil; -import com.vaadin.client.AnimationUtil.AnimationEndListener; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.BrowserInfo; import com.vaadin.client.WidgetUtil; @@ -297,14 +295,10 @@ public class VNotification extends VOverlay { if (getStyleName() .contains(VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { AnimationUtil.addAnimationEndListener(getElement(), - new AnimationEndListener() { - @Override - public void onAnimationEnd(NativeEvent event) { - if (AnimationUtil.getAnimationName(event) - .contains( - VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { - VNotification.this.hide(); - } + event -> { + if (AnimationUtil.getAnimationName(event).contains( + VOverlay.ADDITIONAL_CLASSNAME_ANIMATE_IN)) { + VNotification.this.hide(); } }); } else { diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java index b98452966f..e43d7c8075 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/AbstractInlineDateFieldConnector.java @@ -21,7 +21,6 @@ import com.vaadin.client.ApplicationConnection; import com.vaadin.client.UIDL; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.VAbstractCalendarPanel; -import com.vaadin.client.ui.VAbstractCalendarPanel.FocusChangeListener; import com.vaadin.client.ui.VAbstractDateFieldCalendar; import com.vaadin.shared.ui.datefield.InlineDateFieldState; @@ -50,25 +49,22 @@ public abstract class AbstractInlineDateFieldConnector<PANEL extends VAbstractCa protected void updateListeners() { if (isResolutionMonthOrHigher()) { getWidget().calendarPanel - .setFocusChangeListener(new FocusChangeListener() { - @Override - public void focusChanged(Date date) { - Date date2 = new Date(); - if (getWidget().calendarPanel.getDate() != null) { - date2.setTime(getWidget().calendarPanel - .getDate().getTime()); - } - /* - * Update the value of calendarPanel - */ - date2.setYear(date.getYear()); - date2.setMonth(date.getMonth()); - getWidget().calendarPanel.setDate(date2); - /* - * Then update the value from panel to server - */ - getWidget().updateValueFromPanel(); + .setFocusChangeListener(date -> { + Date date2 = new Date(); + if (getWidget().calendarPanel.getDate() != null) { + date2.setTime(getWidget().calendarPanel.getDate() + .getTime()); } + /* + * Update the value of calendarPanel + */ + date2.setYear(date.getYear()); + date2.setMonth(date.getMonth()); + getWidget().calendarPanel.setDate(date2); + /* + * Then update the value from panel to server + */ + getWidget().updateValueFromPanel(); }); } else { getWidget().calendarPanel.setFocusChangeListener(null); diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/DateTimeFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/DateTimeFieldConnector.java index 5e46fe5372..18a7f9c0ef 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/DateTimeFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/DateTimeFieldConnector.java @@ -19,7 +19,6 @@ import java.util.Date; import com.vaadin.client.DateTimeService; import com.vaadin.client.ui.VDateTimeCalendarPanel; -import com.vaadin.client.ui.VDateTimeCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VPopupTimeCalendar; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.datefield.DateTimeResolution; @@ -58,29 +57,24 @@ public class DateTimeFieldConnector extends if (getWidget().getCurrentResolution() .compareTo(DateTimeResolution.DAY) < 0) { getWidget().calendar - .setTimeChangeListener(new TimeChangeListener() { - @Override - public void changed(int hour, int min, int sec, - int msec) { - Date d = getWidget().getDate(); - if (d == null) { - // date currently null, use the value from - // calendarPanel - // (~ client time at the init of the widget) - d = (Date) getWidget().calendar.getDate() - .clone(); - } - d.setHours(hour); - d.setMinutes(min); - d.setSeconds(sec); - DateTimeService.setMilliseconds(d, msec); + .setTimeChangeListener((hour, min, sec, msec) -> { + Date d = getWidget().getDate(); + if (d == null) { + // date currently null, use the value from + // calendarPanel + // (~ client time at the init of the widget) + d = (Date) getWidget().calendar.getDate().clone(); + } + d.setHours(hour); + d.setMinutes(min); + d.setSeconds(sec); + DateTimeService.setMilliseconds(d, msec); - // Always update time changes to the server - getWidget().updateValue(d); + // Always update time changes to the server + getWidget().updateValue(d); - // Update text field - getWidget().buildDate(); - } + // Update text field + getWidget().buildDate(); }); } } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateTimeFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateTimeFieldConnector.java index 1d3146b652..086363f344 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateTimeFieldConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/InlineDateTimeFieldConnector.java @@ -19,7 +19,6 @@ import java.util.Date; import com.vaadin.client.DateTimeService; import com.vaadin.client.ui.VDateTimeCalendarPanel; -import com.vaadin.client.ui.VDateTimeCalendarPanel.TimeChangeListener; import com.vaadin.client.ui.VDateTimeFieldCalendar; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.datefield.DateTimeResolution; @@ -52,27 +51,23 @@ public class InlineDateTimeFieldConnector extends if (getWidget().getCurrentResolution() .compareTo(DateTimeResolution.DAY) < 0) { getWidget().calendarPanel - .setTimeChangeListener(new TimeChangeListener() { - @Override - public void changed(int hour, int min, int sec, - int msec) { - Date d = getWidget().getDate(); - if (d == null) { - // date currently null, use the value from - // calendarPanel - // (~ client time at the init of the widget) - d = (Date) getWidget().calendarPanel.getDate() - .clone(); - } - d.setHours(hour); - d.setMinutes(min); - d.setSeconds(sec); - DateTimeService.setMilliseconds(d, msec); - - // Always update time changes to the server - getWidget().calendarPanel.setDate(d); - getWidget().updateValueFromPanel(); + .setTimeChangeListener((hour, min, sec, msec) -> { + Date d = getWidget().getDate(); + if (d == null) { + // date currently null, use the value from + // calendarPanel + // (~ client time at the init of the widget) + d = (Date) getWidget().calendarPanel.getDate() + .clone(); } + d.setHours(hour); + d.setMinutes(min); + d.setSeconds(sec); + DateTimeService.setMilliseconds(d, msec); + + // Always update time changes to the server + getWidget().calendarPanel.setDate(d); + getWidget().updateValueFromPanel(); }); } } diff --git a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java index 546b1220a5..c7cfdef71d 100644 --- a/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/datefield/TextualDateConnector.java @@ -80,16 +80,13 @@ public abstract class TextualDateConnector<PANEL extends VAbstractCalendarPanel< protected void updateListeners() { FocusChangeListener listener; if (isResolutionMonthOrHigher()) { - listener = new FocusChangeListener() { - @Override - public void focusChanged(Date date) { - if (isResolutionMonthOrHigher()) { - getWidget().updateValue(date); - getWidget().buildDate(); - Date date2 = getWidget().calendar.getDate(); - date2.setYear(date.getYear()); - date2.setMonth(date.getMonth()); - } + listener = date -> { + if (isResolutionMonthOrHigher()) { + getWidget().updateValue(date); + getWidget().buildDate(); + Date date2 = getWidget().calendar.getDate(); + date2.setYear(date.getYear()); + date2.setMonth(date.getMonth()); } }; } else { diff --git a/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java b/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java index 000966bde7..37c87de489 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java @@ -19,7 +19,6 @@ import com.google.gwt.dom.client.DivElement; import com.google.gwt.dom.client.Element; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; import com.vaadin.client.WidgetUtil; import com.vaadin.client.ui.dd.DragAndDropHandler.DragAndDropCallback; @@ -170,12 +169,9 @@ public class DragHandle { dndHandler = new DragAndDropHandler(); DOM.sinkEvents(element, Event.ONMOUSEDOWN | Event.ONTOUCHSTART); - DOM.setEventListener(element, new EventListener() { - @Override - public void onBrowserEvent(Event event) { - dndHandler.onDragStartOnDraggableElement(event, dndCallback); - event.stopPropagation(); - } + DOM.setEventListener(element, event -> { + dndHandler.onDragStartOnDraggableElement(event, dndCallback); + event.stopPropagation(); }); } diff --git a/client/src/main/java/com/vaadin/client/ui/flash/FlashConnector.java b/client/src/main/java/com/vaadin/client/ui/flash/FlashConnector.java index fd03aec4b6..b020ac95a1 100644 --- a/client/src/main/java/com/vaadin/client/ui/flash/FlashConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/flash/FlashConnector.java @@ -19,7 +19,6 @@ import com.google.gwt.dom.client.Element; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractComponentConnector; import com.vaadin.client.ui.VFlash; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.ui.AbstractEmbeddedState; import com.vaadin.shared.ui.Connect; @@ -55,12 +54,10 @@ public class FlashConnector extends AbstractComponentConnector { getWidget().rebuildIfNeeded(); } - private final ElementResizeListener listener = new ElementResizeListener() { - public void onElementResize(ElementResizeEvent e) { - Element slot = e.getElement().getParentElement(); - getWidget().setSlotHeightAndWidth(slot.getOffsetHeight(), - slot.getOffsetWidth()); - } + private final ElementResizeListener listener = event -> { + Element slot = event.getElement().getParentElement(); + getWidget().setSlotHeightAndWidth(slot.getOffsetHeight(), + slot.getOffsetWidth()); }; @Override diff --git a/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java b/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java index 857d4e07b3..c66686928e 100644 --- a/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java @@ -35,7 +35,6 @@ import com.vaadin.client.ui.VFormLayout; import com.vaadin.client.ui.VFormLayout.Caption; import com.vaadin.client.ui.VFormLayout.ErrorFlag; import com.vaadin.client.ui.VFormLayout.VFormLayoutTable; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.LayoutClickRpc; @@ -70,70 +69,62 @@ public class FormLayoutConnector extends AbstractLayoutConnector private Map<ComponentConnector, String> oldMaxWidths = null; - private static final ElementResizeListener DUMMY_FIRST_CELL_RESIZE_LISTENER = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - // Ignore event, listener added just to make measurements available - } + private static final ElementResizeListener DUMMY_FIRST_CELL_RESIZE_LISTENER = event -> { + // Ignore event, listener added just to make measurements available }; // Detects situations when there's something inside the FormLayout that // prevents it from shrinking - private ElementResizeListener resizeListener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - LayoutManager layoutManager = getLayoutManager(); - double tableWidth = layoutManager - .getOuterWidthDouble(getWidget().table.getElement()); - double ownWidth = layoutManager - .getInnerWidthDouble(getWidget().getElement()); - if (ownWidth < tableWidth) { - // Something inside the table prevents it from shrinking, - // temporarily force column widths - double excessWidth = tableWidth - ownWidth; - - // All td elements in the component column have the same width, - // so we only need to check the width of the first one to know - // how wide the column is. - Element firstComponentTd = findFirstComponentTd(); - if (firstComponentTd == null) { - // Can't do anything if there are no rows - return; - } + private ElementResizeListener resizeListener = event -> { + LayoutManager layoutManager = getLayoutManager(); + double tableWidth = layoutManager + .getOuterWidthDouble(getWidget().table.getElement()); + double ownWidth = layoutManager + .getInnerWidthDouble(getWidget().getElement()); + if (ownWidth < tableWidth) { + // Something inside the table prevents it from shrinking, + // temporarily force column widths + double excessWidth = tableWidth - ownWidth; + + // All td elements in the component column have the same width, + // so we only need to check the width of the first one to know + // how wide the column is. + Element firstComponentTd = findFirstComponentTd(); + if (firstComponentTd == null) { + // Can't do anything if there are no rows + return; + } - double componentColWidth = layoutManager - .getOuterWidthDouble(firstComponentTd); + double componentColWidth = layoutManager + .getOuterWidthDouble(firstComponentTd); - if (componentColWidth == -1) { - // Didn't get a proper width reading, best to not touch - // anything - return; - } + if (componentColWidth == -1) { + // Didn't get a proper width reading, best to not touch + // anything + return; + } - // Restrict content td width - // Round down to prevent interactions with fractional sizes of - // other columns - int targetWidth = (int) Math - .floor(componentColWidth - excessWidth); + // Restrict content td width + // Round down to prevent interactions with fractional sizes of + // other columns + int targetWidth = (int) Math.floor(componentColWidth - excessWidth); - // Target might be negative if captions are wider than the total - // available width - targetWidth = Math.max(0, targetWidth); + // Target might be negative if captions are wider than the total + // available width + targetWidth = Math.max(0, targetWidth); - if (oldMaxWidths == null) { - oldMaxWidths = new HashMap<>(); - } + if (oldMaxWidths == null) { + oldMaxWidths = new HashMap<>(); + } - for (ComponentConnector child : getChildComponents()) { - Element childElement = child.getWidget().getElement(); - if (!oldMaxWidths.containsKey(child)) { - oldMaxWidths.put(child, - childElement.getPropertyString("maxWidth")); - } - childElement.getStyle().setPropertyPx("maxWidth", - targetWidth); - layoutManager.reportOuterWidth(child, targetWidth); + for (ComponentConnector child : getChildComponents()) { + Element childElement = child.getWidget().getElement(); + if (!oldMaxWidths.containsKey(child)) { + oldMaxWidths.put(child, + childElement.getPropertyString("maxWidth")); } + childElement.getStyle().setPropertyPx("maxWidth", targetWidth); + layoutManager.reportOuterWidth(child, targetWidth); } } }; diff --git a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java index 7d363fbeac..c814a72fdf 100644 --- a/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/nativeselect/NativeSelectConnector.java @@ -54,7 +54,7 @@ public class NativeSelectConnector protected void init() { super.init(); selectionChangeRegistration = getWidget().getListBox() - .addChangeHandler(e -> selectionRpc + .addChangeHandler(event -> selectionRpc .select(getWidget().getListBox().getSelectedValue())); } diff --git a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java index 21ffec2507..ca008d0087 100644 --- a/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/optiongroup/RadioButtonGroupConnector.java @@ -57,7 +57,7 @@ public class RadioButtonGroupConnector super.init(); selectionChangeRegistration = getWidget().addSelectionChangeHandler( - e -> selectionRpc.select(getRowKey(e))); + event -> selectionRpc.select(getRowKey(event))); } @Override 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 3e8fc0eb8f..29634b983f 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 @@ -38,7 +38,6 @@ import com.vaadin.client.ui.HasRequiredIndicator; import com.vaadin.client.ui.Icon; import com.vaadin.client.ui.LayoutClickEventHandler; import com.vaadin.client.ui.aria.AriaHelper; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.communication.URLReference; @@ -96,73 +95,64 @@ public abstract class AbstractOrderedLayoutConnector } }; - private ElementResizeListener slotCaptionResizeListener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { + private ElementResizeListener slotCaptionResizeListener = event -> { - // Get all needed element references - Element captionElement = e.getElement(); + // Get all needed element references + Element captionElement = event.getElement(); - // Caption position determines if the widget element is the first or - // last child inside the caption wrap - CaptionPosition pos = getWidget().getCaptionPositionFromElement( - captionElement.getParentElement()); + // Caption position determines if the widget element is the first or + // last child inside the caption wrap + CaptionPosition pos = getWidget().getCaptionPositionFromElement( + captionElement.getParentElement()); - // The default is the last child - Element widgetElement = captionElement.getParentElement() - .getLastChild().cast(); + // The default is the last child + Element widgetElement = captionElement.getParentElement().getLastChild() + .cast(); - // ...but if caption position is bottom or right, the widget is the - // first child - if (pos == CaptionPosition.BOTTOM || pos == CaptionPosition.RIGHT) { - widgetElement = captionElement.getParentElement() - .getFirstChildElement().cast(); - } + // ...but if caption position is bottom or right, the widget is the + // first child + if (pos == CaptionPosition.BOTTOM || pos == CaptionPosition.RIGHT) { + widgetElement = captionElement.getParentElement() + .getFirstChildElement().cast(); + } - if (captionElement == widgetElement) { - // Caption element already detached - Slot slot = getWidget().getSlot(widgetElement); - if (slot != null) { - slot.setCaptionResizeListener(null); - } - return; + if (captionElement == widgetElement) { + // Caption element already detached + Slot slot = getWidget().getSlot(widgetElement); + if (slot != null) { + slot.setCaptionResizeListener(null); } + return; + } - String widgetWidth = widgetElement.getStyle().getWidth(); - String widgetHeight = widgetElement.getStyle().getHeight(); + String widgetWidth = widgetElement.getStyle().getWidth(); + String widgetHeight = widgetElement.getStyle().getHeight(); - if (widgetHeight.endsWith("%") && (pos == CaptionPosition.TOP - || pos == CaptionPosition.BOTTOM)) { - getWidget().updateCaptionOffset(captionElement); - } else if (widgetWidth.endsWith("%") && (pos == CaptionPosition.LEFT - || pos == CaptionPosition.RIGHT)) { - getWidget().updateCaptionOffset(captionElement); - } + if (widgetHeight.endsWith("%") && (pos == CaptionPosition.TOP + || pos == CaptionPosition.BOTTOM)) { + getWidget().updateCaptionOffset(captionElement); + } else if (widgetWidth.endsWith("%") && (pos == CaptionPosition.LEFT + || pos == CaptionPosition.RIGHT)) { + getWidget().updateCaptionOffset(captionElement); + } - updateLayoutHeight(); + updateLayoutHeight(); - if (needsExpand()) { - getWidget().updateExpandCompensation(); - } + if (needsExpand()) { + getWidget().updateExpandCompensation(); } }; - private ElementResizeListener childComponentResizeListener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - updateLayoutHeight(); - if (needsExpand()) { - getWidget().updateExpandCompensation(); - } + private ElementResizeListener childComponentResizeListener = event -> { + updateLayoutHeight(); + if (needsExpand()) { + getWidget().updateExpandCompensation(); } }; - private ElementResizeListener spacingResizeListener = new ElementResizeListener() { - @Override - public void onElementResize(ElementResizeEvent e) { - if (needsExpand()) { - getWidget().updateExpandCompensation(); - } + private ElementResizeListener spacingResizeListener = event -> { + if (needsExpand()) { + getWidget().updateExpandCompensation(); } }; diff --git a/client/src/main/java/com/vaadin/client/ui/slider/SliderConnector.java b/client/src/main/java/com/vaadin/client/ui/slider/SliderConnector.java index a77870ec2f..078b60dc9c 100644 --- a/client/src/main/java/com/vaadin/client/ui/slider/SliderConnector.java +++ b/client/src/main/java/com/vaadin/client/ui/slider/SliderConnector.java @@ -21,7 +21,6 @@ import com.vaadin.client.communication.RpcProxy; import com.vaadin.client.communication.StateChangeEvent; import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.VSlider; -import com.vaadin.client.ui.layout.ElementResizeEvent; import com.vaadin.client.ui.layout.ElementResizeListener; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.slider.SliderServerRpc; @@ -35,13 +34,8 @@ public class SliderConnector extends AbstractFieldConnector protected SliderServerRpc rpc = RpcProxy.create(SliderServerRpc.class, this); - private final ElementResizeListener resizeListener = new ElementResizeListener() { - - @Override - public void onElementResize(ElementResizeEvent e) { - getWidget().iLayout(); - } - }; + private final ElementResizeListener resizeListener = event -> getWidget() + .iLayout(); @Override public void init() { 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 c979325f7e..a425da2231 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 @@ -31,7 +31,6 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.EventListener; import com.google.gwt.user.client.Timer; import com.vaadin.client.BrowserInfo; import com.vaadin.client.DeferredWorker; @@ -727,12 +726,9 @@ public abstract class ScrollbarBundle implements DeferredWorker { if (isInvisibleScrollbar) { Event.sinkEvents(root, Event.ONSCROLL); - Event.setEventListener(root, new EventListener() { - @Override - public void onBrowserEvent(Event event) { - invisibleScrollbarTemporaryResizer.show(); - } - }); + Event.setEventListener(root, + event -> invisibleScrollbarTemporaryResizer.show()); + root.getStyle().setVisibility(Visibility.HIDDEN); } else { Event.sinkEvents(root, 0); |