diff options
author | Denis Anisimov <denis@vaadin.com> | 2014-08-23 13:32:06 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-26 13:24:00 +0000 |
commit | 7305474e4a666d8b986d1d95e7a89fed64277935 (patch) | |
tree | 64ac69b2c817d37aeb74971214dfcc4b591aa22d | |
parent | 17a9993995cfd3434259cd8b0f729f76da36de12 (diff) | |
download | vaadin-framework-7305474e4a666d8b986d1d95e7a89fed64277935.tar.gz vaadin-framework-7305474e4a666d8b986d1d95e7a89fed64277935.zip |
Make table selectable based on presence of ValueChangeListener (#13864).
Change-Id: I272703f1e3178c91a2b1e3e4d0f7c79e4c86e552
-rw-r--r-- | server/src/com/vaadin/ui/Table.java | 19 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java | 75 |
2 files changed, 88 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index ec345e3fc3..e202a4e925 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -62,6 +62,7 @@ import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.table.TableConstants; +import com.vaadin.shared.util.SharedUtil; /** * <p> @@ -442,7 +443,7 @@ public class Table extends AbstractSelect implements Action.Container, /** * Holds value of property selectable. */ - private boolean selectable = false; + private Boolean selectable; /** * Holds value of property columnHeaderMode. @@ -1601,15 +1602,19 @@ public class Table extends AbstractSelect implements Action.Container, } /** - * Getter for property selectable. + * Returns whether table is selectable. * * <p> - * The table is not selectable by default. + * The table is not selectable until it's explicitly set as selectable or at + * least one {@link ValueChangeListener} is added. * </p> * - * @return the Value of property selectable. + * @return whether table is selectable. */ public boolean isSelectable() { + if (selectable == null) { + return hasListeners(ValueChangeEvent.class); + } return selectable; } @@ -1617,14 +1622,16 @@ public class Table extends AbstractSelect implements Action.Container, * Setter for property selectable. * * <p> - * The table is not selectable by default. + * The table is not selectable until it's explicitly set as selectable via + * this method or alternatively at least one {@link ValueChangeListener} is + * added. * </p> * * @param selectable * the New value of property selectable. */ public void setSelectable(boolean selectable) { - if (this.selectable != selectable) { + if (!SharedUtil.equals(this.selectable, selectable)) { this.selectable = selectable; markAsDirty(); } diff --git a/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java b/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java new file mode 100644 index 0000000000..1af99a08eb --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java @@ -0,0 +1,75 @@ +/* + * 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.server.component.table; + +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.ui.Table; + +/** + * Tests for 'selectable' property of {@link Table} class. + * + * @author Vaadin Ltd + */ +public class TableSelectable { + + @Test + public void setSelectable_explicitSelectable_tableIsSelectable() { + Table table = new Table(); + table.setSelectable(true); + + Assert.assertTrue(table.isSelectable()); + } + + @Test + public void addValueChangeListener_explicitSelectable_tableIsSelectable() { + TestTable table = new TestTable(); + table.addValueChangeListener(EasyMock + .createMock(ValueChangeListener.class)); + + Assert.assertTrue(table.isSelectable()); + Assert.assertTrue(table.markAsDirtyCalled); + } + + @Test + public void tableIsNotSelectableByDefult() { + Table table = new Table(); + + Assert.assertFalse(table.isSelectable()); + } + + @Test + public void setSelectable_explicitNotSelectable_tableIsNotSelectable() { + Table table = new Table(); + table.setSelectable(false); + table.addValueChangeListener(EasyMock + .createMock(ValueChangeListener.class)); + + Assert.assertFalse(table.isSelectable()); + } + + private static final class TestTable extends Table { + @Override + public void markAsDirty() { + markAsDirtyCalled = true; + } + + private boolean markAsDirtyCalled; + } +} |