--- /dev/null
+/*
+@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();
+ }
+}
--- /dev/null
+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()));
+ }
+}
--- /dev/null
+/*
+@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();
+ }
+}
--- /dev/null
+/*
+@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
--- /dev/null
+/*
+@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);
+ }
+}
--- /dev/null
+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
--- /dev/null
+/*
+@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;
+ }
+ }
+}
--- /dev/null
+/*
+@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);
+ }
+
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+/*
+@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;
+ }
+}
--- /dev/null
+/*
+@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();
+ }
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+/*
+@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);
+ }
+}
--- /dev/null
+/*
+@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();
+ }
+}
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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 = getChildren();
+ 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