Change-Id: I2622c5c0f6ebea701a0fb07b3a63dc44d6c4c808tags/7.2.7
@@ -605,13 +605,18 @@ public class ConnectorBundleLoaderFactory extends Generator { | |||
private void writeDelegateToWidget(TreeLogger logger, | |||
SplittingSourceWriter 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()); | |||
Map<JClassType, Set<Property>> needsDelegateToWidget = bundle | |||
.getNeedsDelegateToWidgetMap(); | |||
for (Entry<JClassType, Set<Property>> 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(); | |||
} | |||
} |
@@ -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<JClassType, Set<JMethod>> needsOnStateChange = new HashMap<JClassType, Set<JMethod>>(); | |||
private final Set<Property> needsProperty = new HashSet<Property>(); | |||
private final Set<Property> needsDelegateToWidget = new HashSet<Property>(); | |||
private final Map<JClassType, Set<Property>> needsDelegateToWidget = new HashMap<JClassType, Set<Property>>(); | |||
private ConnectorBundle(String name, ConnectorBundle previousBundle, | |||
Collection<TypeVisitor> visitors, | |||
@@ -567,23 +568,41 @@ public class ConnectorBundle { | |||
} | |||
} | |||
@Deprecated | |||
public void setNeedsDelegateToWidget(Property property) { | |||
if (!isNeedsDelegateToWidget(property)) { | |||
needsDelegateToWidget.add(property); | |||
setNeedsDelegateToWidget(property, property.getBeanType()); | |||
} | |||
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); | |||
} | |||
} | |||
@Deprecated | |||
public Set<Property> getNeedsDelegateToWidget() { | |||
return Collections.unmodifiableSet(needsDelegateToWidget); | |||
HashSet<Property> set = new HashSet<Property>(); | |||
for (Set<Property> value : needsDelegateToWidget.values()) { | |||
set.addAll(value); | |||
} | |||
return set; | |||
} | |||
public Map<JClassType, Set<Property>> getNeedsDelegateToWidgetMap() { | |||
return Collections.unmodifiableMap(needsDelegateToWidget); | |||
} | |||
public void setNeedsOnStateChangeHandler(JClassType type, JMethod method) { |
@@ -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 |
@@ -0,0 +1,15 @@ | |||
package com.vaadin.tests.widgetset.client.superText; | |||
import com.vaadin.client.ui.textarea.TextAreaConnector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.tests.widgetset.server.ExtraSuperTextArea; | |||
@Connect(ExtraSuperTextArea.class) | |||
public class ExtraSuperTextAreaConnector extends TextAreaConnector { | |||
// @DelegateToWidget will not work with overridden state | |||
@Override | |||
public ExtraSuperTextAreaState getState() { | |||
return (ExtraSuperTextAreaState) super.getState(); | |||
} | |||
} |
@@ -0,0 +1,7 @@ | |||
package com.vaadin.tests.widgetset.client.superText; | |||
import com.vaadin.shared.ui.textarea.TextAreaState; | |||
public class ExtraSuperTextAreaState extends TextAreaState { | |||
} |
@@ -0,0 +1,19 @@ | |||
package com.vaadin.tests.widgetset.client.superText; | |||
import com.vaadin.client.ui.textarea.TextAreaConnector; | |||
import com.vaadin.shared.ui.Connect; | |||
import com.vaadin.tests.widgetset.server.SuperTextArea; | |||
/** | |||
* @author artamonov | |||
* @version $Id$ | |||
*/ | |||
@Connect(SuperTextArea.class) | |||
public class SuperTextAreaConnector extends TextAreaConnector { | |||
// @DelegateToWidget will not work with overridden state | |||
@Override | |||
public SuperTextAreaState getState() { | |||
return (SuperTextAreaState) super.getState(); | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.vaadin.tests.widgetset.client.superText; | |||
import com.vaadin.shared.ui.textarea.TextAreaState; | |||
/** | |||
* @author artamonov | |||
* @version $Id$ | |||
*/ | |||
public class SuperTextAreaState extends TextAreaState { | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.vaadin.tests.widgetset.server; | |||
import com.vaadin.tests.widgetset.client.superText.SuperTextAreaState; | |||
import com.vaadin.ui.TextArea; | |||
/** | |||
* @author artamonov | |||
* @version $Id$ | |||
*/ | |||
public class ExtraSuperTextArea extends TextArea { | |||
@Override | |||
public SuperTextAreaState getState() { | |||
return (SuperTextAreaState) super.getState(); | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
/* | |||
* 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 | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.widgetset.server; | |||
import com.vaadin.annotations.Widgetset; | |||
import com.vaadin.server.VaadinRequest; | |||
import com.vaadin.tests.components.AbstractTestUI; | |||
import com.vaadin.tests.widgetset.TestingWidgetSet; | |||
import com.vaadin.ui.TextArea; | |||
/** | |||
* UI for testing that @DelegateToWidget works on derived widget states. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
@Widgetset(TestingWidgetSet.NAME) | |||
public class OverriddenDecendants extends AbstractTestUI { | |||
@Override | |||
protected void setup(VaadinRequest request) { | |||
TextArea normalTextArea = new TextArea(); | |||
normalTextArea.setRows(10); | |||
normalTextArea.setWordwrap(true); | |||
getLayout().addComponent(normalTextArea); | |||
// @DelegateToWidget will not work with overridden state in connector | |||
SuperTextArea superTextArea = new SuperTextArea(); | |||
superTextArea.setRows(10); | |||
superTextArea.setWordwrap(true); | |||
getLayout().addComponent(superTextArea); | |||
// @DelegateToWidget will not work with overridden state in connector | |||
ExtraSuperTextArea extraSuperTextArea = new ExtraSuperTextArea(); | |||
extraSuperTextArea.setRows(10); | |||
extraSuperTextArea.setWordwrap(true); | |||
getLayout().addComponent(extraSuperTextArea); | |||
} | |||
@Override | |||
protected String getTestDescription() { | |||
return "@DelegateToWidget does not work for widget descendants with overridden getState"; | |||
} | |||
@Override | |||
protected Integer getTicketNumber() { | |||
return 14059; | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
/* | |||
* 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 | |||
* License for the specific language governing permissions and limitations under | |||
* the License. | |||
*/ | |||
package com.vaadin.tests.widgetset.server; | |||
import static org.junit.Assert.assertEquals; | |||
import java.util.List; | |||
import org.junit.Test; | |||
import com.vaadin.testbench.elements.TextAreaElement; | |||
import com.vaadin.tests.tb3.MultiBrowserTest; | |||
/** | |||
* Class for unit testing that @DelegateToWidget works on derived widget states. | |||
* | |||
* @since | |||
* @author Vaadin Ltd | |||
*/ | |||
public class OverriddenDecendantsTest extends MultiBrowserTest { | |||
@Test | |||
public void allExtendingFieldsShouldGetRowsFromTextAreaStateAnnotation() | |||
throws InterruptedException { | |||
openTestURL(); | |||
List<TextAreaElement> textAreas = $(TextAreaElement.class).all(); | |||
assertEquals("Did not contain all 3 text areas", 3, textAreas.size()); | |||
for (TextAreaElement area : textAreas) { | |||
assertEquals("Text area was missing rows", "10", | |||
area.getAttribute("rows")); | |||
} | |||
} | |||
} |
@@ -0,0 +1,16 @@ | |||
package com.vaadin.tests.widgetset.server; | |||
import com.vaadin.tests.widgetset.client.superText.SuperTextAreaState; | |||
import com.vaadin.ui.TextArea; | |||
/** | |||
* @author artamonov | |||
* @version $Id$ | |||
*/ | |||
public class SuperTextArea extends TextArea { | |||
@Override | |||
public SuperTextAreaState getState() { | |||
return (SuperTextAreaState) super.getState(); | |||
} | |||
} |