From 320a8cd42080c5b2f334375fc44a8a62af9825a2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Fri, 2 Nov 2012 14:09:56 +0200 Subject: [PATCH] Display CustomLayout template even if there are no children (#9725) * Also move a couple of tests from components.customcomponent to .customlayout Change-Id: I72c3507a4f1d40a7027050829e2b54c050563301 --- .../customlayout/CustomLayoutConnector.java | 10 +++-- .../CustomLayoutUsingTemplate.html | 21 ---------- .../CustomLayoutUsingTemplate.html | 42 +++++++++++++++++++ .../CustomLayoutUsingTemplate.java | 16 ++++--- .../CustomLayoutUsingTheme.html | 8 ++-- .../CustomLayoutUsingTheme.java | 2 +- .../template.htm | 0 7 files changed, 64 insertions(+), 35 deletions(-) delete mode 100644 uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.html create mode 100644 uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.html rename uitest/src/com/vaadin/tests/components/{customcomponent => customlayout}/CustomLayoutUsingTemplate.java (78%) rename uitest/src/com/vaadin/tests/components/{customcomponent => customlayout}/CustomLayoutUsingTheme.html (64%) rename uitest/src/com/vaadin/tests/components/{customcomponent => customlayout}/CustomLayoutUsingTheme.java (97%) rename uitest/src/com/vaadin/tests/components/{customcomponent => customlayout}/template.htm (100%) diff --git a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java index 21b32ae7b0..199f3cb3cc 100644 --- a/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java +++ b/client/src/com/vaadin/client/ui/customlayout/CustomLayoutConnector.java @@ -50,6 +50,10 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements public void onStateChanged(StateChangeEvent stateChangeEvent) { super.onStateChanged(stateChangeEvent); + // Ensure the template is initialized even if there are no children + // (#9725) + updateHtmlTemplate(); + // Evaluate scripts VCustomLayout.eval(getWidget().scripts); getWidget().scripts = null; @@ -83,11 +87,9 @@ public class CustomLayoutConnector extends AbstractLayoutConnector implements @Override public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent event) { - // Must do this once here so the HTML has been set up before we start - // adding child widgets. - + // Must call here in addition to onStateChanged because + // onConnectorHierarchyChange is invoked before onStateChanged updateHtmlTemplate(); - // For all contained widgets for (ComponentConnector child : getChildComponents()) { String location = getState().childLocations.get(child); diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.html b/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.html deleted file mode 100644 index b2806afe5c..0000000000 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.html +++ /dev/null @@ -1,21 +0,0 @@ -com.vaadin.tests.components.accordion.AccordionInactiveTabSize - - - - - - - - - - - - - - - - - - - -
com.vaadin.tests.components.accordion.AccordionInactiveTabSize
open/run/com.vaadin.tests.components.customcomponent.CustomLayoutUsingTemplate?restartApplication
screenCaptureinitial
clickvaadin=runcomvaadintestscomponentscustomcomponentCustomLayoutUsingTemplate::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VButton[0]/domChild[0]/domChild[0]
screenCapturewith-text-field
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.html b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.html new file mode 100644 index 0000000000..78a87894c6 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.html @@ -0,0 +1,42 @@ + + + + + + +CustomLayoutUsingTemplate + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
CustomLayoutUsingTemplate
open/run/com.vaadin.tests.components.customlayout.CustomLayoutUsingTemplate?restartApplication
screenCaptureinitial
clickvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTemplate::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[0]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTemplate::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VCustomLayout[0]/VButton[0]/domChild[0]/domChild[0]
screenCapturewith-text-field
+ + diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java similarity index 78% rename from uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java rename to uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java index 28e4dfb385..2e1ac21892 100644 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.customcomponent; +package com.vaadin.tests.components.customlayout; import java.io.IOException; import java.io.InputStream; @@ -15,6 +15,8 @@ public class CustomLayoutUsingTemplate extends TestBase implements ClickListener { CustomLayout layout; + Button button1 = new Button("Add Button to first location", this); + Button button2 = new Button("Add TextField to second location", this); @Override protected void setup() { @@ -25,11 +27,11 @@ public class CustomLayoutUsingTemplate extends TestBase implements String template = thisPackage + "template.htm"; InputStream is = getClass().getClassLoader().getResourceAsStream( template); + + addComponent(button1); + try { layout = new CustomLayout(is); - layout.addComponent(new Button( - "Click to add a TextField to second location", this), - "location1"); addComponent(layout); } catch (IOException e) { addComponent(new Label(e.getMessage())); @@ -56,6 +58,10 @@ public class CustomLayoutUsingTemplate extends TestBase implements @Override public void buttonClick(ClickEvent event) { - layout.addComponent(new TextField("A text field!"), "location2"); + if (event.getButton() == button1) { + layout.addComponent(button2, "location1"); + } else { + layout.addComponent(new TextField("A text field!"), "location2"); + } } } diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.html b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.html similarity index 64% rename from uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.html rename to uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.html index 954afb2adb..7fe2e4c07c 100644 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.html +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.html @@ -1,6 +1,6 @@ com.vaadin.tests.components.accordion.AccordionInactiveTabSize - + @@ -10,7 +10,7 @@ - + @@ -20,7 +20,7 @@ - + @@ -28,4 +28,4 @@ -
com.vaadin.tests.components.accordion.AccordionInactiveTabSize
open/run/com.vaadin.tests.components.customcomponent.CustomLayoutUsingTheme?restartApplication/run/com.vaadin.tests.components.customlayout.CustomLayoutUsingTheme?restartApplication
clickvaadin=runcomvaadintestscomponentscustomcomponentCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]/domChild[0]vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentscustomcomponentCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[1]/domChild[0]/domChild[0]vaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[1]/domChild[0]/domChild[0]
button
\ No newline at end of file + diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java similarity index 97% rename from uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java rename to uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java index 06dd39ac38..db5e81febf 100644 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java @@ -1,4 +1,4 @@ -package com.vaadin.tests.components.customcomponent; +package com.vaadin.tests.components.customlayout; import com.vaadin.tests.components.TestBase; import com.vaadin.tests.util.LoremIpsum; diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/template.htm b/uitest/src/com/vaadin/tests/components/customlayout/template.htm similarity index 100% rename from uitest/src/com/vaadin/tests/components/customcomponent/template.htm rename to uitest/src/com/vaadin/tests/components/customlayout/template.htm -- 2.39.5