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
+ .getNeedsDelegateToWidget();
+ 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();
}
}
/*
* 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
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;
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,
}
}
- 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<Property> getNeedsDelegateToWidget() {
- return Collections.unmodifiableSet(needsDelegateToWidget);
+ public Map<JClassType, Set<Property>> getNeedsDelegateToWidget() {
+ return Collections.unmodifiableMap(needsDelegateToWidget);
}
public void setNeedsOnStateChangeHandler(JClassType type, JMethod method) {
.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
--- /dev/null
+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();
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.vaadin.tests.widgetset.client.superText;
+
+import com.vaadin.shared.ui.textarea.TextAreaState;
+
+public class ExtraSuperTextAreaState extends TextAreaState {
+
+}
\ No newline at end of file
--- /dev/null
+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();
+ }
+}
\ No newline at end of file
--- /dev/null
+package com.vaadin.tests.widgetset.client.superText;
+
+import com.vaadin.shared.ui.textarea.TextAreaState;
+
+/**
+ * @author artamonov
+ * @version $Id$
+ */
+public class SuperTextAreaState extends TextAreaState {
+
+}
\ No newline at end of file
--- /dev/null
+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();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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"));
+ }
+
+ }
+}
--- /dev/null
+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();
+ }
+}
\ No newline at end of file