Bladeren bron

Use lambdas where appropriate

Change-Id: I80b73b653e97904605dc62484a7448f3bfbf722d
tags/8.0.0.alpha7
Per-Åke Minborg 7 jaren geleden
bovenliggende
commit
25eba3c796
38 gewijzigde bestanden met toevoegingen van 346 en 560 verwijderingen
  1. 22
    28
      server/src/main/java/com/vaadin/server/AbstractClientConnector.java
  2. 6
    9
      server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java
  3. 7
    11
      server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java
  4. 6
    10
      server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java
  5. 37
    50
      server/src/main/java/com/vaadin/server/VaadinService.java
  6. 3
    6
      server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java
  7. 17
    20
      server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java
  8. 72
    78
      server/src/main/java/com/vaadin/server/communication/PushHandler.java
  9. 2
    5
      server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java
  10. 9
    14
      server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java
  11. 5
    8
      server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
  12. 4
    9
      server/src/main/java/com/vaadin/ui/AbsoluteLayout.java
  13. 1
    7
      server/src/main/java/com/vaadin/ui/AbstractColorPicker.java
  14. 3
    6
      server/src/main/java/com/vaadin/ui/AbstractComponent.java
  15. 5
    10
      server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java
  16. 22
    28
      server/src/main/java/com/vaadin/ui/CheckBox.java
  17. 3
    8
      server/src/main/java/com/vaadin/ui/CssLayout.java
  18. 2
    6
      server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java
  19. 2
    5
      server/src/main/java/com/vaadin/ui/Embedded.java
  20. 3
    9
      server/src/main/java/com/vaadin/ui/GridLayout.java
  21. 2
    5
      server/src/main/java/com/vaadin/ui/Image.java
  22. 7
    10
      server/src/main/java/com/vaadin/ui/JavaScript.java
  23. 1
    6
      server/src/main/java/com/vaadin/ui/LoginForm.java
  24. 2
    5
      server/src/main/java/com/vaadin/ui/Panel.java
  25. 1
    7
      server/src/main/java/com/vaadin/ui/PopupView.java
  26. 24
    29
      server/src/main/java/com/vaadin/ui/Slider.java
  27. 1
    7
      server/src/main/java/com/vaadin/ui/TabSheet.java
  28. 2
    5
      server/src/main/java/com/vaadin/ui/declarative/Design.java
  29. 2
    6
      server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java
  30. 7
    13
      server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java
  31. 6
    10
      server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java
  32. 27
    37
      server/src/test/java/com/vaadin/server/VaadinSessionTest.java
  33. 1
    8
      server/src/test/java/com/vaadin/tests/VaadinClasses.java
  34. 19
    43
      server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java
  35. 1
    7
      server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java
  36. 4
    10
      server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java
  37. 4
    11
      server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java
  38. 4
    14
      server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java

+ 22
- 28
server/src/main/java/com/vaadin/server/AbstractClientConnector.java Bestand weergeven

