Search in sources :

Example 26 with DummyBodyDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInBackgroundWithCoordsKeyKillSmooth.

@Test
public void testCalculateInBackgroundWithCoordsKeyKillSmooth() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), true, true);
    Object result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as calculation is performed in background, the immediate return value
    // is null
    assertNull(result);
    // now wait so the background process is able to finish
    Thread.sleep(250);
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
    this.valueCache.killCache();
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // killing the cache should have the same effect as clearing non smooth
    assertNull(result);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Example 27 with DummyBodyDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInBackgroundWithCoordsKeyClearSmooth.

@Test
public void testCalculateInBackgroundWithCoordsKeyClearSmooth() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), true, true);
    Object result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as calculation is performed in background, the immediate return value
    // is null
    assertNull(result);
    // now wait so the background process is able to finish
    Thread.sleep(250);
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
    this.valueCache.clearCache();
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as the cache is configured for smooth updates, the value should be
    // still there
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Example 28 with DummyBodyDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInBackgroundWithColumnKey.

@Test
public void testCalculateInBackgroundWithColumnKey() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), true, false);
    Object result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as calculation is performed in background, the immediate return value
    // is null
    assertNull(result);
    // now wait so the background process is able to finish
    Thread.sleep(250);
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Example 29 with DummyBodyDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInBackgroundWithCoordsKeyClearNonSmooth.

@Test
public void testCalculateInBackgroundWithCoordsKeyClearNonSmooth() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), true, true, false);
    Object result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as calculation is performed in background, the immediate return value
    // is null
    assertNull(result);
    // now wait so the background process is able to finish
    Thread.sleep(250);
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
    this.valueCache.clearCache();
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as the cache is configured for non smooth updates, the value should
    // be null again
    assertNull(result);
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Example 30 with DummyBodyDataProvider

use of org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider in project nebula.widgets.nattable by eclipse.

the class CalculatedValueCacheTest method testCalculateInBackgroundWithRowKey.

@Test
public void testCalculateInBackgroundWithRowKey() throws Exception {
    this.valueCache = new CalculatedValueCache(new DataLayer(new DummyBodyDataProvider(10, 10)), false, true);
    Object result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    // as calculation is performed in background, the immediate return value
    // is null
    assertNull(result);
    // now wait so the background process is able to finish
    Thread.sleep(250);
    result = this.valueCache.getCalculatedValue(0, 0, true, this.calculator);
    assertEquals(Integer.valueOf(42), Integer.valueOf(result.toString()));
}
Also used : DummyBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) Test(org.junit.Test)

Aggregations

DummyBodyDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyBodyDataProvider)32 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)32 Test (org.junit.Test)16 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)11 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)11 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)11 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)11 CompositeLayer (org.eclipse.nebula.widgets.nattable.layer.CompositeLayer)9 DummyColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider)8 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)8 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)6 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)6 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)5 Before (org.junit.Before)5 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)4 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)4 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)3 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 CompositeFreezeLayer (org.eclipse.nebula.widgets.nattable.freeze.CompositeFreezeLayer)2