diff options
| author | Dirk Fauth | 2023-01-09 13:37:52 +0000 |
|---|---|---|
| committer | Dirk Fauth | 2023-01-09 13:37:52 +0000 |
| commit | a5ba5c8859378753672b370fc18f75c495d4f08b (patch) | |
| tree | 418bba3394c8d8be6ef10bd643010af48fc843cd | |
| parent | 63fb609615ff39abca58430b1ed3a3a9eaedddca (diff) | |
| download | org.eclipse.nebula.widgets.nattable-a5ba5c8859378753672b370fc18f75c495d4f08b.tar.gz org.eclipse.nebula.widgets.nattable-a5ba5c8859378753672b370fc18f75c495d4f08b.tar.xz org.eclipse.nebula.widgets.nattable-a5ba5c8859378753672b370fc18f75c495d4f08b.zip | |
Bug 581304 - IPersistables on NatTable are ignored
Signed-off-by: Dirk Fauth <dirk.fauth@googlemail.com>
Change-Id: I620a7bf035ae18f03294ce4bfc1353b12c433364
2 files changed, 72 insertions, 9 deletions
diff --git a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/NatTableTest.java b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/NatTableTest.java index e219df06..748dabfa 100644 --- a/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/NatTableTest.java +++ b/org.eclipse.nebula.widgets.nattable.core.test/src/org/eclipse/nebula/widgets/nattable/NatTableTest.java @@ -15,7 +15,10 @@ package org.eclipse.nebula.widgets.nattable; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Properties; + import org.eclipse.nebula.widgets.nattable.command.DisposeResourcesCommand; +import org.eclipse.nebula.widgets.nattable.persistence.IPersistable; import org.eclipse.nebula.widgets.nattable.test.fixture.LayerEventFixture; import org.eclipse.nebula.widgets.nattable.test.fixture.command.AnyCommandHandlerFixture; import org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture; @@ -33,12 +36,11 @@ public class NatTableTest { @BeforeEach public void setup() { this.underlyingLayerFixture = new DataLayerFixture(10, 5, 100, 20); - this.natTable = new NatTable(new Shell(Display.getDefault()), - this.underlyingLayerFixture); + this.natTable = new NatTable(new Shell(Display.getDefault()), this.underlyingLayerFixture); } @Test - public void shouldPassOnLayerEventsToListeners() throws Exception { + public void shouldPassOnLayerEventsToListeners() { LayerListenerFixture listener = new LayerListenerFixture(); this.natTable.addLayerListener(listener); @@ -48,7 +50,7 @@ public class NatTableTest { } @Test - public void shouldFireDisposeCommandOnDisposal() throws Exception { + public void shouldFireDisposeCommandOnDisposal() { AnyCommandHandlerFixture commandHandler = new AnyCommandHandlerFixture(); this.underlyingLayerFixture.registerCommandHandler(commandHandler); @@ -57,4 +59,55 @@ public class NatTableTest { assertEquals(1, commandHandler.getNumberOfCommandsHandled()); assertTrue(commandHandler.getCommadHandled() instanceof DisposeResourcesCommand); } + + @Test + public void shouldSavePersistable() { + + String version = "2.1.0"; + + IPersistable persistable = new IPersistable() { + + @Override + public void saveState(String prefix, Properties properties) { + properties.put(prefix + ".version", version); + } + + @Override + public void loadState(String prefix, Properties properties) { + } + }; + + this.natTable.registerPersistable(persistable); + + Properties props = new Properties(); + this.natTable.saveState("test", props); + + assertTrue(props.containsKey("test.version"), "NatTable persistable was not executed"); + assertEquals(version, props.get("test.version")); + } + + @Test + public void shouldLoadPersistable() { + Properties props = new Properties(); + props.put("test.version", "2.1.0"); + + String[] version = new String[] { "blubb" }; + + IPersistable persistable = new IPersistable() { + + @Override + public void saveState(String prefix, Properties properties) { + } + + @Override + public void loadState(String prefix, Properties properties) { + version[0] = properties.getProperty("test.version"); + } + }; + + this.natTable.registerPersistable(persistable); + + this.natTable.loadState("test", props); + assertEquals("2.1.0", version[0]); + } } diff --git a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/NatTable.java b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/NatTable.java index 15035a75..d07c6dc7 100644 --- a/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/NatTable.java +++ b/org.eclipse.nebula.widgets.nattable.core/src/org/eclipse/nebula/widgets/nattable/NatTable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2020 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 @@ -778,7 +778,13 @@ public class NatTable extends Canvas implements ILayer, PaintListener, IClientAr */ @Override public void saveState(final String prefix, final Properties properties) { - BusyIndicator.showWhile(null, () -> NatTable.this.underlyingLayer.saveState(prefix, properties)); + BusyIndicator.showWhile(null, () -> { + NatTable.this.underlyingLayer.saveState(prefix, properties); + + for (IPersistable persistable : this.persistables) { + persistable.saveState(prefix, properties); + } + }); } /** @@ -791,12 +797,16 @@ public class NatTable extends Canvas implements ILayer, PaintListener, IClientAr public void loadState(final String prefix, final Properties properties) { BusyIndicator.showWhile(null, () -> { // if the initial painting is not finished yet, tell this the - // underlying - // mechanisms so there will be no refresh events fired - if (!NatTable.this.initialPaintComplete) + // underlying mechanisms so there will be no refresh events fired + if (!NatTable.this.initialPaintComplete) { properties.setProperty(INITIAL_PAINT_COMPLETE_FLAG, "true"); //$NON-NLS-1$ + } NatTable.this.underlyingLayer.loadState(prefix, properties); + + for (IPersistable persistable : this.persistables) { + persistable.loadState(prefix, properties); + } }); } |
