From 75f42d32229c2a4c5198a8d2b5ae5b2d90a7f8ff Mon Sep 17 00:00:00 2001 From: Mikael Grankvist Date: Tue, 1 Jul 2014 14:11:05 +0300 Subject: DelegateToWidget will now be run even for parent states for extending states (#14059) Updated the code to encompass Leif's suggestion. Change-Id: I70c0a4a93b9fe9ee8b2c458d666a1fec791f20b4 --- .../ConnectorBundleLoaderFactory.java | 19 +++++++++------ .../widgetsetutils/metadata/ConnectorBundle.java | 27 ++++++++++++---------- .../widgetsetutils/metadata/WidgetInitVisitor.java | 2 +- 3 files changed, 28 insertions(+), 20 deletions(-) (limited to 'client-compiler') diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java index 5519dd1aae..a6ca690a8a 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java @@ -639,13 +639,18 @@ public class ConnectorBundleLoaderFactory extends Generator { private void writeDelegateToWidget(TreeLogger logger, SplittingSourceWriter w, ConnectorBundle bundle) { - Set needsDelegateToWidget = bundle.getNeedsDelegateToWidget(); - for (Property property : needsDelegateToWidget) { - w.println("store.setDelegateToWidget(%s, \"%s\", \"%s\");", - getClassLiteralString(property.getBeanType()), - property.getName(), - property.getAnnotation(DelegateToWidget.class).value()); - + Map> needsDelegateToWidget = bundle + .getNeedsDelegateToWidget(); + for (Entry> entry : needsDelegateToWidget + .entrySet()) { + JClassType beanType = entry.getKey(); + for (Property property : entry.getValue()) { + w.println( + "store.setDelegateToWidget(%s, \"%s\", \"%s\");", + getClassLiteralString(beanType),// property.getBeanType()), + property.getName(), + property.getAnnotation(DelegateToWidget.class).value()); + } w.splitIfNeeded(); } } diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java index 8bbcac4ecb..e8a384298f 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -38,6 +38,7 @@ import com.google.gwt.core.ext.typeinfo.JType; import com.google.gwt.core.ext.typeinfo.NotFoundException; import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.json.client.JSONValue; +import com.google.gwt.thirdparty.guava.common.collect.Sets; import com.vaadin.client.ApplicationConnection; import com.vaadin.client.ComponentConnector; import com.vaadin.client.ServerConnector; @@ -72,7 +73,7 @@ public class ConnectorBundle { private final Map> needsOnStateChange = new HashMap>(); private final Set needsProperty = new HashSet(); - private final Set needsDelegateToWidget = new HashSet(); + private final Map> needsDelegateToWidget = new HashMap>(); private ConnectorBundle(String name, ConnectorBundle previousBundle, Collection visitors, @@ -567,23 +568,25 @@ public class ConnectorBundle { } } - public void setNeedsDelegateToWidget(Property property) { - if (!isNeedsDelegateToWidget(property)) { - needsDelegateToWidget.add(property); + public void setNeedsDelegateToWidget(Property property, JClassType type) { + if (!isNeedsDelegateToWidget(type)) { + needsDelegateToWidget.put(type, Sets.newHashSet(property)); + } else if (!needsDelegateToWidget.get(type).contains(property)) { + needsDelegateToWidget.get(type).add(property); } } - private boolean isNeedsDelegateToWidget(Property property) { - if (needsDelegateToWidget.contains(property)) { + private boolean isNeedsDelegateToWidget(JClassType type) { + if (needsDelegateToWidget.containsKey(type)) { return true; } else { return previousBundle != null - && previousBundle.isNeedsDelegateToWidget(property); + && previousBundle.isNeedsDelegateToWidget(type); } } - public Set getNeedsDelegateToWidget() { - return Collections.unmodifiableSet(needsDelegateToWidget); + public Map> getNeedsDelegateToWidget() { + return Collections.unmodifiableMap(needsDelegateToWidget); } public void setNeedsOnStateChangeHandler(JClassType type, JMethod method) { diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java index e3fee8d9ee..a77b523d14 100644 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java +++ b/client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java @@ -59,7 +59,7 @@ public class WidgetInitVisitor extends TypeVisitor { .getAnnotation(DelegateToWidget.class); if (delegateToWidget != null) { // Generate meta data required for @DelegateToWidget - bundle.setNeedsDelegateToWidget(property); + bundle.setNeedsDelegateToWidget(property, stateType); // Find the delegate target method String methodName = DelegateToWidget.Helper -- cgit v1.2.3