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);
}
// 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;
- }
}
@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
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);
}
}
@Override
protected void setup(VaadinRequest request) {
PasswordField field = new PasswordField("Enter your password");
- new CapsLockWarning().extend(field);
+ CapsLockWarning.warnFor(field);
addComponent(field);
}
}
- public Refresher() {
+ public Refresher(UI ui) {
registerRpc(new RefresherRpc() {
@Override
public void refresh() {
fireEvent(new RefreshEvent(Refresher.this));
}
});
+ extend(ui);
}
@Override
super.removeListener(RefreshEvent.class, listener,
RefreshListener.METHOD);
}
-
- public void extend(UI target) {
- super.extend(target);
- }
}
@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