From 3d0ff32bea81c3e3c64bd044276ff04a4f8555ed Mon Sep 17 00:00:00 2001 From: Johannes Dahlström Date: Tue, 1 Apr 2014 12:28:50 +0300 Subject: Prevent duplicate detach() calls with push (#13261) This used to happen when push was disconnected due to a UI or session expiring. requestStart() and requestEnd() were called on disconnect even though a disconnection is not a request. Change-Id: I31d9cae65ec75b5046802a54bbe4564d6e44b29f --- .../communication/AtmospherePushConnection.java | 9 ++ .../vaadin/server/communication/PushHandler.java | 118 ++++++++++++++------- 2 files changed, 86 insertions(+), 41 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index b9d4955b12..ac02e130dc 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -203,6 +203,15 @@ public class AtmospherePushConnection implements PushConnection { public void disconnect() { assert isConnected(); + if (resource.isResumed()) { + // Calling disconnect may end up invoking it again via + // resource.resume and PushHandler.onResume. Bail out here if + // the resource is already resumed; this is a bit hacky and should + // be implemented in a better way in 7.2. + resource = null; + return; + } + if (outgoingMessage != null) { // Wait for the last message to be sent before closing the // connection (assumes that futures are completed in order) diff --git a/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 09428e47a9..101cf5a14d 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -174,46 +174,6 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter } }; - /** - * Callback used when a connection is closed, either deliberately or because - * an error occurred. - */ - private final PushEventCallback disconnectCallback = new PushEventCallback() { - @Override - public void run(AtmosphereResource resource, UI ui) throws IOException { - PushMode pushMode = ui.getPushConfiguration().getPushMode(); - AtmospherePushConnection pushConnection = getConnectionForUI(ui); - - String id = resource.uuid(); - - if (pushConnection == null) { - getLogger() - .log(Level.WARNING, - "Could not find push connection to close: {0} with transport {1}", - new Object[] { id, resource.transport() }); - } else { - if (!pushMode.isEnabled()) { - /* - * The client is expected to close the connection after push - * mode has been set to disabled. - */ - getLogger().log(Level.FINER, - "Connection closed for resource {0}", id); - } else { - /* - * Unexpected cancel, e.g. if the user closes the browser - * tab. - */ - getLogger() - .log(Level.FINER, - "Connection unexpectedly closed for resource {0} with transport {1}", - new Object[] { id, resource.transport() }); - } - ui.setPushConnection(null); - } - } - }; - private static final String LONG_PADDING; static { @@ -426,7 +386,83 @@ public class PushHandler extends AtmosphereResourceEventListenerAdapter } private void disconnect(AtmosphereResourceEvent event) { - callWithUi(event.getResource(), disconnectCallback); + // We don't want to use callWithUi here, as it assumes there's a client + // request active and does requestStart and requestEnd among other + // things. + + AtmosphereResource resource = event.getResource(); + VaadinServletRequest vaadinRequest = new VaadinServletRequest( + resource.getRequest(), service); + VaadinSession session = null; + + try { + session = service.findVaadinSession(vaadinRequest); + } catch (ServiceException e) { + getLogger().log(Level.SEVERE, + "Could not get session. This should never happen", e); + return; + } catch (SessionExpiredException e) { + getLogger() + .log(Level.SEVERE, + "Session expired before push was disconnected. This should never happen", + e); + return; + } + + UI ui = null; + session.lock(); + try { + VaadinSession.setCurrent(session); + // Sets UI.currentInstance + ui = service.findUI(vaadinRequest); + if (ui == null) { + getLogger().log(Level.SEVERE, + "Could not get UI. This should never happen"); + return; + } + + PushMode pushMode = ui.getPushConfiguration().getPushMode(); + AtmospherePushConnection pushConnection = getConnectionForUI(ui); + + String id = resource.uuid(); + + if (pushConnection == null) { + getLogger() + .log(Level.WARNING, + "Could not find push connection to close: {0} with transport {1}", + new Object[] { id, resource.transport() }); + } else { + if (!pushMode.isEnabled()) { + /* + * The client is expected to close the connection after push + * mode has been set to disabled. + */ + getLogger().log(Level.FINER, + "Connection closed for resource {0}", id); + } else { + /* + * Unexpected cancel, e.g. if the user closes the browser + * tab. + */ + getLogger() + .log(Level.FINER, + "Connection unexpectedly closed for resource {0} with transport {1}", + new Object[] { id, resource.transport() }); + } + ui.setPushConnection(null); + } + + } catch (final Exception e) { + callErrorHandler(session, e); + } finally { + try { + session.unlock(); + } catch (Exception e) { + getLogger().log(Level.WARNING, "Error while unlocking session", + e); + // can't call ErrorHandler, we (hopefully) don't have a lock + } + } } /** -- cgit v1.2.3 From a452badd69632d9159081755b7519ffb743fcb03 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Fri, 21 Mar 2014 22:04:16 +0200 Subject: Refactor VaadinPortletRequest extending. (#13551) Change-Id: Ibe169bf0ec6d2f335e099ac2659079c8fad6ac0b --- server/src/com/vaadin/server/VaadinPortlet.java | 228 +++++++++++---------- .../vaadin/server/VaadinGateInRequestTests.java | 39 ++++ .../server/VaadinHttpAndPortletRequestTests.java | 140 +++++++++++++ .../vaadin/server/VaadinLiferayRequestTests.java | 39 ++++ .../src/com/vaadin/server/VaadinPortletTests.java | 94 +++++++++ .../server/VaadinWebSpherePortalRequestTests.java | 39 ++++ 6 files changed, 472 insertions(+), 107 deletions(-) create mode 100644 server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinPortletTests.java create mode 100644 server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java (limited to 'server/src/com') diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 4c34b0aedb..b3ce238e72 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -29,6 +29,7 @@ import javax.portlet.ActionResponse; import javax.portlet.EventRequest; import javax.portlet.EventResponse; import javax.portlet.GenericPortlet; +import javax.portlet.PortalContext; import javax.portlet.PortletConfig; import javax.portlet.PortletContext; import javax.portlet.PortletException; @@ -51,61 +52,83 @@ import com.vaadin.util.CurrentInstance; * Portlet 2.0 base class. This replaces the servlet in servlet/portlet 1.0 * deployments and handles various portlet requests from the browser. * - * TODO Document me! - * - * @author peholmst + * @author Vaadin Ltd */ public class VaadinPortlet extends GenericPortlet implements Constants, Serializable { /** - * @deprecated As of 7.0. Will likely change or be removed in a future - * version + * Base class for portlet requests that need access to HTTP servlet + * requests. */ - @Deprecated - public static final String RESOURCE_URL_ID = "APP"; - - public static class VaadinHttpAndPortletRequest extends + public static abstract class VaadinHttpAndPortletRequest extends VaadinPortletRequest { + /** + * Constructs a new {@link VaadinHttpAndPortletRequest}. + * + * @since 7.2 + * @param request + * {@link PortletRequest} to be wrapped + * @param vaadinService + * {@link VaadinPortletService} associated with this request + */ public VaadinHttpAndPortletRequest(PortletRequest request, - HttpServletRequest originalRequest, VaadinPortletService vaadinService) { super(request, vaadinService); - this.originalRequest = originalRequest; } - private final HttpServletRequest originalRequest; + private HttpServletRequest originalRequest; + + /** + * Returns the original HTTP servlet request for this portlet request. + * + * @since 7.2 + * @param request + * {@link PortletRequest} used to + * @return the original HTTP servlet request + */ + protected abstract HttpServletRequest getServletRequest( + PortletRequest request); + + private HttpServletRequest getOriginalRequest() { + if (originalRequest == null) { + PortletRequest request = getRequest(); + originalRequest = getServletRequest(request); + } + + return originalRequest; + } @Override public String getParameter(String name) { String parameter = super.getParameter(name); if (parameter == null) { - parameter = originalRequest.getParameter(name); + parameter = getOriginalRequest().getParameter(name); } return parameter; } @Override public String getRemoteAddr() { - return originalRequest.getRemoteAddr(); + return getOriginalRequest().getRemoteAddr(); } @Override public String getRemoteHost() { - return originalRequest.getRemoteHost(); + return getOriginalRequest().getRemoteHost(); } @Override public int getRemotePort() { - return originalRequest.getRemotePort(); + return getOriginalRequest().getRemotePort(); } @Override public String getHeader(String name) { String header = super.getHeader(name); if (header == null) { - header = originalRequest.getHeader(name); + header = getOriginalRequest().getHeader(name); } return header; } @@ -114,7 +137,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants, public Enumeration getHeaderNames() { Enumeration headerNames = super.getHeaderNames(); if (headerNames == null) { - headerNames = originalRequest.getHeaderNames(); + headerNames = getOriginalRequest().getHeaderNames(); } return headerNames; } @@ -123,7 +146,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants, public Enumeration getHeaders(String name) { Enumeration headers = super.getHeaders(name); if (headers == null) { - headers = originalRequest.getHeaders(name); + headers = getOriginalRequest().getHeaders(name); } return headers; } @@ -132,64 +155,21 @@ public class VaadinPortlet extends GenericPortlet implements Constants, public Map getParameterMap() { Map parameterMap = super.getParameterMap(); if (parameterMap == null) { - parameterMap = originalRequest.getParameterMap(); + parameterMap = getOriginalRequest().getParameterMap(); } return parameterMap; } } - public static class VaadinGateinRequest extends VaadinHttpAndPortletRequest { - public VaadinGateinRequest(PortletRequest request, - VaadinPortletService vaadinService) { - super(request, getOriginalRequest(request), vaadinService); - } - - private static final HttpServletRequest getOriginalRequest( - PortletRequest request) { - try { - Method getRealReq = request.getClass().getMethod( - "getRealRequest"); - HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq - .invoke(request); - return origRequest; - } catch (Exception e) { - throw new IllegalStateException("GateIn request not detected", - e); - } - } - } - - // Intentionally internal, will be refactored out in 7.2. - static class WebSpherePortalRequest extends VaadinHttpAndPortletRequest { - - public WebSpherePortalRequest(PortletRequest request, - VaadinPortletService vaadinService) { - super(request, getServletRequest(request), vaadinService); - } - - private static HttpServletRequest getServletRequest( - PortletRequest request) { - try { - Class portletUtils = Class - .forName("com.ibm.ws.portletcontainer.portlet.PortletUtils"); - Method getHttpServletRequest = portletUtils.getMethod( - "getHttpServletRequest", PortletRequest.class); - - return (HttpServletRequest) getHttpServletRequest.invoke(null, - request); - } catch (Exception e) { - throw new IllegalStateException( - "WebSphere Portal request not detected."); - } - } - } - + /** + * Portlet request for Liferay. + */ public static class VaadinLiferayRequest extends VaadinHttpAndPortletRequest { public VaadinLiferayRequest(PortletRequest request, VaadinPortletService vaadinService) { - super(request, getOriginalRequest(request), vaadinService); + super(request, vaadinService); } @Override @@ -219,7 +199,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants, * @throws Exception * @return return value of the invoked method */ - private static Object invokeStaticLiferayMethod(String className, + private Object invokeStaticLiferayMethod(String className, String methodName, Object argument, String parameterClassName) throws Exception { Thread currentThread = Thread.currentThread(); @@ -251,8 +231,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants, } } - private static HttpServletRequest getOriginalRequest( - PortletRequest request) { + @Override + protected HttpServletRequest getServletRequest(PortletRequest request) { try { // httpRequest = PortalUtil.getHttpServletRequest(request); HttpServletRequest httpRequest = (HttpServletRequest) invokeStaticLiferayMethod( @@ -272,9 +252,67 @@ public class VaadinPortlet extends GenericPortlet implements Constants, e); } } + } + /** + * Portlet request for GateIn. + */ + public static class VaadinGateInRequest extends VaadinHttpAndPortletRequest { + public VaadinGateInRequest(PortletRequest request, + VaadinPortletService vaadinService) { + super(request, vaadinService); + } + + @Override + protected HttpServletRequest getServletRequest(PortletRequest request) { + try { + Method getRealReq = request.getClass().getMethod( + "getRealRequest"); + HttpServletRequestWrapper origRequest = (HttpServletRequestWrapper) getRealReq + .invoke(request); + return origRequest; + } catch (Exception e) { + throw new IllegalStateException("GateIn request not detected", + e); + } + } + } + + /** + * Portlet request for WebSphere Portal. + */ + public static class VaadinWebSpherePortalRequest extends + VaadinHttpAndPortletRequest { + + public VaadinWebSpherePortalRequest(PortletRequest request, + VaadinPortletService vaadinService) { + super(request, vaadinService); + } + + @Override + protected HttpServletRequest getServletRequest(PortletRequest request) { + try { + Class portletUtils = Class + .forName("com.ibm.ws.portletcontainer.portlet.PortletUtils"); + Method getHttpServletRequest = portletUtils.getMethod( + "getHttpServletRequest", PortletRequest.class); + + return (HttpServletRequest) getHttpServletRequest.invoke(null, + request); + } catch (Exception e) { + throw new IllegalStateException( + "WebSphere Portal request not detected."); + } + } } + /** + * @deprecated As of 7.0. Will likely change or be removed in a future + * version + */ + @Deprecated + public static final String RESOURCE_URL_ID = "APP"; + /** * This portlet parameter is used to add styles to the main element. E.g * "height:500px" generates a style="height:500px" to the main element. @@ -443,50 +481,26 @@ public class VaadinPortlet extends GenericPortlet implements Constants, * * @param request * The original PortletRequest - * @return A wrapped version of the PorletRequest + * @return A wrapped version of the PortletRequest */ protected VaadinPortletRequest createVaadinRequest(PortletRequest request) { - if (isLiferay(request)) { - return new VaadinLiferayRequest(request, getService()); - } else if (isGateIn(request)) { - return new VaadinGateinRequest(request, getService()); - } else if (isWebSphere(request)) { - return new WebSpherePortalRequest(request, getService()); - } else { + PortalContext portalContext = request.getPortalContext(); + String portalInfo = portalContext.getPortalInfo().toLowerCase().trim(); + VaadinPortletService service = getService(); - return new VaadinPortletRequest(request, getService()); + if (portalInfo.contains("gatein")) { + return new VaadinGateInRequest(request, service); } - } - - /** - * Returns true if the portlet request is from Liferay. - * - * @param request - * @return True if Liferay, false otherwise - */ - private static boolean isLiferay(PortletRequest request) { - String portalInfo = request.getPortalContext().getPortalInfo() - .toLowerCase(); - return portalInfo.contains("liferay"); - } - /** - * Returns true if the portlet request if from GateIn - * - * @param request - * @return True if GateIn, false otherwise - */ - private static boolean isGateIn(PortletRequest request) { - String portalInfo = request.getPortalContext().getPortalInfo() - .toLowerCase(); - return portalInfo.contains("gatein"); - } + if (portalInfo.contains("liferay")) { + return new VaadinLiferayRequest(request, service); + } - private static boolean isWebSphere(PortletRequest request) { - String portalInfo = request.getPortalContext().getPortalInfo() - .toLowerCase(); + if (portalInfo.contains("websphere portal")) { + return new VaadinWebSpherePortalRequest(request, service); + } - return portalInfo.contains("websphere portal"); + return new VaadinPortletRequest(request, service); } private VaadinPortletResponse createVaadinResponse(PortletResponse response) { diff --git a/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java new file mode 100644 index 0000000000..017613661e --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinGateInRequestTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import com.vaadin.server.VaadinPortlet.VaadinGateInRequest; + +public class VaadinGateInRequestTests extends + VaadinHttpAndPortletRequestTests { + + @Override + protected VaadinGateInRequest createSut() { + + VaadinGateInRequest request = new VaadinGateInRequest(portletRequest, + vaadinPortletService); + + // Although partial mocking can be considered a code smell, + // here it's actually quite useful to mock reflection calls. + VaadinGateInRequest spy = spy(request); + doReturn(servletRequest).when(spy).getServletRequest(portletRequest); + + return spy; + } +} diff --git a/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java new file mode 100644 index 0000000000..01d501c4fb --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinHttpAndPortletRequestTests.java @@ -0,0 +1,140 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Enumeration; +import java.util.Map; + +import javax.portlet.PortletRequest; +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import com.vaadin.server.VaadinPortlet.VaadinHttpAndPortletRequest; +import com.vaadin.server.VaadinPortletService; + +//Have to ignore this class - otherwise JUnit tries to instantiate it... +@Ignore +public abstract class VaadinHttpAndPortletRequestTests { + + protected VaadinHttpAndPortletRequest sut; + protected HttpServletRequest servletRequest; + protected PortletRequest portletRequest; + protected VaadinPortletService vaadinPortletService; + + protected abstract T createSut(); + + @Before + public void setup() { + portletRequest = mock(PortletRequest.class); + vaadinPortletService = mock(VaadinPortletService.class); + servletRequest = mock(HttpServletRequest.class); + + sut = createSut(); + } + + @Test + public void parameterIsFetchedFromServletRequest() { + when(servletRequest.getParameter("foo")).thenReturn("bar"); + + String parameter = sut.getParameter("foo"); + + assertThat(parameter, is("bar")); + } + + @Test + public void originalParameterIsOverridden() { + when(servletRequest.getParameter("foo")).thenReturn("braa"); + when(portletRequest.getParameter("foo")).thenReturn("bar"); + + String parameter = sut.getParameter("foo"); + + assertThat(parameter, is("bar")); + } + + @Test + public void remoteAddressIsFetchedFromServletRequest() { + when(servletRequest.getRemoteAddr()).thenReturn("foo"); + + String remoteAddr = sut.getRemoteAddr(); + + assertThat(remoteAddr, is("foo")); + } + + @Test + public void remoteHostIsFetchedFromServletRequest() { + when(servletRequest.getRemoteHost()).thenReturn("foo"); + + String remoteHost = sut.getRemoteHost(); + + assertThat(remoteHost, is("foo")); + } + + @Test + public void remotePortIsFetchedFromServletRequest() { + when(servletRequest.getRemotePort()).thenReturn(12345); + + int remotePort = sut.getRemotePort(); + + assertThat(remotePort, is(12345)); + } + + @Test + public void headerIsFetchedFromServletRequest() { + when(servletRequest.getHeader("foo")).thenReturn("bar"); + + String header = sut.getHeader("foo"); + + assertThat(header, is("bar")); + } + + @Test + public void headerNamesAreFetchedFromServletRequest() { + Enumeration expectedHeaderNames = mock(Enumeration.class); + when(servletRequest.getHeaderNames()).thenReturn(expectedHeaderNames); + + Enumeration actualHeaderNames = sut.getHeaderNames(); + + assertThat(actualHeaderNames, is(expectedHeaderNames)); + } + + @Test + public void headersAreFetchedFromServletRequest() { + Enumeration expectedHeaders = mock(Enumeration.class); + when(servletRequest.getHeaders("foo")).thenReturn(expectedHeaders); + + Enumeration actualHeaders = sut.getHeaders("foo"); + + assertThat(actualHeaders, is(expectedHeaders)); + } + + @Test + public void parameterMapIsFetchedFromServletRequest() { + Map expectedParameterMap = mock(Map.class); + when(servletRequest.getParameterMap()).thenReturn(expectedParameterMap); + + Map actualParameterMap = sut.getParameterMap(); + + assertThat(actualParameterMap, is(expectedParameterMap)); + } +} diff --git a/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java new file mode 100644 index 0000000000..074941a556 --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinLiferayRequestTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest; + +public class VaadinLiferayRequestTests extends + VaadinHttpAndPortletRequestTests { + + @Override + protected VaadinLiferayRequest createSut() { + + VaadinLiferayRequest request = new VaadinLiferayRequest(portletRequest, + vaadinPortletService); + + // Although partial mocking can be considered a code smell, + // here it's actually quite useful to mock reflection calls. + VaadinLiferayRequest spy = spy(request); + doReturn(servletRequest).when(spy).getServletRequest(portletRequest); + + return spy; + } +} \ No newline at end of file diff --git a/server/tests/src/com/vaadin/server/VaadinPortletTests.java b/server/tests/src/com/vaadin/server/VaadinPortletTests.java new file mode 100644 index 0000000000..93f8fd0778 --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinPortletTests.java @@ -0,0 +1,94 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsInstanceOf.instanceOf; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import javax.portlet.PortalContext; +import javax.portlet.PortletRequest; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.server.VaadinPortlet.VaadinGateInRequest; +import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest; +import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest; + +public class VaadinPortletTests { + + private VaadinPortlet sut; + private PortletRequest portletRequest; + private PortalContext portalContext; + + @Before + public void setup() { + sut = new VaadinPortlet(); + + portletRequest = mock(PortletRequest.class); + portalContext = mock(PortalContext.class); + + when(portletRequest.getPortalContext()).thenReturn(portalContext); + } + + private void mockPortalInfo(String name) { + when(portalContext.getPortalInfo()).thenReturn(name); + } + + private VaadinPortletRequest createRequest() { + VaadinPortletRequest request = sut.createVaadinRequest(portletRequest); + return request; + } + + @Test + public void gateInRequestIsCreated() { + mockPortalInfo("gatein"); + + VaadinPortletRequest request = createRequest(); + + assertThat(request, instanceOf(VaadinGateInRequest.class)); + } + + @Test + public void liferayRequestIsCreated() { + mockPortalInfo("liferay"); + + VaadinPortletRequest request = createRequest(); + + assertThat(request, instanceOf(VaadinLiferayRequest.class)); + } + + @Test + public void webspherePortalRequestIsCreated() { + mockPortalInfo("websphere portal"); + + VaadinPortletRequest request = createRequest(); + + assertThat(request, instanceOf(VaadinWebSpherePortalRequest.class)); + } + + @Test + public void defaultPortletRequestIsCreated() { + mockPortalInfo("foobar"); + + VaadinPortletRequest request = createRequest(); + + assertThat(request, instanceOf(VaadinPortletRequest.class)); + } + +} diff --git a/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java new file mode 100644 index 0000000000..0da85c7111 --- /dev/null +++ b/server/tests/src/com/vaadin/server/VaadinWebSpherePortalRequestTests.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.server; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import com.vaadin.server.VaadinPortlet.VaadinWebSpherePortalRequest; + +public class VaadinWebSpherePortalRequestTests extends + VaadinHttpAndPortletRequestTests { + + @Override + protected VaadinWebSpherePortalRequest createSut() { + + VaadinWebSpherePortalRequest request = new VaadinWebSpherePortalRequest( + portletRequest, vaadinPortletService); + + // Although partial mocking can be considered a code smell, + // here it's actually quite useful to mock reflection calls. + VaadinWebSpherePortalRequest spy = spy(request); + doReturn(servletRequest).when(spy).getServletRequest(portletRequest); + + return spy; + } +} \ No newline at end of file -- cgit v1.2.3 From f374bc72f5fe3535600551a14eb3df2d97889ba2 Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Thu, 10 Apr 2014 20:54:08 +0300 Subject: Make ComboBox always immediate (#4054) Change-Id: I34525b7d9e78ede7f9533869326ca0c08474963a --- server/src/com/vaadin/ui/ComboBox.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/ComboBox.java b/server/src/com/vaadin/ui/ComboBox.java index 5fb2f81011..da29618efe 100644 --- a/server/src/com/vaadin/ui/ComboBox.java +++ b/server/src/com/vaadin/ui/ComboBox.java @@ -103,22 +103,30 @@ public class ComboBox extends AbstractSelect implements private boolean textInputAllowed = true; public ComboBox() { - setNewItemsAllowed(false); + initDefaults(); } public ComboBox(String caption, Collection options) { super(caption, options); - setNewItemsAllowed(false); + initDefaults(); } public ComboBox(String caption, Container dataSource) { super(caption, dataSource); - setNewItemsAllowed(false); + initDefaults(); } public ComboBox(String caption) { super(caption); + initDefaults(); + } + + /** + * Initialize the ComboBox with default settings + */ + private void initDefaults() { setNewItemsAllowed(false); + setImmediate(true); } /** -- cgit v1.2.3 From 51c2e93172b0132ead54573c74117efac29c1cec Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Fri, 11 Apr 2014 14:15:52 +0300 Subject: Revert "Added ItemSetAddEvent and ItemSetRemoveEvent (#2794)" This reverts commit 85251833de3bd101d388b20fdb9b02c532a9f1c9. Conflicts: server/src/com/vaadin/data/util/AbstractInMemoryContainer.java server/tests/src/com/vaadin/data/util/TestIndexedContainer.java Change-Id: I49dfdc58ae5841892c6d8e205c520437da9a05e5 --- server/src/com/vaadin/data/Container.java | 54 ------ .../vaadin/data/util/AbstractBeanContainer.java | 20 +-- .../data/util/AbstractInMemoryContainer.java | 149 ++--------------- .../src/com/vaadin/data/util/IndexedContainer.java | 7 +- .../vaadin/data/util/BeanItemContainerTest.java | 185 --------------------- .../com/vaadin/data/util/TestIndexedContainer.java | 113 ------------- 6 files changed, 18 insertions(+), 510 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/data/Container.java b/server/src/com/vaadin/data/Container.java index 1e053d1091..ef507c5f31 100644 --- a/server/src/com/vaadin/data/Container.java +++ b/server/src/com/vaadin/data/Container.java @@ -582,60 +582,6 @@ public interface Container extends Serializable { public Item addItemAt(int index, Object newItemId) throws UnsupportedOperationException; - /** - * An Event object specifying information about the added - * items. - */ - public interface ItemAddEvent extends ItemSetChangeEvent { - - /** - * Gets the item id of the first added item. - * - * @return item id of the first added item - */ - public Object getFirstItemId(); - - /** - * Gets the index of the first added item. - * - * @return index of the first added item - */ - public int getFirstIndex(); - - /** - * Gets the number of the added items. - * - * @return the number of added items. - */ - public int getAddedItemsCount(); - } - - /** - * An Event object specifying information about the removed - * items. - */ - public interface ItemRemoveEvent extends ItemSetChangeEvent { - /** - * Gets the item id of the first removed item. - * - * @return item id of the first removed item - */ - public Object getFirstItemId(); - - /** - * Gets the index of the first removed item. - * - * @return index of the first removed item - */ - public int getFirstIndex(); - - /** - * Gets the number of the removed items. - * - * @return the number of removed items - */ - public int getRemovedItemsCount(); - } } /** diff --git a/server/src/com/vaadin/data/util/AbstractBeanContainer.java b/server/src/com/vaadin/data/util/AbstractBeanContainer.java index d94588bdc9..b19cdd980c 100644 --- a/server/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/server/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -222,7 +222,6 @@ public abstract class AbstractBeanContainer extends @Override public boolean removeAllItems() { int origSize = size(); - IDTYPE firstItem = getFirstVisibleItem(); internalRemoveAllItems(); @@ -235,7 +234,7 @@ public abstract class AbstractBeanContainer extends // fire event only if the visible view changed, regardless of whether // filtered out items were removed or not if (origSize != 0) { - fireItemsRemoved(0, firstItem, origSize); + fireItemSetChange(); } return true; @@ -680,8 +679,6 @@ public abstract class AbstractBeanContainer extends protected void addAll(Collection collection) throws IllegalStateException, IllegalArgumentException { boolean modified = false; - int origSize = size(); - for (BEANTYPE bean : collection) { // TODO skipping invalid beans - should not allow them in javadoc? if (bean == null @@ -702,22 +699,13 @@ public abstract class AbstractBeanContainer extends if (modified) { // Filter the contents when all items have been added if (isFiltered()) { - doFilterContainer(!getFilters().isEmpty()); - } - if (visibleNewItemsWasAdded(origSize)) { - // fire event about added items - int firstPosition = origSize; - IDTYPE firstItemId = getVisibleItemIds().get(firstPosition); - int affectedItems = size() - origSize; - fireItemsAdded(firstPosition, firstItemId, affectedItems); + filterAll(); + } else { + fireItemSetChange(); } } } - private boolean visibleNewItemsWasAdded(int origSize) { - return size() > origSize; - } - /** * Use the bean resolver to get the identifier for a bean. * diff --git a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java index cae9f30fc9..84304431bc 100644 --- a/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java +++ b/server/src/com/vaadin/data/util/AbstractInMemoryContainer.java @@ -15,10 +15,8 @@ */ package com.vaadin.data.util; -import java.io.Serializable; import java.util.Collection; import java.util.Collections; -import java.util.EventObject; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -148,83 +146,6 @@ public abstract class AbstractInMemoryContainerEvent object specifying information about the added - * items. - * - *

- * This class provides information about the first added item and the number - * of added items. - *

- */ - protected static class BaseItemAddEvent extends BaseItemAddOrRemoveEvent - implements Container.Indexed.ItemAddEvent { - - public BaseItemAddEvent(Container source, Object itemId, int index, - int count) { - super(source, itemId, index, count); - } - - @Override - public int getAddedItemsCount() { - return getAffectedItemsCount(); - } - } - - /** - * An Event object specifying information about the removed - * items. - * - *

- * This class provides information about the first removed item and the - * number of removed items. - *

- */ - protected static class BaseItemRemoveEvent extends BaseItemAddOrRemoveEvent - implements Container.Indexed.ItemRemoveEvent { - - public BaseItemRemoveEvent(Container source, Object itemId, int index, - int count) { - super(source, itemId, index, count); - } - - @Override - public int getRemovedItemsCount() { - return getAffectedItemsCount(); - } - } - /** * Get an item even if filtered out. * @@ -977,69 +898,36 @@ public abstract class AbstractInMemoryContainer= 0) { - super.fireItemAdded(position, itemId, item); + fireItemSetChange(new IndexedContainer.ItemSetChangeEvent(this, + position)); } } @@ -1211,5 +1211,4 @@ public class IndexedContainer extends public Collection getContainerFilters() { return super.getContainerFilters(); } - } diff --git a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java index b9633753b4..c7d992dbeb 100644 --- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java @@ -10,15 +10,8 @@ import java.util.Map; import junit.framework.Assert; -import org.easymock.Capture; -import org.easymock.EasyMock; - import com.vaadin.data.Container; -import com.vaadin.data.Container.Indexed.ItemAddEvent; -import com.vaadin.data.Container.Indexed.ItemRemoveEvent; -import com.vaadin.data.Container.ItemSetChangeListener; import com.vaadin.data.Item; -import com.vaadin.data.util.filter.Compare; /** * Test basic functionality of BeanItemContainer. @@ -734,182 +727,4 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest { assertNull(container.getContainerProperty(john, "address.street") .getValue()); } - - public void testItemAddedEvent() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - ItemSetChangeListener addListener = createListenerMockFor(container); - addListener.containerItemSetChange(EasyMock.isA(ItemAddEvent.class)); - EasyMock.replay(addListener); - - container.addItem(bean); - - EasyMock.verify(addListener); - } - - public void testItemAddedEvent_AddedItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItem(bean); - - assertEquals(bean, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemAddedEvent_addItemAt_IndexOfAddedItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItemAt(1, new Person("")); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemAddedEvent_addItemAfter_IndexOfAddedItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItemAfter(bean, new Person("")); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemAddedEvent_amountOfAddedItems() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List beans = Arrays.asList(new Person("Jack"), new Person( - "John")); - - container.addAll(beans); - - assertEquals(2, capturedEvent.getValue().getAddedItemsCount()); - } - - public void testItemAddedEvent_someItemsAreFiltered_amountOfAddedItemsIsReducedByAmountOfFilteredItems() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List beans = Arrays.asList(new Person("Jack"), new Person( - "John")); - container.addFilter(new Compare.Equal("name", "John")); - - container.addAll(beans); - - assertEquals(1, capturedEvent.getValue().getAddedItemsCount()); - } - - public void testItemAddedEvent_someItemsAreFiltered_addedItemIsTheFirstVisibleItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List beans = Arrays.asList(new Person("Jack"), bean); - container.addFilter(new Compare.Equal("name", "John")); - - container.addAll(beans); - - assertEquals(bean, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemRemovedEvent() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener removeListener = createListenerMockFor(container); - removeListener.containerItemSetChange(EasyMock - .isA(ItemRemoveEvent.class)); - EasyMock.replay(removeListener); - - container.removeItem(bean); - - EasyMock.verify(removeListener); - } - - public void testItemRemovedEvent_RemovedItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(bean); - - assertEquals(bean, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemRemovedEvent_indexOfRemovedItem() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - container.addItem(new Person("Jack")); - Person secondBean = new Person("John"); - container.addItem(secondBean); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(secondBean); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemRemovedEvent_amountOfRemovedItems() { - BeanItemContainer container = new BeanItemContainer( - Person.class); - container.addItem(new Person("Jack")); - container.addItem(new Person("John")); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeAllItems(); - - assertEquals(2, capturedEvent.getValue().getRemovedItemsCount()); - } - - private Capture captureAddEvent( - ItemSetChangeListener addListener) { - Capture capturedEvent = new Capture(); - addListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private Capture captureRemoveEvent( - ItemSetChangeListener removeListener) { - Capture capturedEvent = new Capture(); - removeListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private ItemSetChangeListener createListenerMockFor( - BeanItemContainer container) { - ItemSetChangeListener listener = EasyMock - .createNiceMock(ItemSetChangeListener.class); - container.addItemSetChangeListener(listener); - return listener; - } } diff --git a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java index 5da0bdc8a2..09e5a26c15 100644 --- a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java +++ b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java @@ -4,12 +4,6 @@ import java.util.List; import junit.framework.Assert; -import org.easymock.Capture; -import org.easymock.EasyMock; - -import com.vaadin.data.Container.Indexed.ItemAddEvent; -import com.vaadin.data.Container.Indexed.ItemRemoveEvent; -import com.vaadin.data.Container.ItemSetChangeListener; import com.vaadin.data.Item; public class TestIndexedContainer extends AbstractInMemoryContainerTest { @@ -277,113 +271,6 @@ public class TestIndexedContainer extends AbstractInMemoryContainerTest { counter.assertNone(); } - public void testItemAddedEvent() { - IndexedContainer container = new IndexedContainer(); - ItemSetChangeListener addListener = createListenerMockFor(container); - addListener.containerItemSetChange(EasyMock.isA(ItemAddEvent.class)); - EasyMock.replay(addListener); - - container.addItem(); - - EasyMock.verify(addListener); - } - - public void testItemAddedEvent_AddedItem() { - IndexedContainer container = new IndexedContainer(); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - Object itemId = container.addItem(); - - assertEquals(itemId, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemAddedEvent_IndexOfAddedItem() { - IndexedContainer container = new IndexedContainer(); - ItemSetChangeListener addListener = createListenerMockFor(container); - container.addItem(); - Capture capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItemAt(1); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemRemovedEvent() { - IndexedContainer container = new IndexedContainer(); - Object itemId = container.addItem(); - ItemSetChangeListener removeListener = createListenerMockFor(container); - removeListener.containerItemSetChange(EasyMock - .isA(ItemRemoveEvent.class)); - EasyMock.replay(removeListener); - - container.removeItem(itemId); - - EasyMock.verify(removeListener); - } - - public void testItemRemovedEvent_RemovedItem() { - IndexedContainer container = new IndexedContainer(); - Object itemId = container.addItem(); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(itemId); - - assertEquals(itemId, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemRemovedEvent_indexOfRemovedItem() { - IndexedContainer container = new IndexedContainer(); - container.addItem(); - Object secondItemId = container.addItem(); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(secondItemId); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemRemovedEvent_amountOfRemovedItems() { - IndexedContainer container = new IndexedContainer(); - container.addItem(); - container.addItem(); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeAllItems(); - - assertEquals(2, capturedEvent.getValue().getRemovedItemsCount()); - } - - private Capture captureAddEvent( - ItemSetChangeListener addListener) { - Capture capturedEvent = new Capture(); - addListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private Capture captureRemoveEvent( - ItemSetChangeListener removeListener) { - Capture capturedEvent = new Capture(); - removeListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private ItemSetChangeListener createListenerMockFor( - IndexedContainer container) { - ItemSetChangeListener listener = EasyMock - .createNiceMock(ItemSetChangeListener.class); - container.addItemSetChangeListener(listener); - return listener; - } - // Ticket 8028 public void testGetItemIdsRangeIndexOutOfBounds() { IndexedContainer ic = new IndexedContainer(); -- cgit v1.2.3 From 02998d815a989ec13e1a49372c2c010233f6bfb9 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 11 Apr 2014 15:28:24 +0300 Subject: Updated Window API based on 7.2 API review Change-Id: Ie6fa8b51c2fd1d1fe7def9ca7c11b4023eae52b7 --- server/src/com/vaadin/ui/Window.java | 23 ++++++---- .../tests/server/component/window/WindowTest.java | 53 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 9 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index d3afdaacf1..aaba601309 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -18,9 +18,6 @@ package com.vaadin.ui; import java.io.Serializable; import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; import java.util.Map; import com.vaadin.event.FieldEvents.BlurEvent; @@ -1020,12 +1017,12 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * @param connectors * with the components to use as description */ - public void setAssistiveDescription(Connector... connectors) { - if (connectors == null) { + public void setAssistiveDescription(Component... components) { + if (components == null) { throw new IllegalArgumentException( "Parameter connectors must be non-null"); } else { - getState().contentDescription = connectors; + getState().contentDescription = components; } } @@ -1036,9 +1033,17 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * * @return list of previously set components */ - public List getAssistiveDescription() { - return Collections.unmodifiableList(Arrays - .asList(getState().contentDescription)); + public Component[] getAssistiveDescription() { + Connector[] contentDescription = getState().contentDescription; + if (contentDescription == null) { + return null; + } + + Component[] target = new Component[contentDescription.length]; + System.arraycopy(contentDescription, 0, target, 0, + contentDescription.length); + + return target; } /** diff --git a/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java b/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java new file mode 100644 index 0000000000..2cd19ee153 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/window/WindowTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.window; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.ui.Button; +import com.vaadin.ui.Label; +import com.vaadin.ui.Window; + +public class WindowTest { + + public Window window; + + @Before + public void setup() { + window = new Window(); + } + + @Test + public void testAssistiveDescription() { + Label l1 = new Label("label 1"); + Button b2 = new Button("button 2"); + window.setAssistiveDescription(l1, b2); + + Assert.assertEquals(2, window.getAssistiveDescription().length); + Assert.assertEquals(l1, window.getAssistiveDescription()[0]); + Assert.assertEquals(b2, window.getAssistiveDescription()[1]); + + // Modifying return value must not change actual value + window.getAssistiveDescription()[0] = null; + + Assert.assertEquals(2, window.getAssistiveDescription().length); + Assert.assertEquals(l1, window.getAssistiveDescription()[0]); + Assert.assertEquals(b2, window.getAssistiveDescription()[1]); + + } +} -- cgit v1.2.3 From ee203f581aead7b234a4b64db9a6006e2887dc47 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 13 Apr 2014 22:08:22 +0300 Subject: Apply abstract ordered layout settings for replaced component (#13568). Change-Id: If6863d518d902ee48bb73fbb0c9b3725cb7c8707 --- .../src/com/vaadin/ui/AbstractOrderedLayout.java | 10 +++ .../LayoutSettingsOnReplace.java | 85 ++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java index c9eb756daa..f5fd4d7bfc 100644 --- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -213,8 +213,12 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements if (oldLocation == -1) { addComponent(newComponent); } else if (newLocation == -1) { + Alignment alignment = getComponentAlignment(oldComponent); + float expandRatio = getExpandRatio(oldComponent); + removeComponent(oldComponent); addComponent(newComponent, oldLocation); + applyLayoutSettings(newComponent, alignment, expandRatio); } else { // Both old and new are in the layout if (oldLocation > newLocation) { @@ -444,4 +448,10 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements defaultComponentAlignment = defaultAlignment; } + private void applyLayoutSettings(Component target, Alignment alignment, + float expandRatio) { + setComponentAlignment(target, alignment); + setExpandRatio(target, expandRatio); + } + } diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java new file mode 100644 index 0000000000..0af21d8cb8 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/LayoutSettingsOnReplace.java @@ -0,0 +1,85 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.abstractorderedlayout; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.AbstractOrderedLayout; +import com.vaadin.ui.Alignment; + +/** + * Tests for abstract layout settings which should be preserved on replace + * component + * + * @since 7.2 + * @author Vaadin Ltd + */ +public class LayoutSettingsOnReplace { + + @Test + public void testExpandRatio() { + AbstractOrderedLayout layout = new AbstractOrderedLayout() { + }; + + AbstractComponent first = new AbstractComponent() { + }; + AbstractComponent second = new AbstractComponent() { + }; + + layout.addComponent(first); + layout.addComponent(second); + + int ratio = 2; + layout.setExpandRatio(first, ratio); + layout.setExpandRatio(second, 1); + + AbstractComponent replace = new AbstractComponent() { + }; + layout.replaceComponent(first, replace); + + Assert.assertEquals("Expand ratio for replaced component is not " + + "the same as for previous one", ratio, + layout.getExpandRatio(replace), 0.0001); + } + + @Test + public void testAlignment() { + AbstractOrderedLayout layout = new AbstractOrderedLayout() { + }; + + AbstractComponent first = new AbstractComponent() { + }; + AbstractComponent second = new AbstractComponent() { + }; + + layout.addComponent(first); + layout.addComponent(second); + + Alignment alignment = Alignment.BOTTOM_RIGHT; + layout.setComponentAlignment(first, alignment); + layout.setComponentAlignment(second, Alignment.MIDDLE_CENTER); + + AbstractComponent replace = new AbstractComponent() { + }; + layout.replaceComponent(first, replace); + + Assert.assertEquals("Alignment for replaced component is not " + + "the same as for previous one", alignment, + layout.getComponentAlignment(replace)); + } +} -- cgit v1.2.3 From 72d0aa0b82078ec2cda9c2f36a699d3854217db4 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 14 Apr 2014 10:51:02 +0300 Subject: Update Window Javadoc based on 7.2 API review changes Change-Id: Ifdc1379892d8f798f2ceabcf83d772fa6a76dd4b --- server/src/com/vaadin/ui/Window.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index aaba601309..7268aed101 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -1014,8 +1014,8 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * window. Text contained in these components will be read by assistive * devices when it is opened. * - * @param connectors - * with the components to use as description + * @param components + * the components to use as description */ public void setAssistiveDescription(Component... components) { if (components == null) { @@ -1031,7 +1031,7 @@ public class Window extends Panel implements FocusNotifier, BlurNotifier, * contained in these components will be read by assistive devices when the * window is opened. * - * @return list of previously set components + * @return array of previously set components */ public Component[] getAssistiveDescription() { Connector[] contentDescription = getState().contentDescription; -- cgit v1.2.3 From d2e24feb09ccba7f3a2f253687488774af2bc340 Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Tue, 8 Apr 2014 15:02:58 +0300 Subject: Update some APIs based on the 7.2 API review comments * NotificationConfiguration "helpers" removed from Notification * NotificationConfiguration methods accept Type instead of style (String) * Tab.setIconAltText -> Tab.setIconAlternateText * Remove the two new TabSheet.addTab() methods * UI.reinit() -> UI.refresh() Change-Id: I97488e7c6de8cfacc591450d69c821b2973b8707 --- client/src/com/vaadin/client/ui/VNotification.java | 45 ++-- client/src/com/vaadin/client/ui/VWindow.java | 2 +- .../com/vaadin/annotations/PreserveOnRefresh.java | 2 +- server/src/com/vaadin/server/Page.java | 2 +- server/src/com/vaadin/server/UIProvider.java | 2 +- .../vaadin/server/communication/UIInitHandler.java | 2 +- server/src/com/vaadin/ui/Notification.java | 167 ++------------ .../com/vaadin/ui/NotificationConfiguration.java | 240 +++++++-------------- server/src/com/vaadin/ui/TabSheet.java | 85 ++------ server/src/com/vaadin/ui/UI.java | 10 +- server/src/com/vaadin/ui/Window.java | 2 +- .../tests/src/com/vaadin/ui/UIInitRefreshTest.java | 116 ++++++++++ .../tests/src/com/vaadin/ui/UIInitReinitTest.java | 116 ---------- .../ui/ui/NotificationConfigurationBean.java | 137 ------------ .../com/vaadin/shared/ui/ui/NotificationRole.java | 25 +++ shared/src/com/vaadin/shared/ui/ui/UIState.java | 83 ++++--- .../com/vaadin/shared/ui/window/WindowRole.java | 25 +++ .../com/vaadin/shared/ui/window/WindowState.java | 7 - .../notification/NotificationsWaiAria.java | 19 +- .../tests/components/tabsheet/TabSheetIcons.java | 2 +- .../com/vaadin/tests/components/ui/UIRefresh.java | 49 +++++ .../vaadin/tests/components/ui/UIRefreshTest.java | 39 ++++ .../com/vaadin/tests/components/ui/UIReinit.java | 49 ----- .../vaadin/tests/components/ui/UIReinitTest.java | 39 ---- .../components/window/ExtraWindowShownWaiAria.java | 2 +- 25 files changed, 469 insertions(+), 798 deletions(-) create mode 100644 server/tests/src/com/vaadin/ui/UIInitRefreshTest.java delete mode 100644 server/tests/src/com/vaadin/ui/UIInitReinitTest.java delete mode 100644 shared/src/com/vaadin/shared/ui/ui/NotificationConfigurationBean.java create mode 100644 shared/src/com/vaadin/shared/ui/ui/NotificationRole.java create mode 100644 shared/src/com/vaadin/shared/ui/window/WindowRole.java create mode 100644 uitest/src/com/vaadin/tests/components/ui/UIRefresh.java create mode 100644 uitest/src/com/vaadin/tests/components/ui/UIRefreshTest.java delete mode 100644 uitest/src/com/vaadin/tests/components/ui/UIReinit.java delete mode 100644 uitest/src/com/vaadin/tests/components/ui/UIReinitTest.java (limited to 'server/src/com') diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java index 3aa3fa847d..a43f508f6e 100644 --- a/client/src/com/vaadin/client/ui/VNotification.java +++ b/client/src/com/vaadin/client/ui/VNotification.java @@ -38,9 +38,9 @@ import com.vaadin.client.UIDL; import com.vaadin.client.Util; import com.vaadin.client.ui.aria.AriaHelper; import com.vaadin.shared.Position; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.shared.ui.ui.UIState.NotificationTypeConfiguration; +import com.vaadin.shared.ui.ui.NotificationRole; public class VNotification extends VOverlay { @@ -161,20 +161,20 @@ public class VNotification extends VOverlay { } public void show(Widget widget, Position position, String style) { - NotificationConfigurationBean styleSetup = getUiState(style); + NotificationTypeConfiguration styleSetup = getUiState(style); setWaiAriaRole(styleSetup); FlowPanel panel = new FlowPanel(); - if (styleSetup.hasAssistivePrefix()) { - panel.add(new Label(styleSetup.getAssistivePrefix())); + if (hasPrefix(styleSetup)) { + panel.add(new Label(styleSetup.prefix)); AriaHelper.setVisibleForAssistiveDevicesOnly(panel.getElement(), true); } panel.add(widget); - if (styleSetup.hasAssistivePostfix()) { - panel.add(new Label(styleSetup.getAssistivePostfix())); + if (hasPostfix(styleSetup)) { + panel.add(new Label(styleSetup.postfix)); AriaHelper.setVisibleForAssistiveDevicesOnly(panel.getElement(), true); } @@ -182,8 +182,16 @@ public class VNotification extends VOverlay { show(position, style); } + private boolean hasPostfix(NotificationTypeConfiguration styleSetup) { + return styleSetup != null && styleSetup.postfix != null && !styleSetup.postfix.isEmpty(); + } + + private boolean hasPrefix(NotificationTypeConfiguration styleSetup) { + return styleSetup != null && styleSetup.prefix != null && !styleSetup.prefix.isEmpty(); + } + public void show(String html, Position position, String style) { - NotificationConfigurationBean styleSetup = getUiState(style); + NotificationTypeConfiguration styleSetup = getUiState(style); String assistiveDeviceOnlyStyle = AriaHelper.ASSISTIVE_DEVICE_ONLY_STYLE; setWaiAriaRole(styleSetup); @@ -191,32 +199,31 @@ public class VNotification extends VOverlay { String type = ""; String usage = ""; - if (styleSetup != null && styleSetup.hasAssistivePrefix()) { + if (hasPrefix(styleSetup)) { type = "" - + styleSetup.getAssistivePrefix() + ""; + + styleSetup.prefix + ""; } - if (styleSetup != null && styleSetup.hasAssistivePostfix()) { + if (hasPostfix(styleSetup)) { usage = "" - + styleSetup.getAssistivePostfix() + ""; + + styleSetup.postfix + ""; } setWidget(new HTML(type + html + usage)); show(position, style); } - private NotificationConfigurationBean getUiState(String style) { - NotificationConfigurationBean styleSetup = getApplicationConnection() - .getUIConnector().getState().notificationConfiguration.setup + private NotificationTypeConfiguration getUiState(String style) { + return getApplicationConnection() + .getUIConnector().getState().notificationConfigurations .get(style); - return styleSetup; } - private void setWaiAriaRole(NotificationConfigurationBean styleSetup) { + private void setWaiAriaRole(NotificationTypeConfiguration styleSetup) { Roles.getAlertRole().set(getElement()); - if (styleSetup != null && styleSetup.getAssistiveRole() != null) { - if (Role.STATUS == styleSetup.getAssistiveRole()) { + if (styleSetup != null && styleSetup.notificationRole != null) { + if (NotificationRole.STATUS == styleSetup.notificationRole) { Roles.getStatusRole().set(getElement()); } } diff --git a/client/src/com/vaadin/client/ui/VWindow.java b/client/src/com/vaadin/client/ui/VWindow.java index 396fc76eb0..5b6595ea43 100644 --- a/client/src/com/vaadin/client/ui/VWindow.java +++ b/client/src/com/vaadin/client/ui/VWindow.java @@ -67,7 +67,7 @@ import com.vaadin.client.ui.window.WindowMoveHandler; import com.vaadin.shared.Connector; import com.vaadin.shared.EventId; import com.vaadin.shared.ui.window.WindowMode; -import com.vaadin.shared.ui.window.WindowState.WindowRole; +import com.vaadin.shared.ui.window.WindowRole; /** * "Sub window" component. diff --git a/server/src/com/vaadin/annotations/PreserveOnRefresh.java b/server/src/com/vaadin/annotations/PreserveOnRefresh.java index 801c1e78f2..48ea74c217 100644 --- a/server/src/com/vaadin/annotations/PreserveOnRefresh.java +++ b/server/src/com/vaadin/annotations/PreserveOnRefresh.java @@ -32,7 +32,7 @@ import com.vaadin.ui.UI; * current UI instance when a reload is detected. *

* Whenever a request is received that reloads a preserved UI, the UI's - * {@link UI#reinit(com.vaadin.server.VaadinRequest) reinit} method is invoked + * {@link UI#refresh(com.vaadin.server.VaadinRequest) refresh} method is invoked * by the framework. *

* By using diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 70b8306bc3..64c658cd3e 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -636,7 +636,7 @@ public class Page implements Serializable { } public void init(VaadinRequest request) { - // NOTE: UI.reinit makes assumptions about the semantics of this method. + // NOTE: UI.refresh makes assumptions about the semantics of this method. // It should be kept in sync if this method is changed. // Extract special parameter sent by vaadinBootstrap.js diff --git a/server/src/com/vaadin/server/UIProvider.java b/server/src/com/vaadin/server/UIProvider.java index a76f396767..46439650c0 100644 --- a/server/src/com/vaadin/server/UIProvider.java +++ b/server/src/com/vaadin/server/UIProvider.java @@ -131,7 +131,7 @@ public abstract class UIProvider implements Serializable { * the value of window.name in the browser. *

* Whenever a preserved UI is reused, its - * {@link UI#reinit(com.vaadin.server.VaadinRequest) reinit} method is + * {@link UI#refresh(com.vaadin.server.VaadinRequest) refresh} method is * invoked by the framework first. * * diff --git a/server/src/com/vaadin/server/communication/UIInitHandler.java b/server/src/com/vaadin/server/communication/UIInitHandler.java index 5dc44208d1..76460e153a 100644 --- a/server/src/com/vaadin/server/communication/UIInitHandler.java +++ b/server/src/com/vaadin/server/communication/UIInitHandler.java @@ -266,7 +266,7 @@ public abstract class UIInitHandler extends SynchronizedRequestHandler { */ private void reinitUI(UI ui, VaadinRequest request) { UI.setCurrent(ui); - ui.doReinit(request); + ui.doRefresh(request); } /** diff --git a/server/src/com/vaadin/ui/Notification.java b/server/src/com/vaadin/ui/Notification.java index 31fa265b02..7064bfcf39 100644 --- a/server/src/com/vaadin/ui/Notification.java +++ b/server/src/com/vaadin/ui/Notification.java @@ -21,7 +21,6 @@ import java.io.Serializable; import com.vaadin.server.Page; import com.vaadin.server.Resource; import com.vaadin.shared.Position; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; /** * A notification message, used to display temporary messages to the user - for @@ -64,7 +63,27 @@ import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; */ public class Notification implements Serializable { public enum Type { - HUMANIZED_MESSAGE, WARNING_MESSAGE, ERROR_MESSAGE, TRAY_NOTIFICATION, ASSISTIVE_NOTIFICATION; + HUMANIZED_MESSAGE("humanized"), WARNING_MESSAGE("warning"), ERROR_MESSAGE( + "error"), TRAY_NOTIFICATION("tray"), + /** + * @since 7.2 + */ + ASSISTIVE_NOTIFICATION("assistive"); + + private String style; + + Type(String style) { + this.style = style; + } + + /** + * @since 7.2 + * + * @return the style name for this notification type. + */ + public String getStyle() { + return style; + } } @Deprecated @@ -187,44 +206,28 @@ public class Notification implements Serializable { } private void setType(Type type) { + styleName = type.getStyle(); switch (type) { case WARNING_MESSAGE: delayMsec = 1500; - styleName = "warning"; - setNavigationConfiguration("Warning: ", "", Role.ALERT); break; case ERROR_MESSAGE: delayMsec = -1; - styleName = "error"; - setNavigationConfiguration("Error: ", " - close with ESC", - Role.ALERT); break; case TRAY_NOTIFICATION: delayMsec = 3000; position = Position.BOTTOM_RIGHT; - styleName = "tray"; - setNavigationConfiguration("Info: ", "", Role.STATUS); break; case ASSISTIVE_NOTIFICATION: delayMsec = 3000; position = Position.ASSISTIVE; - styleName = "assistive"; - setNavigationConfiguration("Note: ", "", Role.ALERT); break; case HUMANIZED_MESSAGE: default: - styleName = "humanized"; - setNavigationConfiguration("Info: ", "", Role.ALERT); break; } } - private void setNavigationConfiguration(String prefix, String postfix, - Role ariaRole) { - UI.getCurrent().getNotificationConfiguration() - .setStyleConfiguration(styleName, prefix, postfix, ariaRole); - } - /** * Gets the caption part of the notification message. * @@ -339,132 +342,6 @@ public class Notification implements Serializable { return styleName; } - /** - * Sets the accessibility prefix for a notification type. - * - * This prefix is read to assistive device users before the content of the - * notification, but not visible on the page. - * - * @param type - * Type of the notification - * @param prefix - * String that is placed before the notification content - */ - public void setAssistivePrefixForType(Type type, String prefix) { - UI.getCurrent().getNotificationConfiguration() - .setAssistivePrefixForStyle(getStyle(type), prefix); - } - - /** - * Gets the accessibility prefix for a notification type. - * - * This prefix is read to assistive device users before the content of the - * notification, but not visible on the page. - * - * @param type - * Type of the notification - * @return The accessibility prefix for the provided notification type - */ - public String getAssistivePrefixForType(Type type) { - return UI.getCurrent().getNotificationConfiguration() - .getAssistivePrefixForStyle(getStyle(type)); - } - - /** - * Sets the accessibility postfix for a notification type. - * - * This postfix is read to assistive device users after the content of the - * notification, but not visible on the page. - * - * @param type - * Type of the notification - * @param postfix - * String that is placed after the notification content - */ - public void setAssistivePostfixForType(Type type, String postfix) { - UI.getCurrent().getNotificationConfiguration() - .setAssistivePostfixForStyle(getStyle(type), postfix); - } - - /** - * Gets the accessibility postfix for a notification type. - * - * This postfix is read to assistive device users after the content of the - * notification, but not visible on the page. - * - * @param type - * Type of the notification - * @return The accessibility postfix for the provided notification type - */ - public String getAssistivePostfixForType(Type type) { - return UI.getCurrent().getNotificationConfiguration() - .getAssistivePostfixForStyle(getStyle(type)); - } - - /** - * Sets the WAI-ARIA role for a notification type. - * - * This role defines how an assistive device handles a notification. - * Available roles are alert and status (@see Roles - * Model). - * - * The default role is alert. - * - * @param type - * Type of the notification - * @param role - * Role to set for the notification type - */ - public void setAssistiveRoleForType(Type type, Role role) { - UI.getCurrent().getNotificationConfiguration() - .setAssistiveRoleForStyle(getStyle(type), role); - } - - /** - * Gets the WAI-ARIA role for a notification type. - * - * This role defines how an assistive device handles a notification. - * Available roles are alert and status (@see Roles - * Model) - * - * The default role is alert. - * - * @param type - * Type of the notification - * @return Role to set for the notification type - */ - public Role getAssistiveRoleForType(Type type) { - return UI.getCurrent().getNotificationConfiguration() - .getAssistiveRoleForStyle(getStyle(type)); - } - - private String getStyle(Type type) { - String style = ""; - - switch (type) { - case WARNING_MESSAGE: - style = "warning"; - break; - case ERROR_MESSAGE: - style = "error"; - break; - case TRAY_NOTIFICATION: - style = "tray"; - break; - case ASSISTIVE_NOTIFICATION: - style = "assistive"; - break; - case HUMANIZED_MESSAGE: - default: - style = "humanized"; - break; - } - - return style; - } - /** * Sets whether html is allowed in the caption and description. If set to * true, the texts are passed to the browser as html and the developer is diff --git a/server/src/com/vaadin/ui/NotificationConfiguration.java b/server/src/com/vaadin/ui/NotificationConfiguration.java index 52d3e76d63..e6d19f84f7 100644 --- a/server/src/com/vaadin/ui/NotificationConfiguration.java +++ b/server/src/com/vaadin/ui/NotificationConfiguration.java @@ -21,112 +21,99 @@ package com.vaadin.ui; import java.io.Serializable; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; -import com.vaadin.shared.ui.ui.UIState.NotificationConfigurationState; +import com.vaadin.shared.ui.ui.NotificationRole; +import com.vaadin.shared.ui.ui.UIState.NotificationTypeConfiguration; +import com.vaadin.ui.Notification.Type; /** * Provides methods for configuring the notification. - * + * * @author Vaadin Ltd - * @since 7.1 + * @since 7.2 */ public interface NotificationConfiguration extends Serializable { - public void setStyleConfiguration(String style, String prefix, - String postfix, Role ariaRole); - /** - * Returns the complete configuration object for the given notification - * style. - * - * @param style - * String of the notification style to return - * @return The notification configuration object - */ - public NotificationConfigurationBean getStyleConfiguration(String style); - - /** - * Sets the accessibility prefix for the given notification style. - * - * This prefix is read to assistive device users in front of the content of - * the notification, but not visible on the page. - * - * @param style - * String of the notification style + * Sets the accessibility prefix for a notification type. + *

+ * This prefix is read to assistive device users before the content of the + * notification, but not visible on the page. + * + * @param type + * type of the notification * @param prefix - * String that is placed before the notification content + * string that is placed before the notification content */ - public void setAssistivePrefixForStyle(String style, String prefix); + public void setAssistivePrefix(Type type, String prefix); /** - * Returns the accessibility prefix for the given notification style. - * - * This prefix is read to assistive device users in front of the content of - * the notification, but not visible on the page. - * - * @param style - * String of the notification style - * @return The prefix of the provided notification style + * Gets the accessibility prefix for a notification type. + *

+ * This prefix is read to assistive device users before the content of the + * notification, but not visible on the page. + * + * @param type + * type of the notification + * @return The accessibility prefix for the provided notification type */ - public String getAssistivePrefixForStyle(String style); + public String getAssistivePrefix(Type type); /** - * Sets the accessibility postfix for the given notification style. - * + * Sets the accessibility postfix for a notification type. + *

* This postfix is read to assistive device users after the content of the * notification, but not visible on the page. - * - * @param style - * String of the notification style + * + * @param type + * type of the notification * @param postfix - * String that is placed after the notification content + * string that is placed after the notification content */ - public void setAssistivePostfixForStyle(String style, String postfix); + public void setAssistivePostfix(Type type, String postfix); /** - * Returns the accessibility postfix for the given notification style. - * + * Gets the accessibility postfix for a notification type. + *

* This postfix is read to assistive device users after the content of the * notification, but not visible on the page. - * - * @param style - * String of the notification style - * @return The postfix of the provided notification style + * + * @param type + * type of the notification + * @return The accessibility postfix for the provided notification type */ - public String getAssistivePostfixForStyle(String style); + public String getAssistivePostfix(Type type); /** - * Sets the WAI-ARIA role for a notification style. - * + * Sets the WAI-ARIA role for a notification type. + *

* This role defines how an assistive device handles a notification. - * Available roles are alert, alertdialog and status (@see Roles - * Model) - * + * Model). + * * The default role is alert. - * - * @param style - * String of the notification style + * + * @param type + * type of the notification * @param role - * Role to set for the notification type + * role to set for the notification type */ - public void setAssistiveRoleForStyle(String style, Role role); + public void setAssistiveRole(Type type, NotificationRole role); /** - * Returns the WAI-ARIA role for a notification style. - * + * Gets the WAI-ARIA role for a notification type. + *

* This role defines how an assistive device handles a notification. - * Available roles are alert, alertdialog and status (@see Roles - * Model ) - * + * Model) + *

* The default role is alert. - * - * @param style - * String of the notification style - * @return The current Role for the notification type + * + * @param type + * type of the notification + * @return role to set for the notification type */ - public Role getAssistiveRoleForStyle(String style); + public NotificationRole getAssistiveRole(Type type); } class NotificationConfigurationImpl implements NotificationConfiguration { @@ -137,133 +124,62 @@ class NotificationConfigurationImpl implements NotificationConfiguration { this.ui = ui; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#setStyleConfiguration(java.lang - * .String, java.lang.String, java.lang.String, - * com.vaadin.ui.NotificationConfiguration.Role) - */ - @Override - public void setStyleConfiguration(String style, String prefix, - String postfix, Role ariaRole) { - getState().setup.put(style, new NotificationConfigurationBean(prefix, - postfix, ariaRole)); - } - - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#getStyleConfiguration(java.lang - * .String) - */ @Override - public NotificationConfigurationBean getStyleConfiguration(String style) { - return getState(false).setup.get(style); + public void setAssistivePrefix(Type type, String prefix) { + getConfigurationBean(type).prefix = prefix; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#setStylePrefix(java.lang.String, - * java.lang.String) - */ @Override - public void setAssistivePrefixForStyle(String style, String prefix) { - getConfigurationBean(style).setAssistivePrefix(prefix); - } - - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#getStylePrefix(java.lang.String) - */ - @Override - public String getAssistivePrefixForStyle(String style) { - NotificationConfigurationBean styleSetup = getState().setup.get(style); + public String getAssistivePrefix(Type type) { + NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { - return styleSetup.getAssistivePrefix(); + return styleSetup.prefix; } return null; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#setStylePostfix(com.vaadin.ui - * .Notification.Type, java.lang.String) - */ @Override - public void setAssistivePostfixForStyle(String style, String postfix) { - getConfigurationBean(style).setAssistivePostfix(postfix); + public void setAssistivePostfix(Type type, String postfix) { + getConfigurationBean(type).postfix = postfix; } - /* - * (non-Javadoc) - * - * @see - * com.vaadin.ui.NotificationConfiguration#getStylePostfix(com.vaadin.ui - * .Notification.Type) - */ @Override - public String getAssistivePostfixForStyle(String style) { - NotificationConfigurationBean styleSetup = getState().setup.get(style); + public String getAssistivePostfix(Type type) { + NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { - return styleSetup.getAssistivePostfix(); + return styleSetup.postfix; } return null; } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.NotificationConfiguration#setStyleRole(com.vaadin.ui. - * Notification.Type, com.vaadin.ui.NotificationConfiguration.Role) - */ @Override - public void setAssistiveRoleForStyle(String style, Role role) { - getConfigurationBean(style).setAssistiveRole(role); + public void setAssistiveRole(Type type, NotificationRole role) { + getConfigurationBean(type).notificationRole = role; } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.NotificationConfiguration#getStyleRole(com.vaadin.ui. - * Notification.Type) - */ @Override - public Role getAssistiveRoleForStyle(String style) { - NotificationConfigurationBean styleSetup = getState().setup.get(style); + public NotificationRole getAssistiveRole(Type type) { + NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup != null) { - return styleSetup.getAssistiveRole(); + return styleSetup.notificationRole; } return null; } - private NotificationConfigurationBean getConfigurationBean(String style) { - NotificationConfigurationBean styleSetup = getState().setup.get(style); + private NotificationTypeConfiguration getConfigurationBean(Type type) { + NotificationTypeConfiguration styleSetup = getTypeConf(type); if (styleSetup == null) { - styleSetup = new NotificationConfigurationBean(); - getState().setup.put(style, styleSetup); + styleSetup = new NotificationTypeConfiguration(); + ui.getState().notificationConfigurations.put(type.getStyle(), styleSetup); } return styleSetup; } - private NotificationConfigurationState getState() { - return ui.getState().notificationConfiguration; + private NotificationTypeConfiguration getTypeConf(Type type) { + return ui.getState().notificationConfigurations.get(type.getStyle()); } - - private NotificationConfigurationState getState(boolean markAsDirty) { - return ui.getState(markAsDirty).notificationConfiguration; - } - } diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java index 8e2c40fc0f..17ea352d49 100644 --- a/server/src/com/vaadin/ui/TabSheet.java +++ b/server/src/com/vaadin/ui/TabSheet.java @@ -292,34 +292,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, * @return the created {@link Tab} */ public Tab addTab(Component c, String caption, Resource icon) { - return addTab(c, caption, icon, "", components.size()); - } - - /** - * Adds a new tab into TabSheet. - * - * The first tab added to a tab sheet is automatically selected and a tab - * selection event is fired. - * - * If the component is already present in the tab sheet, changes its caption - * and icon and icon alternate text and returns the corresponding (old) tab, - * preserving other tab metadata. - * - * @param c - * the component to be added onto tab - should not be null. - * @param caption - * the caption to be set for the component and used rendered in - * tab bar - * @param icon - * the icon to be set for the component and used rendered in tab - * bar - * @param iconAltText - * the alternate text for the icon - * @return the created {@link Tab} - */ - public Tab addTab(Component c, String caption, Resource icon, - String iconAltText) { - return addTab(c, caption, icon, iconAltText, components.size()); + return addTab(c, caption, icon, components.size()); } /** @@ -344,43 +317,13 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, * the position at where the the tab should be added. * @return the created {@link Tab} */ - public Tab addTab(Component c, String caption, Resource icon, int position) { - return addTab(c, caption, icon, "", position); - } - - /** - * Adds a new tab into TabSheet. - * - * The first tab added to a tab sheet is automatically selected and a tab - * selection event is fired. - * - * If the component is already present in the tab sheet, changes its caption - * and icon and icon alternate text and returns the corresponding (old) tab, - * preserving other tab metadata like the position. - * - * @param tabComponent - * the component to be added onto tab - should not be null. - * @param caption - * the caption to be set for the component and used rendered in - * tab bar - * @param icon - * the icon to be set for the component and used rendered in tab - * bar - * @param iconAltText - * the alternate text for the icon - * @param position - * the position at where the the tab should be added. - * @return the created {@link Tab} - */ - public Tab addTab(Component tabComponent, String caption, Resource icon, - String iconAltText, int position) { - + public Tab addTab(Component tabComponent, String caption, Resource icon, int position) { if (tabComponent == null) { return null; } else if (tabs.containsKey(tabComponent)) { Tab tab = tabs.get(tabComponent); tab.setCaption(caption); - tab.setIcon(icon, iconAltText); + tab.setIcon(icon); return tab; } else { components.add(position, tabComponent); @@ -461,11 +404,11 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, Tab tab = ((TabSheet) source).getTab(c); caption = tab.getCaption(); icon = tab.getIcon(); - iconAltText = tab.getIconAltText(); + iconAltText = tab.getIconAlternateText(); } source.removeComponent(c); - addTab(c, caption, icon, iconAltText); - + Tab tab = addTab(c, caption, icon); + tab.setIconAlternateText(iconAltText); } } @@ -968,16 +911,20 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, /** * Gets the icon alt text for the tab. + * + * @since 7.2 */ - public String getIconAltText(); + public String getIconAlternateText(); /** * Sets the icon alt text for the tab. - * + * + * @since 7.2 + * * @param iconAltText * the icon to set */ - public void setIconAltText(String iconAltText); + public void setIconAlternateText(String iconAltText); /** * Gets the description for the tab. The description can be used to @@ -1135,12 +1082,12 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, } @Override - public String getIconAltText() { + public String getIconAlternateText() { return tabState.iconAltText; } @Override - public void setIconAltText(String iconAltText) { + public void setIconAlternateText(String iconAltText) { tabState.iconAltText = iconAltText; markAsDirty(); } @@ -1428,7 +1375,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, */ private static void copyTabMetadata(Tab from, Tab to) { to.setCaption(from.getCaption()); - to.setIcon(from.getIcon(), from.getIconAltText()); + to.setIcon(from.getIcon(), from.getIconAlternateText()); to.setDescription(from.getDescription()); to.setVisible(from.isVisible()); to.setEnabled(from.isEnabled()); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 2b2e773601..5fbd654dcf 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -668,10 +668,10 @@ public abstract class UI extends AbstractSingleComponentContainer implements * @param request * the request that caused this UI to be reloaded */ - public void doReinit(VaadinRequest request) { + public void doRefresh(VaadinRequest request) { // This is a horrible hack. We want to have the most recent location and - // browser window size available in reinit(), but we want to call - // listeners, if any, only after reinit(). So we momentarily assign the + // browser window size available in refresh(), but we want to call + // listeners, if any, only after refresh(). So we momentarily assign the // old values back before setting the new values again to ensure the // events are properly fired. @@ -683,7 +683,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements page.init(request); - reinit(request); + refresh(request); URI newLocation = page.getLocation(); int newWidth = page.getBrowserWindowWidth(); @@ -709,7 +709,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements * @param request * the request that caused this UI to be reloaded */ - protected void reinit(VaadinRequest request) { + protected void refresh(VaadinRequest request) { } /** diff --git a/server/src/com/vaadin/ui/Window.java b/server/src/com/vaadin/ui/Window.java index d3afdaacf1..022adc6373 100644 --- a/server/src/com/vaadin/ui/Window.java +++ b/server/src/com/vaadin/ui/Window.java @@ -41,7 +41,7 @@ import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.window.WindowMode; import com.vaadin.shared.ui.window.WindowServerRpc; import com.vaadin.shared.ui.window.WindowState; -import com.vaadin.shared.ui.window.WindowState.WindowRole; +import com.vaadin.shared.ui.window.WindowRole; import com.vaadin.util.ReflectTools; /** diff --git a/server/tests/src/com/vaadin/ui/UIInitRefreshTest.java b/server/tests/src/com/vaadin/ui/UIInitRefreshTest.java new file mode 100644 index 0000000000..a807e4b656 --- /dev/null +++ b/server/tests/src/com/vaadin/ui/UIInitRefreshTest.java @@ -0,0 +1,116 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.ui; + +import org.easymock.EasyMock; +import org.easymock.IMocksControl; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.server.Page.BrowserWindowResizeEvent; +import com.vaadin.server.Page.BrowserWindowResizeListener; +import com.vaadin.server.Page.UriFragmentChangedEvent; +import com.vaadin.server.Page.UriFragmentChangedListener; +import com.vaadin.server.VaadinRequest; + +public class UIInitRefreshTest { + + private boolean initCalled; + private boolean refreshCalled; + private boolean fragmentChangeCalled; + private boolean browserWindowResizeCalled; + + private class TestUI extends UI implements UriFragmentChangedListener, + BrowserWindowResizeListener { + @Override + protected void init(VaadinRequest request) { + getPage().addBrowserWindowResizeListener(this); + getPage().addUriFragmentChangedListener(this); + + initCalled = true; + + Assert.assertEquals("foo", getPage().getUriFragment()); + Assert.assertEquals(100, getPage().getBrowserWindowWidth()); + Assert.assertEquals(100, getPage().getBrowserWindowHeight()); + + Assert.assertFalse(fragmentChangeCalled); + Assert.assertFalse(browserWindowResizeCalled); + } + + @Override + protected void refresh(VaadinRequest request) { + refreshCalled = true; + + Assert.assertEquals("bar", getPage().getUriFragment()); + Assert.assertEquals(200, getPage().getBrowserWindowWidth()); + Assert.assertEquals(200, getPage().getBrowserWindowHeight()); + + Assert.assertFalse(fragmentChangeCalled); + Assert.assertFalse(browserWindowResizeCalled); + } + + @Override + public void browserWindowResized(BrowserWindowResizeEvent event) { + Assert.assertEquals(200, event.getWidth()); + Assert.assertEquals(200, event.getHeight()); + browserWindowResizeCalled = true; + } + + @Override + public void uriFragmentChanged(UriFragmentChangedEvent event) { + Assert.assertEquals("bar", event.getUriFragment()); + fragmentChangeCalled = true; + } + }; + + @Before + public void setUp() { + initCalled = refreshCalled = fragmentChangeCalled = browserWindowResizeCalled = false; + } + + @Test + public void testListenersCalled() { + IMocksControl control = EasyMock.createNiceControl(); + + VaadinRequest initRequest = control.createMock(VaadinRequest.class); + EasyMock.expect(initRequest.getParameter("v-loc")).andReturn( + "http://example.com/#foo"); + EasyMock.expect(initRequest.getParameter("v-cw")).andReturn("100"); + EasyMock.expect(initRequest.getParameter("v-ch")).andReturn("100"); + + VaadinRequest reinitRequest = control.createMock(VaadinRequest.class); + EasyMock.expect(reinitRequest.getParameter("v-loc")).andReturn( + "http://example.com/#bar"); + EasyMock.expect(reinitRequest.getParameter("v-cw")).andReturn("200"); + EasyMock.expect(reinitRequest.getParameter("v-ch")).andReturn("200"); + + control.replay(); + + UI ui = new TestUI(); + ui.doInit(initRequest, 0, ""); + + Assert.assertTrue(initCalled); + Assert.assertFalse(fragmentChangeCalled); + Assert.assertFalse(browserWindowResizeCalled); + + ui.doRefresh(reinitRequest); + + Assert.assertTrue(refreshCalled); + Assert.assertTrue(fragmentChangeCalled); + Assert.assertTrue(browserWindowResizeCalled); + } +} diff --git a/server/tests/src/com/vaadin/ui/UIInitReinitTest.java b/server/tests/src/com/vaadin/ui/UIInitReinitTest.java deleted file mode 100644 index f8ec0e68c2..0000000000 --- a/server/tests/src/com/vaadin/ui/UIInitReinitTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.ui; - -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.server.Page.BrowserWindowResizeEvent; -import com.vaadin.server.Page.BrowserWindowResizeListener; -import com.vaadin.server.Page.UriFragmentChangedEvent; -import com.vaadin.server.Page.UriFragmentChangedListener; -import com.vaadin.server.VaadinRequest; - -public class UIInitReinitTest { - - private boolean initCalled; - private boolean reinitCalled; - private boolean fragmentChangeCalled; - private boolean browserWindowResizeCalled; - - private class TestUI extends UI implements UriFragmentChangedListener, - BrowserWindowResizeListener { - @Override - protected void init(VaadinRequest request) { - getPage().addBrowserWindowResizeListener(this); - getPage().addUriFragmentChangedListener(this); - - initCalled = true; - - Assert.assertEquals("foo", getPage().getUriFragment()); - Assert.assertEquals(100, getPage().getBrowserWindowWidth()); - Assert.assertEquals(100, getPage().getBrowserWindowHeight()); - - Assert.assertFalse(fragmentChangeCalled); - Assert.assertFalse(browserWindowResizeCalled); - } - - @Override - protected void reinit(VaadinRequest request) { - reinitCalled = true; - - Assert.assertEquals("bar", getPage().getUriFragment()); - Assert.assertEquals(200, getPage().getBrowserWindowWidth()); - Assert.assertEquals(200, getPage().getBrowserWindowHeight()); - - Assert.assertFalse(fragmentChangeCalled); - Assert.assertFalse(browserWindowResizeCalled); - } - - @Override - public void browserWindowResized(BrowserWindowResizeEvent event) { - Assert.assertEquals(200, event.getWidth()); - Assert.assertEquals(200, event.getHeight()); - browserWindowResizeCalled = true; - } - - @Override - public void uriFragmentChanged(UriFragmentChangedEvent event) { - Assert.assertEquals("bar", event.getUriFragment()); - fragmentChangeCalled = true; - } - }; - - @Before - public void setUp() { - initCalled = reinitCalled = fragmentChangeCalled = browserWindowResizeCalled = false; - } - - @Test - public void testListenersCalled() { - IMocksControl control = EasyMock.createNiceControl(); - - VaadinRequest initRequest = control.createMock(VaadinRequest.class); - EasyMock.expect(initRequest.getParameter("v-loc")).andReturn( - "http://example.com/#foo"); - EasyMock.expect(initRequest.getParameter("v-cw")).andReturn("100"); - EasyMock.expect(initRequest.getParameter("v-ch")).andReturn("100"); - - VaadinRequest reinitRequest = control.createMock(VaadinRequest.class); - EasyMock.expect(reinitRequest.getParameter("v-loc")).andReturn( - "http://example.com/#bar"); - EasyMock.expect(reinitRequest.getParameter("v-cw")).andReturn("200"); - EasyMock.expect(reinitRequest.getParameter("v-ch")).andReturn("200"); - - control.replay(); - - UI ui = new TestUI(); - ui.doInit(initRequest, 0, ""); - - Assert.assertTrue(initCalled); - Assert.assertFalse(fragmentChangeCalled); - Assert.assertFalse(browserWindowResizeCalled); - - ui.doReinit(reinitRequest); - - Assert.assertTrue(reinitCalled); - Assert.assertTrue(fragmentChangeCalled); - Assert.assertTrue(browserWindowResizeCalled); - } -} diff --git a/shared/src/com/vaadin/shared/ui/ui/NotificationConfigurationBean.java b/shared/src/com/vaadin/shared/ui/ui/NotificationConfigurationBean.java deleted file mode 100644 index 6c8c743d57..0000000000 --- a/shared/src/com/vaadin/shared/ui/ui/NotificationConfigurationBean.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/** - * - */ -package com.vaadin.shared.ui.ui; - -import java.io.Serializable; - -/** - * Holds configuration information for a notification type. - * - * @author Vaadin Ltd - */ -public class NotificationConfigurationBean implements Serializable { - /** - * Available WAI-ARIA roles for a notification. - */ - public enum Role { - ALERT, STATUS - } - - private String prefix; - private String postfix; - private Role role = Role.ALERT; - - public NotificationConfigurationBean() { - } - - public NotificationConfigurationBean(String prefix, String postfix, - Role role) { - this.prefix = prefix; - this.postfix = postfix; - this.role = role; - } - - /** - * Returns the accessibility prefix, which is placed before the notification - * content. - * - * @return the prefix - */ - public String getAssistivePrefix() { - return prefix; - } - - /** - * Sets the accessibility prefix, which is placed before the notification - * content. - * - * @param pefix - * the prefix to set - */ - public void setAssistivePrefix(String prefix) { - this.prefix = prefix; - } - - /** - * Checks if an accessibility prefix is set. - * - * @return true when assistivePrefix is not null and has a length > 0, false - * otherwise - */ - public boolean hasAssistivePrefix() { - return prefix != null && !prefix.isEmpty(); - } - - /** - * Returns the accessibility postfix, which is placed after the notification - * content. - * - * @return the postfix - */ - public String getAssistivePostfix() { - return postfix; - } - - /** - * Sets the accessibility postfix, which is placed after the notification - * content. - * - * @param postfix - * the postfix to set - */ - public void setAssistivePostfix(String postfix) { - this.postfix = postfix; - } - - /** - * Checks if an accessibility postfix is set. - * - * @return true when postfix is not null and has a length > 0, false - * otherwise - */ - public boolean hasAssistivePostfix() { - return postfix != null && !postfix.isEmpty(); - } - - /** - * Returns the WAI-ARIA role that defines how an assistive device will - * inform the user about a notification. - * - * @return the role - */ - public Role getAssistiveRole() { - return role; - } - - /** - * Sets the WAI-ARIA role that defines how an assistive device will inform - * the user about a notification. - * - * Available roles are alert, alertdialog and status (@see Roles - * Model). - * - * @param role - * the role to set - */ - public void setAssistiveRole(Role role) { - this.role = role; - } -} diff --git a/shared/src/com/vaadin/shared/ui/ui/NotificationRole.java b/shared/src/com/vaadin/shared/ui/ui/NotificationRole.java new file mode 100644 index 0000000000..218e5e59e6 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/ui/NotificationRole.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.ui; + +/** + * Available WAI-ARIA roles for a notification. + * + * @since 7.2 + */ +public enum NotificationRole { + ALERT, STATUS +} diff --git a/shared/src/com/vaadin/shared/ui/ui/UIState.java b/shared/src/com/vaadin/shared/ui/ui/UIState.java index d2e6f037e9..08fe3c7d64 100644 --- a/shared/src/com/vaadin/shared/ui/ui/UIState.java +++ b/shared/src/com/vaadin/shared/ui/ui/UIState.java @@ -23,17 +23,50 @@ import java.util.Map; import com.vaadin.shared.communication.PushMode; import com.vaadin.shared.ui.TabIndexState; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; public class UIState extends TabIndexState { public TooltipConfigurationState tooltipConfiguration = new TooltipConfigurationState(); public LoadingIndicatorConfigurationState loadingIndicatorConfiguration = new LoadingIndicatorConfigurationState(); - public NotificationConfigurationState notificationConfiguration = new NotificationConfigurationState(); public int pollInterval = -1; // Informing users of assistive devices, that the content of this container // is announced automatically and does not need to be navigated into public String overlayContainerLabel = "This content is announced automatically and does not need to be navigated into."; + public Map notificationConfigurations = new HashMap(); + { + notificationConfigurations.put("error", + new NotificationTypeConfiguration("Error: ", + " - close with ESC-key", NotificationRole.ALERT)); + notificationConfigurations.put("warning", + new NotificationTypeConfiguration("Warning: ", null, + NotificationRole.ALERT)); + notificationConfigurations.put("humanized", + new NotificationTypeConfiguration("Info: ", null, + NotificationRole.ALERT)); + notificationConfigurations.put("tray", + new NotificationTypeConfiguration("Status: ", null, + NotificationRole.STATUS)); + notificationConfigurations.put("assistive", + new NotificationTypeConfiguration("Note: ", null, + NotificationRole.STATUS)); + } + /** + * State related to the Page class. + */ + public PageState pageState = new PageState(); + /** + * State related to the LocaleService class. + */ + public LocaleServiceState localeServiceState = new LocaleServiceState(); + /** + * Configuration for the push channel + */ + public PushConfigurationState pushConfiguration = new PushConfigurationState(); + { + primaryStyleName = "v-ui"; + // Default is 1 for legacy reasons + tabIndex = 1; + } public static class LoadingIndicatorConfigurationState implements Serializable { @@ -50,19 +83,19 @@ public class UIState extends TabIndexState { public int maxWidth = 500; } - public static class NotificationConfigurationState implements Serializable { - public Map setup = new HashMap(); - { - setup.put("error", new NotificationConfigurationBean("Error: ", - " - close with ESC-key", Role.ALERT)); - setup.put("warning", new NotificationConfigurationBean("Warning: ", - null, Role.ALERT)); - setup.put("humanized", new NotificationConfigurationBean("Info: ", - null, Role.ALERT)); - setup.put("tray", new NotificationConfigurationBean("Status: ", - null, Role.STATUS)); - setup.put("assistive", new NotificationConfigurationBean("Note: ", - null, Role.STATUS)); + public static class NotificationTypeConfiguration implements Serializable { + public String prefix; + public String postfix; + public NotificationRole notificationRole = NotificationRole.ALERT; + + public NotificationTypeConfiguration() { + } + + public NotificationTypeConfiguration(String prefix, String postfix, + NotificationRole role) { + this.prefix = prefix; + this.postfix = postfix; + this.notificationRole = role; } } @@ -80,26 +113,6 @@ public class UIState extends TabIndexState { } } - /** - * State related to the Page class. - */ - public PageState pageState = new PageState(); - /** - * State related to the LocaleService class. - */ - public LocaleServiceState localeServiceState = new LocaleServiceState(); - - /** - * Configuration for the push channel - */ - public PushConfigurationState pushConfiguration = new PushConfigurationState(); - - { - primaryStyleName = "v-ui"; - // Default is 1 for legacy reasons - tabIndex = 1; - } - public static class LocaleServiceState implements Serializable { public List localeData = new ArrayList(); } diff --git a/shared/src/com/vaadin/shared/ui/window/WindowRole.java b/shared/src/com/vaadin/shared/ui/window/WindowRole.java new file mode 100644 index 0000000000..fc6b099620 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/window/WindowRole.java @@ -0,0 +1,25 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.shared.ui.window; + +/** + * Available WAI-ARIA roles for a window. + * + * @since 7.2 + */ +public enum WindowRole { + ALERTDIALOG, DIALOG +} diff --git a/shared/src/com/vaadin/shared/ui/window/WindowState.java b/shared/src/com/vaadin/shared/ui/window/WindowState.java index e27bf87e88..ebb1995287 100644 --- a/shared/src/com/vaadin/shared/ui/window/WindowState.java +++ b/shared/src/com/vaadin/shared/ui/window/WindowState.java @@ -23,13 +23,6 @@ public class WindowState extends PanelState { primaryStyleName = "v-window"; } - /** - * Available WAI-ARIA roles for a window. - */ - public enum WindowRole { - ALERTDIALOG, DIALOG - } - public boolean modal = false; public boolean resizable = true; public boolean resizeLazy = false; diff --git a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java index 27af49a397..ecf704835f 100644 --- a/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java +++ b/uitest/src/com/vaadin/tests/components/notification/NotificationsWaiAria.java @@ -2,7 +2,7 @@ package com.vaadin.tests.components.notification; import com.vaadin.data.Item; import com.vaadin.server.Page; -import com.vaadin.shared.ui.ui.NotificationConfigurationBean.Role; +import com.vaadin.shared.ui.ui.NotificationRole; import com.vaadin.tests.components.TestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -11,8 +11,10 @@ import com.vaadin.ui.ComboBox; import com.vaadin.ui.NativeSelect; import com.vaadin.ui.Notification; import com.vaadin.ui.Notification.Type; +import com.vaadin.ui.NotificationConfiguration; import com.vaadin.ui.TextArea; import com.vaadin.ui.TextField; +import com.vaadin.ui.UI; public class NotificationsWaiAria extends TestBase { @@ -36,9 +38,9 @@ public class NotificationsWaiAria extends TestBase { " - closes automatically after 10 seconds"); addComponent(postfix); - role = new NativeSelect("Role"); - role.addItem(Role.ALERT); - role.addItem(Role.STATUS); + role = new NativeSelect("NotificationRole"); + role.addItem(NotificationRole.ALERT); + role.addItem(NotificationRole.STATUS); role.setValue(role.getItemIds().iterator().next()); addComponent(role); @@ -96,9 +98,12 @@ public class NotificationsWaiAria extends TestBase { Notification n = new Notification(tf.getValue(), typeValue); n.setHtmlContentAllowed(true); - n.setAssistivePrefixForType(typeValue, prefix.getValue()); - n.setAssistivePostfixForType(typeValue, postfix.getValue()); - n.setAssistiveRoleForType(typeValue, (Role) role.getValue()); + NotificationConfiguration notificationConf = UI.getCurrent() + .getNotificationConfiguration(); + notificationConf.setAssistivePrefix(typeValue, prefix.getValue()); + notificationConf.setAssistivePostfix(typeValue, postfix.getValue()); + notificationConf + .setAssistiveRole(typeValue, (NotificationRole) role.getValue()); n.show(Page.getCurrent()); } diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetIcons.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetIcons.java index ccdc4ecb38..c5e01969a1 100644 --- a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetIcons.java +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetIcons.java @@ -46,7 +46,7 @@ public class TabSheetIcons extends TestBase { for (Component c : tab) { tabsheet.addTab(c); - tabsheet.getTab(c).setIconAltText( + tabsheet.getTab(c).setIconAlternateText( "iconalt" + tabsheet.getComponentCount()); } diff --git a/uitest/src/com/vaadin/tests/components/ui/UIRefresh.java b/uitest/src/com/vaadin/tests/components/ui/UIRefresh.java new file mode 100644 index 0000000000..b61e32c984 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIRefresh.java @@ -0,0 +1,49 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.ui; + +import com.vaadin.annotations.PreserveOnRefresh; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Label; + +@PreserveOnRefresh +public class UIRefresh extends AbstractTestUI { + + public static final String REINIT_ID = "reinit"; + + @Override + protected void setup(VaadinRequest request) { + } + + @Override + protected void refresh(VaadinRequest request) { + Label l = new Label("Reinit!"); + l.setId(REINIT_ID); + addComponent(l); + } + + @Override + public String getTestDescription() { + return "UI reinit after refresh"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(12191); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIRefreshTest.java b/uitest/src/com/vaadin/tests/components/ui/UIRefreshTest.java new file mode 100644 index 0000000000..974c4bfe5a --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/ui/UIRefreshTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.tests.components.ui; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.testbench.By; +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class UIRefreshTest extends MultiBrowserTest { + + @Test + public void testUIRefresh() { + openTestURL(); + Assert.assertFalse(reinitLabelExists()); + // Reload the page; UI.refresh should be invoked + openTestURL(); + Assert.assertTrue(reinitLabelExists()); + } + + private boolean reinitLabelExists() { + return !getDriver().findElements(By.id(UIRefresh.REINIT_ID)).isEmpty(); + } +} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIReinit.java b/uitest/src/com/vaadin/tests/components/ui/UIReinit.java deleted file mode 100644 index bef7a5a6d1..0000000000 --- a/uitest/src/com/vaadin/tests/components/ui/UIReinit.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.tests.components.ui; - -import com.vaadin.annotations.PreserveOnRefresh; -import com.vaadin.server.VaadinRequest; -import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Label; - -@PreserveOnRefresh -public class UIReinit extends AbstractTestUI { - - public static final String REINIT_ID = "reinit"; - - @Override - protected void setup(VaadinRequest request) { - } - - @Override - protected void reinit(VaadinRequest request) { - Label l = new Label("Reinit!"); - l.setId(REINIT_ID); - addComponent(l); - } - - @Override - public String getTestDescription() { - return "UI reinit after refresh"; - } - - @Override - protected Integer getTicketNumber() { - return Integer.valueOf(12191); - } -} diff --git a/uitest/src/com/vaadin/tests/components/ui/UIReinitTest.java b/uitest/src/com/vaadin/tests/components/ui/UIReinitTest.java deleted file mode 100644 index 82132d3c65..0000000000 --- a/uitest/src/com/vaadin/tests/components/ui/UIReinitTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.vaadin.tests.components.ui; - -import org.junit.Assert; -import org.junit.Test; - -import com.vaadin.testbench.By; -import com.vaadin.tests.tb3.MultiBrowserTest; - -public class UIReinitTest extends MultiBrowserTest { - - @Test - public void testUIReinit() { - openTestURL(); - Assert.assertFalse(reinitLabelExists()); - // Reload the page; UI.reinit should be invoked - openTestURL(); - Assert.assertTrue(reinitLabelExists()); - } - - private boolean reinitLabelExists() { - return !getDriver().findElements(By.id(UIReinit.REINIT_ID)).isEmpty(); - } -} diff --git a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAria.java b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAria.java index 39989926e7..c7379f666b 100644 --- a/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAria.java +++ b/uitest/src/com/vaadin/tests/components/window/ExtraWindowShownWaiAria.java @@ -2,7 +2,7 @@ package com.vaadin.tests.components.window; import com.vaadin.server.ThemeResource; import com.vaadin.server.VaadinRequest; -import com.vaadin.shared.ui.window.WindowState.WindowRole; +import com.vaadin.shared.ui.window.WindowRole; import com.vaadin.tests.components.AbstractTestUI; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; -- cgit v1.2.3 From c544c6cbfac98fb6c2e22465d89802caa6fd0ee6 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Mon, 14 Apr 2014 11:11:07 +0300 Subject: Fix copyright headers not passing the validation Also let through some other formatting changes that Eclipse insisted on when saving the touched files. Change-Id: I319de35c4862555b010d6da6d4a5e096619e2c34 --- .../com/vaadin/client/ApplicationConnection.java | 3 +-- .../client/extensions/ResponsiveConnector.java | 26 +++++++++++----------- server/src/com/vaadin/server/FontAwesome.java | 3 ++- server/src/com/vaadin/server/FontIcon.java | 3 ++- server/src/com/vaadin/server/Responsive.java | 8 +++---- 5 files changed, 22 insertions(+), 21 deletions(-) (limited to 'server/src/com') diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 5d614439bb..229460ed20 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -1,4 +1,4 @@ -/* +/* * Copyright 2000-2013 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not @@ -65,7 +65,6 @@ import com.google.gwt.user.client.Window.ClosingHandler; import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; -import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; import com.vaadin.client.ResourceLoader.ResourceLoadEvent; import com.vaadin.client.ResourceLoader.ResourceLoadListener; import com.vaadin.client.communication.HasJavaScriptConnectorHelper; diff --git a/client/src/com/vaadin/client/extensions/ResponsiveConnector.java b/client/src/com/vaadin/client/extensions/ResponsiveConnector.java index 500e4a0916..20a5278e1a 100644 --- a/client/src/com/vaadin/client/extensions/ResponsiveConnector.java +++ b/client/src/com/vaadin/client/extensions/ResponsiveConnector.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2013 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -100,13 +100,13 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements * @return The selectors in a comma delimited string. */ protected String constructSelectorsForTarget() { - String primaryStyle = this.target.getState().primaryStyleName; + String primaryStyle = target.getState().primaryStyleName; StringBuilder selectors = new StringBuilder(); selectors.append(".").append(primaryStyle); - if (this.target.getState().styles != null - && this.target.getState().styles.size() > 0) { - for (String style : this.target.getState().styles) { + if (target.getState().styles != null + && target.getState().styles.size() > 0) { + for (String style : target.getState().styles) { selectors.append(",.").append(style); selectors.append(",.").append(primaryStyle).append(".") .append(style); @@ -118,8 +118,8 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements } // Allow the ID to be used as the selector as well for ranges - if (this.target.getState().id != null) { - selectors.append(",#").append(this.target.getState().id); + if (target.getState().id != null) { + selectors.append(",#").append(target.getState().id); } return selectors.toString(); } @@ -128,7 +128,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements public void onUnregister() { super.onUnregister(); LayoutManager.get(getConnection()).removeElementResizeListener( - this.target.getWidget().getElement(), this); + target.getWidget().getElement(), this); } /** @@ -314,7 +314,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements int height = event.getLayoutManager() .getOuterHeight(event.getElement()); - com.google.gwt.user.client.Element element = this.target.getWidget() + com.google.gwt.user.client.Element element = target.getWidget() .getElement(); boolean forceRedraw = false; @@ -323,7 +323,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements event.getElement()); if (!"".equals(currentWidthRanges)) { - this.target.getWidget().getElement() + target.getWidget().getElement() .setAttribute("width-range", currentWidthRanges); forceRedraw = true; } else { @@ -335,7 +335,7 @@ public class ResponsiveConnector extends AbstractExtensionConnector implements event.getElement()); if (!"".equals(currentHeightRanges)) { - this.target.getWidget().getElement() + target.getWidget().getElement() .setAttribute("height-range", currentHeightRanges); forceRedraw = true; } else { diff --git a/server/src/com/vaadin/server/FontAwesome.java b/server/src/com/vaadin/server/FontAwesome.java index a7f4c7b342..d4ad612d45 100644 --- a/server/src/com/vaadin/server/FontAwesome.java +++ b/server/src/com/vaadin/server/FontAwesome.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 Vaadin Ltd. + * Copyright 2000-2013 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.vaadin.server; /** diff --git a/server/src/com/vaadin/server/FontIcon.java b/server/src/com/vaadin/server/FontIcon.java index 45279f2c44..6b9a55cf20 100644 --- a/server/src/com/vaadin/server/FontIcon.java +++ b/server/src/com/vaadin/server/FontIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 Vaadin Ltd. + * Copyright 2000-2013 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.vaadin.server; import com.vaadin.shared.ui.label.ContentMode; diff --git a/server/src/com/vaadin/server/Responsive.java b/server/src/com/vaadin/server/Responsive.java index d69c204c94..b92870b621 100644 --- a/server/src/com/vaadin/server/Responsive.java +++ b/server/src/com/vaadin/server/Responsive.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2013 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -49,7 +49,7 @@ import com.vaadin.ui.Component; * *

  * CssLayout layout = new CssLayout();
- * layout.setStyleName("responsive");
+ * layout.setStyleName("responsive");
  * layout.setSizeFull();
  * Responsive.makeResponsive(layout);
  * 
-- cgit v1.2.3 From 4709b75bb47d28630dacbb240bb43de16d972371 Mon Sep 17 00:00:00 2001 From: Maciej Przepióra Date: Fri, 11 Apr 2014 23:53:43 +0300 Subject: ContainerEventProvider returns style names from container. Fixes #10718 ContainerEventProvider doesn't actually return style names from container in certain situations (copy-pasted code). This patch fixes the problem. Change-Id: I512ea260f34a6db0572b614db393699da152fa8d --- .../calendar/ContainerEventProvider.java | 4 +-- .../component/calendar/ContainerDataSource.java | 32 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java index 37ea255d27..b025de6f9a 100644 --- a/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java +++ b/server/src/com/vaadin/ui/components/calendar/ContainerEventProvider.java @@ -224,8 +224,8 @@ public class ContainerEventProvider implements CalendarEditableEventProvider, } if (styleNameProperty != null && item.getItemPropertyIds().contains(styleNameProperty)) { - basicEvent.setDescription(String.valueOf(item.getItemProperty( - descriptionProperty).getValue())); + basicEvent.setStyleName(String.valueOf(item.getItemProperty( + styleNameProperty).getValue())); } event = basicEvent; } diff --git a/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java b/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java index 2bc95e371c..d5b0d5d9c8 100644 --- a/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java +++ b/server/tests/src/com/vaadin/tests/server/component/calendar/ContainerDataSource.java @@ -25,6 +25,7 @@ import org.junit.Test; import com.vaadin.data.Container.Indexed; import com.vaadin.data.Container.Sortable; import com.vaadin.data.Item; +import com.vaadin.data.Property; import com.vaadin.data.util.BeanItemContainer; import com.vaadin.data.util.IndexedContainer; import com.vaadin.ui.Calendar; @@ -327,6 +328,37 @@ public class ContainerDataSource extends TestCase { assertEquals(0, calendar.getEvents(start, end).size()); } + @Test + public void testStyleNamePropertyRetrieved() { + IndexedContainer ic = (IndexedContainer) createTestIndexedContainer(); + ic.addContainerProperty("testStyleName", String.class, ""); + for (int i = 0; i < 10; i++) { + Item item = ic.getItem(ic.getIdByIndex(i)); + @SuppressWarnings("unchecked") + Property itemProperty = item + .getItemProperty("testStyleName"); + itemProperty.setValue("testStyle"); + } + + ContainerEventProvider provider = new ContainerEventProvider(ic); + provider.setCaptionProperty("testCaption"); + provider.setDescriptionProperty("testDescription"); + provider.setStartDateProperty("testStartDate"); + provider.setEndDateProperty("testEndDate"); + provider.setStyleNameProperty("testStyleName"); + + calendar.setEventProvider(provider); + java.util.Calendar cal = java.util.Calendar.getInstance(); + Date now = cal.getTime(); + cal.add(java.util.Calendar.DAY_OF_MONTH, 20); + Date then = cal.getTime(); + List events = calendar.getEventProvider().getEvents(now, + then); + for (CalendarEvent ce : events) { + assertEquals("testStyle", ce.getStyleName()); + } + } + private static Indexed createTestBeanItemContainer() { BeanItemContainer eventContainer = new BeanItemContainer( CalendarEvent.class); -- cgit v1.2.3 From 134c3bb96bfeaf1eab488e685f3b5dce3093e0ef Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 18 Mar 2014 13:48:07 +0200 Subject: Clarify lock check assert message if another session is locked (#13473) Change-Id: I1120ad5acd553e22db95e3635fffbd453fd26310 --- server/src/com/vaadin/server/AbstractClientConnector.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/server/AbstractClientConnector.java b/server/src/com/vaadin/server/AbstractClientConnector.java index a73ca3d985..9fc4a9c3a2 100644 --- a/server/src/com/vaadin/server/AbstractClientConnector.java +++ b/server/src/com/vaadin/server/AbstractClientConnector.java @@ -132,13 +132,22 @@ public abstract class AbstractClientConnector implements ClientConnector, /* Documentation copied from interface */ @Override public void markAsDirty() { - assert getSession() == null || getSession().hasLock() : "Session must be locked when markAsDirty() is called"; + assert getSession() == null || getSession().hasLock() : buildLockAssertMessage("markAsDirty()"); UI uI = getUI(); if (uI != null) { uI.getConnectorTracker().markDirty(this); } } + private String buildLockAssertMessage(String method) { + if (VaadinService.isOtherSessionLocked(getSession())) { + return "The session of this connecor is not locked, but there is another session that is locked. " + + "This might be caused by accidentally using a connector that belongs to another session."; + } else { + return "Session must be locked when " + method + " is called"; + } + } + /** * Registers an RPC interface implementation for this component. * @@ -217,7 +226,7 @@ public abstract class AbstractClientConnector implements ClientConnector, * @see #getState() */ protected SharedState getState(boolean markAsDirty) { - assert getSession() == null || getSession().hasLock() : "Session must be locked when getState() is called"; + assert getSession() == null || getSession().hasLock() : buildLockAssertMessage("getState()"); if (null == sharedState) { sharedState = createState(); -- cgit v1.2.3 From e77818472d1195b2937f3f654712afec00fadc26 Mon Sep 17 00:00:00 2001 From: Juuso Valli Date: Wed, 16 Apr 2014 11:07:44 +0300 Subject: Clean Table.propertyValueConverters if the property is removed (#8168) Clean Table.propertyValueConverters if the property it attached to is removed, or if the container is changed and the new container does not contain a property with that identifier with a matching type. Change-Id: I894ee6462ea7b9c1f9138a24fcb84db829165c7d --- server/src/com/vaadin/ui/Table.java | 74 +++- .../table/TablePropertyValueConverter.java | 380 +++++++++++++++++++++ 2 files changed, 445 insertions(+), 9 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/table/TablePropertyValueConverter.java (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 06e82dedcb..00a7038afd 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -2647,6 +2647,10 @@ public class Table extends AbstractSelect implements Action.Container, * new container contains properties that are not meant to be shown you * should use {@link Table#setContainerDataSource(Container, Collection)} * instead, especially if the table is editable. + *

+ * Keeps propertyValueConverters if the corresponding id exists in the new + * data source and is of a compatible type. + *

* * @param newDataSource * the new data source. @@ -2681,9 +2685,14 @@ public class Table extends AbstractSelect implements Action.Container, /** * Sets the container data source and the columns that will be visible. * Columns are shown in the collection's iteration order. + *

+ * Keeps propertyValueConverters if the corresponding id exists in the new + * data source and is of a compatible type. + *

* * @see Table#setContainerDataSource(Container) * @see Table#setVisibleColumns(Object[]) + * @see Table#setConverter(Object, Converter) * * @param newDataSource * the new data source. @@ -2702,6 +2711,26 @@ public class Table extends AbstractSelect implements Action.Container, visibleIds = new ArrayList(); } + // Retain propertyValueConverters if their corresponding ids are + // properties of the new + // data source and are of a compatible type + if (propertyValueConverters != null) { + Collection newPropertyIds = newDataSource + .getContainerPropertyIds(); + LinkedList retainableValueConverters = new LinkedList(); + for (Object propertyId : newPropertyIds) { + Converter converter = getConverter(propertyId); + if (converter != null) { + if (typeIsCompatible(converter.getModelType(), + newDataSource.getType(propertyId))) { + retainableValueConverters.add(propertyId); + } + } + } + propertyValueConverters.keySet().retainAll( + retainableValueConverters); + } + // Assures that the data source is ordered by making unordered // containers ordered by wrapping them if (newDataSource instanceof Container.Ordered) { @@ -2737,6 +2766,34 @@ public class Table extends AbstractSelect implements Action.Container, enableContentRefreshing(true); } + /** + * Checks if class b can be safely assigned to class a. + * + * @param a + * @param b + * @return + */ + private boolean typeIsCompatible(Class a, Class b) { + // TODO Implement this check properly + // Map, Class> typemap = new HashMap, Class>(); + // typemap.put(byte.class, Byte.class); + // typemap.put(short.class, Short.class); + // typemap.put(int.class, Integer.class); + // typemap.put(long.class, Long.class); + // typemap.put(float.class, Float.class); + // typemap.put(double.class, Double.class); + // typemap.put(char.class, Character.class); + // typemap.put(boolean.class, Boolean.class); + // if (typemap.containsKey(a)) { + // a = typemap.get(a); + // } + // if (typemap.containsKey(b)) { + // b = typemap.get(b); + // } + // return a.isAssignableFrom(b); + return true; + } + /** * Gets items ids from a range of key values * @@ -4229,6 +4286,8 @@ public class Table extends AbstractSelect implements Action.Container, columnIcons.remove(propertyId); columnHeaders.remove(propertyId); columnFooters.remove(propertyId); + // If a propertyValueConverter was defined for the property, remove it. + propertyValueConverters.remove(propertyId); return super.removeContainerProperty(propertyId); } @@ -5844,16 +5903,13 @@ public class Table extends AbstractSelect implements Action.Container, throw new IllegalArgumentException("PropertyId " + propertyId + " must be in the container"); } - // FIXME: This check should be here but primitive types like Boolean - // formatter for boolean property must be handled - // if (!converter.getSourceType().isAssignableFrom(getType(propertyId))) - // { - // throw new IllegalArgumentException("Property type (" - // + getType(propertyId) - // + ") must match converter source type (" - // + converter.getSourceType() + ")"); - // } + if (!typeIsCompatible(converter.getModelType(), getType(propertyId))) { + throw new IllegalArgumentException("Property type (" + + getType(propertyId) + + ") must match converter source type (" + + converter.getModelType() + ")"); + } propertyValueConverters.put(propertyId, (Converter) converter); refreshRowCache(); diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TablePropertyValueConverter.java b/server/tests/src/com/vaadin/tests/server/component/table/TablePropertyValueConverter.java new file mode 100644 index 0000000000..418ca333bc --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/table/TablePropertyValueConverter.java @@ -0,0 +1,380 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.table; + +import java.lang.reflect.Field; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +import java.util.Map.Entry; +import java.util.Set; + +import junit.framework.TestCase; + +import org.junit.Test; + +import com.vaadin.data.Container; +import com.vaadin.data.Item; +import com.vaadin.data.Property; +import com.vaadin.data.util.IndexedContainer; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.ui.Table; + +/** + * + * @since + * @author Vaadin Ltd + */ +public class TablePropertyValueConverter extends TestCase { + protected TestableTable table; + protected Collection initialProperties; + + @Test + public void testRemovePropertyId() { + Collection converters = table.getCurrentConverters(); + assertTrue("Set of converters was empty at the start.", + converters.size() > 0); + + Object firstId = converters.iterator().next(); + + table.removeContainerProperty(firstId); + + Collection converters2 = table.getCurrentConverters(); + assertTrue("FirstId was not removed", !converters2.contains(firstId)); + + assertTrue("The number of removed converters was not one.", + converters.size() - converters2.size() == 1); + + for (Object originalId : converters) { + if (!originalId.equals(firstId)) { + assertTrue("The wrong converter was removed.", + converters2.contains(originalId)); + } + } + + } + + @Test + public void testSetContainer() { + table.setContainerDataSource(createContainer(new String[] { "col1", + "col3", "col4", "col5" })); + Collection converters = table.getCurrentConverters(); + assertTrue("There should only have been one converter left.", + converters.size() == 1); + Object onlyKey = converters.iterator().next(); + assertTrue("The incorrect key was left.", onlyKey.equals("col1")); + + } + + @Test + public void testSetContainerWithInexactButCompatibleTypes() { + TestableTable customTable = new TestableTable("Test table", + createContainer(new String[] { "col1", "col2", "col3" }, + new Class[] { String.class, BaseClass.class, + DerivedClass.class })); + customTable.setConverter("col1", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model"; + } + + @Override + public String convertToPresentation(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + }); + customTable.setConverter("col2", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public BaseClass convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return new BaseClass("model"); + } + + @Override + public Class getModelType() { + return BaseClass.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + @Override + public String convertToPresentation(BaseClass value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + }); + customTable.setConverter("col3", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public DerivedClass convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return new DerivedClass("derived" + 1001); + } + + @Override + public Class getModelType() { + return DerivedClass.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + @Override + public String convertToPresentation(DerivedClass value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + }); + customTable.setContainerDataSource(createContainer(new String[] { + "col1", "col2", "col3" }, new Class[] { DerivedClass.class, + DerivedClass.class, BaseClass.class })); + Set converters = customTable.getCurrentConverters(); + // TODO Test temporarily disabled as this feature + // is not yet implemented in Table + /* + * assertTrue("Incompatible types were not removed.", converters.size() + * <= 1); assertTrue("Even compatible types were removed", + * converters.size() == 1); assertTrue("Compatible type was missing.", + * converters.contains("col2")); + */ + } + + @Test + public void testPrimitiveTypeConverters() { + TestableTable customTable = new TestableTable("Test table", + createContainer(new String[] { "col1", "col2", "col3" }, + new Class[] { int.class, BaseClass.class, + DerivedClass.class })); + customTable.setConverter("col1", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public Integer convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return 11; + } + + @Override + public String convertToPresentation(Integer value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class getModelType() { + return Integer.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + Set converters = customTable.getCurrentConverters(); + assertTrue("Converter was not set.", converters.size() > 0); + } + + @Test + public void testInheritance() { + assertTrue("BaseClass isn't assignable from DerivedClass", + BaseClass.class.isAssignableFrom(DerivedClass.class)); + assertFalse("DerivedClass is assignable from BaseClass", + DerivedClass.class.isAssignableFrom(BaseClass.class)); + } + + @Override + public void setUp() { + table = new TestableTable("Test table", createContainer(new String[] { + "col1", "col2", "col3" })); + table.setConverter("col1", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model"; + } + + @Override + public String convertToPresentation(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + }); + + table.setConverter("col2", new Converter() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model2"; + } + + @Override + public String convertToPresentation(String value, + Class targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation2"; + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + + }); + + initialProperties = table.getContainerPropertyIds(); + } + + private static Container createContainer(Object[] ids) { + Class[] types = new Class[ids.length]; + for (int i = 0; i < types.length; ++i) { + types[i] = String.class; + } + return createContainer(ids, types); + } + + private static Container createContainer(Object[] ids, Class[] types) { + IndexedContainer container = new IndexedContainer(); + if (ids.length > types.length) { + throw new IllegalArgumentException("Too few defined types"); + } + for (int i = 0; i < ids.length; ++i) { + container.addContainerProperty(ids[i], types[i], ""); + } + + for (int i = 0; i < 100; i++) { + Item item = container.addItem("item " + i); + for (int j = 0; j < ids.length; ++j) { + Property itemProperty = item.getItemProperty(ids[j]); + if (types[j] == String.class) { + itemProperty.setValue(ids[j].toString() + i); + } else if (types[j] == BaseClass.class) { + itemProperty.setValue(new BaseClass("base" + i)); + } else if (types[j] == DerivedClass.class) { + itemProperty.setValue(new DerivedClass("derived" + i)); + } else if (types[j] == int.class) { + // FIXME can't set values because the int is autoboxed into + // an Integer and not unboxed prior to set + + // itemProperty.setValue(i); + } else { + throw new IllegalArgumentException( + "Unhandled type in createContainer: " + types[j]); + } + } + } + + return container; + } + + private class TestableTable extends Table { + /** + * @param string + * @param createContainer + */ + public TestableTable(String string, Container container) { + super(string, container); + } + + Set getCurrentConverters() { + try { + Field f = Table.class + .getDeclaredField("propertyValueConverters"); + f.setAccessible(true); + HashMap> pvc = (HashMap>) f + .get(this); + Set currentConverters = new HashSet(); + for (Entry> entry : pvc + .entrySet()) { + currentConverters.add(entry.getKey()); + } + return currentConverters; + + } catch (Exception e) { + fail("Unable to retrieve propertyValueConverters"); + return null; + } + } + } + + private static class BaseClass { + private String title; + + public BaseClass(String title) { + this.title = title; + } + } + + private static class DerivedClass extends BaseClass { + public DerivedClass(String title) { + super(title); + } + } +} -- cgit v1.2.3 From eeb956bc645a9c2aa3714747b7889e40bcca4d5f Mon Sep 17 00:00:00 2001 From: Juuso Valli Date: Wed, 23 Apr 2014 09:58:57 +0300 Subject: Add caching support for PublishedFileHandler (#13574) Add caching support for PublishedFileHandler similar to VaadinServlet. Testing is done manually as browser caching is difficult to develop tests for. Change-Id: I314745766c9feb60758547dba77eb9e13976ce91 --- .../server/communication/PublishedFileHandler.java | 9 ++- .../resources/CachingJavaScriptComponent.java | 26 ++++++++ .../resources/PublishedFileHandlerCaching.java | 77 ++++++++++++++++++++++ .../src/com/vaadin/tests/resources/cachingtest.js | 6 ++ 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 uitest/src/com/vaadin/tests/resources/CachingJavaScriptComponent.java create mode 100644 uitest/src/com/vaadin/tests/resources/PublishedFileHandlerCaching.java create mode 100644 uitest/src/com/vaadin/tests/resources/cachingtest.js (limited to 'server/src/com') diff --git a/server/src/com/vaadin/server/communication/PublishedFileHandler.java b/server/src/com/vaadin/server/communication/PublishedFileHandler.java index 8fe0f7085f..d33481435e 100644 --- a/server/src/com/vaadin/server/communication/PublishedFileHandler.java +++ b/server/src/com/vaadin/server/communication/PublishedFileHandler.java @@ -110,7 +110,14 @@ public class PublishedFileHandler implements RequestHandler { return true; } - // TODO Check and set cache headers + // Set caching for the published file + String cacheControl = "public, max-age=0, must-revalidate"; + int resourceCacheTime = request.getService() + .getDeploymentConfiguration().getResourceCacheTime(); + if (resourceCacheTime > 0) { + cacheControl = "max-age=" + String.valueOf(resourceCacheTime); + } + response.setHeader("Cache-Control", cacheControl); OutputStream out = null; try { diff --git a/uitest/src/com/vaadin/tests/resources/CachingJavaScriptComponent.java b/uitest/src/com/vaadin/tests/resources/CachingJavaScriptComponent.java new file mode 100644 index 0000000000..b6e409d4ba --- /dev/null +++ b/uitest/src/com/vaadin/tests/resources/CachingJavaScriptComponent.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.resources; + +import com.vaadin.annotations.JavaScript; +import com.vaadin.ui.AbstractJavaScriptComponent; + +@JavaScript({ "cachingtest.js" }) +public class CachingJavaScriptComponent extends AbstractJavaScriptComponent { + public CachingJavaScriptComponent() { + + } +} diff --git a/uitest/src/com/vaadin/tests/resources/PublishedFileHandlerCaching.java b/uitest/src/com/vaadin/tests/resources/PublishedFileHandlerCaching.java new file mode 100644 index 0000000000..a2828032c7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/resources/PublishedFileHandlerCaching.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.resources; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; + +/** + * This class tests the caching behavior of PublishedFileHandler. + * + * Previously PublishedFileHandler did not include cache headers in it's + * responses. Unfortunately there isn't a good way to automate this test, so + * manual testing is required at this time. To test the caching behavior run + * this file as a java application on the development server debug + * configuration, and access it through the url + * http://localhost:8888/run/com.vaadin + * .tests.resources.PublishedFileHandlerCaching?restartApplication + * + * On loading the page you'll need to examine the network traffic (e.g. with + * FireBug), keeping an eye on the GET requests for cachingtest.js and it's + * cache headers. + * + * @since + * @author Vaadin Ltd + */ +public class PublishedFileHandlerCaching extends AbstractTestUI { + + /** + * generated serialVersionUID + */ + private static final long serialVersionUID = 2275457343547688505L; + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server. + * VaadinRequest) + */ + @Override + protected void setup(VaadinRequest request) { + addComponent(new CachingJavaScriptComponent()); + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription() + */ + @Override + protected String getTestDescription() { + return "Test that PublishedFileHandler includes appropriate cache headers."; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber() + */ + @Override + protected Integer getTicketNumber() { + return new Integer(13574); + } + +} diff --git a/uitest/src/com/vaadin/tests/resources/cachingtest.js b/uitest/src/com/vaadin/tests/resources/cachingtest.js new file mode 100644 index 0000000000..f948e680ad --- /dev/null +++ b/uitest/src/com/vaadin/tests/resources/cachingtest.js @@ -0,0 +1,6 @@ +/** + * Used for testing cache header behavior. + */ + +function com_vaadin_tests_resources_CachingJavaScriptComponent() { +} \ No newline at end of file -- cgit v1.2.3 From 2e58e97e5297c0e0c718df52ba1c4b30742f3c03 Mon Sep 17 00:00:00 2001 From: Juuso Valli Date: Wed, 16 Apr 2014 14:47:32 +0300 Subject: Fix findUI throwing NullPointerException when extending Vaadin (#13556) findUI sometimes threw a NPE when the session wasn't set but the UI ID was. Doesn't occur in normal use, just when doing custom things with requestStart/requestEnd or runPendingAccessTasks Change-Id: Id7733567923fa30dcab4946c43b73200c2a0fac2 --- server/src/com/vaadin/server/VaadinService.java | 2 +- .../vaadin/server/VaadinPortletServiceTests.java | 31 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index b96e284e6e..ce9badaf98 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -982,7 +982,7 @@ public abstract class VaadinService implements Serializable { // Get UI id from the request String uiIdString = request.getParameter(UIConstants.UI_ID_PARAMETER); UI ui = null; - if (uiIdString != null) { + if (uiIdString != null && session != null) { int uiId = Integer.parseInt(uiIdString); ui = session.getUIById(uiId); } diff --git a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java index 62befdc516..c3b2d6b1d4 100644 --- a/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java +++ b/server/tests/src/com/vaadin/server/VaadinPortletServiceTests.java @@ -20,8 +20,15 @@ import static org.hamcrest.core.Is.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.concurrent.locks.ReentrantLock; + +import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; + +import com.vaadin.shared.ui.ui.UIConstants; +import com.vaadin.ui.UI; public class VaadinPortletServiceTests { @@ -188,4 +195,28 @@ public class VaadinPortletServiceTests { assertThat(widgetset, is("com.vaadin.portal.gwt.PortalDefaultWidgetSet")); } + + @Test + public void findUIDoesntThrowNPE() { + try { + ReentrantLock mockLock = Mockito.mock(ReentrantLock.class); + when(mockLock.isHeldByCurrentThread()).thenReturn(true); + + WrappedSession emptyWrappedSession = Mockito + .mock(WrappedSession.class); + when(emptyWrappedSession.getAttribute("null.lock")).thenReturn( + mockLock); + VaadinRequest requestWithUIIDSet = Mockito + .mock(VaadinRequest.class); + when(requestWithUIIDSet.getParameter(UIConstants.UI_ID_PARAMETER)) + .thenReturn("1"); + when(requestWithUIIDSet.getWrappedSession()).thenReturn( + emptyWrappedSession); + + UI ui = sut.findUI(requestWithUIIDSet); + Assert.assertNull("Unset session did not return null", ui); + } catch (NullPointerException e) { + Assert.fail("findUI threw a NullPointerException"); + } + } } -- cgit v1.2.3 From 716046af83ec05a44314a792648863646398d3b9 Mon Sep 17 00:00:00 2001 From: Juuso Valli Date: Wed, 23 Apr 2014 16:19:18 +0300 Subject: Clarify comments in Table.typeIsCompatible (#8168) Change-Id: Idc9b2e2052afe2b5586904c535674ec686bb4685 --- server/src/com/vaadin/ui/Table.java | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 00a7038afd..e23a1bf688 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -2775,22 +2775,8 @@ public class Table extends AbstractSelect implements Action.Container, */ private boolean typeIsCompatible(Class a, Class b) { // TODO Implement this check properly - // Map, Class> typemap = new HashMap, Class>(); - // typemap.put(byte.class, Byte.class); - // typemap.put(short.class, Short.class); - // typemap.put(int.class, Integer.class); - // typemap.put(long.class, Long.class); - // typemap.put(float.class, Float.class); - // typemap.put(double.class, Double.class); - // typemap.put(char.class, Character.class); - // typemap.put(boolean.class, Boolean.class); - // if (typemap.containsKey(a)) { - // a = typemap.get(a); - // } - // if (typemap.containsKey(b)) { - // b = typemap.get(b); - // } - // return a.isAssignableFrom(b); + // Basically we need to do a a.isAssignableFrom(b) + // with special considerations for primitive types. return true; } -- cgit v1.2.3