Search in sources :

Example 36 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class PersistenceHelperTest method testDeleteStateOnNullState.

@Test
public void testDeleteStateOnNullState() {
    Properties properties = new Properties();
    NatTable natTable = new NatTableFixture();
    natTable.saveState("", properties);
    natTable.saveState("Blubb", properties);
    natTable.saveState("Temp", properties);
    Collection<String> stateNames = PersistenceHelper.getAvailableStates(properties);
    assertTrue("Resulting state name collection does not contain the empty default state", stateNames.contains(""));
    assertTrue("Resulting state name collection does not contain the 'Blubb' state", stateNames.contains("Blubb"));
    assertTrue("Resulting state name collection does not contain the 'Temp' state", stateNames.contains("Temp"));
    PersistenceHelper.deleteState(null, properties);
    // no impact
    stateNames = PersistenceHelper.getAvailableStates(properties);
    assertTrue("Resulting state name collection does not contain the empty default state", stateNames.contains(""));
    assertTrue("Resulting state name collection does not contain the 'Blubb' state", stateNames.contains("Blubb"));
    assertTrue("Resulting state name collection does not contain the 'Temp' state", stateNames.contains("Temp"));
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Properties(java.util.Properties) Test(org.junit.Test)

Example 37 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class PersistenceHelperTest method testDeleteStateOnNullProperties.

@Test
public void testDeleteStateOnNullProperties() {
    Properties properties = new Properties();
    NatTable natTable = new NatTableFixture();
    natTable.saveState("", properties);
    natTable.saveState("Blubb", properties);
    natTable.saveState("Temp", properties);
    Collection<String> stateNames = PersistenceHelper.getAvailableStates(properties);
    assertTrue("Resulting state name collection does not contain the empty default state", stateNames.contains(""));
    assertTrue("Resulting state name collection does not contain the 'Blubb' state", stateNames.contains("Blubb"));
    assertTrue("Resulting state name collection does not contain the 'Temp' state", stateNames.contains("Temp"));
    PersistenceHelper.deleteState("Blubb", null);
    // no impact
    stateNames = PersistenceHelper.getAvailableStates(properties);
    assertTrue("Resulting state name collection does not contain the empty default state", stateNames.contains(""));
    assertTrue("Resulting state name collection does not contain the 'Blubb' state", stateNames.contains("Blubb"));
    assertTrue("Resulting state name collection does not contain the 'Temp' state", stateNames.contains("Temp"));
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Properties(java.util.Properties) Test(org.junit.Test)

Example 38 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class PersistenceHelperTest method testGetAvailableStates.

@Test
public void testGetAvailableStates() {
    Properties properties = new Properties();
    NatTable natTable = new NatTableFixture();
    natTable.saveState("", properties);
    natTable.saveState("Blubb", properties);
    natTable.saveState("Temp", properties);
    Collection<String> stateNames = PersistenceHelper.getAvailableStates(properties);
    assertTrue("Resulting state name collection does not contain the empty default state", stateNames.contains(""));
    assertTrue("Resulting state name collection does not contain the 'Blubb' state", stateNames.contains("Blubb"));
    assertTrue("Resulting state name collection does not contain the 'Temp' state", stateNames.contains("Temp"));
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) Properties(java.util.Properties) Test(org.junit.Test)

Example 39 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class ConfigLabelProviderTest method testProvidedRegionLabels.

@Test
public void testProvidedRegionLabels() {
    GridLayer grid = new GridLayer(this.bodyDataLayer, this.columnHeaderDataLayer, this.rowHeaderDataLayer, this.cornerDataLayer, false);
    Collection<String> labels = grid.getProvidedLabels();
    assertEquals(4, labels.size());
    assertTrue(labels.contains(GridRegion.CORNER));
    assertTrue(labels.contains(GridRegion.COLUMN_HEADER));
    assertTrue(labels.contains(GridRegion.ROW_HEADER));
    assertTrue(labels.contains(GridRegion.BODY));
    NatTable natTable = new NatTableFixture(grid);
    labels = natTable.getProvidedLabels();
    assertEquals(4, labels.size());
    assertTrue(labels.contains(GridRegion.CORNER));
    assertTrue(labels.contains(GridRegion.COLUMN_HEADER));
    assertTrue(labels.contains(GridRegion.ROW_HEADER));
    assertTrue(labels.contains(GridRegion.BODY));
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) Test(org.junit.Test)

Example 40 with NatTableFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture in project nebula.widgets.nattable by eclipse.

the class BoxingStyleTest method retrievedCellShouldBeConvertedUsingTheDisplayConverter.

@Test
public void retrievedCellShouldBeConvertedUsingTheDisplayConverter() throws Exception {
    IConfigRegistry configRegistry = new ConfigRegistry();
    configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DisplayConverter() {

        @Override
        public Object canonicalToDisplayValue(Object canonicalValue) {
            if (canonicalValue == null) {
                return null;
            } else {
                return canonicalValue.toString().equals("MN") ? "Manual" : "Automatic";
            }
        }

        @Override
        public Object displayToCanonicalValue(Object displayValue) {
            return displayValue.toString().equals("Manual") ? new PricingTypeBean("MN") : new PricingTypeBean("AT");
        }
    });
    NatTableFixture natTableFixture = new NatTableFixture(new DefaultGridLayer(RowDataListFixture.getList(), RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap()), false);
    natTableFixture.setConfigRegistry(configRegistry);
    natTableFixture.configure();
    int columnIndex = RowDataListFixture.getColumnIndexOfProperty(RowDataListFixture.PRICING_TYPE_PROP_NAME);
    Object dataValue = natTableFixture.getDataValueByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    // Verify displayed value
    ILayerCell cell = natTableFixture.getCellByPosition(columnIndex + ROW_HEADER_COLUMN_COUNT, 2);
    TextPainter cellPainter = new TextPainter();
    Assert.assertEquals("Automatic", cellPainter.convertDataType(cell, configRegistry));
    // Assert that the display value is converted to an Object
    Assert.assertTrue(dataValue instanceof PricingTypeBean);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) PricingTypeBean(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.PricingTypeBean) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Aggregations

NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)51 Test (org.junit.Test)29 Before (org.junit.Before)22 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)16 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)13 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)13 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)11 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)8 Properties (java.util.Properties)7 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)7 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)6 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)5 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)5 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)5 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)5 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)4 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)4 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)4 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4