diff options
3 files changed, 127 insertions, 0 deletions
diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java index fc328dd56a..afc66d0f7b 100644 --- a/client/src/com/vaadin/client/ui/VAccordion.java +++ b/client/src/com/vaadin/client/ui/VAccordion.java @@ -36,6 +36,7 @@ import com.vaadin.shared.ComponentConstants; import com.vaadin.shared.ui.accordion.AccordionState; import com.vaadin.shared.ui.tabsheet.TabState; import com.vaadin.shared.ui.tabsheet.TabsheetServerRpc; +import com.vaadin.shared.util.SharedUtil; public class VAccordion extends VTabsheetBase { @@ -79,6 +80,8 @@ public class VAccordion extends VTabsheetBase { item.updateTabStyleName(tabState.styleName); item.setVisible(tabState.visible); + + item.setId(tabState.id); } @Override @@ -160,6 +163,7 @@ public class VAccordion extends VTabsheetBase { public class StackItem extends ComplexPanel implements ClickHandler { private Widget widget; + private String id; public void setHeight(int height) { if (height == -1) { @@ -172,6 +176,18 @@ public class VAccordion extends VTabsheetBase { } } + public void setId(String newId) { + if (!SharedUtil.equals(newId, id)) { + if (id != null) { + getElement().removeAttribute("id"); + } + id = newId; + if (id != null && !id.isEmpty()) { + getElement().setId(id); + } + } + } + public Widget getComponent() { return widget; } diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIds.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIds.java new file mode 100644 index 0000000000..31bd8d99fb --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIds.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.components.accordion;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Accordion;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.TabSheet.Tab;
+
+@SuppressWarnings("serial")
+public class AccordionTabIds extends AbstractTestUI {
+
+ protected static final String FIRST_TAB_ID = "ID 1";
+ protected static final String FIRST_TAB_MESSAGE = "First tab";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
+ * VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+ Accordion accordion = new Accordion();
+ final Tab firstTab = accordion.addTab(new Label(FIRST_TAB_MESSAGE));
+ firstTab.setId(FIRST_TAB_ID);
+ Button setIdButton = new Button("Set id");
+ setIdButton.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ firstTab.setId(FIRST_TAB_ID);
+ }
+ });
+ Button clearIdButton = new Button("Clear id");
+ clearIdButton.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ firstTab.setId(null);
+ }
+ });
+ addComponents(setIdButton, clearIdButton, accordion);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Accordion should set server side defined ids on Tabs.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 18456;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIdsTest.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIdsTest.java new file mode 100644 index 0000000000..17c7fe6804 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionTabIdsTest.java @@ -0,0 +1,54 @@ +/* + * 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.components.accordion; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openqa.selenium.WebElement; + +import com.vaadin.testbench.By; +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.LabelElement; +import com.vaadin.tests.tb3.MultiBrowserTest; + +/** + * Test for Accordion: Tab.setId should be propagated to client side tabs. + * + * @since + * @author Vaadin Ltd + */ +public class AccordionTabIdsTest extends MultiBrowserTest { + + @Test + public void testGeTabByIds() { + openTestURL(); + ButtonElement setIdButton = $(ButtonElement.class).first(); + ButtonElement clearIdbutton = $(ButtonElement.class).get(1); + + WebElement firstItem = driver + .findElement(By.id(AccordionTabIds.FIRST_TAB_ID)); + WebElement label = $(LabelElement.class).context(firstItem).first(); + assertEquals(AccordionTabIds.FIRST_TAB_MESSAGE, label.getText()); + + clearIdbutton.click(); + assertEquals("", firstItem.getAttribute("id")); + + setIdButton.click(); + assertEquals(AccordionTabIds.FIRST_TAB_ID, + firstItem.getAttribute("id")); + } +} |