summaryrefslogtreecommitdiffstats
path: root/client-compiler
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-08-24 11:25:05 +0300
committerLeif Åstrand <leif@vaadin.com>2012-08-24 11:25:26 +0300
commit38ffd4a097094a01c35fbd5b79563e6c8ea02e92 (patch)
tree90b07bee9ff39dfcebe51909fb63bd1c782611dd /client-compiler
parent52986fdf881260994e5465012af2afd80447b8b6 (diff)
downloadvaadin-framework-38ffd4a097094a01c35fbd5b79563e6c8ea02e92.tar.gz
vaadin-framework-38ffd4a097094a01c35fbd5b79563e6c8ea02e92.zip
Make it possible to delegate state changes to widget (#9297)
Diffstat (limited to 'client-compiler')
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/ConnectorBundleLoaderFactory.java20
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/ConnectorBundle.java20
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/FieldProperty.java9
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/MethodProperty.java6
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/Property.java5
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/TypeVisitor.java3
-rw-r--r--client-compiler/src/com/vaadin/terminal/gwt/widgetsetutils/metadata/WidgetInitVisitor.java45
7 files changed, 101 insertions, 7 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);
+ }
+ }
}
}
}