Browse Source

Make table selectable based on presence of ValueChangeListener (#13864).

Change-Id: I272703f1e3178c91a2b1e3e4d0f7c79e4c86e552
tags/7.4.0.beta3
Denis Anisimov 9 years ago
parent
commit
7305474e4a

+ 13
- 6
server/src/com/vaadin/ui/Table.java View File

@@ -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();
}

+ 75
- 0
server/tests/src/com/vaadin/tests/server/component/table/TableSelectable.java View File

@@ -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;
}
}

Loading…
Cancel
Save