diff options
author | Henri Sara <hesara@vaadin.com> | 2012-06-21 11:15:24 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-06-21 11:15:24 +0300 |
commit | b526fe5313b829758f536a6621c6d4036461b7d1 (patch) | |
tree | 3a1c1bea4ed0d0bd409f50a2181d8a83a50e4166 | |
parent | d83a57c7facca417e4e92cacaa64ee9b6dbe4597 (diff) | |
parent | 0a35fe732f1c96027e859e2f15fa1909a26b5ae0 (diff) | |
download | vaadin-framework-b526fe5313b829758f536a6621c6d4036461b7d1.tar.gz vaadin-framework-b526fe5313b829758f536a6621c6d4036461b7d1.zip |
Merge branch 'master' into gwt
36 files changed, 701 insertions, 19 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterion.java b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterion.java index 32dac10170..8a026e4d2e 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterion.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/AcceptCriterion.java @@ -25,9 +25,9 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) public @interface AcceptCriterion { /** - * @return the fully qualified class name of the server side counterpart for - * the annotated criterion + * @return the class of the server side counterpart for the annotated + * criterion */ - String value(); + Class<?> value(); } diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptAll.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptAll.java index 07e931fb02..a864a93c2a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptAll.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAcceptAll.java @@ -6,9 +6,10 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.AcceptAll; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.AcceptAll") +@AcceptCriterion(AcceptAll.class) final public class VAcceptAll extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VAnd.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VAnd.java index 727c30075c..19399d7d4a 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VAnd.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VAnd.java @@ -6,9 +6,10 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.And; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.And") +@AcceptCriterion(And.class) final public class VAnd extends VAcceptCriterion implements VAcceptCallback { private boolean b1; diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VContainsDataFlavor.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VContainsDataFlavor.java index 5786068174..3cd341eefd 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VContainsDataFlavor.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VContainsDataFlavor.java @@ -6,9 +6,10 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.ContainsDataFlavor") +@AcceptCriterion(ContainsDataFlavor.class) final public class VContainsDataFlavor extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java index 58550af918..b6af81085f 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VDragSourceIs.java @@ -3,6 +3,7 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.SourceIs; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorMap; import com.vaadin.terminal.gwt.client.UIDL; @@ -12,7 +13,7 @@ import com.vaadin.terminal.gwt.client.UIDL; * * @since 6.3 */ -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.SourceIs") +@AcceptCriterion(SourceIs.class) final public class VDragSourceIs extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java index 3fc54e6fd3..5dad4873ea 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VIsOverId.java @@ -9,8 +9,9 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.ConnectorMap; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.ui.AbstractSelect; -@AcceptCriterion("com.vaadin.ui.AbstractSelect.TargetItemIs") +@AcceptCriterion(AbstractSelect.TargetItemIs.class) final public class VIsOverId extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java index 5f1fe978b5..ca4d0e900d 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VItemIdIs.java @@ -8,8 +8,9 @@ package com.vaadin.terminal.gwt.client.ui.dd; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.ui.AbstractSelect; -@AcceptCriterion("com.vaadin.ui.AbstractSelect.AcceptItem") +@AcceptCriterion(AbstractSelect.AcceptItem.class) final public class VItemIdIs extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java index e972371b9f..e3bed02642 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VLazyInitItemIdentifiers.java @@ -9,6 +9,8 @@ package com.vaadin.terminal.gwt.client.ui.dd; import java.util.HashSet; import com.vaadin.terminal.gwt.client.UIDL; +import com.vaadin.ui.Table; +import com.vaadin.ui.Tree; /** * @@ -18,13 +20,13 @@ public class VLazyInitItemIdentifiers extends VAcceptCriterion { private HashSet<String> hashSet; private VDragEvent lastDragEvent; - @AcceptCriterion("com.vaadin.ui.Table.TableDropCriterion") + @AcceptCriterion(Table.TableDropCriterion.class) final public static class VTableLazyInitItemIdentifiers extends VLazyInitItemIdentifiers { // all logic in superclass } - @AcceptCriterion("com.vaadin.ui.Tree.TreeDropCriterion") + @AcceptCriterion(Tree.TreeDropCriterion.class) final public static class VTreeLazyInitItemIdentifiers extends VLazyInitItemIdentifiers { // all logic in superclass diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VNot.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VNot.java index e91ad6149a..e4d2dff606 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VNot.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VNot.java @@ -6,6 +6,7 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.Not; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.VConsole; @@ -13,7 +14,7 @@ import com.vaadin.terminal.gwt.client.VConsole; * TODO implementation could now be simplified/optimized * */ -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.Not") +@AcceptCriterion(Not.class) final public class VNot extends VAcceptCriterion { private boolean b1; private VAcceptCriterion crit1; diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java index 3664326568..91ba4bf0c4 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VOr.java @@ -6,12 +6,13 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.Or; import com.vaadin.terminal.gwt.client.UIDL; /** * */ -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.Or") +@AcceptCriterion(Or.class) final public class VOr extends VAcceptCriterion implements VAcceptCallback { private boolean accepted; diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VServerAccept.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VServerAccept.java index e679b64369..64c2da5320 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VServerAccept.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VServerAccept.java @@ -6,9 +6,10 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.ServerSideCriterion; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.ServerSideCriterion") +@AcceptCriterion(ServerSideCriterion.class) final public class VServerAccept extends VAcceptCriterion { @Override public void accept(final VDragEvent drag, UIDL configuration, diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VSourceIsTarget.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VSourceIsTarget.java index 9bbabe9d29..2365eabe22 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VSourceIsTarget.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VSourceIsTarget.java @@ -6,10 +6,11 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.SourceIsTarget; import com.vaadin.terminal.gwt.client.ComponentConnector; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.SourceIsTarget") +@AcceptCriterion(SourceIsTarget.class) final public class VSourceIsTarget extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetDetailIs.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetDetailIs.java index 7d92359f7d..610d555745 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetDetailIs.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetDetailIs.java @@ -6,9 +6,10 @@ */ package com.vaadin.terminal.gwt.client.ui.dd; +import com.vaadin.event.dd.acceptcriteria.TargetDetailIs; import com.vaadin.terminal.gwt.client.UIDL; -@AcceptCriterion("com.vaadin.event.dd.acceptcriteria.TargetDetailIs") +@AcceptCriterion(TargetDetailIs.class) final public class VTargetDetailIs extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetInSubtree.java b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetInSubtree.java index 3db44f3162..56478b2b95 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetInSubtree.java +++ b/src/com/vaadin/terminal/gwt/client/ui/dd/VTargetInSubtree.java @@ -10,8 +10,9 @@ import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.UIDL; import com.vaadin.terminal.gwt.client.ui.tree.VTree; import com.vaadin.terminal.gwt.client.ui.tree.VTree.TreeNode; +import com.vaadin.ui.Tree; -@AcceptCriterion("com.vaadin.ui.Tree.TargetInSubtree") +@AcceptCriterion(Tree.TargetInSubtree.class) final public class VTargetInSubtree extends VAcceptCriterion { @Override diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriteriaFactoryGenerator.java b/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriteriaFactoryGenerator.java index 459b6ddd30..6d90a51761 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriteriaFactoryGenerator.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/AcceptCriteriaFactoryGenerator.java @@ -107,8 +107,9 @@ public class AcceptCriteriaFactoryGenerator extends Generator { .getAnnotation(AcceptCriterion.class); if (annotation != null) { String clientClassName = clientClass.getQualifiedSourceName(); - String serverClassName = clientClass.getAnnotation( + Class<?> serverClass = clientClass.getAnnotation( AcceptCriterion.class).value(); + String serverClassName = serverClass.getCanonicalName(); logger.log(Type.INFO, "creating mapping for " + serverClassName); sourceWriter.print("if (\""); sourceWriter.print(serverClassName); @@ -123,5 +124,4 @@ public class AcceptCriteriaFactoryGenerator extends Generator { sourceWriter.outdent(); sourceWriter.println("}"); } - } diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateComponent.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateComponent.java new file mode 100644 index 0000000000..78a945901d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateComponent.java @@ -0,0 +1,26 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.tests.widgetset.client.minitutorials.v7a2.ComponentInStateState; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.Component; + +public class ComponentInStateComponent extends AbstractComponent { + + @Override + public ComponentInStateState getState() { + return (ComponentInStateState) super.getState(); + } + + public void setOtherComponent(Component component) { + getState().setOtherComponent(component); + requestRepaint(); + } + + public Component getOtherComponent() { + return (Component) getState().getOtherComponent(); + } +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateRoot.java new file mode 100644 index 0000000000..61b5f98f99 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ComponentInStateRoot.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.ui.Label; +import com.vaadin.ui.Root; + +/** + * Mini tutorial code for + * https://vaadin.com/wiki/-/wiki/Main/Using%20Components% + * 20in%20the%20shared%20state + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class ComponentInStateRoot extends Root { + @Override + protected void init(WrappedRequest request) { + ComponentInStateComponent component = new ComponentInStateComponent(); + component.setOtherComponent(this); + addComponent(component); + addComponent(new Label("Server-side type of other component: " + + component.getOtherComponent().getClass().getName())); + } +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponent.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponent.java new file mode 100644 index 0000000000..5c4fa9d10b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponent.java @@ -0,0 +1,47 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentClientRpc; +import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentServerRpc; +import com.vaadin.tests.widgetset.client.minitutorials.v7a2.MyComponentState; +import com.vaadin.ui.AbstractComponent; + +public class MyComponent extends AbstractComponent { + private int clickCount = 0; + + private MyComponentServerRpc rpc = new MyComponentServerRpc() { + public void clicked(MouseEventDetails mouseDetails) { + clickCount++; + + // nag every 5:th click + if (clickCount % 5 == 0) { + getRpcProxy(MyComponentClientRpc.class).alert( + "Ok, that's enough!"); + } + + setText("You have clicked " + clickCount + " times"); + } + }; + + public MyComponent() { + registerRpc(rpc); + } + + @Override + public MyComponentState getState() { + return (MyComponentState) super.getState(); + } + + public void setText(String text) { + getState().setText(text); + requestRepaint(); + } + + public String getText() { + return getState().getText(); + } +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponentRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponentRoot.java new file mode 100644 index 0000000000..77792436f5 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyComponentRoot.java @@ -0,0 +1,36 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.ui.Root; + +/** + * Mini tutorial code for + * https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20simple%20component, + * https://vaadin.com/wiki/-/wiki/Main/Creating%20a%20simple%20component, + * https://vaadin.com/wiki/-/wiki/Main/Sending% + * 20events%20from%20the%20client%20to%20the%20server%20using%20RPC, + * https://vaadin + * .com/wiki/-/wiki/Main/Using%20RPC%20to%20send%20events%20to%20the%20client + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class MyComponentRoot extends Root { + + @Override + protected void init(WrappedRequest request) { + MyComponent component = new MyComponent(); + + component.setText("My component text"); + + addComponent(component); + } + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerConnector.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerConnector.java new file mode 100644 index 0000000000..ea278da218 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerConnector.java @@ -0,0 +1,61 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.google.gwt.user.client.Element; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.SimpleManagedLayout; +import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeEvent; +import com.vaadin.terminal.gwt.client.ui.layout.ElementResizeListener; + +/** + * Mini tutorial code for + * https://vaadin.com/wiki/-/wiki/Main/Widget%20styling%20using%20only%20CSS, + * https + * ://vaadin.com/wiki/-/wiki/Main/Lightweight%20calculations%20of%20widget%20l + * ayout and https://vaadin.com/wiki/-/wiki/Main/Complex%20widget%20layouts + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +public class MyPickerConnector extends AbstractComponentConnector implements + SimpleManagedLayout { + @Override + public MyPickerWidget getWidget() { + return (MyPickerWidget) super.getWidget(); + } + + private final ElementResizeListener listener = new ElementResizeListener() { + public void onElementResize(ElementResizeEvent e) { + int buttonWidth = getLayoutManager().getOuterWidth(e.getElement()); + buttonWidth -= getLayoutManager().getMarginRight(e.getElement()); + getWidget().adjustButtonSpace(buttonWidth); + } + }; + + @Override + protected void init() { + Element button = getWidget().getWidget(1).getElement(); + getLayoutManager().addElementResizeListener(button, listener); + + getLayoutManager().registerDependency(this, button); + } + + @Override + public void onUnregister() { + Element button = getWidget().getWidget(1).getElement(); + getLayoutManager().removeElementResizeListener(button, listener); + + getLayoutManager().unregisterDependency(this, button); + } + + public void layout() { + Element button = getWidget().getWidget(1).getElement(); + int buttonWidth = getLayoutManager().getOuterWidth(button); + buttonWidth -= getLayoutManager().getMarginRight(button); + getWidget().adjustButtonSpace(buttonWidth); + } +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerWidget.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerWidget.java new file mode 100644 index 0000000000..213a1b9e6b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/MyPickerWidget.java @@ -0,0 +1,51 @@ +package com.vaadin.tests.minitutorials.v7a2; + +import com.google.gwt.dom.client.Document; +import com.google.gwt.dom.client.Style.Unit; +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.ComplexPanel; +import com.google.gwt.user.client.ui.PushButton; +import com.google.gwt.user.client.ui.TextBox; + +public class MyPickerWidget extends ComplexPanel { + + public static final String CLASSNAME = "mypicker"; + + private final TextBox textBox = new TextBox(); + private final PushButton button = new PushButton("..."); + + public MyPickerWidget() { + setElement(Document.get().createDivElement()); + setStylePrimaryName(CLASSNAME); + + textBox.setStylePrimaryName(CLASSNAME + "-field"); + button.setStylePrimaryName(CLASSNAME + "-button"); + + add(textBox, getElement()); + add(button, getElement()); + + button.addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + Window.alert("Calendar picker not yet supported!"); + } + }); + } + + public void setButtonText(String buttonText, boolean adjustSpace) { + if (buttonText == null || buttonText.length() == 0) { + buttonText = "..."; + } + button.setText(buttonText); + + if (adjustSpace) { + adjustButtonSpace(button.getOffsetWidth()); + } + } + + public void adjustButtonSpace(int width) { + getElement().getStyle().setPaddingRight(width, Unit.PX); + button.getElement().getStyle().setMarginRight(-width, Unit.PX); + } +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java new file mode 100644 index 0000000000..f9d4cb38e6 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateComponent.java @@ -0,0 +1,30 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.terminal.Resource; +import com.vaadin.terminal.gwt.server.ResourceReference; +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) { + getState().setMyIcon(new ResourceReference(icon)); + } + + public Resource getMyIcon() { + ResourceReference ref = ((ResourceReference) getState().getMyIcon()); + if (ref != null) { + return ref.getResource(); + } else { + return null; + } + } +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateRoot.java new file mode 100644 index 0000000000..135d36828d --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/ResourceInStateRoot.java @@ -0,0 +1,32 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.minitutorials.v7a2; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.ThemeResource; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.ui.Root; + +/** + * Mini tutorial code for + * https://vaadin.com/wiki/-/wiki/Main/Using%20Resources%20 + * in%20the%20shared%20state + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0.0 + */ +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class ResourceInStateRoot extends Root { + + @Override + protected void init(WrappedRequest request) { + ResourceInStateComponent component = new ResourceInStateComponent(); + component.setIcon(new ThemeResource("../runo/icons/32/calendar.png")); + + addComponent(component); + } + +} diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetContainer.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetContainer.java new file mode 100644 index 0000000000..3c2f9a68b4 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetContainer.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.minitutorials.v7a2; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.vaadin.ui.AbstractComponentContainer; +import com.vaadin.ui.Component; + +public class WidgetContainer extends AbstractComponentContainer { + + List<Component> children = new ArrayList<Component>(); + + @Override + public void addComponent(Component c) { + children.add(c); + super.addComponent(c); + requestRepaint(); + } + + @Override + public void removeComponent(Component c) { + children.remove(c); + super.removeComponent(c); + requestRepaint(); + } + + public void replaceComponent(Component oldComponent, Component newComponent) { + int index = children.indexOf(oldComponent); + if (index != -1) { + children.remove(index); + children.add(index, newComponent); + fireComponentDetachEvent(oldComponent); + fireComponentAttachEvent(newComponent); + requestRepaint(); + } + } + + public int getComponentCount() { + return children.size(); + } + + public Iterator<Component> getComponentIterator() { + return children.iterator(); + } +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerRoot.java b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerRoot.java new file mode 100644 index 0000000000..3b24ec400e --- /dev/null +++ b/tests/testbench/com/vaadin/tests/minitutorials/v7a2/WidgetcontainerRoot.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.minitutorials.v7a2; + +import java.util.Random; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.terminal.WrappedRequest; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.Component; +import com.vaadin.ui.Label; +import com.vaadin.ui.Root; + +@Widgetset("com.vaadin.tests.widgetset.TestingWidgetSet") +public class WidgetcontainerRoot extends Root { + @Override + public void init(WrappedRequest request) { + Label label = new Label("Hello Vaadin user"); + addComponent(label); + final WidgetContainer widgetContainer = new WidgetContainer(); + addComponent(widgetContainer); + widgetContainer.addComponent(new Label( + "Click the button to add components to the WidgetContainer.")); + Button button = new Button("Add more components", new ClickListener() { + + public void buttonClick(ClickEvent event) { + Random randomGenerator = new Random(); + int random = randomGenerator.nextInt(3); + Component component; + if (random % 3 == 0) { + component = new Label("A new label"); + } else if (random % 3 == 1) { + component = new Button("A button!"); + } else { + component = new CheckBox("A textfield"); + } + widgetContainer.addComponent(component); + } + }); + addComponent(button); + } + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateState.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateState.java new file mode 100644 index 0000000000..a5a5f504ab --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateState.java @@ -0,0 +1,20 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.ComponentState; +import com.vaadin.terminal.gwt.client.Connector; + +public class ComponentInStateState extends ComponentState { + private Connector otherComponent; + + public Connector getOtherComponent() { + return otherComponent; + } + + public void setOtherComponent(Connector otherComponent) { + this.otherComponent = otherComponent; + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateStateConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateStateConnector.java new file mode 100644 index 0000000000..6e855f7c04 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ComponentInStateStateConnector.java @@ -0,0 +1,38 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.google.gwt.user.client.ui.Label; +import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.Connect; +import com.vaadin.tests.minitutorials.v7a2.ComponentInStateComponent; + +@Connect(ComponentInStateComponent.class) +public class ComponentInStateStateConnector extends AbstractComponentConnector { + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + getWidget().setText( + "Client-side type of other component: " + + getOtherComponent().getClass().getName()); + } + + public ComponentConnector getOtherComponent() { + return (ComponentConnector) getState().getOtherComponent(); + } + + @Override + public ComponentInStateState getState() { + return (ComponentInStateState) super.getState(); + } + + @Override + public Label getWidget() { + return (Label) super.getWidget(); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentClientRpc.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentClientRpc.java new file mode 100644 index 0000000000..68e2df533c --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentClientRpc.java @@ -0,0 +1,9 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.communication.ClientRpc; + +public interface MyComponentClientRpc extends ClientRpc { + + public void alert(String message); + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentConnector.java new file mode 100644 index 0000000000..2a131c07c8 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentConnector.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +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.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.terminal.gwt.client.MouseEventDetailsBuilder; +import com.vaadin.terminal.gwt.client.communication.RpcProxy; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.Connect; +import com.vaadin.tests.minitutorials.v7a2.MyComponent; + +@Connect(MyComponent.class) +public class MyComponentConnector extends AbstractComponentConnector { + + MyComponentServerRpc rpc = RpcProxy + .create(MyComponentServerRpc.class, this); + + public MyComponentConnector() { + getWidget().addClickHandler(new ClickHandler() { + public void onClick(ClickEvent event) { + + final MouseEventDetails mouseDetails = MouseEventDetailsBuilder + .buildMouseEventDetails(event.getNativeEvent(), + getWidget().getElement()); + + rpc.clicked(mouseDetails); + } + }); + registerRpc(MyComponentClientRpc.class, new MyComponentClientRpc() { + public void alert(String message) { + Window.alert(message); + } + }); + } + + @Override + public MyComponentState getState() { + return (MyComponentState) super.getState(); + } + + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + final String text = getState().getText(); + getWidget().setText(text); + } + + @Override + public MyComponentWidget getWidget() { + return (MyComponentWidget) super.getWidget(); + } + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentServerRpc.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentServerRpc.java new file mode 100644 index 0000000000..7f273c28d2 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentServerRpc.java @@ -0,0 +1,10 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.MouseEventDetails; +import com.vaadin.terminal.gwt.client.communication.ServerRpc; + +public interface MyComponentServerRpc extends ServerRpc { + + public void clicked(MouseEventDetails mouseDetails); + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentState.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentState.java new file mode 100644 index 0000000000..a80aa7bca8 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentState.java @@ -0,0 +1,17 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.ComponentState; + +public class MyComponentState extends ComponentState { + + private String text; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentWidget.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentWidget.java new file mode 100644 index 0000000000..ab03d51806 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/MyComponentWidget.java @@ -0,0 +1,16 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.google.gwt.user.client.ui.Label; + +public class MyComponentWidget extends Label { + public static final String CLASSNAME = "mycomponent"; + + public MyComponentWidget() { + setText("This is MyComponent"); + setStyleName(CLASSNAME); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java new file mode 100644 index 0000000000..f05d4a0eb9 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateConnector.java @@ -0,0 +1,38 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ + +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.google.gwt.user.client.ui.Image; +import com.vaadin.terminal.gwt.client.communication.StateChangeEvent; +import com.vaadin.terminal.gwt.client.communication.URLReference; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentConnector; +import com.vaadin.terminal.gwt.client.ui.Connect; +import com.vaadin.tests.minitutorials.v7a2.ResourceInStateComponent; + +@Connect(ResourceInStateComponent.class) +public class ResourceInStateConnector extends AbstractComponentConnector { + @Override + public void onStateChanged(StateChangeEvent stateChangeEvent) { + super.onStateChanged(stateChangeEvent); + + URLReference icon = getState().getMyIcon(); + if (icon != null) { + getWidget().setUrl(icon.getURL()); + } else { + getWidget().setUrl(""); + } + + } + + @Override + public ResourceInStateState getState() { + return (ResourceInStateState) super.getState(); + } + + @Override + public Image getWidget() { + return (Image) super.getWidget(); + } +} diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java new file mode 100644 index 0000000000..7c124e7bf8 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/ResourceInStateState.java @@ -0,0 +1,17 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.vaadin.terminal.gwt.client.ComponentState; +import com.vaadin.terminal.gwt.client.communication.URLReference; + +public class ResourceInStateState extends ComponentState { + + private URLReference myIcon; + + public URLReference getMyIcon() { + return myIcon; + } + + public void setMyIcon(URLReference icon) { + myIcon = icon; + } +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/VWidgetContainer.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/VWidgetContainer.java new file mode 100644 index 0000000000..6ec0a6da7c --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/VWidgetContainer.java @@ -0,0 +1,12 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import com.google.gwt.user.client.ui.VerticalPanel; + +public class VWidgetContainer extends VerticalPanel { + + public static final String CLASSNAME = "v-widgetcontainer"; + + public VWidgetContainer() { + setStyleName(CLASSNAME); + } +}
\ No newline at end of file diff --git a/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/WidgetContainerConnector.java b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/WidgetContainerConnector.java new file mode 100644 index 0000000000..012060f437 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/widgetset/client/minitutorials/v7a2/WidgetContainerConnector.java @@ -0,0 +1,35 @@ +package com.vaadin.tests.widgetset.client.minitutorials.v7a2; + +import java.util.List; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.user.client.ui.Widget; +import com.vaadin.terminal.gwt.client.ComponentConnector; +import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent; +import com.vaadin.terminal.gwt.client.ui.AbstractComponentContainerConnector; +import com.vaadin.terminal.gwt.client.ui.Connect; +import com.vaadin.tests.minitutorials.v7a2.WidgetContainer; + +@Connect(WidgetContainer.class) +public class WidgetContainerConnector extends + AbstractComponentContainerConnector { + + @Override + public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { + List<ComponentConnector> children = getChildComponents(); + VWidgetContainer widget = (VWidgetContainer) getWidget(); + widget.clear(); + for (ComponentConnector connector : children) { + widget.add(connector.getWidget()); + } + super.onConnectorHierarchyChange(event); + } + + @Override + protected Widget createWidget() { + return GWT.create(VWidgetContainer.class); + } + + public void updateCaption(ComponentConnector connector) { + } +}
\ No newline at end of file |