diff options
author | John Ahlroos <john@vaadin.com> | 2014-04-24 13:27:57 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2014-04-25 06:28:11 +0000 |
commit | 91fa89a9a384d64a953996efa6d6f42eff1f4c8a (patch) | |
tree | 408e8fbee4a554fbd100b4e3ef3923596f04af29 /server | |
parent | 387603a6712a68c05fdb154824fe950b2df9c451 (diff) | |
parent | 0a5eeeca649676432a4166255a4aee0028a3adcc (diff) | |
download | vaadin-framework-91fa89a9a384d64a953996efa6d6f42eff1f4c8a.tar.gz vaadin-framework-91fa89a9a384d64a953996efa6d6f42eff1f4c8a.zip |
Merge remote-tracking branch 'origin/master' into grid
Change-Id: I596407a5d5c28c6ec3fb27d443e6bf143bddee6c
Diffstat (limited to 'server')
40 files changed, 1411 insertions, 1048 deletions
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. * <p> * 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. * <p> * By using 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 <code>Event</code> 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 <code>Event</code> 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<IDTYPE, BEANTYPE> extends @Override public boolean removeAllItems() { int origSize = size(); - IDTYPE firstItem = getFirstVisibleItem(); internalRemoveAllItems(); @@ -235,7 +234,7 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> 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<IDTYPE, BEANTYPE> extends protected void addAll(Collection<? extends BEANTYPE> 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<IDTYPE, BEANTYPE> 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 AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE } } - private static abstract class BaseItemAddOrRemoveEvent extends EventObject - implements Serializable { - protected Object itemId; - protected int index; - protected int count; - - public BaseItemAddOrRemoveEvent(Container source, Object itemId, - int index, int count) { - super(source); - this.itemId = itemId; - this.index = index; - this.count = count; - } - - public Container getContainer() { - return (Container) getSource(); - } - - public Object getFirstItemId() { - return itemId; - } - - public int getFirstIndex() { - return index; - } - - public int getAffectedItemsCount() { - return count; - } - } - - /** - * An <code>Event</code> object specifying information about the added - * items. - * - * <p> - * This class provides information about the first added item and the number - * of added items. - * </p> - */ - 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 <code>Event</code> object specifying information about the removed - * items. - * - * <p> - * This class provides information about the first removed item and the - * number of removed items. - * </p> - */ - 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<ITEMIDTYPE, PROPERTYIDCLASS, ITE * Notify item set change listeners that an item has been added to the * container. * + * Unless subclasses specify otherwise, the default notification indicates a + * full refresh. + * * @param postion - * position of the added item in the view + * position of the added item in the view (if visible) * @param itemId * id of the added item * @param item * the added item */ protected void fireItemAdded(int position, ITEMIDTYPE itemId, ITEMCLASS item) { - fireItemsAdded(position, itemId, 1); - } - - /** - * Notify item set change listeners that items has been added to the - * container. - * - * @param firstPosition - * position of the first visible added item in the view - * @param firstItemId - * id of the first visible added item - * @param numberOfItems - * the number of visible added items - */ - protected void fireItemsAdded(int firstPosition, ITEMIDTYPE firstItemId, - int numberOfItems) { - BaseItemAddEvent addEvent = new BaseItemAddEvent(this, firstItemId, - firstPosition, numberOfItems); - fireItemSetChange(addEvent); + fireItemSetChange(); } /** * Notify item set change listeners that an item has been removed from the * container. * - * @param position - * position of the removed item in the view prior to removal + * Unless subclasses specify otherwise, the default notification indicates a + * full refresh. * + * @param postion + * position of the removed item in the view prior to removal (if + * was visible) * @param itemId * id of the removed item, of type {@link Object} to satisfy * {@link Container#removeItem(Object)} API */ protected void fireItemRemoved(int position, Object itemId) { - fireItemsRemoved(position, itemId, 1); - } - - /** - * Notify item set change listeners that items has been removed from the - * container. - * - * @param firstPosition - * position of the first visible removed item in the view prior - * to removal - * @param firstItemId - * id of the first visible removed item, of type {@link Object} - * to satisfy {@link Container#removeItem(Object)} API - * @param numberOfItems - * the number of removed visible items - * - */ - protected void fireItemsRemoved(int firstPosition, Object firstItemId, - int numberOfItems) { - BaseItemRemoveEvent removeEvent = new BaseItemRemoveEvent(this, - firstItemId, firstPosition, numberOfItems); - fireItemSetChange(removeEvent); + fireItemSetChange(); } // visible and filtered item identifier lists @@ -1058,21 +946,6 @@ public abstract class AbstractInMemoryContainer<ITEMIDTYPE, PROPERTYIDCLASS, ITE } /** - * Returns the item id of the first visible item after filtering. 'Null' is - * returned if there is no visible items. - * - * For internal use only. - * - * @return item id of the first visible item - */ - protected ITEMIDTYPE getFirstVisibleItem() { - if (!getVisibleItemIds().isEmpty()) { - return getVisibleItemIds().get(0); - } - return null; - } - - /** * Returns true is the container has active filters. * * @return true if the container is currently filtered diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java index 5d20919208..d7bf70caf6 100644 --- a/server/src/com/vaadin/data/util/IndexedContainer.java +++ b/server/src/com/vaadin/data/util/IndexedContainer.java @@ -226,7 +226,6 @@ public class IndexedContainer extends @Override public boolean removeAllItems() { int origSize = size(); - Object firstItem = getFirstVisibleItem(); internalRemoveAllItems(); @@ -236,7 +235,7 @@ public class IndexedContainer extends // filtered out items were removed or not if (origSize != 0) { // Sends a change event - fireItemsRemoved(0, firstItem, origSize); + fireItemSetChange(); } return true; @@ -621,7 +620,8 @@ public class IndexedContainer extends @Override protected void fireItemAdded(int position, Object itemId, Item item) { if (position >= 0) { - super.fireItemAdded(position, itemId, item); + fireItemSetChange(new IndexedContainer.ItemSetChangeEvent(this, + position)); } } @@ -1211,5 +1211,4 @@ public class IndexedContainer extends public Collection<Filter> getContainerFilters() { return super.getContainerFilters(); } - } 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(); 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/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/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; * * <pre> * CssLayout layout = new CssLayout(); - * layout.setStyleName("responsive"); + * layout.setStyleName("responsive"); * layout.setSizeFull(); * Responsive.makeResponsive(layout); * </pre> 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. * <p> * 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/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<String> getHeaderNames() { Enumeration<String> 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<String> getHeaders(String name) { Enumeration<String> 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<String, String[]> getParameterMap() { Map<String, String[]> 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,10 +252,68 @@ 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/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/src/com/vaadin/server/communication/AtmospherePushConnection.java b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java index 65ea43ddd4..a4290a31cf 100644 --- a/server/src/com/vaadin/server/communication/AtmospherePushConnection.java +++ b/server/src/com/vaadin/server/communication/AtmospherePushConnection.java @@ -260,6 +260,16 @@ public class AtmospherePushConnection implements PushConnection { @Override 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/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/server/src/com/vaadin/server/communication/PushHandler.java b/server/src/com/vaadin/server/communication/PushHandler.java index 1557ae9b19..e028968494 100644 --- a/server/src/com/vaadin/server/communication/PushHandler.java +++ b/server/src/com/vaadin/server/communication/PushHandler.java @@ -365,7 +365,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 + } + } } /** 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/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/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); } /** 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. * @@ -340,132 +343,6 @@ public class Notification implements Serializable { } /** - * 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 <a - * href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles - * Model</a>). - * - * 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 <a - * href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles - * Model</a>) - * - * 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 * responsible for ensuring no harmful html is used. If set to false, the 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. + * <p> + * 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. + * <p> + * 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. + * <p> * 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. + * <p> * 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. + * <p> * This role defines how an assistive device handles a notification. - * Available roles are alert, alertdialog and status (@see <a + * Available roles are alert and status (@see <a * href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles - * Model</a>) - * + * Model</a>). + * * 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. + * <p> * This role defines how an assistive device handles a notification. - * Available roles are alert, alertdialog and status (@see <a + * Available roles are alert and status (@see <a * href="http://www.w3.org/TR/2011/CR-wai-aria-20110118/roles">Roles - * Model</a> ) - * + * Model</a>) + * <p> * 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/Table.java b/server/src/com/vaadin/ui/Table.java index 06e82dedcb..e23a1bf688 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. + * <p> + * Keeps propertyValueConverters if the corresponding id exists in the new + * data source and is of a compatible type. + * </p> * * @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. + * <p> + * Keeps propertyValueConverters if the corresponding id exists in the new + * data source and is of a compatible type. + * </p> * * @see Table#setContainerDataSource(Container) * @see Table#setVisibleColumns(Object[]) + * @see Table#setConverter(Object, Converter<String, ?>) * * @param newDataSource * the new data source. @@ -2702,6 +2711,26 @@ public class Table extends AbstractSelect implements Action.Container, visibleIds = new ArrayList<Object>(); } + // 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<Object> retainableValueConverters = new LinkedList<Object>(); + for (Object propertyId : newPropertyIds) { + Converter<String, ?> 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) { @@ -2738,6 +2767,20 @@ public class Table extends AbstractSelect implements Action.Container, } /** + * 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 + // Basically we need to do a a.isAssignableFrom(b) + // with special considerations for primitive types. + return true; + } + + /** * Gets items ids from a range of key values * * @param startRowKey @@ -4229,6 +4272,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 +5889,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<String, Object>) converter); refreshRowCache(); diff --git a/server/src/com/vaadin/ui/UI.java b/server/src/com/vaadin/ui/UI.java index 275aeb4c79..3ae0aea6f7 100644 --- a/server/src/com/vaadin/ui/UI.java +++ b/server/src/com/vaadin/ui/UI.java @@ -669,10 +669,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. @@ -684,7 +684,7 @@ public abstract class UI extends AbstractSingleComponentContainer implements page.init(request); - reinit(request); + refresh(request); URI newLocation = page.getLocation(); int newWidth = page.getBrowserWindowWidth(); @@ -710,7 +710,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..11a6fde853 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; @@ -41,7 +38,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; /** @@ -1017,15 +1014,15 @@ 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(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; } } @@ -1034,11 +1031,19 @@ 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 List<Connector> 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/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/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<Person> container = new BeanItemContainer<Person>( - 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<Person> container = new BeanItemContainer<Person>( - Person.class); - Person bean = new Person("John"); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItem(bean); - - assertEquals(bean, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemAddedEvent_addItemAt_IndexOfAddedItem() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItemAt(1, new Person("")); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemAddedEvent_addItemAfter_IndexOfAddedItem() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - - container.addItemAfter(bean, new Person("")); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemAddedEvent_amountOfAddedItems() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List<Person> beans = Arrays.asList(new Person("Jack"), new Person( - "John")); - - container.addAll(beans); - - assertEquals(2, capturedEvent.getValue().getAddedItemsCount()); - } - - public void testItemAddedEvent_someItemsAreFiltered_amountOfAddedItemsIsReducedByAmountOfFilteredItems() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List<Person> 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<Person> container = new BeanItemContainer<Person>( - Person.class); - Person bean = new Person("John"); - ItemSetChangeListener addListener = createListenerMockFor(container); - Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener); - EasyMock.replay(addListener); - List<Person> 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<Person> container = new BeanItemContainer<Person>( - 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<Person> container = new BeanItemContainer<Person>( - Person.class); - Person bean = new Person("John"); - container.addItem(bean); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(bean); - - assertEquals(bean, capturedEvent.getValue().getFirstItemId()); - } - - public void testItemRemovedEvent_indexOfRemovedItem() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - container.addItem(new Person("Jack")); - Person secondBean = new Person("John"); - container.addItem(secondBean); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeItem(secondBean); - - assertEquals(1, capturedEvent.getValue().getFirstIndex()); - } - - public void testItemRemovedEvent_amountOfRemovedItems() { - BeanItemContainer<Person> container = new BeanItemContainer<Person>( - Person.class); - container.addItem(new Person("Jack")); - container.addItem(new Person("John")); - ItemSetChangeListener removeListener = createListenerMockFor(container); - Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeAllItems(); - - assertEquals(2, capturedEvent.getValue().getRemovedItemsCount()); - } - - private Capture<ItemAddEvent> captureAddEvent( - ItemSetChangeListener addListener) { - Capture<ItemAddEvent> capturedEvent = new Capture<ItemAddEvent>(); - addListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private Capture<ItemRemoveEvent> captureRemoveEvent( - ItemSetChangeListener removeListener) { - Capture<ItemRemoveEvent> capturedEvent = new Capture<ItemRemoveEvent>(); - removeListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private ItemSetChangeListener createListenerMockFor( - BeanItemContainer<Person> 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<ItemAddEvent> 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<ItemAddEvent> 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<ItemRemoveEvent> 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<ItemRemoveEvent> 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<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener); - EasyMock.replay(removeListener); - - container.removeAllItems(); - - assertEquals(2, capturedEvent.getValue().getRemovedItemsCount()); - } - - private Capture<ItemAddEvent> captureAddEvent( - ItemSetChangeListener addListener) { - Capture<ItemAddEvent> capturedEvent = new Capture<ItemAddEvent>(); - addListener.containerItemSetChange(EasyMock.capture(capturedEvent)); - return capturedEvent; - } - - private Capture<ItemRemoveEvent> captureRemoveEvent( - ItemSetChangeListener removeListener) { - Capture<ItemRemoveEvent> capturedEvent = new Capture<ItemRemoveEvent>(); - 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(); 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<VaadinGateInRequest> { + + @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<T extends VaadinHttpAndPortletRequest> { + + 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<String> actualHeaderNames = sut.getHeaderNames(); + + assertThat(actualHeaderNames, is(expectedHeaderNames)); + } + + @Test + public void headersAreFetchedFromServletRequest() { + Enumeration expectedHeaders = mock(Enumeration.class); + when(servletRequest.getHeaders("foo")).thenReturn(expectedHeaders); + + Enumeration<String> actualHeaders = sut.getHeaders("foo"); + + assertThat(actualHeaders, is(expectedHeaders)); + } + + @Test + public void parameterMapIsFetchedFromServletRequest() { + Map expectedParameterMap = mock(Map.class); + when(servletRequest.getParameterMap()).thenReturn(expectedParameterMap); + + Map<String, String[]> 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<VaadinLiferayRequest> { + + @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/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"); + } + } } 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<VaadinWebSpherePortalRequest> { + + @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 diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToLongConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToLongConverter.java index 18e2ed06c0..3210703445 100644 --- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToLongConverter.java +++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToLongConverter.java @@ -51,7 +51,7 @@ public class TestStringToLongConverter extends TestCase { String.class, Locale.ENGLISH); Assert.assertEquals("9,223,372,036,854,775,807", str); str = reverseConverter.convertToModel(Long.MIN_VALUE, String.class, - null); + Locale.ENGLISH); Assert.assertEquals("-9,223,372,036,854,775,808", str); } 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)); + } +} 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<String> 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<CalendarEvent> events = calendar.getEventProvider().getEvents(now, + then); + for (CalendarEvent ce : events) { + assertEquals("testStyle", ce.getStyleName()); + } + } + private static Indexed createTestBeanItemContainer() { BeanItemContainer<CalendarEvent> eventContainer = new BeanItemContainer<CalendarEvent>( CalendarEvent.class); 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<Object> converters = table.getCurrentConverters(); + assertTrue("Set of converters was empty at the start.", + converters.size() > 0); + + Object firstId = converters.iterator().next(); + + table.removeContainerProperty(firstId); + + Collection<Object> 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<Object> 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<String, String>() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model"; + } + + @Override + public String convertToPresentation(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class<String> getModelType() { + return String.class; + } + + @Override + public Class<String> getPresentationType() { + return String.class; + } + + }); + customTable.setConverter("col2", new Converter<String, BaseClass>() { + private static final long serialVersionUID = 1L; + + @Override + public BaseClass convertToModel(String value, + Class<? extends BaseClass> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return new BaseClass("model"); + } + + @Override + public Class<BaseClass> getModelType() { + return BaseClass.class; + } + + @Override + public Class<String> getPresentationType() { + return String.class; + } + + @Override + public String convertToPresentation(BaseClass value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return null; + } + }); + customTable.setConverter("col3", new Converter<String, DerivedClass>() { + private static final long serialVersionUID = 1L; + + @Override + public DerivedClass convertToModel(String value, + Class<? extends DerivedClass> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return new DerivedClass("derived" + 1001); + } + + @Override + public Class<DerivedClass> getModelType() { + return DerivedClass.class; + } + + @Override + public Class<String> getPresentationType() { + return String.class; + } + + @Override + public String convertToPresentation(DerivedClass value, + Class<? extends String> 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<Object> 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<String, Integer>() { + private static final long serialVersionUID = 1L; + + @Override + public Integer convertToModel(String value, + Class<? extends Integer> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return 11; + } + + @Override + public String convertToPresentation(Integer value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class<Integer> getModelType() { + return Integer.class; + } + + @Override + public Class<String> getPresentationType() { + return String.class; + } + }); + Set<Object> 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<String, String>() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model"; + } + + @Override + public String convertToPresentation(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation"; + } + + @Override + public Class<String> getModelType() { + return String.class; + } + + @Override + public Class<String> getPresentationType() { + return String.class; + } + + }); + + table.setConverter("col2", new Converter<String, String>() { + private static final long serialVersionUID = 1L; + + @Override + public String convertToModel(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "model2"; + } + + @Override + public String convertToPresentation(String value, + Class<? extends String> targetType, Locale locale) + throws com.vaadin.data.util.converter.Converter.ConversionException { + return "presentation2"; + } + + @Override + public Class<String> getModelType() { + return String.class; + } + + @Override + public Class<String> 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<Object> getCurrentConverters() { + try { + Field f = Table.class + .getDeclaredField("propertyValueConverters"); + f.setAccessible(true); + HashMap<Object, Converter<String, Object>> pvc = (HashMap<Object, Converter<String, Object>>) f + .get(this); + Set<Object> currentConverters = new HashSet<Object>(); + for (Entry<Object, Converter<String, Object>> 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); + } + } +} 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]); + + } +} diff --git a/server/tests/src/com/vaadin/ui/UIInitReinitTest.java b/server/tests/src/com/vaadin/ui/UIInitRefreshTest.java index f8ec0e68c2..a807e4b656 100644 --- a/server/tests/src/com/vaadin/ui/UIInitReinitTest.java +++ b/server/tests/src/com/vaadin/ui/UIInitRefreshTest.java @@ -27,10 +27,10 @@ import com.vaadin.server.Page.UriFragmentChangedEvent; import com.vaadin.server.Page.UriFragmentChangedListener; import com.vaadin.server.VaadinRequest; -public class UIInitReinitTest { +public class UIInitRefreshTest { private boolean initCalled; - private boolean reinitCalled; + private boolean refreshCalled; private boolean fragmentChangeCalled; private boolean browserWindowResizeCalled; @@ -52,8 +52,8 @@ public class UIInitReinitTest { } @Override - protected void reinit(VaadinRequest request) { - reinitCalled = true; + protected void refresh(VaadinRequest request) { + refreshCalled = true; Assert.assertEquals("bar", getPage().getUriFragment()); Assert.assertEquals(200, getPage().getBrowserWindowWidth()); @@ -79,7 +79,7 @@ public class UIInitReinitTest { @Before public void setUp() { - initCalled = reinitCalled = fragmentChangeCalled = browserWindowResizeCalled = false; + initCalled = refreshCalled = fragmentChangeCalled = browserWindowResizeCalled = false; } @Test @@ -107,9 +107,9 @@ public class UIInitReinitTest { Assert.assertFalse(fragmentChangeCalled); Assert.assertFalse(browserWindowResizeCalled); - ui.doReinit(reinitRequest); + ui.doRefresh(reinitRequest); - Assert.assertTrue(reinitCalled); + Assert.assertTrue(refreshCalled); Assert.assertTrue(fragmentChangeCalled); Assert.assertTrue(browserWindowResizeCalled); } |