aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-06-25 19:04:56 +0300
committerArtur Signell <artur@vaadin.com>2012-06-25 19:05:40 +0300
commit3b86074ed81a8112e350cbb22d88d802f12108cd (patch)
tree3d4a9283aafc43e3a7c12214c8e5c86e9b93276e
parent57ff1fc5b5597df4bf7a631fbf6bb507bc85d1f3 (diff)
downloadvaadin-framework-3b86074ed81a8112e350cbb22d88d802f12108cd.tar.gz
vaadin-framework-3b86074ed81a8112e350cbb22d88d802f12108cd.zip
Added Table.setSortEnabled and deprecated setSortDisabled (#9021)
-rw-r--r--src/com/vaadin/ui/Table.java52
-rw-r--r--tests/testbench/com/vaadin/tests/components/beanitemcontainer/BeanItemContainerNullValues.java8
-rw-r--r--tests/testbench/com/vaadin/tests/components/table/HeaderClick.java2
-rw-r--r--tests/testbench/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java4
4 files changed, 47 insertions, 19 deletions
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index b74de7e180..a1cc4f95fe 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -476,10 +476,9 @@ public class Table extends AbstractSelect implements Action.Container,
private Object sortContainerPropertyId = null;
/**
- * Is table sorting disabled alltogether; even if some of the properties
- * would be sortable.
+ * Is table sorting by the user enabled.
*/
- private boolean sortDisabled = false;
+ private boolean sortEnabled = true;
/**
* Number of rows explicitly requested by the client to be painted on next
@@ -2589,7 +2588,7 @@ public class Table extends AbstractSelect implements Action.Container,
clientNeedsContentRefresh = true;
}
- if (!sortDisabled) {
+ if (isSortEnabled()) {
// Sorting
boolean doSort = false;
if (variables.containsKey("sortcolumn")) {
@@ -4323,16 +4322,21 @@ public class Table extends AbstractSelect implements Action.Container,
/**
* Gets the container property IDs, which can be used to sort the item.
+ * <p>
+ * Note that the {@link #isSortEnabled()} state affects what this method
+ * returns. Disabling sorting causes this method to always return an empty
+ * collection.
+ * </p>
*
* @see com.vaadin.data.Container.Sortable#getSortableContainerPropertyIds()
*/
public Collection<?> getSortableContainerPropertyIds() {
final Container c = getContainerDataSource();
- if (c instanceof Container.Sortable && !isSortDisabled()) {
+ if (c instanceof Container.Sortable && isSortEnabled()) {
return ((Container.Sortable) c).getSortableContainerPropertyIds();
} else {
- return new LinkedList<Object>();
+ return Collections.EMPTY_LIST;
}
}
@@ -4423,23 +4427,47 @@ public class Table extends AbstractSelect implements Action.Container,
* would support this.
*
* @return True iff sorting is disabled.
+ * @deprecated Use {@link #isSortEnabled()} instead
*/
+ @Deprecated
public boolean isSortDisabled() {
- return sortDisabled;
+ return !isSortEnabled();
}
/**
- * Disables the sorting altogether.
+ * Checks if sorting is enabled.
*
- * To disable sorting altogether, set to true. In this case no sortable
- * columns are given even in the case where datasource would support this.
+ * @return true if sorting by the user is allowed, false otherwise
+ */
+ public boolean isSortEnabled() {
+ return sortEnabled;
+ }
+
+ /**
+ * Disables the sorting by the user altogether.
*
* @param sortDisabled
* True iff sorting is disabled.
+ * @deprecated Use {@link #setSortEnabled(boolean)} instead
*/
+ @Deprecated
public void setSortDisabled(boolean sortDisabled) {
- if (this.sortDisabled != sortDisabled) {
- this.sortDisabled = sortDisabled;
+ setSortEnabled(!sortDisabled);
+ }
+
+ /**
+ * Enables or disables sorting.
+ * <p>
+ * Setting this to false disallows sorting by the user. It is still possible
+ * to call {@link #sort()}.
+ * </p>
+ *
+ * @param sortEnabled
+ * true to allow the user to sort the table, false to disallow it
+ */
+ public void setSortEnabled(boolean sortEnabled) {
+ if (this.sortEnabled != sortEnabled) {
+ this.sortEnabled = sortEnabled;
requestRepaint();
}
}
diff --git a/tests/testbench/com/vaadin/tests/components/beanitemcontainer/BeanItemContainerNullValues.java b/tests/testbench/com/vaadin/tests/components/beanitemcontainer/BeanItemContainerNullValues.java
index 9045d18940..f613a8b14f 100644
--- a/tests/testbench/com/vaadin/tests/components/beanitemcontainer/BeanItemContainerNullValues.java
+++ b/tests/testbench/com/vaadin/tests/components/beanitemcontainer/BeanItemContainerNullValues.java
@@ -30,11 +30,11 @@ public class BeanItemContainerNullValues extends TestBase {
Button b = new Button("Disable sorting", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
- table.setSortDisabled(!table.isSortDisabled());
- if (table.isSortDisabled()) {
- event.getButton().setCaption("Enable sorting");
- } else {
+ table.setSortEnabled(!table.isSortEnabled());
+ if (table.isSortEnabled()) {
event.getButton().setCaption("Disable sorting");
+ } else {
+ event.getButton().setCaption("Enable sorting");
}
}
diff --git a/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java b/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java
index 970618374e..d5debcfe16 100644
--- a/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java
+++ b/tests/testbench/com/vaadin/tests/components/table/HeaderClick.java
@@ -45,7 +45,7 @@ public class HeaderClick extends TestBase {
CheckBox sortEnabledCheckbox = new CheckBox("Sortable");
sortEnabledCheckbox.setImmediate(true);
- sortEnabledCheckbox.setValue(!table.isSortDisabled());
+ sortEnabledCheckbox.setValue(table.isSortEnabled());
sortEnabledCheckbox.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
diff --git a/tests/testbench/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java b/tests/testbench/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java
index 091891043f..cd54e21395 100644
--- a/tests/testbench/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java
+++ b/tests/testbench/com/vaadin/tests/components/table/HeaderFooterClickLeftRightMiddle.java
@@ -93,10 +93,10 @@ public class HeaderFooterClickLeftRightMiddle extends TestBase {
CheckBox sortEnabledCheckbox = new CheckBox("Sortable");
sortEnabledCheckbox.setImmediate(true);
- sortEnabledCheckbox.setValue(!table.isSortDisabled());
+ sortEnabledCheckbox.setValue(table.isSortEnabled());
sortEnabledCheckbox.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
- table.setSortDisabled(!(Boolean) event.getProperty().getValue());
+ table.setSortEnabled((Boolean) event.getProperty().getValue());
}
});