From: Johannes Dahlström Date: Fri, 2 Nov 2012 12:09:56 +0000 (+0200) Subject: Display CustomLayout template even if there are no children (#9725) X-Git-Tag: 7.0.0.beta8~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F199%2F1;p=vaadin-framework.git Display CustomLayout template even if there are no children (#9725) * Also move a couple of tests from components.customcomponent to .customlayout Change-Id: I72c3507a4f1d40a7027050829e2b54c050563301 --- 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/customcomponent/CustomLayoutUsingTemplate.java b/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java deleted file mode 100644 index 28e4dfb385..0000000000 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTemplate.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.vaadin.tests.components.customcomponent; - -import java.io.IOException; -import java.io.InputStream; - -import com.vaadin.tests.components.TestBase; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CustomLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.TextField; - -public class CustomLayoutUsingTemplate extends TestBase implements - ClickListener { - - CustomLayout layout; - - @Override - protected void setup() { - String thisPackage = CustomLayoutUsingTemplate.class.getName().replace( - '.', '/'); - thisPackage = thisPackage.replaceAll( - CustomLayoutUsingTemplate.class.getSimpleName() + "$", ""); - String template = thisPackage + "template.htm"; - InputStream is = getClass().getClassLoader().getResourceAsStream( - template); - 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())); - e.printStackTrace(); - } finally { - try { - is.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - } - - @Override - protected String getDescription() { - return "Test for using a CustomLayout with a template read from an input stream and passed through the state"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - - @Override - public void buttonClick(ClickEvent event) { - 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/customcomponent/CustomLayoutUsingTheme.html deleted file mode 100644 index 954afb2adb..0000000000 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.html +++ /dev/null @@ -1,31 +0,0 @@ -com.vaadin.tests.components.accordion.AccordionInactiveTabSize - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
com.vaadin.tests.components.accordion.AccordionInactiveTabSize
open/run/com.vaadin.tests.components.customcomponent.CustomLayoutUsingTheme?restartApplication
screenCaptureinitial
clickvaadin=runcomvaadintestscomponentscustomcomponentCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]/domChild[0]
screenCapturelabel
clickvaadin=runcomvaadintestscomponentscustomcomponentCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[1]/domChild[0]/domChild[0]
screenCapturebutton
\ 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/customcomponent/CustomLayoutUsingTheme.java deleted file mode 100644 index 06dd39ac38..0000000000 --- a/uitest/src/com/vaadin/tests/components/customcomponent/CustomLayoutUsingTheme.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.vaadin.tests.components.customcomponent; - -import com.vaadin.tests.components.TestBase; -import com.vaadin.tests.util.LoremIpsum; -import com.vaadin.ui.Button; -import com.vaadin.ui.Button.ClickEvent; -import com.vaadin.ui.Button.ClickListener; -import com.vaadin.ui.CustomLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.NativeButton; -import com.vaadin.ui.TextField; -import com.vaadin.ui.VerticalLayout; - -public class CustomLayoutUsingTheme extends TestBase implements ClickListener { - - private CustomLayout layout; - - @Override - protected void setup() { - setTheme("tests-tickets"); - layout = new CustomLayout("Ticket1775"); - addComponent(layout); - layout.addComponent(new TextField("Username"), "loginUser"); - layout.addComponent(new TextField("Password"), "loginPassword"); - layout.addComponent(new Button("Login"), "loginButton"); - layout.setWidth(null); - - VerticalLayout menu = new VerticalLayout(); - menu.addComponent(new Button("Set body to label", new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - layout.addComponent(new Label(LoremIpsum.get(200)), "body"); - } - })); - menu.addComponent(new Button("Set body to huge NativeButton", - new ClickListener() { - - @Override - public void buttonClick(ClickEvent event) { - layout.addComponent(new NativeButton( - "This is it, the body!"), "body"); - } - })); - layout.addComponent(menu, "menu"); - } - - @Override - protected String getDescription() { - return "Test for using a CustomLayout with a template read from an input stream and passed through the state"; - } - - @Override - protected Integer getTicketNumber() { - return null; - } - - @Override - public void buttonClick(ClickEvent event) { - layout.addComponent(new TextField("A text field!"), "location2"); - } - -} diff --git a/uitest/src/com/vaadin/tests/components/customcomponent/template.htm b/uitest/src/com/vaadin/tests/components/customcomponent/template.htm deleted file mode 100644 index fa023050da..0000000000 --- a/uitest/src/com/vaadin/tests/components/customcomponent/template.htm +++ /dev/null @@ -1,4 +0,0 @@ -Contents -
This is where the first component goes
-
This is where the second component goes
-End of template \ 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/customlayout/CustomLayoutUsingTemplate.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java new file mode 100644 index 0000000000..2e1ac21892 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTemplate.java @@ -0,0 +1,67 @@ +package com.vaadin.tests.components.customlayout; + +import java.io.IOException; +import java.io.InputStream; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.CustomLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.TextField; + +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() { + String thisPackage = CustomLayoutUsingTemplate.class.getName().replace( + '.', '/'); + thisPackage = thisPackage.replaceAll( + CustomLayoutUsingTemplate.class.getSimpleName() + "$", ""); + String template = thisPackage + "template.htm"; + InputStream is = getClass().getClassLoader().getResourceAsStream( + template); + + addComponent(button1); + + try { + layout = new CustomLayout(is); + addComponent(layout); + } catch (IOException e) { + addComponent(new Label(e.getMessage())); + e.printStackTrace(); + } finally { + try { + is.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + @Override + protected String getDescription() { + return "Test for using a CustomLayout with a template read from an input stream and passed through the state"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + @Override + public void buttonClick(ClickEvent event) { + 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/customlayout/CustomLayoutUsingTheme.html b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.html new file mode 100644 index 0000000000..7fe2e4c07c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.html @@ -0,0 +1,31 @@ +com.vaadin.tests.components.accordion.AccordionInactiveTabSize + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
com.vaadin.tests.components.accordion.AccordionInactiveTabSize
open/run/com.vaadin.tests.components.customlayout.CustomLayoutUsingTheme?restartApplication
screenCaptureinitial
clickvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[0]/domChild[0]/domChild[0]
screenCapturelabel
clickvaadin=runcomvaadintestscomponentscustomlayoutCustomLayoutUsingTheme::/VVerticalLayout[0]/VVerticalLayout[0]/VCustomLayout[0]/VVerticalLayout[0]/VButton[1]/domChild[0]/domChild[0]
screenCapturebutton
diff --git a/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java new file mode 100644 index 0000000000..db5e81febf --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/CustomLayoutUsingTheme.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.components.customlayout; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.LoremIpsum; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Button.ClickListener; +import com.vaadin.ui.CustomLayout; +import com.vaadin.ui.Label; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; + +public class CustomLayoutUsingTheme extends TestBase implements ClickListener { + + private CustomLayout layout; + + @Override + protected void setup() { + setTheme("tests-tickets"); + layout = new CustomLayout("Ticket1775"); + addComponent(layout); + layout.addComponent(new TextField("Username"), "loginUser"); + layout.addComponent(new TextField("Password"), "loginPassword"); + layout.addComponent(new Button("Login"), "loginButton"); + layout.setWidth(null); + + VerticalLayout menu = new VerticalLayout(); + menu.addComponent(new Button("Set body to label", new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + layout.addComponent(new Label(LoremIpsum.get(200)), "body"); + } + })); + menu.addComponent(new Button("Set body to huge NativeButton", + new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + layout.addComponent(new NativeButton( + "This is it, the body!"), "body"); + } + })); + layout.addComponent(menu, "menu"); + } + + @Override + protected String getDescription() { + return "Test for using a CustomLayout with a template read from an input stream and passed through the state"; + } + + @Override + protected Integer getTicketNumber() { + return null; + } + + @Override + public void buttonClick(ClickEvent event) { + layout.addComponent(new TextField("A text field!"), "location2"); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/customlayout/template.htm b/uitest/src/com/vaadin/tests/components/customlayout/template.htm new file mode 100644 index 0000000000..fa023050da --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/customlayout/template.htm @@ -0,0 +1,4 @@ +Contents +
This is where the first component goes
+
This is where the second component goes
+End of template \ No newline at end of file