diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-08-24 11:25:05 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-08-24 11:25:26 +0300 |
commit | 38ffd4a097094a01c35fbd5b79563e6c8ea02e92 (patch) | |
tree | 90b07bee9ff39dfcebe51909fb63bd1c782611dd | |
parent | 52986fdf881260994e5465012af2afd80447b8b6 (diff) | |
download | vaadin-framework-38ffd4a097094a01c35fbd5b79563e6c8ea02e92.tar.gz vaadin-framework-38ffd4a097094a01c35fbd5b79563e6c8ea02e92.zip |
Make it possible to delegate state changes to widget (#9297)
24 files changed, 465 insertions, 27 deletions
diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java index a2e61947e8..752f290a42 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -30,6 +30,7 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; import com.google.gwt.user.rebind.SourceWriter; import com.vaadin.shared.annotations.Delayed; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.communication.ClientRpc; import com.vaadin.shared.communication.ServerRpc; import com.vaadin.shared.ui.Connect; @@ -182,6 +183,18 @@ public class ConnectorBundleLoaderFactory extends Generator { writeSetters(logger, w, bundle); writeGetters(logger, w, bundle); writeSerializers(logger, w, bundle); + writeDelegateToWidget(logger, w, bundle); + } + + private void writeDelegateToWidget(TreeLogger logger, SourceWriter w, + ConnectorBundle bundle) { + Set<Property> needsDelegateToWidget = bundle.getNeedsDelegateToWidget(); + for (Property property : needsDelegateToWidget) { + w.println("store.setDelegateToWidget(%s, \"%s\", \"%s\");", + getClassLiteralString(property.getBeanType()), + property.getName(), + property.getAnnotation(DelegateToWidget.class).value()); + } } private void writeSerializers(TreeLogger logger, SourceWriter w, @@ -535,8 +548,11 @@ public class ConnectorBundleLoaderFactory extends Generator { } public static void writeClassLiteral(SourceWriter w, JType type) { - w.print(type.getQualifiedSourceName()); - w.print(".class"); + w.print(getClassLiteralString(type)); + } + + public static String getClassLiteralString(JType type) { + return type.getQualifiedSourceName() + ".class"; } private void writeIdentifiers(SourceWriter w, ConnectorBundle bundle) { diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java index 7515124a5a..1db551ed9a 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java @@ -61,6 +61,7 @@ public class ConnectorBundle { private final Set<Property> needsSetter = new HashSet<Property>(); private final Set<Property> needsType = new HashSet<Property>(); private final Set<Property> needsGetter = new HashSet<Property>(); + private final Set<Property> needsDelegateToWidget = new HashSet<Property>(); private ConnectorBundle(String name, ConnectorBundle previousBundle, Collection<TypeVisitor> visitors, @@ -585,4 +586,23 @@ public class ConnectorBundle { && previousBundle.hasSserializeSupport(type); } } + + public void setNeedsDelegateToWidget(Property property) { + if (!isNeedsDelegateToWidget(property)) { + needsDelegateToWidget.add(property); + } + } + + private boolean isNeedsDelegateToWidget(Property property) { + if (needsDelegateToWidget.contains(property)) { + return true; + } else { + return previousBundle != null + && previousBundle.isNeedsDelegateToWidget(property); + } + } + + public Set<Property> getNeedsDelegateToWidget() { + return Collections.unmodifiableSet(needsDelegateToWidget); + } }
\ No newline at end of file diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java index 31555cc30b..c4c2a50e1c 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java @@ -16,6 +16,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -29,8 +30,11 @@ import com.google.gwt.user.rebind.SourceWriter; public class FieldProperty extends Property { + private final JField field; + private FieldProperty(JClassType beanType, JField field) { super(field.getName(), beanType, field.getType()); + this.field = field; } @Override @@ -74,4 +78,9 @@ public class FieldProperty extends Property { return fields; } + @Override + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { + return field.getAnnotation(annotationClass); + } + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java index f422205175..431ead7f96 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java @@ -16,6 +16,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -121,4 +122,9 @@ public class MethodProperty extends Property { + baseName.substring(1); } + @Override + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { + return setter.getAnnotation(annotationClass); + } + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java index 1714489db5..5ef0293688 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java @@ -16,6 +16,8 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.lang.annotation.Annotation; + import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JPrimitiveType; @@ -81,4 +83,7 @@ public abstract class Property { + getName().hashCode(); } + public abstract <T extends Annotation> T getAnnotation( + Class<T> annotationClass); + } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java index 976eb6417a..cda849f564 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; import com.google.gwt.core.ext.TreeLogger; +import com.google.gwt.core.ext.UnableToCompleteException; import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JMethod; import com.google.gwt.core.ext.typeinfo.JType; @@ -17,7 +18,7 @@ public abstract class TypeVisitor { } public void visitConnector(TreeLogger logger, JClassType type, - ConnectorBundle bundle) { + ConnectorBundle bundle) throws UnableToCompleteException { // Default does nothing } diff --git a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java index 4d63703151..2b0e3e1f61 100644 --- a/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java +++ b/client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java @@ -4,17 +4,21 @@ package com.vaadin.terminal.gwt.widgetsetutils.metadata; +import java.util.Collection; + 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.core.ext.typeinfo.JMethod; -import com.google.gwt.core.ext.typeinfo.JType; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; public class WidgetInitVisitor extends TypeVisitor { @Override public void visitConnector(TreeLogger logger, JClassType type, - ConnectorBundle bundle) { + ConnectorBundle bundle) throws UnableToCompleteException { if (ConnectorBundle.isConnectedComponentConnector(type)) { JClassType createWidgetClass = findInheritedMethod(type, "createWidget").getEnclosingType(); @@ -29,8 +33,41 @@ public class WidgetInitVisitor extends TypeVisitor { JMethod getWidget = findInheritedMethod(type, "getWidget"); bundle.setNeedsReturnType(type, getWidget); - JType widgetType = getWidget.getReturnType(); - bundle.setNeedsGwtConstructor(widgetType.isClass()); + JClassType widgetType = getWidget.getReturnType().isClass(); + bundle.setNeedsGwtConstructor(widgetType); + + JMethod getState = findInheritedMethod(type, "getState"); + JClassType stateType = getState.getReturnType().isClass(); + + Collection<Property> properties = bundle.getProperties(stateType); + for (Property property : properties) { + DelegateToWidget delegateToWidget = property + .getAnnotation(DelegateToWidget.class); + if (delegateToWidget != null) { + bundle.setNeedsDelegateToWidget(property); + String methodName = DelegateToWidget.Helper + .getDelegateTarget(property.getName(), + delegateToWidget.value()); + JMethod delegatedSetter = findInheritedMethod(widgetType, + methodName, property.getPropertyType()); + if (delegatedSetter == null) { + logger.log( + Type.ERROR, + widgetType.getName() + + "." + + methodName + + "(" + + property.getPropertyType() + .getSimpleSourceName() + + ") required by @DelegateToWidget for " + + stateType.getName() + "." + + property.getName() + + " can not be found."); + throw new UnableToCompleteException(); + } + bundle.setNeedsInvoker(widgetType, delegatedSetter); + } + } } } } diff --git a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java index 58357ae3fc..10f63d0f51 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java +++ b/client/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java @@ -68,7 +68,10 @@ import com.vaadin.terminal.gwt.client.communication.RpcManager; import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.extensions.AbstractExtensionConnector; import com.vaadin.terminal.gwt.client.metadata.ConnectorBundleLoader; +import com.vaadin.terminal.gwt.client.metadata.NoDataException; +import com.vaadin.terminal.gwt.client.metadata.Property; import com.vaadin.terminal.gwt.client.metadata.Type; +import com.vaadin.terminal.gwt.client.metadata.TypeData; import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; import com.vaadin.terminal.gwt.client.ui.VContextMenu; import com.vaadin.terminal.gwt.client.ui.dd.VDragAndDropManager; @@ -1148,6 +1151,8 @@ public class ApplicationConnection { " * Hierarchy state change event processing completed", 10); + delegateToWidget(pendingStateChangeEvents); + // Fire state change events. sendStateChangeEvents(pendingStateChangeEvents); @@ -1264,6 +1269,62 @@ public class ApplicationConnection { } + private void delegateToWidget( + Collection<StateChangeEvent> pendingStateChangeEvents) { + VConsole.log(" * Running @DelegateToWidget"); + + for (StateChangeEvent sce : pendingStateChangeEvents) { + ServerConnector connector = sce.getConnector(); + if (connector instanceof ComponentConnector) { + ComponentConnector component = (ComponentConnector) connector; + Type type = TypeData.getType(component.getClass()); + + Type stateType; + try { + stateType = type.getMethod("getState") + .getReturnType(); + } catch (NoDataException e) { + throw new RuntimeException( + "Can not find the state type for " + + type.getSignature(), e); + } + + Set<String> changedProperties = sce + .getChangedProperties(); + for (String propertyName : changedProperties) { + Property property = stateType + .getProperty(propertyName); + String method = property + .getDelegateToWidgetMethodName(); + if (method != null) { + doDelegateToWidget(component, property, method); + } + } + + } + } + } + + private void doDelegateToWidget(ComponentConnector component, + Property property, String methodName) { + Type type = TypeData.getType(component.getClass()); + try { + Type widgetType = type.getMethod("getWidget") + .getReturnType(); + Widget widget = component.getWidget(); + + Object propertyValue = property.getValue(component + .getState()); + + widgetType.getMethod(methodName).invoke(widget, + propertyValue); + } catch (NoDataException e) { + throw new RuntimeException( + "Missing data needed to invoke @DelegateToWidget for " + + Util.getSimpleName(component), e); + } + } + /** * Sends the state change events created while updating the state * information. diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java index 082d032e64..69e41ce75d 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/Property.java @@ -4,6 +4,8 @@ package com.vaadin.terminal.gwt.client.metadata; +import com.vaadin.shared.annotations.DelegateToWidget; + public class Property { private final Type bean; private final String name; @@ -21,15 +23,12 @@ public class Property { TypeDataStore.getSetter(this).invoke(bean, value); } - public String getDelegateToWidgetMethod() { + public String getDelegateToWidgetMethodName() { String value = TypeDataStore.getDelegateToWidget(this); if (value == null) { return null; - } else if (value.isEmpty()) { - return "set" + Character.toUpperCase(value.charAt(0)) - + value.substring(1); } else { - return value; + return DelegateToWidget.Helper.getDelegateTarget(getName(), value); } } diff --git a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java index 55740f69da..9c19410c88 100644 --- a/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java +++ b/client/src/com/vaadin/terminal/gwt/client/metadata/TypeDataStore.java @@ -101,6 +101,12 @@ public class TypeDataStore { return get().delegateToWidget.get(property); } + public void setDelegateToWidget(Class<?> clazz, String propertyName, + String delegateValue) { + delegateToWidget.put(new Property(getType(clazz), propertyName), + delegateValue); + } + public void setReturnType(Class<?> type, String methodName, Type returnType) { returnTypes.put(new Method(getType(type), methodName), returnType); } diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java index 2f52971aeb..33d97f4ed8 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/MediaBaseConnector.java @@ -49,9 +49,6 @@ public abstract class MediaBaseConnector extends AbstractComponentConnector { public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); - getWidget().setControls(getState().isShowControls()); - getWidget().setAutoplay(getState().isAutoplay()); - getWidget().setMuted(getState().isMuted()); for (int i = 0; i < getState().getSources().size(); i++) { URLReference source = getState().getSources().get(i); String sourceType = getState().getSourceTypes().get(i); diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java index 9f4df02380..912f9a7c83 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/splitpanel/AbstractSplitPanelConnector.java @@ -138,9 +138,6 @@ public abstract class AbstractSplitPanelConnector extends // Splitter updates SplitterState splitterState = getState().getSplitterState(); - getWidget().setLocked(splitterState.isLocked()); - getWidget().setPositionReversed(splitterState.isPositionReversed()); - getWidget().setStylenames(); getWidget().minimumPosition = splitterState.getMinPosition() diff --git a/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java b/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java index 5fb7f97044..d5abed4fa9 100644 --- a/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java +++ b/client/src/com/vaadin/terminal/gwt/client/ui/textarea/TextAreaConnector.java @@ -18,7 +18,6 @@ package com.vaadin.terminal.gwt.client.ui.textarea; import com.vaadin.shared.ui.Connect; import com.vaadin.shared.ui.textarea.TextAreaState; -import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; import com.vaadin.terminal.gwt.client.ui.textfield.TextFieldConnector; import com.vaadin.ui.TextArea; @@ -31,14 +30,6 @@ public class TextAreaConnector extends TextFieldConnector { } @Override - public void onStateChanged(StateChangeEvent stateChangeEvent) { - super.onStateChanged(stateChangeEvent); - - getWidget().setRows(getState().getRows()); - getWidget().setWordwrap(getState().isWordwrap()); - } - - @Override public VTextArea getWidget() { return (VTextArea) super.getWidget(); } diff --git a/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java new file mode 100644 index 0000000000..0ac16ecea9 --- /dev/null +++ b/shared/src/com/vaadin/shared/annotations/DelegateToWidget.java @@ -0,0 +1,25 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.shared.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Target; + +@Target({ ElementType.METHOD, ElementType.FIELD }) +public @interface DelegateToWidget { + public String value() default ""; + + public static class Helper { + public static String getDelegateTarget(String propertyName, + String annotationValue) { + String name = annotationValue; + if (name.isEmpty()) { + name = "set" + Character.toUpperCase(propertyName.charAt(0)) + + propertyName.substring(1); + } + return name; + } + } +} diff --git a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java index 2731529caf..80d41dd797 100644 --- a/shared/src/com/vaadin/shared/ui/AbstractMediaState.java +++ b/shared/src/com/vaadin/shared/ui/AbstractMediaState.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; import com.vaadin.shared.ComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.communication.URLReference; public class AbstractMediaState extends ComponentState { @@ -39,6 +40,7 @@ public class AbstractMediaState extends ComponentState { return showControls; } + @DelegateToWidget("setControls") public void setShowControls(boolean showControls) { this.showControls = showControls; } @@ -63,6 +65,7 @@ public class AbstractMediaState extends ComponentState { return autoplay; } + @DelegateToWidget public void setAutoplay(boolean autoplay) { this.autoplay = autoplay; } @@ -71,6 +74,7 @@ public class AbstractMediaState extends ComponentState { return muted; } + @DelegateToWidget public void setMuted(boolean muted) { this.muted = muted; } diff --git a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java index 46eb851edd..71f789b70d 100644 --- a/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java +++ b/shared/src/com/vaadin/shared/ui/splitpanel/AbstractSplitPanelState.java @@ -19,6 +19,7 @@ import java.io.Serializable; import com.vaadin.shared.ComponentState; import com.vaadin.shared.Connector; +import com.vaadin.shared.annotations.DelegateToWidget; public class AbstractSplitPanelState extends ComponentState { @@ -120,6 +121,7 @@ public class AbstractSplitPanelState extends ComponentState { return positionReversed; } + @DelegateToWidget public void setPositionReversed(boolean positionReversed) { this.positionReversed = positionReversed; } @@ -128,6 +130,7 @@ public class AbstractSplitPanelState extends ComponentState { return locked; } + @DelegateToWidget public void setLocked(boolean locked) { this.locked = locked; } diff --git a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java index 31cec77554..50dc1393a3 100644 --- a/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java +++ b/shared/src/com/vaadin/shared/ui/textarea/TextAreaState.java @@ -15,6 +15,7 @@ */ package com.vaadin.shared.ui.textarea; +import com.vaadin.shared.annotations.DelegateToWidget; import com.vaadin.shared.ui.textfield.AbstractTextFieldState; public class TextAreaState extends AbstractTextFieldState { @@ -33,6 +34,7 @@ public class TextAreaState extends AbstractTextFieldState { return rows; } + @DelegateToWidget public void setRows(int rows) { this.rows = rows; } @@ -41,6 +43,7 @@ public class TextAreaState extends AbstractTextFieldState { return wordwrap; } + @DelegateToWidget public void setWordwrap(boolean wordwrap) { this.wordwrap = wordwrap; } diff --git a/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.html new file mode 100644 index 0000000000..12228eb9f0 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.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.serialization.DelegateToWidgetTest?restartApplication</td> + <td></td> +</tr> +<tr> + <td>assertText</td> + <td>vaadin=runcomvaadintestsserializationDelegateToWidgetTest::/VVerticalLayout[0]/VVerticalLayout[0]/DelegateWidget[0]</td> + <td>My String<br />42<br />true<br />3.141592653589793</td> +</tr> +</tbody></table> +</body> +</html> diff --git a/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java new file mode 100644 index 0000000000..54170c880f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/serialization/DelegateToWidgetTest.java @@ -0,0 +1,42 @@ +/* + * Copyright 2011 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.serialization; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.tests.components.AbstractTestRoot; +import com.vaadin.tests.widgetset.TestingWidgetSet; +import com.vaadin.tests.widgetset.server.DelegateToWidgetComponent; + +@Widgetset(TestingWidgetSet.NAME) +public class DelegateToWidgetTest extends AbstractTestRoot { + @Override + protected void setup(WrappedRequest request) { + addComponent(new DelegateToWidgetComponent()); + } + + @Override + protected String getTestDescription() { + return "Verifies that @DelegateToWidget has the desired effect"; + } + + @Override + protected Integer getTicketNumber() { + return Integer.valueOf(9297); + } + +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java b/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java new file mode 100644 index 0000000000..0464a53a95 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/TestingWidgetSet.java @@ -0,0 +1,21 @@ +/* + * Copyright 2011 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; + +public class TestingWidgetSet { + public static final String NAME = "com.vaadin.tests.widgetset.TestingWidgetSet"; +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java new file mode 100644 index 0000000000..c711be232f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateConnector.java @@ -0,0 +1,34 @@ +/* + * Copyright 2011 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.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.tests.widgetset.server.DelegateToWidgetComponent; + +@Connect(DelegateToWidgetComponent.class) +public class DelegateConnector extends AbstractComponentConnector { + @Override + public DelegateWidget getWidget() { + return (DelegateWidget) super.getWidget(); + } + + @Override + public DelegateState getState() { + return (DelegateState) super.getState(); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java new file mode 100644 index 0000000000..e9ac8a1e61 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateState.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011 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.ComponentState; +import com.vaadin.shared.annotations.DelegateToWidget; + +public class DelegateState extends ComponentState { + @DelegateToWidget + public String value1; + + @DelegateToWidget("setValue2") + public int renamedValue2; + + private Boolean value3; + + private double renamedValue4; + + @DelegateToWidget + public void setValue3(Boolean value3) { + this.value3 = value3; + } + + public Boolean getValue3() { + return value3; + } + + @DelegateToWidget("setValue4") + public void setRenamedValue4(double renamedValue4) { + this.renamedValue4 = renamedValue4; + } + + public double getRenamedValue4() { + return renamedValue4; + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java new file mode 100644 index 0000000000..4776eced9a --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/DelegateWidget.java @@ -0,0 +1,50 @@ +/* + * Copyright 2011 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; + +public class DelegateWidget extends HTML { + private String value1; + private int value2; + private Boolean value3; + private double value4; + + public void setValue1(String value1) { + this.value1 = value1; + updateText(); + } + + public void setValue2(int value2) { + this.value2 = value2; + updateText(); + } + + public void setValue3(Boolean value3) { + this.value3 = value3; + updateText(); + } + + public void setValue4(double value4) { + this.value4 = value4; + } + + private void updateText() { + setHTML(value1 + "<br />" + value2 + "<br />" + value3 + "<br />" + + value4 + "<br />"); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java b/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java new file mode 100644 index 0000000000..34c9699f7f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/server/DelegateToWidgetComponent.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 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.tests.widgetset.client.DelegateState; +import com.vaadin.ui.AbstractComponent; + +public class DelegateToWidgetComponent extends AbstractComponent { + public DelegateToWidgetComponent() { + DelegateState state = getState(); + state.value1 = "My String"; + state.renamedValue2 = 42; + state.setValue3(Boolean.TRUE); + state.setRenamedValue4(Math.PI); + } + + @Override + protected DelegateState getState() { + return (DelegateState) super.getState(); + } +} |