diff options
27 files changed, 757 insertions, 95 deletions
diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java index aa220225c9..0e29c07405 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -583,10 +583,12 @@ public class ConnectorBundleLoaderFactory extends Generator { JClassType connectorType = typeOracle.getType(ServerConnector.class .getName()); JClassType[] subtypes = connectorType.getSubtypes(); - for (JClassType connectorSubtype : subtypes) { - if (!connectorSubtype.isAnnotationPresent(Connect.class)) { - continue; - } + + // Find all types with a valid mapping + Collection<JClassType> selectedTypes = getMappedTypes(logger, subtypes); + + // Group by load style + for (JClassType connectorSubtype : selectedTypes) { LoadStyle loadStyle = getLoadStyle(connectorSubtype); if (loadStyle != null) { connectorsByLoadStyle.get(loadStyle).add(connectorSubtype); @@ -637,6 +639,79 @@ public class ConnectorBundleLoaderFactory extends Generator { return bundles; } + private Collection<JClassType> getMappedTypes(TreeLogger logger, + JClassType[] types) throws UnableToCompleteException { + Map<String, JClassType> mappings = new HashMap<String, JClassType>(); + + // Keep track of what has happened to avoid logging intermediate state + Map<JClassType, List<JClassType>> replaced = new HashMap<JClassType, List<JClassType>>(); + + for (JClassType type : types) { + Connect connectAnnotation = type.getAnnotation(Connect.class); + if (connectAnnotation == null) { + continue; + } + + String identifier = connectAnnotation.value().getCanonicalName(); + + JClassType previousMapping = mappings.put(identifier, type); + if (previousMapping != null) { + // There are multiple mappings, pick the subclass + JClassType subclass; + JClassType superclass; + if (previousMapping.isAssignableFrom(type)) { + subclass = type; + superclass = previousMapping; + } else if (type.isAssignableFrom(previousMapping)) { + subclass = previousMapping; + superclass = type; + } else { + // Neither inherits from the other - this is a conflict + logger.log( + Type.ERROR, + "Conflicting @Connect mappings detected for " + + identifier + + ": " + + type.getQualifiedSourceName() + + " and " + + previousMapping.getQualifiedSourceName() + + ". There can only be multiple @Connect mappings for the same server-side type if one is the subclass of the other."); + throw new UnableToCompleteException(); + } + + mappings.put(identifier, subclass); + + // Inherit any previous replacements + List<JClassType> previousReplacements = replaced + .remove(superclass); + if (previousReplacements == null) { + previousReplacements = new ArrayList<JClassType>(); + } + + previousReplacements.add(superclass); + replaced.put(subclass, previousReplacements); + } + } + + // Log the final set of replacements + for (Entry<JClassType, List<JClassType>> entry : replaced.entrySet()) { + String msg = entry.getKey().getQualifiedSourceName() + " replaces "; + + List<JClassType> list = entry.getValue(); + for (int i = 0; i < list.size(); i++) { + if (i != 0) { + msg += ", "; + } + msg += list.get(i).getQualifiedSourceName(); + } + + logger.log(Type.INFO, msg); + } + + // Return the types of the final mapping + return mappings.values(); + } + private Collection<TypeVisitor> getVisitors(TypeOracle oracle) throws NotFoundException { List<TypeVisitor> visitors = Arrays.<TypeVisitor> asList( diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorInitVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorInitVisitor.java index 7500d65443..253d657af0 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorInitVisitor.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorInitVisitor.java @@ -4,19 +4,14 @@ package com.vaadin.server.widgetsetutils.metadata; -import java.util.Map; - import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.TreeLogger.Type; import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; -import com.google.gwt.dev.util.collect.HashMap; import com.vaadin.shared.ui.Connect; public class ConnectorInitVisitor extends TypeVisitor { - private Map<String, JClassType> processedConnections = new HashMap<String, JClassType>(); - @Override public void visitConnector(TreeLogger logger, JClassType type, ConnectorBundle bundle) throws UnableToCompleteException { @@ -26,18 +21,6 @@ public class ConnectorInitVisitor extends TypeVisitor { + bundle.getName().replaceAll("^_*", "") + " bundle"); String identifier = connectAnnotation.value().getCanonicalName(); - JClassType previousMapping = processedConnections.put(identifier, - type); - if (previousMapping != null) { - logger.log( - Type.ERROR, - "Multiple @Connect mappings detected for " + identifier - + ": " + type.getQualifiedSourceName() - + " and " - + previousMapping.getQualifiedSourceName()); - throw new UnableToCompleteException(); - } - bundle.setIdentifier(type, identifier); bundle.setNeedsGwtConstructor(type); } diff --git a/client/src/com/vaadin/client/ui/accordion/VAccordion.java b/client/src/com/vaadin/client/ui/accordion/VAccordion.java index 0fbbcf5780..ce973f9630 100644 --- a/client/src/com/vaadin/client/ui/accordion/VAccordion.java +++ b/client/src/com/vaadin/client/ui/accordion/VAccordion.java @@ -89,16 +89,17 @@ public class VAccordion extends VTabsheetBase { @Override public void setStylePrimaryName(String style) { + super.setStylePrimaryName(style); updateStyleNames(style); } @Override public void setStyleName(String style) { + super.setStyleName(style); updateStyleNames(style); } protected void updateStyleNames(String primaryStyleName) { - super.setStyleName(primaryStyleName); for (Widget w : getChildren()) { if (w instanceof StackItem) { StackItem item = (StackItem) w; diff --git a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java index 70c1b130fd..b1d60f50b5 100644 --- a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java +++ b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java @@ -22,7 +22,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { private static final String IE8_WINDOWS = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)"; private static final String IE8_IN_IE7_MODE_WINDOWS = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2)"; - private static final String IE9_BETA_IN_IE7_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"; + private static final String IE9_IN_IE7_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"; private static final String IE9_BETA_IN_IE8_MODE_WINDOWS_7 = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"; private static final String IE9_BETA_WINDOWS_7 = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"; @@ -279,7 +279,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { public void testIE6() { VBrowserDetails bd = new VBrowserDetails(IE6_WINDOWS); - // assertTrident(bd); + assertEngineVersion(bd, -1); assertIE(bd); assertBrowserMajorVersion(bd, 6); assertBrowserMinorVersion(bd, 0); @@ -288,7 +288,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { public void testIE7() { VBrowserDetails bd = new VBrowserDetails(IE7_WINDOWS); - // assertTrident(bd); + assertEngineVersion(bd, -1); assertIE(bd); assertBrowserMajorVersion(bd, 7); assertBrowserMinorVersion(bd, 0); @@ -297,7 +297,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { public void testIE8() { VBrowserDetails bd = new VBrowserDetails(IE8_WINDOWS); - // assertTrident(bd); + assertEngineVersion(bd, 4); assertIE(bd); assertBrowserMajorVersion(bd, 8); assertBrowserMinorVersion(bd, 0); @@ -308,7 +308,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { VBrowserDetails bd = new VBrowserDetails(IE8_IN_IE7_MODE_WINDOWS); bd.setIEMode(7); - // assertTrident(bd); + assertEngineVersion(bd, 4); assertIE(bd); assertBrowserMajorVersion(bd, 7); assertBrowserMinorVersion(bd, 0); @@ -318,7 +318,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { public void testIE9() { VBrowserDetails bd = new VBrowserDetails(IE9_BETA_WINDOWS_7); - // assertTrident(bd); + assertEngineVersion(bd, 5); assertIE(bd); assertBrowserMajorVersion(bd, 9); assertBrowserMinorVersion(bd, 0); @@ -326,10 +326,10 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { } public void testIE9InIE7CompatibilityMode() { - VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE7_MODE_WINDOWS_7); + VBrowserDetails bd = new VBrowserDetails(IE9_IN_IE7_MODE_WINDOWS_7); // bd.setIE8InCompatibilityMode(); - // assertTrident(bd); + assertEngineVersion(bd, 5); assertIE(bd); assertBrowserMajorVersion(bd, 7); assertBrowserMinorVersion(bd, 0); @@ -341,7 +341,11 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { VBrowserDetails bd = new VBrowserDetails(IE9_BETA_IN_IE8_MODE_WINDOWS_7); // bd.setIE8InCompatibilityMode(); - // assertTrident(bd); + /* + * Trident/4.0 in example user agent string based on beta even though it + * should be Trident/5.0 in real (non-beta) user agent strings + */ + assertEngineVersion(bd, 4); assertIE(bd); assertBrowserMajorVersion(bd, 8); assertBrowserMinorVersion(bd, 0); diff --git a/server/src/com/vaadin/server/BootstrapHandler.java b/server/src/com/vaadin/server/BootstrapHandler.java index 9a0e4c2071..f4da147667 100644 --- a/server/src/com/vaadin/server/BootstrapHandler.java +++ b/server/src/com/vaadin/server/BootstrapHandler.java @@ -239,10 +239,13 @@ public abstract class BootstrapHandler implements RequestHandler { head.appendElement("meta").attr("http-equiv", "Content-Type") .attr("content", "text/html; charset=utf-8"); - // Chrome frame in all versions of IE (only if Chrome frame is - // installed) + /* + * Enable Chrome Frame in all versions of IE if installed. + * + * Claim IE10 support to avoid using compatibility mode. + */ head.appendElement("meta").attr("http-equiv", "X-UA-Compatible") - .attr("content", "chrome=1"); + .attr("content", "IE=10;chrome=1"); String title = response.getUIProvider().getPageTitle( new UICreateEvent(context.getRequest(), context.getUIClass())); diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java index 2143e884c0..46d29ac75c 100644 --- a/shared/src/com/vaadin/shared/VBrowserDetails.java +++ b/shared/src/com/vaadin/shared/VBrowserDetails.java @@ -95,6 +95,14 @@ public class VBrowserDetails implements Serializable { .substring(userAgent.indexOf("webkit/") + 7); tmp = tmp.replaceFirst("([0-9]+)[^0-9].+", "$1"); browserEngineVersion = Float.parseFloat(tmp); + } else if (isIE) { + int tridentPos = userAgent.indexOf("trident/"); + if (tridentPos >= 0) { + String tmp = userAgent.substring(tridentPos + + "Trident/".length()); + tmp = tmp.replaceFirst("([0-9]+\\.[0-9]+).*", "$1"); + browserEngineVersion = Float.parseFloat(tmp); + } } } catch (Exception e) { // Browser engine version parsing failed @@ -456,7 +464,9 @@ public class VBrowserDetails implements Serializable { * supported or might work */ public boolean isTooOldToFunctionProperly() { - if (isIE() && getBrowserMajorVersion() < 8) { + // Check Trident version to detect compatibility mode + if (isIE() && getBrowserMajorVersion() < 8 + && getBrowserEngineVersion() < 4) { return true; } // Webkit 533 in Safari 4.1+, Android 2.2+, iOS 4+ diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java index b5057dd9c2..61cbd94f3a 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/DynamicImageUI.java @@ -2,56 +2,36 @@ package com.vaadin.tests.minitutorials.v7a1; import java.awt.image.BufferedImage; import java.io.IOException; +import java.util.HashMap; import javax.imageio.ImageIO; -import com.vaadin.server.ExternalResource; -import com.vaadin.server.RequestHandler; +import com.vaadin.server.DynamicConnectorResource; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinResponse; -import com.vaadin.server.VaadinServiceSession; import com.vaadin.tests.components.AbstractTestUI; -import com.vaadin.ui.Embedded; +import com.vaadin.ui.Image; public class DynamicImageUI extends AbstractTestUI { + public static final String IMAGE_URL = "myimage.png"; @Override public void setup(VaadinRequest request) { - // Add the request handler that handles our dynamic image - getSession().addRequestHandler(new DynamicImageRequestHandler()); - - // Create a URL that we can handle in DynamicImageRequestHandler - String imageUrl = "app://" + DynamicImageRequestHandler.IMAGE_URL - + "?text=Hello!"; + HashMap<String, String> parameters = new HashMap<String, String>(); + parameters.put("text", "Hello!"); + DynamicConnectorResource resource = new DynamicConnectorResource(this, + IMAGE_URL, parameters); - // Add an embedded using the created URL - Embedded embedded = new Embedded("A dynamically generated image", - new ExternalResource(imageUrl)); - embedded.setType(Embedded.TYPE_IMAGE); - getContent().addComponent(embedded); - - } + // Add an image using the resource + Image image = new Image("A dynamically generated image", resource); - @Override - protected String getTestDescription() { - return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Generating%20dynamic%20resources%20based%20on%20URI%20or%20parameters"; + getContent().addComponent(image); } @Override - protected Integer getTicketNumber() { - return null; - } -} - -class DynamicImageRequestHandler implements RequestHandler { - - public static final String IMAGE_URL = "myimage.png"; - - @Override - public boolean handleRequest(VaadinServiceSession session, - VaadinRequest request, VaadinResponse response) throws IOException { - String pathInfo = request.getRequestPathInfo(); - if (("/" + IMAGE_URL).equals(pathInfo)) { + public boolean handleConnectorRequest(VaadinRequest request, + VaadinResponse response, String path) throws IOException { + if ((IMAGE_URL).equals(path)) { // Create an image, draw the "text" parameter to it and output it to // the browser. String text = request.getParameter("text"); @@ -68,4 +48,14 @@ class DynamicImageRequestHandler implements RequestHandler { // handlers handle it return false; } -} + + @Override + protected String getTestDescription() { + return "Mini tutorial for https://vaadin.com/wiki/-/wiki/Main/Generating%20dynamic%20resources%20based%20on%20URI%20or%20parameters"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java index 6d9890a21c..5d7555a952 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a1/UsingUriFragments.java @@ -36,7 +36,7 @@ public class UsingUriFragments extends UI { @Override protected void init(VaadinRequest request) { Label label = new Label("Hello, your fragment is " - + getPage().getLocation().getFragment()); + + getPage().getFragment()); getContent().addComponent(label); // React to fragment changes @@ -48,7 +48,7 @@ public class UsingUriFragments extends UI { }); // Handle the fragment received in the initial request - handleFragment(getPage().getLocation().getFragment()); + handleFragment(getPage().getFragment()); addComponent(new Button("Show and set fragment", new Button.ClickListener() { diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java index cf0c5a3e2b..caaca14ae8 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java @@ -17,20 +17,15 @@ package com.vaadin.tests.minitutorials.v7a2; import com.vaadin.server.Resource; -import com.vaadin.tests.widgetset.client.minitutorials.v7a2.ResourceInStateState; import com.vaadin.ui.AbstractComponent; public class ResourceInStateComponent extends AbstractComponent { - @Override - public ResourceInStateState getState() { - return (ResourceInStateState) super.getState(); - } public void setMyIcon(Resource icon) { - setResource(ResourceInStateState.MY_ICON_RESOURCE, icon); + setResource("myIcon", icon); } public Resource getMyIcon() { - return getResource(ResourceInStateState.MY_ICON_RESOURCE); + return getResource("myIcon"); } } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java index 2a64792646..155c1d9ded 100644 --- a/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a2/ResourceInStateUI.java @@ -35,7 +35,7 @@ public class ResourceInStateUI extends UI { @Override protected void init(VaadinRequest request) { ResourceInStateComponent component = new ResourceInStateComponent(); - component.setIcon(new ThemeResource("../runo/icons/32/calendar.png")); + component.setMyIcon(new ThemeResource("../runo/icons/32/calendar.png")); addComponent(component); } diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/Refresher.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/Refresher.java new file mode 100644 index 0000000000..408b04b3b4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/Refresher.java @@ -0,0 +1,61 @@ +package com.vaadin.tests.minitutorials.v7a3; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.AbstractExtension; +import com.vaadin.tests.widgetset.client.minitutorials.v7a3.RefresherRpc; +import com.vaadin.tests.widgetset.client.minitutorials.v7a3.RefresherState; +import com.vaadin.ui.UI; + +public class Refresher extends AbstractExtension { + public interface RefreshListener { + public void refresh(Refresher source); + } + + private List<RefreshListener> listeners = new ArrayList<RefreshListener>(); + + public Refresher() { + registerRpc(new RefresherRpc() { + @Override + public void refresh() { + for (RefreshListener listener : listeners) { + listener.refresh(Refresher.this); + } + } + }); + } + + @Override + public RefresherState getState() { + return (RefresherState) super.getState(); + } + + public void setInterval(int millis) { + getState().interval = millis; + } + + public int getInterval() { + return getState().interval; + } + + public void setEnabled(boolean enabled) { + getState().enabled = enabled; + } + + public boolean isEnabled() { + return getState().enabled; + } + + public void addListener(RefreshListener listener) { + listeners.add(listener); + } + + public void removeListener(RefreshListener listener) { + listeners.remove(listener); + } + + public void extend(UI target) { + super.extend(target); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java new file mode 100644 index 0000000000..430da55fa1 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012 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.minitutorials.v7a3; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.minitutorials.v7a3.Refresher.RefreshListener; +import com.vaadin.tests.widgetset.TestingWidgetSet; + +@Widgetset(TestingWidgetSet.NAME) +public class RefresherTestUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + Refresher refresher = new Refresher(); + refresher.extend(this); + refresher.addListener(new RefreshListener() { + @Override + public void refresh(Refresher source) { + System.out.println("Got refresh"); + } + }); + } + + @Override + protected String getTestDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b1/AxessingWebPageAndBrowserInfoUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b1/AxessingWebPageAndBrowserInfoUI.java new file mode 100644 index 0000000000..8623dd0b73 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b1/AxessingWebPageAndBrowserInfoUI.java @@ -0,0 +1,67 @@ +/* + * Copyright 2012 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.minitutorials.v7b1; + +import com.vaadin.server.Page; +import com.vaadin.server.Page.BrowserWindowResizeEvent; +import com.vaadin.server.Page.BrowserWindowResizeListener; +import com.vaadin.server.Page.FragmentChangedEvent; +import com.vaadin.server.Page.FragmentChangedListener; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Notification; +import com.vaadin.ui.UI; + +public class AxessingWebPageAndBrowserInfoUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + UI someUI = this; + + Page page = someUI.getPage(); + page.setBrowserWindowSize(page.getBrowserWindowWidth() + 10, + page.getBrowserWindowHeight() + 10); + page.addBrowserWindowResizeListener(new BrowserWindowResizeListener() { + @Override + public void browserWindowResized(BrowserWindowResizeEvent event) { + Notification.show("Window width=" + event.getWidth() + + ", height=" + event.getHeight()); + } + }); + + page.setFragment(page.getFragment() + "foo"); + page.addFragmentChangedListener(new FragmentChangedListener() { + @Override + public void fragmentChanged(FragmentChangedEvent event) { + Notification.show("Fragment=" + event.getFragment()); + } + }); + } + + @Override + protected String getTestDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b1/BootstrapListenerCode.java b/uitest/src/com/vaadin/tests/minitutorials/v7b1/BootstrapListenerCode.java new file mode 100644 index 0000000000..422e44e402 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b1/BootstrapListenerCode.java @@ -0,0 +1,91 @@ +/* + * Copyright 2012 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.minitutorials.v7b1; + +import java.util.List; + +import javax.portlet.PortletException; +import javax.servlet.ServletException; + +import org.jsoup.nodes.Comment; +import org.jsoup.nodes.Element; +import org.jsoup.nodes.Node; +import org.jsoup.parser.Tag; + +import com.vaadin.server.BootstrapFragmentResponse; +import com.vaadin.server.BootstrapListener; +import com.vaadin.server.BootstrapPageResponse; +import com.vaadin.server.ServiceException; +import com.vaadin.server.SessionInitEvent; +import com.vaadin.server.SessionInitListener; +import com.vaadin.server.VaadinPortlet; +import com.vaadin.server.VaadinServlet; + +public class BootstrapListenerCode { + public static BootstrapListener listener = new BootstrapListener() { + @Override + public void modifyBootstrapPage(BootstrapPageResponse response) { + response.getDocument().body() + .appendChild(new Comment("Powered by Vaadin!", "")); + response.setHeader("X-Powered-By", "Vaadin 7"); + } + + @Override + public void modifyBootstrapFragment(BootstrapFragmentResponse response) { + // Wrap the fragment in a custom div element + Element myDiv = new Element(Tag.valueOf("div"), ""); + List<Node> nodes = response.getFragmentNodes(); + for (Node node : nodes) { + myDiv.appendChild(node); + } + nodes.clear(); + nodes.add(myDiv); + } + }; +} + +class MyVaadinServlet extends VaadinServlet { + @Override + protected void servletInitialized() throws ServletException { + super.servletInitialized(); + getService().addSessionInitListener(new SessionInitListener() { + @Override + public void sessionInit(SessionInitEvent event) + throws ServiceException { + event.getSession().addBootstrapListener( + BootstrapListenerCode.listener); + } + }); + } +} + +// Or... + +class MyVaadinPortlet extends VaadinPortlet { + @Override + protected void portletInitialized() throws PortletException { + super.portletInitialized(); + getService().addSessionInitListener(new SessionInitListener() { + @Override + public void sessionInit(SessionInitEvent event) + throws ServiceException { + event.getSession().addBootstrapListener( + BootstrapListenerCode.listener); + } + }); + } +} diff --git a/uitest/src/com/vaadin/tests/minitutorials/v7b2/CleanupUI.java b/uitest/src/com/vaadin/tests/minitutorials/v7b2/CleanupUI.java new file mode 100644 index 0000000000..9e89d65811 --- /dev/null +++ b/uitest/src/com/vaadin/tests/minitutorials/v7b2/CleanupUI.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012 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.minitutorials.v7b2; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.ui.UI; + +public class CleanupUI extends UI implements UI.CleanupListener { + @Override + protected void init(VaadinRequest request) { + addCleanupListener(new UI.CleanupListener() { + @Override + public void cleanup(UI.CleanupEvent event) { + releaseSomeResources(); + } + }); + + // ... + addCleanupListener(this); + } + + private void releaseSomeResources() { + // ... + } + + @Override + public void cleanup(UI.CleanupEvent event) { + // do cleanup + event.getUI(); + // or equivalent: + UI.getCurrent(); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/IntermediateReplaceConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/IntermediateReplaceConnector.java new file mode 100644 index 0000000000..7f2b5a9a93 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/IntermediateReplaceConnector.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012 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.widgetset.client; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.ReplaceComponent; + +@Connect(value = ReplaceComponent.class) +public class IntermediateReplaceConnector extends ReplacedConnector { + @Override + protected void init() { + super.init(); + getWidget().setHTML( + IntermediateReplaceConnector.class.getName() + + ", should not be used"); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/ReplacedConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/ReplacedConnector.java new file mode 100644 index 0000000000..7f116e4803 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/ReplacedConnector.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012 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.widgetset.client; + +import com.google.gwt.user.client.ui.HTML; +import com.vaadin.client.ui.AbstractComponentConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.ReplaceComponent; + +@Connect(ReplaceComponent.class) +public class ReplacedConnector extends AbstractComponentConnector { + + @Override + protected void init() { + getWidget().setHTML( + ReplacedConnector.class.getName() + ", should not be used"); + } + + @Override + public HTML getWidget() { + return (HTML) super.getWidget(); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/ReplacingConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/ReplacingConnector.java new file mode 100644 index 0000000000..03e50aab16 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/ReplacingConnector.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012 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.widgetset.client; + +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.widgetset.server.ReplaceComponent; + +@Connect(value = ReplaceComponent.class) +public class ReplacingConnector extends IntermediateReplaceConnector { + @Override + protected void init() { + super.init(); + getWidget().setHTML( + ReplacingConnector.class.getName() + ", this is the right one"); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java index 93b12dbc68..a4b816e47e 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java @@ -27,10 +27,10 @@ public class ResourceInStateConnector extends AbstractComponentConnector { @Override public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - String icon = getResourceUrl(ResourceInStateState.MY_ICON_RESOURCE); + String iconUrl = getResourceUrl("myIcon"); - if (icon != null) { - getWidget().setUrl(icon); + if (iconUrl != null) { + getWidget().setUrl(iconUrl); } else { getWidget().setUrl(""); } @@ -38,11 +38,6 @@ public class ResourceInStateConnector extends AbstractComponentConnector { } @Override - public ResourceInStateState getState() { - return (ResourceInStateState) super.getState(); - } - - @Override public Image getWidget() { return (Image) super.getWidget(); } diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java deleted file mode 100644 index 728f0ba5e1..0000000000 --- a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.vaadin.tests.widgetset.client.minitutorials.v7a2; - -import com.vaadin.shared.ComponentState; - -public class ResourceInStateState extends ComponentState { - public static final String MY_ICON_RESOURCE = "myIcon"; -}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/ClientSideModule.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/ClientSideModule.java new file mode 100644 index 0000000000..48bd8a76fb --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/ClientSideModule.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012 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.widgetset.client.minitutorials.v7a3; + +import com.google.gwt.core.client.EntryPoint; +import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.ui.Button; +import com.google.gwt.user.client.ui.RootPanel; +import com.google.gwt.user.client.ui.TextBox; +import com.google.gwt.user.client.ui.VerticalPanel; + +public class ClientSideModule implements EntryPoint { + + @Override + public void onModuleLoad() { + final TextBox nameField = new TextBox(); + nameField.setText("GWT User"); + final Button button = new Button("Check"); + + VerticalPanel vp = new VerticalPanel(); + vp.add(nameField); + vp.add(button); + RootPanel.get().add(vp); + + button.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + if ("GWT User".equals(nameField.getText())) { + Window.alert("User OK"); + } else { + Window.alert("Unauthorized user"); + } + } + }); + } +} diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherConnector.java new file mode 100644 index 0000000000..26fa22a667 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherConnector.java @@ -0,0 +1,40 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a3; + +import com.google.gwt.user.client.Timer; +import com.vaadin.client.communication.RpcProxy; +import com.vaadin.client.communication.StateChangeEvent; +import com.vaadin.client.extensions.AbstractExtensionConnector; +import com.vaadin.shared.ui.Connect; +import com.vaadin.tests.minitutorials.v7a3.Refresher; + +@Connect(Refresher.class) +public class RefresherConnector extends AbstractExtensionConnector { + + private RefresherRpc rpc = RpcProxy.create(RefresherRpc.class, this); + + private Timer timer = new Timer() { + @Override + public void run() { + rpc.refresh(); + } + }; + + @Override + public void onStateChanged(StateChangeEvent event) { + super.onStateChanged(event); + timer.cancel(); + if (isEnabled()) { + timer.scheduleRepeating(getState().interval); + } + } + + @Override + public void onUnregister() { + timer.cancel(); + } + + @Override + public RefresherState getState() { + return (RefresherState) super.getState(); + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherRpc.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherRpc.java new file mode 100644 index 0000000000..df9c9733f7 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherRpc.java @@ -0,0 +1,7 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a3; + +import com.vaadin.shared.communication.ServerRpc; + +public interface RefresherRpc extends ServerRpc { + public void refresh(); +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java new file mode 100644 index 0000000000..769f6330a9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/client/minitutorials/v7a3/RefresherState.java @@ -0,0 +1,7 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a3; + +import com.vaadin.shared.communication.SharedState; + +public class RefresherState extends SharedState { + public int interval = 1000; +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.html b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.html new file mode 100644 index 0000000000..79b231949c --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.html @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>New Test</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">New Test</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.widgetset.server.ReplaceComponentUI?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestswidgetsetserverReplaceComponentUI::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/HTML[0]</td> + <td>com.vaadin.tests.widgetset.client.ReplacingConnector, this is the right one</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.java b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.java new file mode 100644 index 0000000000..81c8af95a6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponent.java @@ -0,0 +1,23 @@ +/* + * Copyright 2012 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.widgetset.server; + +import com.vaadin.ui.AbstractComponent; + +public class ReplaceComponent extends AbstractComponent { + +} diff --git a/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponentUI.java b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponentUI.java new file mode 100644 index 0000000000..1f83cb0d48 --- /dev/null +++ b/uitest/src/com/vaadin/tests/widgetset/server/ReplaceComponentUI.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012 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.widgetset.server; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.tests.widgetset.TestingWidgetSet; + +@Widgetset(TestingWidgetSet.NAME) +public class ReplaceComponentUI extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + addComponent(new ReplaceComponent()); + } + + @Override + protected String getTestDescription() { + return "Tests that the right client-side connector is used when there are multiple connectors with @Connect mappings to the same server-side component."; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9826); + } + +} |