private final Element deco;
- /** For internal use only. May be removed or replaced in the future. */
- public boolean waitingForResponse;
-
private String currentStyle;
/**
*/
private boolean canSelectTab(final int tabIndex) {
Tab tab = tb.getTab(tabIndex);
- if (getApplicationConnection() == null || disabled
- || waitingForResponse) {
+ if (getApplicationConnection() == null || disabled) {
return false;
}
if (!tab.isEnabledOnServer() || tab.isHiddenOnServer()) {
getRpcProxy().setSelected(tabKeys.get(tabIndex).toString());
- waitingForResponse = true;
-
tb.getTab(tabIndex).focus(); // move keyboard focus to active tab
return true;
final String key = getState().tabs.get(i).key;
final boolean selected = key.equals(getState().selected);
if (selected) {
+ getWidget().setActiveTabIndex(i);
getWidget().selectTab(i);
break;
}
}
getWidget().iLayout();
-
- getWidget().waitingForResponse = false;
}
@Override
--- /dev/null
+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.Button.ClickListener;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Notification;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
+import com.vaadin.ui.TabSheet.SelectedTabChangeListener;
+
+/**
+ * TabSheet test in case user selects a tab and on the selection listener the
+ * selected tab is changed to another one.
+ *
+ * This test used to cause nonfunctional TabSheet if the current tab was 1, user
+ * selects 5, then the selection listener will revert the selected tab to 1.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TabSelectionRevertedByServer extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+
+ final TabSheet tabsheet = new TabSheet();
+ tabsheet.setWidth("400px");
+
+ Component lastLabel = null;
+
+ for (int i = 1; i <= 5; i++) {
+ String caption = "Tab " + i;
+ Label label = new Label(caption);
+ tabsheet.addTab(label, caption);
+
+ lastLabel = label;
+ }
+
+ tabsheet.setSelectedTab(0);
+
+ final Component lastTab = lastLabel;
+
+ tabsheet.addSelectedTabChangeListener(new SelectedTabChangeListener() {
+
+ @Override
+ public void selectedTabChange(SelectedTabChangeEvent event) {
+ if (tabsheet.getSelectedTab().equals(lastTab)) {
+
+ // Set focus back to first tab in tabsheet
+ tabsheet.setSelectedTab(0);
+ Notification.show("Focus set back to tab at position 0");
+ }
+ }
+ });
+
+ addComponent(tabsheet);
+
+ Button button = new Button("Select Last Tab");
+ button.addClickListener(new ClickListener() {
+
+ @Override
+ public void buttonClick(ClickEvent event) {
+ tabsheet.setSelectedTab(lastTab);
+ }
+ });
+ addComponent(button);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Clicking on Tab 5 will revert to Tab 1. The action is handled on the server side and will set the selected tab to 1 if Tab 5 is selected.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14710;
+ }
+
+}
--- /dev/null
+/*
+ * 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.tabsheet;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+
+import com.vaadin.testbench.TestBenchElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * If user selected the last tab the test will change it back to the first one
+ * from a server side selection listener. This test makes sure that actually
+ * happen.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class TabSelectionRevertedByServerTest extends MultiBrowserTest {
+
+ @Test
+ public void testFocus() throws InterruptedException, IOException {
+ openTestURL();
+
+ // Selects Tab 4 which should be selected.
+ click(4);
+ assertSelection(4, 1);
+
+ // Select Tab 5 which should revert to Tab 1.
+ click(5);
+ assertSelection(1, 5);
+
+ // Make sure after reverting the selection the tab selection still
+ // works.
+ click(3);
+ assertSelection(3, 1);
+
+ }
+
+ private void assertSelection(int expectedIndex, int wrongIndex) {
+ TestBenchElement tabExpected = tab(expectedIndex);
+ String attributeClassExpected = tabExpected.getAttribute("class");
+
+ Assert.assertTrue("Tab " + expectedIndex + " should be selected.",
+ attributeClassExpected
+ .contains("v-tabsheet-tabitemcell-selected"));
+
+ TestBenchElement tabWrong = tab(wrongIndex);
+ String attributeClassWrong = tabWrong.getAttribute("class");
+
+ Assert.assertTrue("Tab " + wrongIndex
+ + " should be selected when click on Tab 4",
+ !attributeClassWrong
+ .contains("v-tabsheet-tabitemcell-selected"));
+ }
+
+ /*
+ * Click on the element.
+ */
+ private void click(int tabIndex) throws InterruptedException {
+ click(tab(tabIndex));
+ }
+
+ /*
+ * Click on the element.
+ */
+ private void click(TestBenchElement element) throws InterruptedException {
+
+ element.click(10, 10);
+ if (DELAY > 0) {
+ sleep(DELAY);
+ }
+ }
+
+ /*
+ * Delay for PhantomJS.
+ */
+ private final static int DELAY = 10;
+
+ /*
+ * Provide the tab at specified index.
+ */
+ private TestBenchElement tab(int index) {
+ By by = By.className("v-tabsheet-tabitemcell");
+
+ TestBenchElement element = (TestBenchElement) getDriver().findElements(
+ by).get(index - 1);
+
+ String expected = "Tab " + index;
+ Assert.assertEquals(expected,
+ element.getText().substring(0, expected.length()));
+
+ return element;
+ }
+
+}