diff options
author | tapio <tapio@vaadin.com> | 2013-06-17 14:41:18 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2013-06-24 09:12:27 +0000 |
commit | cdb8d682af602cc8731e7a63827b499c2da5144e (patch) | |
tree | b7e12cf7b984360e6133815dacfea27a81182b17 | |
parent | cc8bb2c509024076421abc37113cd7c6d8867571 (diff) | |
download | vaadin-framework-cdb8d682af602cc8731e7a63827b499c2da5144e.tar.gz vaadin-framework-cdb8d682af602cc8731e7a63827b499c2da5144e.zip |
Add support for setId to TabSheet.Tab (#12064)
Change-Id: Ia88b9d03a26b9670ab4026f8083a0b932dafa1c0
5 files changed, 206 insertions, 7 deletions
diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index fe29e2ebc0..dc20c27837 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -112,6 +112,8 @@ public class VTabsheet extends VTabsheetBase implements Focusable, private String styleName; + private String id; + private Tab(TabBar tabBar) { super(DOM.createTD()); this.tabBar = tabBar; @@ -204,10 +206,10 @@ public class VTabsheet extends VTabsheetBase implements Focusable, String newStyleName = tabUidl .getStringAttribute(TabsheetConstants.TAB_STYLE_NAME); // Find the nth td element - if (newStyleName != null && newStyleName.length() != 0) { + if (newStyleName != null && !newStyleName.isEmpty()) { if (!newStyleName.equals(styleName)) { // If we have a new style name - if (styleName != null && styleName.length() != 0) { + if (styleName != null && !styleName.isEmpty()) { // Remove old style name if present td.removeClassName(TD_CLASSNAME + "-" + styleName); } @@ -221,6 +223,15 @@ public class VTabsheet extends VTabsheetBase implements Focusable, td.removeClassName(TD_CLASSNAME + "-" + styleName); styleName = null; } + + String newId = tabUidl.getStringAttribute("id"); + if (newId != null && !newId.isEmpty()) { + td.setId(newId); + id = newId; + } else if (id != null) { + td.removeAttribute("id"); + id = null; + } } public void recalculateCaptionWidth() { diff --git a/server/src/com/vaadin/ui/Component.java b/server/src/com/vaadin/ui/Component.java index 485327bb54..c385805675 100644 --- a/server/src/com/vaadin/ui/Component.java +++ b/server/src/com/vaadin/ui/Component.java @@ -651,7 +651,7 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public Locale getLocale(); /** - * Adds an unique id for component that get's transferred to terminal for + * Adds an unique id for component that is used in the client-side for * testing purposes. Keeping identifiers unique is the responsibility of the * programmer. * @@ -661,7 +661,7 @@ public interface Component extends ClientConnector, Sizeable, Serializable { public void setId(String id); /** - * Get's currently set debug identifier + * Gets currently set debug identifier * * @return current id, null if not set */ @@ -669,7 +669,7 @@ public interface Component extends ClientConnector, Sizeable, Serializable { /** * <p> - * Gets the component's description, used in tooltips and can be displayed + * Gets the components description, used in tooltips and can be displayed * directly in certain other components such as forms. The description can * be used to briefly describe the state of the component to the user. The * description string may contain certain XML tags: diff --git a/server/src/com/vaadin/ui/TabSheet.java b/server/src/com/vaadin/ui/TabSheet.java index 36022adb74..2c85b279cd 100644 --- a/server/src/com/vaadin/ui/TabSheet.java +++ b/server/src/com/vaadin/ui/TabSheet.java @@ -431,7 +431,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, icon); } final String caption = tab.getCaption(); - if (caption != null && caption.length() > 0) { + if (caption != null && !caption.isEmpty()) { target.addAttribute( TabsheetBaseConstants.ATTRIBUTE_TAB_CAPTION, caption); } @@ -449,10 +449,15 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, } final String styleName = tab.getStyleName(); - if (styleName != null && styleName.length() != 0) { + if (styleName != null && !styleName.isEmpty()) { target.addAttribute(TabsheetConstants.TAB_STYLE_NAME, styleName); } + final String id = tab.getId(); + if (id != null && !id.isEmpty()) { + target.addAttribute("id", id); + } + target.addAttribute("key", keyMapper.key(component)); if (component.equals(selected)) { target.addAttribute("selected", true); @@ -1015,6 +1020,23 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, * @see #setStyleName(String) */ public String getStyleName(); + + /** + * Adds an unique id for component that is used in the client-side for + * testing purposes. Keeping identifiers unique is the responsibility of + * the programmer. + * + * @param id + * An alphanumeric id + */ + public void setId(String id); + + /** + * Gets currently set debug identifier + * + * @return current id, null if not set + */ + public String getId(); } /** @@ -1030,6 +1052,7 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, private String description = null; private ErrorMessage componentError = null; private String styleName; + private String id; public TabSheetTabImpl(String caption, Resource icon) { if (caption == null) { @@ -1150,6 +1173,18 @@ public class TabSheet extends AbstractComponentContainer implements Focusable, public String getStyleName() { return styleName; } + + @Override + public void setId(String id) { + this.id = id; + markAsDirty(); + + } + + @Override + public String getId() { + return id; + } } /** diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.html b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.html new file mode 100644 index 0000000000..64e85f55e3 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.html @@ -0,0 +1,76 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="http://localhost:8888/" /> +<title>TabSheetWithTabIds</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">TabSheetWithTabIds</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.tabsheet.TabSheetWithTabIds</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab1</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab2</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab3</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstabsheetTabSheetWithTabIds::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertElementPresent</td> + <td>tab1</td> + <td></td> +</tr> +<tr> + <td>assertElementPresent</td> + <td>tab2</td> + <td></td> +</tr> +<tr> + <td>assertElementPresent</td> + <td>tab3</td> + <td></td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstabsheetTabSheetWithTabIds::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab1</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab2</td> + <td></td> +</tr> +<tr> + <td>assertElementNotPresent</td> + <td>tab3</td> + <td></td> +</tr> +</tbody></table> +</body> +</html> diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.java new file mode 100644 index 0000000000..ae5adea45e --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetWithTabIds.java @@ -0,0 +1,77 @@ +/* + * Copyright 2000-2013 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.tabsheet; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Label; +import com.vaadin.ui.TabSheet; +import com.vaadin.ui.TabSheet.Tab; + +public class TabSheetWithTabIds extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + TabSheet tabSheet = new TabSheet(); + + final Tab tab1 = tabSheet.addTab(new Label("Label 1"), "Tab 1", null); + + final Tab tab2 = tabSheet.addTab(new Label("Label 2"), "Tab 2", null); + + final Tab tab3 = tabSheet.addTab(new Label("Label 3"), "Tab 3", null); + + addComponent(tabSheet); + + Button b = new Button("Set ids", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + tab1.setId("tab1"); + tab2.setId("tab2"); + tab3.setId("tab3"); + } + }); + addComponent(b); + + Button b2 = new Button("Clear ids", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + tab1.setId(null); + tab2.setId(null); + tab3.setId(null); + } + }); + addComponent(b2); + } + + @Override + protected String getTestDescription() { + return "Add support for setId to TabSheet.Tab"; + } + + @Override + protected Integer getTicketNumber() { + return 12064; + } + +} |