]> source.dussan.org Git - vaadin-framework.git/commitdiff
Update tutorial code to show more user-friendly API
authorLeif Åstrand <leif@vaadin.com>
Thu, 10 Apr 2014 08:47:29 +0000 (11:47 +0300)
committerJonatan Kronqvist <jonatan@vaadin.com>
Wed, 14 May 2014 07:52:04 +0000 (07:52 +0000)
Change-Id: I95c82d2256221b0068d6c2762f6dbb8a1e29b6b8

uitest/src/com/vaadin/tests/minitutorials/v7a3/Analytics.java
uitest/src/com/vaadin/tests/minitutorials/v7a3/AnalyticsUI.java
uitest/src/com/vaadin/tests/minitutorials/v7a3/CapsLockWarning.java
uitest/src/com/vaadin/tests/minitutorials/v7a3/CapsLockWarningUI.java
uitest/src/com/vaadin/tests/minitutorials/v7a3/Refresher.java
uitest/src/com/vaadin/tests/minitutorials/v7a3/RefresherTestUI.java

index db4a88ab7a3672ca5935e05acd9f4c47c8927343..338fb208939391a2188930dc7958f50bedf16acb 100644 (file)
@@ -18,13 +18,13 @@ package com.vaadin.tests.minitutorials.v7a3;
 
 import com.vaadin.annotations.JavaScript;
 import com.vaadin.server.AbstractJavaScriptExtension;
-import com.vaadin.server.ClientConnector;
 import com.vaadin.ui.UI;
 
 @JavaScript("analytics_connector.js")
 public class Analytics extends AbstractJavaScriptExtension {
 
-    public Analytics(String account) {
+    public Analytics(UI ui, String account) {
+        extend(ui);
         pushCommand("_setAccount", account);
     }
 
@@ -37,13 +37,4 @@ public class Analytics extends AbstractJavaScriptExtension {
         // varargs argument instead of as the full varargs argument array.
         callFunction("pushCommand", (Object) commandAndArguments);
     }
-
-    protected void extend(UI uI) {
-        super.extend(uI);
-    }
-
-    @Override
-    protected Class<? extends ClientConnector> getSupportedParentType() {
-        return UI.class;
-    }
 }
index 19a7ce8a191971b8c84b07e568b3d8bcd4d10569..b12f5829fcca480cc89e3269adecdc3d451fc2f5 100644 (file)
@@ -25,8 +25,7 @@ public class AnalyticsUI extends UI {
 
     @Override
     protected void init(VaadinRequest request) {
-        final Analytics analytics = new Analytics("UA-33036133-12");
-        analytics.extend(this);
+        final Analytics analytics = new Analytics(this, "UA-33036133-12");
 
         setContent(new Button("Track pageview", new Button.ClickListener() {
             @Override
index d10bd0edf85ae85d33f3300dfee834783ce14415..4165e63951e2c45de9e947de8a65594dec4c2a71 100644 (file)
@@ -20,7 +20,12 @@ import com.vaadin.server.AbstractExtension;
 import com.vaadin.ui.PasswordField;
 
 public class CapsLockWarning extends AbstractExtension {
-    public void extend(PasswordField field) {
-        super.extend(field);
+    protected CapsLockWarning(PasswordField field) {
+        // Non-public constructor to discourage direct instantiation
+        extend(field);
+    }
+
+    public static CapsLockWarning warnFor(PasswordField field) {
+        return new CapsLockWarning(field);
     }
 }
index 88a308a9e916f8b5b93afc2e41e373df405e0e85..19a7da71144a2f82918b4b1657d334dbb8cc98e2 100644 (file)
@@ -28,7 +28,7 @@ public class CapsLockWarningUI extends AbstractTestUI {
     @Override
     protected void setup(VaadinRequest request) {
         PasswordField field = new PasswordField("Enter your password");
-        new CapsLockWarning().extend(field);
+        CapsLockWarning.warnFor(field);
 
         addComponent(field);
     }
index 1b855e4e517eb58d6b6181a7c51e361ab5b6a2e5..6878fc1bc6e208a43fef6b88b1022592662be0d5 100644 (file)
@@ -29,13 +29,14 @@ public class Refresher extends AbstractExtension {
 
     }
 
-    public Refresher() {
+    public Refresher(UI ui) {
         registerRpc(new RefresherRpc() {
             @Override
             public void refresh() {
                 fireEvent(new RefreshEvent(Refresher.this));
             }
         });
+        extend(ui);
     }
 
     @Override
@@ -67,8 +68,4 @@ public class Refresher extends AbstractExtension {
         super.removeListener(RefreshEvent.class, listener,
                 RefreshListener.METHOD);
     }
-
-    public void extend(UI target) {
-        super.extend(target);
-    }
 }
index 0b2fad21aa96f8a7a740dab9a199d7ed338e2935..e9243ac0cb6ae18bcdcfad6561807dbb97c63cba 100644 (file)
@@ -30,8 +30,7 @@ public class RefresherTestUI extends AbstractTestUI {
 
     @Override
     protected void setup(VaadinRequest request) {
-        final Refresher refresher = new Refresher();
-        refresher.extend(this);
+        final Refresher refresher = new Refresher(this);
         refresher.setInterval(1000);
         refresher.addRefreshListener(new RefreshListener() {
             @Override