From 184114b0881a5323139e5cafd6bd7e5c04afd8e2 Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Fri, 12 Apr 2013 10:35:36 +0000 Subject: Fixed Accordion tab stylenames which never got applied on the tab widgets #11645 (merged from #10605 in 6.8 branch) Change-Id: I6af93e3846ecedd31cb9afac6321316b122c9df5 --- client/src/com/vaadin/client/ui/VAccordion.java | 32 +++++++++++++++++ .../accordion/AccordionTabStylenames.html | 41 ++++++++++++++++++++++ .../accordion/AccordionTabStylenames.java | 32 +++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.html create mode 100644 uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.java diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java index 6c4bd06b6d..f87186fe37 100644 --- a/client/src/com/vaadin/client/ui/VAccordion.java +++ b/client/src/com/vaadin/client/ui/VAccordion.java @@ -34,6 +34,7 @@ import com.vaadin.client.Util; import com.vaadin.client.VCaption; import com.vaadin.client.ui.TouchScrollDelegate.TouchScrollHandler; import com.vaadin.shared.ui.tabsheet.TabsheetBaseConstants; +import com.vaadin.shared.ui.tabsheet.TabsheetConstants; public class VAccordion extends VTabsheetBase { @@ -76,6 +77,9 @@ public class VAccordion extends VTabsheetBase { } item.updateCaption(tabUidl); + item.updateTabStyleName(tabUidl + .getStringAttribute(TabsheetConstants.TAB_STYLE_NAME)); + item.setVisible(!hidden); if (selected) { @@ -290,6 +294,7 @@ public class VAccordion extends VTabsheetBase { private boolean open = false; private Element content = DOM.createDiv(); private Element captionNode = DOM.createDiv(); + private String styleName; public StackItem(UIDL tabUidl) { setElement(DOM.createDiv()); @@ -312,6 +317,7 @@ public class VAccordion extends VTabsheetBase { captionNode.removeClassName(getStylePrimaryName() + "-caption"); setStylePrimaryName(primaryStyleName + "-item"); + updateTabStyleName(getStylePrimaryName()); captionNode.addClassName(getStylePrimaryName() + "-caption"); content.addClassName(getStylePrimaryName() + "-content"); @@ -399,6 +405,32 @@ public class VAccordion extends VTabsheetBase { uidl.getStringAttribute(TabsheetBaseConstants.ATTRIBUTE_TAB_ICON)); } + /** + * Updates a tabs stylename from the child UIDL + * + * @param uidl + * The child uidl of the tab + */ + private void updateTabStyleName(String newStyleName) { + if (newStyleName != null && newStyleName.length() != 0) { + if (!newStyleName.equals(styleName)) { + // If we have a new style name + if (styleName != null && styleName.length() != 0) { + // Remove old style name if present + removeStyleDependentName(styleName); + } + // Set new style name + addStyleDependentName(newStyleName); + styleName = newStyleName; + } + } else if (styleName != null) { + // Remove the set stylename if no stylename is present in the + // uidl + removeStyleDependentName(styleName); + styleName = null; + } + } + public int getWidgetWidth() { return DOM.getFirstChild(content).getOffsetWidth(); } diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.html b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.html new file mode 100644 index 0000000000..4870777717 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.html @@ -0,0 +1,41 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.accordion.AccordionTabStylenames?restartApplication
assertCSSClassvaadin=runcomvaadintestscomponentsaccordionAccordionTabStylenames::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VAccordion[0]/domChild[0]v-accordion-item-tab0
assertCSSClassvaadin=runcomvaadintestscomponentsaccordionAccordionTabStylenames::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VAccordion[0]/domChild[1]v-accordion-item-tab1
assertCSSClassvaadin=runcomvaadintestscomponentsaccordionAccordionTabStylenames::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VAccordion[0]/domChild[2]v-accordion-item-tab2
assertCSSClassvaadin=runcomvaadintestscomponentsaccordionAccordionTabStylenames::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VAccordion[0]/domChild[3]v-accordion-item-tab3
+ + diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.java new file mode 100644 index 0000000000..1412ae6289 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabStylenames.java @@ -0,0 +1,32 @@ +package com.vaadin.tests.components.accordion; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Accordion; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet.Tab; + +public class AccordionTabStylenames extends TestBase { + + @Override + protected void setup() { + Accordion acc = new Accordion(); + addComponent(acc); + + for (int tabIndex = 0; tabIndex < 5; tabIndex++) { + Tab tab = acc.addTab(new Label("Tab " + tabIndex)); + tab.setCaption("Tab " + tabIndex); + tab.setStyleName("tab" + tabIndex); + } + } + + @Override + protected String getDescription() { + return null; + } + + @Override + protected Integer getTicketNumber() { + return 10605; + } + +} -- cgit v1.2.3