]> source.dussan.org Git - vaadin-framework.git/commitdiff
DelegateToWidget will now be run even for parent states for extending
authorMikael Grankvist <mgrankvi@vaadin.com>
Tue, 1 Jul 2014 11:11:05 +0000 (14:11 +0300)
committerVaadin Code Review <review@vaadin.com>
Thu, 7 Aug 2014 06:32:16 +0000 (06:32 +0000)
states (#14059)

Updated the code to encompass Leif's suggestion.

Change-Id: I70c0a4a93b9fe9ee8b2c458d666a1fec791f20b4

client-compiler/src/com/vaadin/server/widgetsetutils/ConnectorBundleLoaderFactory.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/ConnectorBundle.java
client-compiler/src/com/vaadin/server/widgetsetutils/metadata/WidgetInitVisitor.java
uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaConnector.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaState.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaConnector.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaState.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/server/ExtraSuperTextArea.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendants.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendantsTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/widgetset/server/SuperTextArea.java [new file with mode: 0644]

index 5519dd1aaeed0d3f492c385e11ad0e4e0ed4237e..a6ca690a8a3898f1c75e84cc0f4e54a3d2214820 100644 (file)
@@ -639,13 +639,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
+                .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();
         }
     }
index 8bbcac4ecb516d9dffe6d2ac8cb90245b92042ba..e8a384298f760735baf867860d39b9048fb2487f 100644 (file)
@@ -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,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<Property> getNeedsDelegateToWidget() {
-        return Collections.unmodifiableSet(needsDelegateToWidget);
+    public Map<JClassType, Set<Property>> getNeedsDelegateToWidget() {
+        return Collections.unmodifiableMap(needsDelegateToWidget);
     }
 
     public void setNeedsOnStateChangeHandler(JClassType type, JMethod method) {
index e3fee8d9eee6c5142e1d3f8c84fa9498f19e736e..a77b523d144669ff190033b35dd47a382edd2e75 100644 (file)
@@ -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
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaConnector.java
new file mode 100644 (file)
index 0000000..b903720
--- /dev/null
@@ -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();
+    }
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaState.java b/uitest/src/com/vaadin/tests/widgetset/client/superText/ExtraSuperTextAreaState.java
new file mode 100644 (file)
index 0000000..44456b2
--- /dev/null
@@ -0,0 +1,7 @@
+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
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaConnector.java b/uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaConnector.java
new file mode 100644 (file)
index 0000000..fda1fc6
--- /dev/null
@@ -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();
+    }
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaState.java b/uitest/src/com/vaadin/tests/widgetset/client/superText/SuperTextAreaState.java
new file mode 100644 (file)
index 0000000..0050754
--- /dev/null
@@ -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 {
+
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/widgetset/server/ExtraSuperTextArea.java b/uitest/src/com/vaadin/tests/widgetset/server/ExtraSuperTextArea.java
new file mode 100644 (file)
index 0000000..b741c09
--- /dev/null
@@ -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();
+    }
+}
\ No newline at end of file
diff --git a/uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendants.java b/uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendants.java
new file mode 100644 (file)
index 0000000..aadabb3
--- /dev/null
@@ -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;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendantsTest.java b/uitest/src/com/vaadin/tests/widgetset/server/OverriddenDecendantsTest.java
new file mode 100644 (file)
index 0000000..aa29284
--- /dev/null
@@ -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"));
+        }
+
+    }
+}
diff --git a/uitest/src/com/vaadin/tests/widgetset/server/SuperTextArea.java b/uitest/src/com/vaadin/tests/widgetset/server/SuperTextArea.java
new file mode 100644 (file)
index 0000000..6e73915
--- /dev/null
@@ -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();
+    }
+}
\ No newline at end of file