Search in sources :

Example 1 with IDataProvider

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

the class DefaultColumnHeaderDataProviderTest method shouldThrowExceptionOnSet.

@Test(expected = UnsupportedOperationException.class)
public void shouldThrowExceptionOnSet() {
    IDataProvider dataProvider = new DefaultColumnHeaderDataProvider(new String[] { "One", "Two", "Three" });
    dataProvider.setDataValue(0, 0, "Foo");
}
Also used : IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) Test(org.junit.Test)

Example 2 with IDataProvider

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

the class DefaultColumnHeaderDataProviderTest method shouldReturnNullOnInvalidColumnIndex.

@Test
public void shouldReturnNullOnInvalidColumnIndex() {
    String[] properties = { "firstname", "lastname", "gender", "birthday" };
    Map<String, String> mapping = new HashMap<>();
    mapping.put("firstname", "Vorname");
    mapping.put("lastname", "Nachname");
    mapping.put("gender", "Geschlecht");
    mapping.put("birthday", "Geburtstag");
    IDataProvider dataProvider = new DefaultColumnHeaderDataProvider(properties, mapping);
    assertNull(dataProvider.getDataValue(-1, 0));
    assertNull(dataProvider.getDataValue(4, 0));
}
Also used : HashMap(java.util.HashMap) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) Test(org.junit.Test)

Example 3 with IDataProvider

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

the class DefaultColumnHeaderDataProviderTest method shouldReturnColumnLabel.

@Test
public void shouldReturnColumnLabel() {
    IDataProvider dataProvider = new DefaultColumnHeaderDataProvider(new String[] { "One", "Two", "Three" });
    assertEquals(1, dataProvider.getRowCount());
    assertEquals(3, dataProvider.getColumnCount());
    assertEquals("One", dataProvider.getDataValue(0, 0));
    assertEquals("Two", dataProvider.getDataValue(1, 0));
    assertEquals("Three", dataProvider.getDataValue(2, 0));
    // any other row will work too
    assertEquals("One", dataProvider.getDataValue(0, 1));
}
Also used : IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) Test(org.junit.Test)

Example 4 with IDataProvider

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

the class DefaultColumnHeaderDataProviderTest method shouldReturnPropertyLabel.

@Test
public void shouldReturnPropertyLabel() {
    String[] properties = { "firstname", "lastname", "gender", "birthday" };
    Map<String, String> mapping = new HashMap<>();
    mapping.put("firstname", "Vorname");
    mapping.put("lastname", "Nachname");
    mapping.put("gender", "Geschlecht");
    mapping.put("birthday", "Geburtstag");
    IDataProvider dataProvider = new DefaultColumnHeaderDataProvider(properties, mapping);
    assertEquals(1, dataProvider.getRowCount());
    assertEquals(4, dataProvider.getColumnCount());
    assertEquals("Vorname", dataProvider.getDataValue(0, 0));
    assertEquals("Nachname", dataProvider.getDataValue(1, 0));
    assertEquals("Geschlecht", dataProvider.getDataValue(2, 0));
    assertEquals("Geburtstag", dataProvider.getDataValue(3, 0));
    // any other row will work too
    assertEquals("Vorname", dataProvider.getDataValue(0, 1));
}
Also used : HashMap(java.util.HashMap) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) Test(org.junit.Test)

Example 5 with IDataProvider

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

the class MaxCellBoundsHelperTest method getPreferedRowHeights.

@Test
public void getPreferedRowHeights() throws Exception {
    DataLayerFixture dataLayer = new DataLayerFixture(3, 2, 10, 10);
    IDataProvider dataProvider = dataLayer.getDataProvider();
    // Row 0
    dataProvider.setDataValue(0, 0, "..");
    dataProvider.setDataValue(1, 0, "...");
    dataProvider.setDataValue(2, 0, "...");
    // Row 1
    dataProvider.setDataValue(0, 1, "Elephant");
    dataProvider.setDataValue(1, 1, "Cat");
    dataProvider.setDataValue(2, 1, "Rat");
    AutoResizeRowCommandFixture command = new AutoResizeRowCommandFixture();
    GCFactory gcFactory = command.getGCFactory();
    IConfigRegistry registry = command.getConfigRegistry();
    GC gc = gcFactory.createGC();
    int row0MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture(".."), gc, registry);
    int row1MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture("Elephant"), gc, registry);
    gc.dispose();
    int[] maxRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(registry, gcFactory, dataLayer, new int[] { 0, 1 });
    // Adjust heights
    int row0AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, 10, maxRowHeights[0])).height;
    int row1AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 1, new Rectangle(0, 0, 10, maxRowHeights[1])).height;
    Assert.assertEquals(row0MaxTextHeight, row0AdjustedMaxHeight);
    Assert.assertEquals(row1MaxTextHeight, row1AdjustedMaxHeight);
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) CellFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) AutoResizeRowCommandFixture(org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeRowCommandFixture) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Aggregations

IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)113 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)100 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)99 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)77 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)74 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)73 HashMap (java.util.HashMap)72 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)72 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)65 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)65 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)65 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)62 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)58 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)58 DefaultColumnHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer)56 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)56 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)54 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)46 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)43 GridLayout (org.eclipse.swt.layout.GridLayout)41