} else {
final Object id = itemIdMapper
.get(clientSideSelectedKeys[0]);
- if (!isNullSelectionAllowed() && id == null) {
- markAsDirty();
- } else if (id != null
- && id.equals(getNullSelectionItemId())) {
- setValue(null, true);
+
+ if (id != null) {
+ if (isNullSelectionAllowed()
+ && id.equals(getNullSelectionItemId())) {
+ setValue(null, true);
+ } else {
+ setValue(id, true);
+ }
} else {
- setValue(id, true);
+ markAsDirty();
}
}
}
--- /dev/null
+package com.vaadin.tests.components.tree;
+
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Tree;
+
+public class SelectItemAfterRemove extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Tree tree = new Tree();
+
+ tree.setImmediate(true);
+ tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
+ @Override
+ public void itemClick(ItemClickEvent event) {
+
+ tree.removeItem(tree.getValue());
+ tree.select(event.getItemId());
+ }
+ });
+
+ tree.addItem("first");
+ tree.addItem("second");
+ tree.addItem("third");
+
+ tree.select("first");
+
+ addComponent(tree);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Clicking on an item should select the clicked item and remove "
+ + "the previously selected item.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15181;
+ }
+}
--- /dev/null
+package com.vaadin.tests.components.tree;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class SelectItemAfterRemoveTest extends MultiBrowserTest {
+
+ @Test
+ public void selectedItemIsSelected() {
+ openTestURL();
+
+ getSecondSpan().click();
+
+ assertThat(getNodes().size(), is(2));
+ assertThat(getFirstNode().getAttribute("class"),
+ containsString("v-tree-node-selected"));
+ }
+
+ private WebElement getFirstNode() {
+ return getNodes().get(0);
+ }
+
+ private List<WebElement> getNodes() {
+ return findElements(By.className("v-tree-node-caption"));
+ }
+
+ private WebElement getSecondSpan() {
+ for (WebElement e : getSpans()) {
+ if (e.getText().equals("second")) {
+ return e;
+ }
+ }
+
+ return null;
+ }
+
+ private List<WebElement> getSpans() {
+ return findElements(By.tagName("span"));
+ }
+}
\ No newline at end of file