diff options
| author | Dirk Fauth | 2023-01-20 13:29:46 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2023-01-20 13:29:46 +0000 |
| commit | 0b6472ec0c7fda0d2555d74a398325333b2c8d0b (patch) | |
| tree | a2fb38f243e8f136890705f406817dced7641f35 | |
| parent | 7ec2577ecb80969aefe6598cd76a2769ae9de676 (diff) | |
| download | org.eclipse.nebula.widgets.nattable-0b6472ec0c7fda0d2555d74a398325333b2c8d0b.tar.gz org.eclipse.nebula.widgets.nattable-0b6472ec0c7fda0d2555d74a398325333b2c8d0b.tar.xz org.eclipse.nebula.widgets.nattable-0b6472ec0c7fda0d2555d74a398325333b2c8d0b.zip | |
Bug 581391 - [Filter] Persistence failure for values with comma
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: Iaa3fa18562f72d8fc00908be0d36da1934ed0f45
2 files changed, 53 insertions, 2 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/FilterRowDataProvider.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/FilterRowDataProvider.java index 80eb05d7..9aa76a78 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/FilterRowDataProvider.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/filterrow/FilterRowDataProvider.java @@ -57,6 +57,14 @@ public class FilterRowDataProvider<T> implements IDataProvider, IPersistable { public static final String PIPE_REPLACEMENT = "°~°"; //$NON-NLS-1$ /** + * Replacement for the comma character , that is used for persisting + * collection values in case of combobox filters. + * + * @since 2.1 + */ + public static final String COMMA_REPLACEMENT = "°#°"; //$NON-NLS-1$ + + /** * The prefix String that will be used to mark that the following filter * value in the persisted state is a collection. */ @@ -276,7 +284,9 @@ public class FilterRowDataProvider<T> implements IDataProvider, IPersistable { Collection<?> filterCollection = (Collection<?>) filterValue; for (Iterator<?> iterator = filterCollection.iterator(); iterator.hasNext();) { Object filterObject = iterator.next(); - builder.append(converter.canonicalToDisplayValue(filterObject)); + String displayValue = (String) converter.canonicalToDisplayValue(filterObject); + displayValue = displayValue.replace(IPersistable.VALUE_SEPARATOR, COMMA_REPLACEMENT); + builder.append(displayValue); if (iterator.hasNext()) { builder.append(IPersistable.VALUE_SEPARATOR); } @@ -326,6 +336,7 @@ public class FilterRowDataProvider<T> implements IDataProvider, IPersistable { filterText = filterText.substring(indexEndCollSpec + 2, filterText.length() - 1); String[] filterSplit = filterText.split(IPersistable.VALUE_SEPARATOR); for (String filterString : filterSplit) { + filterString = filterString.replace(COMMA_REPLACEMENT, IPersistable.VALUE_SEPARATOR); filterCollection.add(converter.displayToCanonicalValue(filterString)); } diff --git a/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/FilterRowDataProviderTest.java b/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/FilterRowDataProviderTest.java index cdeefb12..8cb0dd1f 100644 --- a/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/FilterRowDataProviderTest.java +++ b/org.eclipse.nebula.widgets.nattable.extension.glazedlists.test/src/org/eclipse/nebula/widgets/nattable/extension/glazedlists/filterrow/FilterRowDataProviderTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2021 Original authors and others. + * Copyright (c) 2012, 2023 Original authors and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -16,6 +16,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Properties; import org.eclipse.nebula.widgets.nattable.config.ConfigRegistry; @@ -32,6 +35,7 @@ import org.eclipse.nebula.widgets.nattable.filterrow.TextMatchingMode; import org.eclipse.nebula.widgets.nattable.filterrow.config.DefaultFilterRowConfiguration; import org.eclipse.nebula.widgets.nattable.filterrow.config.FilterRowConfigAttributes; import org.eclipse.nebula.widgets.nattable.filterrow.event.FilterAppliedEvent; +import org.eclipse.nebula.widgets.nattable.persistence.IPersistable; import org.eclipse.nebula.widgets.nattable.style.DisplayMode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -327,4 +331,40 @@ public class FilterRowDataProviderTest { assertEquals(":testValue:", this.dataProvider.getDataValue(4, 1)); assertEquals(":test:Value:", this.dataProvider.getDataValue(5, 1)); } + + @SuppressWarnings("rawtypes") + @Test + public void shouldRetainCommaInFilterPersistence() { + // first check that a sort state is persisted in the properties + this.dataProvider.setDataValue(1, 1, "foo,bar"); + this.dataProvider.setDataValue(3, 1, new ArrayList<>(Arrays.asList("foo", "bar", "foo,bar"))); + + Properties properties = new Properties(); + + // save state + this.dataProvider.saveState("prefix", properties); + String persistedProperty = properties.getProperty("prefix" + FilterRowDataLayer.PERSISTENCE_KEY_FILTER_ROW_TOKENS); + + String expectedPersistedCollection = FilterRowDataProvider.FILTER_COLLECTION_PREFIX + ArrayList.class.getName() + ")[" + + "foo" + IPersistable.VALUE_SEPARATOR + + "bar" + IPersistable.VALUE_SEPARATOR + + "foo" + FilterRowDataProvider.COMMA_REPLACEMENT + "bar" + + "]"; + + assertEquals("1:foo,bar|3:" + expectedPersistedCollection + "|", persistedProperty); + + // reset state + setup(); + + assertNull(this.dataProvider.getDataValue(1, 1)); + assertNull(this.dataProvider.getDataValue(3, 1)); + + // load state + this.dataProvider.loadState("prefix", properties); + + assertEquals("foo,bar", this.dataProvider.getDataValue(1, 1)); + Collection data = (Collection) this.dataProvider.getDataValue(3, 1); + assertEquals(3, data.size()); + assertEquals(new ArrayList<>(Arrays.asList("foo", "bar", "foo,bar")), data); + } }
\ No newline at end of file |
