From 3b86074ed81a8112e350cbb22d88d802f12108cd Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 25 Jun 2012 19:04:56 +0300 Subject: [PATCH] Added Table.setSortEnabled and deprecated setSortDisabled (#9021) --- src/com/vaadin/ui/Table.java | 52 ++++++++++++++----- .../BeanItemContainerNullValues.java | 8 +-- .../tests/components/table/HeaderClick.java | 2 +- .../HeaderFooterClickLeftRightMiddle.java | 4 +- 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. + *

+ * Note that the {@link #isSortEnabled()} state affects what this method + * returns. Disabling sorting causes this method to always return an empty + * collection. + *

* * @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(); + 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. + *

+ * Setting this to false disallows sorting by the user. It is still possible + * to call {@link #sort()}. + *

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