@@ -537,36 +537,30 @@ public abstract class AbstractClientConnector
final Iterator<Component> componentsIterator = ((HasComponents) connector)
.iterator();
final Iterator<Extension> extensionsIterator = extensions.iterator();
Iterable<? extends ClientConnector> combinedIterable = new Iterable<ClientConnector>() {
Iterable<? extends ClientConnector> combinedIterable = () -> new Iterator<ClientConnector>() {
@Override
public Iterator<ClientConnector> iterator() {
return new Iterator<ClientConnector>() {

@Override
public boolean hasNext() {
return componentsIterator.hasNext()
|| extensionsIterator.hasNext();
}

@Override
public ClientConnector next() {
if (componentsIterator.hasNext()) {
return componentsIterator.next();
}
if (extensionsIterator.hasNext()) {
return extensionsIterator.next();
}
throw new NoSuchElementException();
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}

};
public boolean hasNext() {
return componentsIterator.hasNext()
|| extensionsIterator.hasNext();
}
@Override
public ClientConnector next() {
if (componentsIterator.hasNext()) {
return componentsIterator.next();
}
if (extensionsIterator.hasNext()) {
return extensionsIterator.next();
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return combinedIterable;
}

+ 6
- 9
server/src/main/java/com/vaadin/server/JavaScriptCallbackHelper.java Bestand weergeven

@@ -72,15 +72,12 @@ public class JavaScriptCallbackHelper implements Serializable {

private void ensureRpc() {
if (javascriptCallbackRpc == null) {
javascriptCallbackRpc = new JavaScriptCallbackRpc() {
@Override
public void call(String name, JsonArray arguments) {
JavaScriptFunction callback = callbacks.get(name);
try {
callback.call(arguments);
} catch (JsonException e) {
throw new IllegalArgumentException(e);
}
javascriptCallbackRpc = (String name, JsonArray arguments) -> {
JavaScriptFunction callback = callbacks.get(name);
try {
callback.call(arguments);
} catch (JsonException e) {
throw new IllegalArgumentException(e);
}
};
connector.registerRpc(javascriptCallbackRpc);

+ 7
- 11
server/src/main/java/com/vaadin/server/LegacyVaadinPortlet.java Bestand weergeven

@@ -46,17 +46,13 @@ public class LegacyVaadinPortlet extends VaadinPortlet {
public void init(PortletConfig portletConfig) throws PortletException {
super.init(portletConfig);

getService().addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent event)
throws ServiceException {
try {
onVaadinSessionStarted(
(VaadinPortletRequest) event.getRequest(),
(VaadinPortletSession) event.getSession());
} catch (PortletException e) {
throw new ServiceException(e);
}
getService().addSessionInitListener((SessionInitEvent event) -> {
try {
onVaadinSessionStarted(
(VaadinPortletRequest) event.getRequest(),
(VaadinPortletSession) event.getSession());
} catch (PortletException e) {
throw new ServiceException(e);
}
});
}

+ 6
- 10
server/src/main/java/com/vaadin/server/LegacyVaadinServlet.java Bestand weergeven

@@ -47,16 +47,12 @@ public class LegacyVaadinServlet extends VaadinServlet {
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);

getService().addSessionInitListener(new SessionInitListener() {
@Override
public void sessionInit(SessionInitEvent event)
throws ServiceException {
try {
onVaadinSessionStarted(event.getRequest(),
event.getSession());
} catch (ServletException e) {
throw new ServiceException(e);
}
getService().addSessionInitListener((SessionInitEvent event) -> {
try {
onVaadinSessionStarted(event.getRequest(),
event.getSession());
} catch (ServletException e) {
throw new ServiceException(e);
}
});
}

+ 37
- 50
server/src/main/java/com/vaadin/server/VaadinService.java Bestand weergeven

@@ -457,42 +457,35 @@ public abstract class VaadinService implements Serializable {
*/
public void fireSessionDestroy(VaadinSession vaadinSession) {
final VaadinSession session = vaadinSession;
session.access(new Runnable() {
@Override
public void run() {
if (session.getState() == State.CLOSED) {
return;
}
if (session.getState() == State.OPEN) {
closeSession(session);
}
ArrayList<UI> uis = new ArrayList<>(session.getUIs());
for (final UI ui : uis) {
ui.accessSynchronously(new Runnable() {
@Override
public void run() {
/*
* close() called here for consistency so that it is
* always called before a UI is removed.
* UI.isClosing() is thus always true in UI.detach()
* and associated detach listeners.
*/
if (!ui.isClosing()) {
ui.close();
}
session.removeUI(ui);
}
});
}
// for now, use the session error handler; in the future, could
// have an API for using some other handler for session init and
// destroy listeners
eventRouter.fireEvent(
new SessionDestroyEvent(VaadinService.this, session),
session.getErrorHandler());

session.setState(State.CLOSED);
session.access(() -> {
if (session.getState() == State.CLOSED) {
return;
}
if (session.getState() == State.OPEN) {
closeSession(session);
}
ArrayList<UI> uis = new ArrayList<>(session.getUIs());
for (final UI ui : uis) {
ui.accessSynchronously(() -> {
/*
* close() called here for consistency so that it is
* always called before a UI is removed.
* UI.isClosing() is thus always true in UI.detach()
* and associated detach listeners.
*/
if (!ui.isClosing()) {
ui.close();
}
session.removeUI(ui);
});
}
// for now, use the session error handler; in the future, could
// have an API for using some other handler for session init and
// destroy listeners
eventRouter.fireEvent(
new SessionDestroyEvent(VaadinService.this, session),
session.getErrorHandler());
session.setState(State.CLOSED);
});
}

@@ -1193,13 +1186,10 @@ public abstract class VaadinService implements Serializable {
ArrayList<UI> uis = new ArrayList<>(session.getUIs());
for (final UI ui : uis) {
if (ui.isClosing()) {
ui.accessSynchronously(new Runnable() {
@Override
public void run() {
getLogger().log(Level.FINER, "Removing closed UI {0}",
ui.getUIId());
session.removeUI(ui);
}
ui.accessSynchronously(() -> {
getLogger().log(Level.FINER, "Removing closed UI {0}",
ui.getUIId());
session.removeUI(ui);
});
}
}
@@ -1215,14 +1205,11 @@ public abstract class VaadinService implements Serializable {
final String sessionId = session.getSession().getId();
for (final UI ui : session.getUIs()) {
if (!isUIActive(ui) && !ui.isClosing()) {
ui.accessSynchronously(new Runnable() {
@Override
public void run() {
getLogger().log(Level.FINE,
"Closing inactive UI #{0} in session {1}",
new Object[] { ui.getUIId(), sessionId });
ui.close();
}
ui.accessSynchronously(() -> {
getLogger().log(Level.FINE,
"Closing inactive UI #{0} in session {1}",
new Object[] { ui.getUIId(), sessionId });
ui.close();
});
}
}

+ 3
- 6
server/src/main/java/com/vaadin/server/communication/FileUploadHandler.java Bestand weergeven

@@ -686,12 +686,9 @@ public class FileUploadHandler implements RequestHandler {

private void cleanStreamVariable(VaadinSession session, final UI ui,
final ClientConnector owner, final String variableName) {
session.accessSynchronously(new Runnable() {
@Override
public void run() {
ui.getConnectorTracker().cleanStreamVariable(
owner.getConnectorId(), variableName);
}
session.accessSynchronously(() -> {
ui.getConnectorTracker().cleanStreamVariable(
owner.getConnectorId(), variableName);
});
}
}

+ 17
- 20
server/src/main/java/com/vaadin/server/communication/LegacyUidlWriter.java Bestand weergeven

@@ -89,27 +89,24 @@ public class LegacyUidlWriter implements Serializable {
// Vaadin 6 requires parents to be painted before children as component
// containers rely on that their updateFromUIDL method has been called
// before children start calling e.g. updateCaption
Collections.sort(paintables, new Comparator<Component>() {
@Override
public int compare(Component c1, Component c2) {
int depth1 = 0;
while (c1.getParent() != null) {
depth1++;
c1 = c1.getParent();
}
int depth2 = 0;
while (c2.getParent() != null) {
depth2++;
c2 = c2.getParent();
}
if (depth1 < depth2) {
return -1;
}
if (depth1 > depth2) {
return 1;
}
return 0;
Collections.sort(paintables, (Component c1, Component c2) -> {
int depth1 = 0;
while (c1.getParent() != null) {
depth1++;
c1 = c1.getParent();
}
int depth2 = 0;
while (c2.getParent() != null) {
depth2++;
c2 = c2.getParent();
}
if (depth1 < depth2) {
return -1;
}
if (depth1 > depth2) {
return 1;
}
return 0;
});
}


+ 72
- 78
server/src/main/java/com/vaadin/server/communication/PushHandler.java Bestand weergeven

@@ -71,43 +71,40 @@ public class PushHandler {
* open by calling resource.suspend(). If there is a pending push, send it
* now.
*/
private final PushEventCallback establishCallback = new PushEventCallback() {
@Override
public void run(AtmosphereResource resource, UI ui) throws IOException {
getLogger().log(Level.FINER,
"New push connection for resource {0} with transport {1}",
new Object[] { resource.uuid(), resource.transport() });

resource.getResponse().setContentType("text/plain; charset=UTF-8");

VaadinSession session = ui.getSession();
if (resource.transport() == TRANSPORT.STREAMING) {
// Must ensure that the streaming response contains
// "Connection: close", otherwise iOS 6 will wait for the
// response to this request before sending another request to
// the same server (as it will apparently try to reuse the same
// connection)
resource.getResponse().addHeader("Connection", "close");
}

String requestToken = resource.getRequest()
.getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER);
if (!VaadinService.isCsrfTokenValid(session, requestToken)) {
getLogger().log(Level.WARNING,
"Invalid CSRF token in new connection received from {0}",
resource.getRequest().getRemoteHost());
// Refresh on client side, create connection just for
// sending a message
sendRefreshAndDisconnect(resource);
return;
}

suspend(resource);

AtmospherePushConnection connection = getConnectionForUI(ui);
assert (connection != null);
connection.connect(resource);
private final PushEventCallback establishCallback = (AtmosphereResource resource, UI ui) -> {
getLogger().log(Level.FINER,
"New push connection for resource {0} with transport {1}",
new Object[] { resource.uuid(), resource.transport() });
resource.getResponse().setContentType("text/plain; charset=UTF-8");
VaadinSession session = ui.getSession();
if (resource.transport() == TRANSPORT.STREAMING) {
// Must ensure that the streaming response contains
// "Connection: close", otherwise iOS 6 will wait for the
// response to this request before sending another request to
// the same server (as it will apparently try to reuse the same
// connection)
resource.getResponse().addHeader("Connection", "close");
}
String requestToken = resource.getRequest()
.getParameter(ApplicationConstants.CSRF_TOKEN_PARAMETER);
if (!VaadinService.isCsrfTokenValid(session, requestToken)) {
getLogger().log(Level.WARNING,
"Invalid CSRF token in new connection received from {0}",
resource.getRequest().getRemoteHost());
// Refresh on client side, create connection just for
// sending a message
sendRefreshAndDisconnect(resource);
return;
}
suspend(resource);
AtmospherePushConnection connection = getConnectionForUI(ui);
assert (connection != null);
connection.connect(resource);
};

/**
@@ -117,48 +114,45 @@ public class PushHandler {
* the request and send changed UI state via the push channel (we do not
* respond to the request directly.)
*/
private final PushEventCallback receiveCallback = new PushEventCallback() {
@Override
public void run(AtmosphereResource resource, UI ui) throws IOException {
getLogger().log(Level.FINER, "Received message from resource {0}",
resource.uuid());

AtmosphereRequest req = resource.getRequest();

AtmospherePushConnection connection = getConnectionForUI(ui);

assert connection != null : "Got push from the client "
+ "even though the connection does not seem to be "
+ "valid. This might happen if a HttpSession is "
+ "serialized and deserialized while the push "
+ "connection is kept open or if the UI has a "
+ "connection of unexpected type.";

Reader reader = connection.receiveMessage(req.getReader());
if (reader == null) {
// The whole message was not yet received
return;
}

// Should be set up by caller
VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
assert vaadinRequest != null;

try {
new ServerRpcHandler().handleRpc(ui, reader, vaadinRequest);
connection.push(false);
} catch (JsonException e) {
getLogger().log(Level.SEVERE, "Error writing JSON to response",
e);
// Refresh on client side
sendRefreshAndDisconnect(resource);
} catch (InvalidUIDLSecurityKeyException e) {
getLogger().log(Level.WARNING,
"Invalid security key received from {0}",
resource.getRequest().getRemoteHost());
// Refresh on client side
sendRefreshAndDisconnect(resource);
}
private final PushEventCallback receiveCallback = (AtmosphereResource resource, UI ui) -> {
getLogger().log(Level.FINER, "Received message from resource {0}",
resource.uuid());
AtmosphereRequest req = resource.getRequest();
AtmospherePushConnection connection = getConnectionForUI(ui);
assert connection != null : "Got push from the client "
+ "even though the connection does not seem to be "
+ "valid. This might happen if a HttpSession is "
+ "serialized and deserialized while the push "
+ "connection is kept open or if the UI has a "
+ "connection of unexpected type.";
Reader reader = connection.receiveMessage(req.getReader());
if (reader == null) {
// The whole message was not yet received
return;
}
// Should be set up by caller
VaadinRequest vaadinRequest = VaadinService.getCurrentRequest();
assert vaadinRequest != null;
try {
new ServerRpcHandler().handleRpc(ui, reader, vaadinRequest);
connection.push(false);
} catch (JsonException e) {
getLogger().log(Level.SEVERE, "Error writing JSON to response",
e);
// Refresh on client side
sendRefreshAndDisconnect(resource);
} catch (InvalidUIDLSecurityKeyException e) {
getLogger().log(Level.WARNING,
"Invalid security key received from {0}",
resource.getRequest().getRemoteHost());
// Refresh on client side
sendRefreshAndDisconnect(resource);
}
};


+ 2
- 5
server/src/main/java/com/vaadin/server/communication/PushRequestHandler.java Bestand weergeven

@@ -67,11 +67,8 @@ public class PushRequestHandler
public PushRequestHandler(VaadinServletService service)
throws ServiceException {

service.addServiceDestroyListener(new ServiceDestroyListener() {
@Override
public void serviceDestroy(ServiceDestroyEvent event) {
destroy();
}
service.addServiceDestroyListener((ServiceDestroyEvent event) -> {
destroy();
});

final ServletConfig vaadinServletConfig = service.getServlet()

+ 9
- 14
server/src/main/java/com/vaadin/server/themeutils/SASSAddonImportFileCreator.java Bestand weergeven

@@ -23,7 +23,6 @@ import java.io.PrintStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
@@ -101,20 +100,16 @@ public class SASSAddonImportFileCreator {
// Sort addon styles so that CSS imports are first and SCSS import
// last
List<String> paths = new ArrayList<>(addonThemes.keySet());
Collections.sort(paths, new Comparator<String>() {

@Override
public int compare(String path1, String path2) {
if (path1.toLowerCase().endsWith(".css")
&& path2.toLowerCase().endsWith(".scss")) {
return -1;
}
if (path1.toLowerCase().endsWith(".scss")
&& path2.toLowerCase().endsWith(".css")) {
return 1;
}
return 0;
Collections.sort(paths, (String path1, String path2) -> {
if (path1.toLowerCase().endsWith(".css")
&& path2.toLowerCase().endsWith(".scss")) {
return -1;
}
if (path1.toLowerCase().endsWith(".scss")
&& path2.toLowerCase().endsWith(".css")) {
return 1;
}
return 0;
});

List<String> mixins = new ArrayList<>();

+ 5
- 8
server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java Bestand weergeven

@@ -58,14 +58,11 @@ public class ClassPathExplorer {
/**
* File filter that only accepts directories.
*/
private final static FileFilter DIRECTORIES_ONLY = new FileFilter() {
@Override
public boolean accept(File f) {
if (f.exists() && f.isDirectory()) {
return true;
} else {
return false;
}
private final static FileFilter DIRECTORIES_ONLY = (File f) -> {
if (f.exists() && f.isDirectory()) {
return true;
} else {
return false;
}
};


+ 4
- 9
server/src/main/java/com/vaadin/ui/AbsoluteLayout.java Bestand weergeven

@@ -20,7 +20,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;
@@ -55,14 +54,10 @@ public class AbsoluteLayout extends AbstractLayout
private static final String ATTR_LEFT = ":left";
private static final String ATTR_Z_INDEX = ":z-index";

private AbsoluteLayoutServerRpc rpc = new AbsoluteLayoutServerRpc() {

@Override
public void layoutClick(MouseEventDetails mouseDetails,
Connector clickedConnector) {
fireEvent(LayoutClickEvent.createEvent(AbsoluteLayout.this,
mouseDetails, clickedConnector));
}
private final AbsoluteLayoutServerRpc rpc = (MouseEventDetails mouseDetails,
Connector clickedConnector) -> {
fireEvent(LayoutClickEvent.createEvent(AbsoluteLayout.this,
mouseDetails, clickedConnector));
};
// Maps each component to a position
private LinkedHashMap<Component, ComponentPosition> componentToCoordinates = new LinkedHashMap<>();

+ 1
- 7
server/src/main/java/com/vaadin/ui/AbstractColorPicker.java Bestand weergeven

@@ -87,13 +87,7 @@ public abstract class AbstractColorPicker extends AbstractField<Color> {
}
}

private ColorPickerServerRpc rpc = new ColorPickerServerRpc() {

@Override
public void openPopup(boolean open) {
showPopup(open);
}
};
private ColorPickerServerRpc rpc = this::showPopup;

protected static final String STYLENAME_DEFAULT = "v-colorpicker";
protected static final String STYLENAME_BUTTON = "v-button";

+ 3
- 6
server/src/main/java/com/vaadin/ui/AbstractComponent.java Bestand weergeven

@@ -1374,12 +1374,9 @@ public abstract class AbstractComponent extends AbstractClientConnector
// called if there are no listeners on the server-side. A client-side
// connector can override this and use a different RPC channel.
if (getRpcManager(ContextClickRpc.class.getName()) == null) {
registerRpc(new ContextClickRpc() {
@Override
public void contextClick(MouseEventDetails details) {
fireEvent(new ContextClickEvent(AbstractComponent.this,
details));
}
registerRpc((ContextClickRpc) (MouseEventDetails details) -> {
fireEvent(new ContextClickEvent(AbstractComponent.this,
details));
});
}


+ 5
- 10
server/src/main/java/com/vaadin/ui/AbstractOrderedLayout.java Bestand weergeven

@@ -44,14 +44,10 @@ public abstract class AbstractOrderedLayout extends AbstractLayout
implements Layout.AlignmentHandler, Layout.SpacingHandler,
LayoutClickNotifier, Layout.MarginHandler {

private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() {

@Override
public void layoutClick(MouseEventDetails mouseDetails,
Connector clickedConnector) {
fireEvent(LayoutClickEvent.createEvent(AbstractOrderedLayout.this,
mouseDetails, clickedConnector));
}
private final AbstractOrderedLayoutServerRpc rpc = (
MouseEventDetails mouseDetails, Connector clickedConnector) -> {
fireEvent(LayoutClickEvent.createEvent(AbstractOrderedLayout.this,
mouseDetails, clickedConnector));
};

public static final Alignment ALIGNMENT_DEFAULT = Alignment.TOP_LEFT;
@@ -507,8 +503,7 @@ public abstract class AbstractOrderedLayout extends AbstractLayout
// write default attributes
super.writeDesign(design, designContext);

AbstractOrderedLayout def = designContext
.getDefaultInstance(this);
AbstractOrderedLayout def = designContext.getDefaultInstance(this);

writeMargin(design, getMargin(), def.getMargin(), designContext);


+ 22
- 28
server/src/main/java/com/vaadin/ui/CheckBox.java Bestand weergeven

@@ -38,34 +38,28 @@ import com.vaadin.ui.declarative.DesignContext;
public class CheckBox extends AbstractField<Boolean>
implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier {

private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {

@Override
public void setChecked(boolean checked,
MouseEventDetails mouseEventDetails) {
if (isReadOnly()) {
return;
}

/*
* Client side updates the state before sending the event so we need
* to make sure the cached state is updated to match the client. If
* we do not do this, a reverting setValue() call in a listener will
* not cause the new state to be sent to the client.
*
* See #11028, #10030.
*/
getUI().getConnectorTracker().getDiffState(CheckBox.this)
.put("checked", checked);

final Boolean oldValue = getValue();
final Boolean newValue = checked;

if (!newValue.equals(oldValue)) {
// The event is only sent if the switch state is changed
setValue(newValue);
}

private CheckBoxServerRpc rpc = (boolean checked, MouseEventDetails mouseEventDetails) -> {
if (isReadOnly()) {
return;
}
/*
* Client side updates the state before sending the event so we need
* to make sure the cached state is updated to match the client. If
* we do not do this, a reverting setValue() call in a listener will
* not cause the new state to be sent to the client.
*
* See #11028, #10030.
*/
getUI().getConnectorTracker().getDiffState(CheckBox.this)
.put("checked", checked);
final Boolean oldValue = getValue();
final Boolean newValue = checked;
if (!newValue.equals(oldValue)) {
// The event is only sent if the switch state is changed
setValue(newValue);
}
};


+ 3
- 8
server/src/main/java/com/vaadin/ui/CssLayout.java Bestand weergeven

@@ -75,14 +75,9 @@ import com.vaadin.ui.declarative.DesignContext;
*/
public class CssLayout extends AbstractLayout implements LayoutClickNotifier {

private CssLayoutServerRpc rpc = new CssLayoutServerRpc() {

@Override
public void layoutClick(MouseEventDetails mouseDetails,
Connector clickedConnector) {
fireEvent(LayoutClickEvent.createEvent(CssLayout.this, mouseDetails,
clickedConnector));
}
private CssLayoutServerRpc rpc = (MouseEventDetails mouseDetails, Connector clickedConnector) -> {
fireEvent(LayoutClickEvent.createEvent(CssLayout.this, mouseDetails,
clickedConnector));
};
/**
* Custom layout slots containing the components.

+ 2
- 6
server/src/main/java/com/vaadin/ui/DragAndDropWrapper.java Bestand weergeven

@@ -112,12 +112,8 @@ public class DragAndDropWrapper extends CustomComponent

}

private final DragAndDropWrapperServerRpc rpc = new DragAndDropWrapperServerRpc() {

@Override
public void poll() {
// #19616 RPC to poll the server for changes
}
private final DragAndDropWrapperServerRpc rpc = () -> {
// #19616 RPC to poll the server for changes
};

private Map<String, ProxyReceiver> receivers = new HashMap<>();

+ 2
- 5
server/src/main/java/com/vaadin/ui/Embedded.java Bestand weergeven

@@ -104,11 +104,8 @@ public class Embedded extends AbstractComponent implements LegacyComponent {

private String altText;

private EmbeddedServerRpc rpc = new EmbeddedServerRpc() {
@Override
public void click(MouseEventDetails mouseDetails) {
fireEvent(new ClickEvent(Embedded.this, mouseDetails));
}
private EmbeddedServerRpc rpc = (MouseEventDetails mouseDetails) -> {
fireEvent(new ClickEvent(Embedded.this, mouseDetails));
};

/**

+ 3
- 9
server/src/main/java/com/vaadin/ui/GridLayout.java Bestand weergeven

@@ -76,15 +76,9 @@ public class GridLayout extends AbstractLayout
implements Layout.AlignmentHandler, Layout.SpacingHandler,
Layout.MarginHandler, LayoutClickNotifier {

private GridLayoutServerRpc rpc = new GridLayoutServerRpc() {

@Override
public void layoutClick(MouseEventDetails mouseDetails,
Connector clickedConnector) {
fireEvent(LayoutClickEvent.createEvent(GridLayout.this,
mouseDetails, clickedConnector));

}
private GridLayoutServerRpc rpc = (MouseEventDetails mouseDetails, Connector clickedConnector) -> {
fireEvent(LayoutClickEvent.createEvent(GridLayout.this,
mouseDetails, clickedConnector));
};
/**
* Cursor X position: this is where the next component with unspecified x,y

+ 2
- 5
server/src/main/java/com/vaadin/ui/Image.java Bestand weergeven

@@ -34,11 +34,8 @@ import com.vaadin.shared.ui.image.ImageState;
@SuppressWarnings("serial")
public class Image extends AbstractEmbedded {

protected ImageServerRpc rpc = new ImageServerRpc() {
@Override
public void click(MouseEventDetails mouseDetails) {
fireEvent(new ClickEvent(Image.this, mouseDetails));
}
protected ImageServerRpc rpc = (MouseEventDetails mouseDetails) -> {
fireEvent(new ClickEvent(Image.this, mouseDetails));
};

/**

+ 7
- 10
server/src/main/java/com/vaadin/ui/JavaScript.java Bestand weergeven

@@ -52,16 +52,13 @@ public class JavaScript extends AbstractExtension {
* object.
*/
public JavaScript() {
registerRpc(new JavaScriptCallbackRpc() {
@Override
public void call(String name, JsonArray arguments) {
JavaScriptFunction function = functions.get(name);
// TODO handle situation if name is not registered
try {
function.call(arguments);
} catch (JsonException e) {
throw new IllegalArgumentException(e);
}
registerRpc((JavaScriptCallbackRpc) (String name, JsonArray arguments) -> {
JavaScriptFunction function = functions.get(name);
// TODO handle situation if name is not registered
try {
function.call(arguments);
} catch (JsonException e) {
throw new IllegalArgumentException(e);
}
});
}

+ 1
- 6
server/src/main/java/com/vaadin/ui/LoginForm.java Bestand weergeven

@@ -315,12 +315,7 @@ public class LoginForm extends AbstractSingleComponentContainer {
resource.setCacheTime(-1);
setResource(LoginFormConstants.LOGIN_RESOURCE_NAME, resource);

registerRpc(new LoginFormRpc() {
@Override
public void submitCompleted() {
login();
}
});
registerRpc((LoginFormRpc) this::login);

initialized = true;


+ 2
- 5
server/src/main/java/com/vaadin/ui/Panel.java Bestand weergeven

@@ -53,11 +53,8 @@ public class Panel extends AbstractSingleComponentContainer
*/
protected ActionManager actionManager;

private PanelServerRpc rpc = new PanelServerRpc() {
@Override
public void click(MouseEventDetails mouseDetails) {
fireEvent(new ClickEvent(Panel.this, mouseDetails));
}
private PanelServerRpc rpc = (MouseEventDetails mouseDetails) -> {
fireEvent(new ClickEvent(Panel.this, mouseDetails));
};

/**

+ 1
- 7
server/src/main/java/com/vaadin/ui/PopupView.java Bestand weergeven

@@ -57,13 +57,7 @@ public class PopupView extends AbstractComponent implements HasComponents {
}
}

private final PopupViewServerRpc rpc = new PopupViewServerRpc() {

@Override
public void setPopupVisibility(boolean visible) {
setPopupVisible(visible);
}
};
private final PopupViewServerRpc rpc = this::setPopupVisible;

/* Constructors */


+ 24
- 29
server/src/main/java/com/vaadin/ui/Slider.java Bestand weergeven

@@ -35,37 +35,32 @@ import com.vaadin.ui.declarative.DesignContext;
*/
public class Slider extends AbstractField<Double> {

private SliderServerRpc rpc = new SliderServerRpc() {

@Override
public void valueChanged(double value) {

/*
* Client side updates the state before sending the event so we need
* to make sure the cached state is updated to match the client. If
* we do not do this, a reverting setValue() call in a listener will
* not cause the new state to be sent to the client.
*
* See #12133.
*/
getUI().getConnectorTracker().getDiffState(Slider.this).put("value",
value);

try {
setValue(value, true);
} catch (final ValueOutOfBoundsException e) {
// Convert to nearest bound
double out = e.getValue().doubleValue();
if (out < getState().minValue) {
out = getState().minValue;
}
if (out > getState().maxValue) {
out = getState().maxValue;
}
Slider.super.setValue(new Double(out), false);
private SliderServerRpc rpc = (double value) -> {

/*
* Client side updates the state before sending the event so we need to
* make sure the cached state is updated to match the client. If we do
* not do this, a reverting setValue() call in a listener will not cause
* the new state to be sent to the client.
*
* See #12133.
*/
getUI().getConnectorTracker().getDiffState(Slider.this).put("value",
value);

try {
setValue(value, true);
} catch (final ValueOutOfBoundsException e) {
// Convert to nearest bound
double out = e.getValue().doubleValue();
if (out < getState().minValue) {
out = getState().minValue;
}
if (out > getState().maxValue) {
out = getState().maxValue;
}
Slider.super.setValue(new Double(out), false);
}

};

/**

+ 1
- 7
server/src/main/java/com/vaadin/ui/TabSheet.java Bestand weergeven

@@ -138,13 +138,7 @@ public class TabSheet extends AbstractComponentContainer

// expand horizontally by default
setWidth(100, UNITS_PERCENTAGE);
setCloseHandler(new CloseHandler() {

@Override
public void onTabClose(TabSheet tabsheet, Component c) {
tabsheet.removeComponent(c);
}
});
setCloseHandler(TabSheet::removeComponent);
}

/**

+ 2
- 5
server/src/main/java/com/vaadin/ui/declarative/Design.java Bestand weergeven

@@ -472,11 +472,8 @@ public class Design implements Serializable {
}
// create listener for component creations that binds the created
// components to the componentRoot instance fields
ComponentCreationListener creationListener = new ComponentCreationListener() {
@Override
public void componentCreated(ComponentCreatedEvent event) {
binder.bindField(event.getComponent(), event.getLocalId());
}
ComponentCreationListener creationListener = (ComponentCreatedEvent event) -> {
binder.bindField(event.getComponent(), event.getLocalId());
};
designContext.addComponentCreationListener(creationListener);
// create subtree

+ 2
- 6
server/src/main/java/com/vaadin/ui/declarative/ShouldWriteDataDelegate.java Bestand weergeven

@@ -35,12 +35,8 @@ public interface ShouldWriteDataDelegate extends Serializable {
* is provided by a data source connected to a back end system and that the
* data should thus not be written.
*/
public static final ShouldWriteDataDelegate DEFAULT = new ShouldWriteDataDelegate() {
@Override
public boolean shouldWriteData(Component component) {
return false;
}
};
public static final ShouldWriteDataDelegate DEFAULT = (
Component component) -> false;

/**
* Determines whether the container data of a component should be written

+ 7
- 13
server/src/main/java/com/vaadin/ui/renderers/ClickableRenderer.java Bestand weergeven

@@ -126,19 +126,13 @@ public abstract class ClickableRenderer<T, V> extends AbstractRenderer<T, V> {
protected ClickableRenderer(Class<V> presentationType,
String nullRepresentation) {
super(presentationType, nullRepresentation);
registerRpc(new RendererClickRpc() {

@Override
public void click(String rowKey, String columnId,
MouseEventDetails mouseDetails) {

Grid<T> grid = getParentGrid();
T item = grid.getDataCommunicator().getKeyMapper().get(rowKey);
Column column = grid.getColumn(columnId);

fireEvent(new RendererClickEvent<>(grid, item, column,
mouseDetails));
}
registerRpc((RendererClickRpc) (String rowKey, String columnId, MouseEventDetails mouseDetails) -> {
Grid<T> grid = getParentGrid();
T item = grid.getDataCommunicator().getKeyMapper().get(rowKey);
Column column = grid.getColumn(columnId);
fireEvent(new RendererClickEvent<>(grid, item, column,
mouseDetails));
});
}


+ 6
- 10
server/src/test/java/com/vaadin/data/BinderConverterValidatorTest.java Bestand weergeven

@@ -91,12 +91,8 @@ public class BinderConverterValidatorTest
binding.withValidator(Validator.alwaysPass());
String msg1 = "foo";
String msg2 = "bar";
binding.withValidator(new Validator<String>() {
@Override
public ValidationResult apply(String value, ValueContext context) {
return ValidationResult.error(msg1);
}
});
binding.withValidator((String value,
ValueContext context) -> ValidationResult.error(msg1));
binding.withValidator(value -> false, msg2);
binding.bind(Person::getFirstName, Person::setFirstName);

@@ -356,8 +352,8 @@ public class BinderConverterValidatorTest
bindName();

AtomicBoolean beanLevelValidationRun = new AtomicBoolean();
binder.withValidator(Validator.from(
bean -> beanLevelValidationRun.getAndSet(true), ""));
binder.withValidator(Validator
.from(bean -> beanLevelValidationRun.getAndSet(true), ""));

ageField.setValue("not a number");

@@ -373,8 +369,8 @@ public class BinderConverterValidatorTest
bindName();

AtomicBoolean beanLevelValidationRun = new AtomicBoolean();
binder.withValidator(Validator.from(
bean -> beanLevelValidationRun.getAndSet(true), ""));
binder.withValidator(Validator
.from(bean -> beanLevelValidationRun.getAndSet(true), ""));

ageField.setValue(String.valueOf(12));


+ 27
- 37
server/src/test/java/com/vaadin/server/VaadinSessionTest.java Bestand weergeven

@@ -37,7 +37,6 @@ import org.junit.Before;
import org.junit.Test;

import com.vaadin.server.ClientConnector.DetachEvent;
import com.vaadin.server.ClientConnector.DetachListener;
import com.vaadin.server.communication.UIInitHandler;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
@@ -146,24 +145,21 @@ public class VaadinSessionTest implements Serializable {

// this simulates servlet container's session invalidation from another
// thread
new Thread(new Runnable() {
@Override
public void run() {
new Thread(() -> {
try {
Thread.sleep(150); // delay selected so that VaadinSession
// will be already locked by the main
// thread
// when we get here
httpSessionLock.lock();// simulating servlet container's
// session lock
try {
Thread.sleep(150); // delay selected so that VaadinSession
// will be already locked by the main
// thread
// when we get here
httpSessionLock.lock();// simulating servlet container's
// session lock
try {
mockService.fireSessionDestroy(session);
} finally {
httpSessionLock.unlock();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
mockService.fireSessionDestroy(session);
} finally {
httpSessionLock.unlock();
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();

@@ -180,16 +176,13 @@ public class VaadinSessionTest implements Serializable {
throws InterruptedException {

final AtomicBoolean detachCalled = new AtomicBoolean(false);
ui.addDetachListener(new DetachListener() {
@Override
public void detach(DetachEvent event) {
detachCalled.set(true);
Assert.assertEquals(ui, UI.getCurrent());
Assert.assertEquals(ui.getPage(), Page.getCurrent());
Assert.assertEquals(session, VaadinSession.getCurrent());
Assert.assertEquals(mockService, VaadinService.getCurrent());
Assert.assertEquals(mockServlet, VaadinServlet.getCurrent());
}
ui.addDetachListener((DetachEvent event) -> {
detachCalled.set(true);
Assert.assertEquals(ui, UI.getCurrent());
Assert.assertEquals(ui.getPage(), Page.getCurrent());
Assert.assertEquals(session, VaadinSession.getCurrent());
Assert.assertEquals(mockService, VaadinService.getCurrent());
Assert.assertEquals(mockServlet, VaadinServlet.getCurrent());
});

session.valueUnbound(
@@ -206,16 +199,13 @@ public class VaadinSessionTest implements Serializable {
@Test
public void threadLocalsAfterSessionDestroy() throws InterruptedException {
final AtomicBoolean detachCalled = new AtomicBoolean(false);
ui.addDetachListener(new DetachListener() {
@Override
public void detach(DetachEvent event) {
detachCalled.set(true);
Assert.assertEquals(ui, UI.getCurrent());
Assert.assertEquals(ui.getPage(), Page.getCurrent());
Assert.assertEquals(session, VaadinSession.getCurrent());
Assert.assertEquals(mockService, VaadinService.getCurrent());
Assert.assertEquals(mockServlet, VaadinServlet.getCurrent());
}
ui.addDetachListener((DetachEvent event) -> {
detachCalled.set(true);
Assert.assertEquals(ui, UI.getCurrent());
Assert.assertEquals(ui.getPage(), Page.getCurrent());
Assert.assertEquals(session, VaadinSession.getCurrent());
Assert.assertEquals(mockService, VaadinService.getCurrent());
Assert.assertEquals(mockServlet, VaadinServlet.getCurrent());
});
CurrentInstance.clearAll();
session.close();

+ 1
- 8
server/src/test/java/com/vaadin/tests/VaadinClasses.java Bestand weergeven

@@ -152,14 +152,7 @@ public class VaadinClasses {
findPackages(juc, basePackage, baseClass, classes);
}

Collections.sort(classes, new Comparator<Class<? extends T>>() {

@Override
public int compare(Class<? extends T> o1, Class<? extends T> o2) {
return o1.getName().compareTo(o2.getName());
}

});
Collections.sort(classes, (Class<? extends T> o1, Class<? extends T> o2) -> o1.getName().compareTo(o2.getName()));
return classes;
}


+ 19
- 43
server/src/test/java/com/vaadin/tests/design/ComponentFactoryTest.java Bestand weergeven

@@ -40,18 +40,14 @@ public class ComponentFactoryTest {

// Set static component factory that delegate to a thread local factory
static {
Design.setComponentFactory(new ComponentFactory() {
@Override
public Component createComponent(String fullyQualifiedClassName,
DesignContext context) {
ComponentFactory componentFactory = currentComponentFactory
.get();
if (componentFactory == null) {
componentFactory = defaultFactory;
}
return componentFactory.createComponent(fullyQualifiedClassName,
context);
Design.setComponentFactory((String fullyQualifiedClassName, DesignContext context) -> {
ComponentFactory componentFactory = currentComponentFactory
.get();
if (componentFactory == null) {
componentFactory = defaultFactory;
}
return componentFactory.createComponent(fullyQualifiedClassName,
context);
});
}

@@ -63,14 +59,10 @@ public class ComponentFactoryTest {
@Test
public void testComponentFactoryLogging() {
final List<String> messages = new ArrayList<>();
currentComponentFactory.set(new ComponentFactory() {
@Override
public Component createComponent(String fullyQualifiedClassName,
DesignContext context) {
messages.add("Requested class " + fullyQualifiedClassName);
return defaultFactory.createComponent(fullyQualifiedClassName,
context);
}
currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> {
messages.add("Requested class " + fullyQualifiedClassName);
return defaultFactory.createComponent(fullyQualifiedClassName,
context);
});

Design.read(new ByteArrayInputStream("<vaadin-label />".getBytes()));
@@ -83,28 +75,16 @@ public class ComponentFactoryTest {

@Test(expected = DesignException.class)
public void testComponentFactoryReturningNull() {
currentComponentFactory.set(new ComponentFactory() {
@Override
public Component createComponent(String fullyQualifiedClassName,
DesignContext context) {
return null;
}
});
currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> null);

Design.read(new ByteArrayInputStream("<vaadin-label />".getBytes()));
}

@Test(expected = DesignException.class)
public void testComponentFactoryThrowingStuff() {
currentComponentFactory.set(new ComponentFactory() {
@Override
public Component createComponent(String fullyQualifiedClassName,
DesignContext context) {
// Will throw because class is not found
return defaultFactory.createComponent(
"foobar." + fullyQualifiedClassName, context);
}
});
currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> defaultFactory.createComponent(
"foobar." + fullyQualifiedClassName, context) // Will throw because class is not found
);

Design.read(new ByteArrayInputStream("<vaadin-label />".getBytes()));
}
@@ -112,14 +92,10 @@ public class ComponentFactoryTest {
@Test
public void testGetDefaultInstanceUsesComponentFactory() {
final List<String> classes = new ArrayList<>();
currentComponentFactory.set(new ComponentFactory() {
@Override
public Component createComponent(String fullyQualifiedClassName,
DesignContext context) {
classes.add(fullyQualifiedClassName);
return defaultFactory.createComponent(fullyQualifiedClassName,
context);
}
currentComponentFactory.set((ComponentFactory) (String fullyQualifiedClassName, DesignContext context) -> {
classes.add(fullyQualifiedClassName);
return defaultFactory.createComponent(fullyQualifiedClassName,
context);
});

DesignContext designContext = new DesignContext();

+ 1
- 7
server/src/test/java/com/vaadin/tests/design/DeclarativeTestBase.java Bestand weergeven

@@ -34,13 +34,7 @@ public abstract class DeclarativeTestBase<T extends Component>
private static boolean debug = false;

private final Map<Class<?>, EqualsAsserter<?>> comparators = new HashMap<>();
private static EqualsAsserter standardEqualsComparator = new EqualsAsserter<Object>() {

@Override
public void assertObjectEquals(Object o1, Object o2) {
Assert.assertEquals(o1, o2);
}
};
private static final EqualsAsserter standardEqualsComparator = (EqualsAsserter<Object>) Assert::assertEquals;

public class IntrospectorEqualsAsserter<C> implements EqualsAsserter<C> {


+ 4
- 10
server/src/test/java/com/vaadin/tests/design/designroot/ExtendedDesignWithEmptyAnnotation.java Bestand weergeven

@@ -30,18 +30,12 @@ public class ExtendedDesignWithEmptyAnnotation
customField.setPlaceholder("Something");
addComponent(customField);

ok.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Notification.show("OK");
}
ok.addClickListener((ClickEvent event) -> {
Notification.show("OK");
});

CaNCEL.addClickListener(new ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
Notification.show("cancel");
}
CaNCEL.addClickListener((ClickEvent event) -> {
Notification.show("cancel");
});
}
}

+ 4
- 11
server/src/test/java/com/vaadin/tests/server/component/button/ButtonClickTest.java Bestand weergeven

@@ -21,12 +21,8 @@ public class ButtonClickTest {
public void clickDetachedButton() {
Button b = new Button();
AtomicInteger counter = new AtomicInteger(0);
b.addClickListener(new ClickListener() {

@Override
public void buttonClick(ClickEvent event) {
counter.incrementAndGet();
}
b.addClickListener((ClickEvent event) -> {
counter.incrementAndGet();
});

b.click();
@@ -67,11 +63,8 @@ public class ButtonClickTest {

private void addClickListener(Button b) {
clicked = false;
b.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent ev) {
clicked = true;
}
b.addClickListener((ClickEvent ev) -> {
clicked = true;
});
}
}

+ 4
- 14
server/src/test/java/com/vaadin/tests/server/component/window/AttachDetachWindowTest.java Bestand weergeven

@@ -224,13 +224,8 @@ public class AttachDetachWindowTest {
final Window window = new Window();

final boolean[] eventFired = new boolean[1];
ui.addComponentAttachListener(new ComponentAttachListener() {

@Override
public void componentAttachedToContainer(
ComponentAttachEvent event) {
eventFired[0] = event.getAttachedComponent().equals(window);
}
ui.addComponentAttachListener((ComponentAttachEvent event) -> {
eventFired[0] = event.getAttachedComponent().equals(window);
});
ui.addWindow(window);
Assert.assertTrue("Attach event is not fired for added window",
@@ -243,13 +238,8 @@ public class AttachDetachWindowTest {
final Window window = new Window();

final boolean[] eventFired = new boolean[1];
ui.addComponentDetachListener(new ComponentDetachListener() {

@Override
public void componentDetachedFromContainer(
ComponentDetachEvent event) {
eventFired[0] = event.getDetachedComponent().equals(window);
}
ui.addComponentDetachListener((ComponentDetachEvent event) -> {
eventFired[0] = event.getDetachedComponent().equals(window);
});
ui.addWindow(window);
ui.removeWindow(window);

Laden…
Annuleren
Opslaan