Search in sources :

Example 16 with DataLayerFixture

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

the class ReorderColumnEventTest method reorderMultipleNotConsecutiveColumnsInHiddenState.

@Test
public void reorderMultipleNotConsecutiveColumnsInHiddenState() {
    DefaultBodyLayerStack underlyingLayer = new DefaultBodyLayerStack(new DataLayerFixture(10, 10, 100, 20));
    NatTableFixture natTableFixture = new NatTableFixture(underlyingLayer, 1000, 400, true);
    // Add listener
    LayerListenerFixture listenerFixture = new LayerListenerFixture();
    natTableFixture.addLayerListener(listenerFixture);
    assertEquals(10, natTableFixture.getColumnCount());
    // hide some columns
    natTableFixture.doCommand(new MultiColumnHideCommand(natTableFixture, new int[] { 2, 5, 8 }));
    assertEquals(7, natTableFixture.getColumnCount());
    List<Integer> columnToMove = Arrays.asList(3, 4, 6, 7);
    int destinationPosition = 0;
    natTableFixture.doCommand(new MultiColumnReorderCommand(underlyingLayer.getColumnReorderLayer(), columnToMove, destinationPosition));
    // verify the event
    ColumnReorderEvent event = (ColumnReorderEvent) listenerFixture.getReceivedEvent(ColumnReorderEvent.class);
    assertNotNull(event);
    assertTrue(StructuralChangeEventHelper.isReorder(event.getColumnDiffs()));
    assertEquals(7, natTableFixture.getColumnCount());
    assertEquals(0, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(3));
    assertEquals(1, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(4));
    assertEquals(2, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(6));
    assertEquals(3, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(7));
    assertEquals(4, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(0));
    assertEquals(5, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(1));
    assertEquals(6, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(2));
    assertEquals(7, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(5));
    assertEquals(8, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(8));
    assertEquals(9, underlyingLayer.getColumnReorderLayer().getColumnPositionByIndex(9));
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) Test(org.junit.Test)

Example 17 with DataLayerFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture 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)

Example 18 with DataLayerFixture

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

the class MaxCellBoundsHelperTest method getPreferedColumnWidths.

@Test
public void getPreferedColumnWidths() throws Exception {
    DataLayerFixture dataLayer = new DataLayerFixture(2, 3, 10, 10);
    IDataProvider dataProvider = dataLayer.getDataProvider();
    // Col 0
    dataProvider.setDataValue(0, 0, "Long");
    dataProvider.setDataValue(0, 1, "Longer");
    dataProvider.setDataValue(0, 2, "Longest Text");
    // Col 1
    dataProvider.setDataValue(1, 0, "Elephant");
    dataProvider.setDataValue(1, 1, "Cat");
    dataProvider.setDataValue(1, 2, "Rat");
    AutoResizeColumnCommandFixture command = new AutoResizeColumnCommandFixture();
    GCFactory gcFactory = command.getGCFactory();
    IConfigRegistry registry = command.getConfigRegistry();
    GC gc = gcFactory.createGC();
    int col0MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Longest Text"), gc, registry);
    int col1MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Elephant"), gc, registry);
    gc.dispose();
    int[] maxColumnWidths = MaxCellBoundsHelper.getPreferredColumnWidths(registry, gcFactory, dataLayer, new int[] { 0, 1 });
    // Adjust widths
    int col0AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, maxColumnWidths[0], 10)).width;
    int col1AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(1, 0, new Rectangle(0, 0, maxColumnWidths[1], 10)).width;
    Assert.assertEquals(col0MaxTextWidth, col0AdjustedMaxWidth);
    Assert.assertEquals(col1MaxTextWidth, col1AdjustedMaxWidth);
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) CellFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture) AutoResizeColumnCommandFixture(org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeColumnCommandFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) 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)

Example 19 with DataLayerFixture

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

the class MultiColumnResizeCommandTest method getColumnWidth.

@Test
public void getColumnWidth() {
    MultiColumnResizeCommand resizeCommand = new MultiColumnResizeCommand(new DataLayerFixture(), new int[] { 5, 9 }, new int[] { 12, 20 });
    assertEquals(12, resizeCommand.getColumnWidth(5));
    assertEquals(20, resizeCommand.getColumnWidth(9));
    // Error case
    assertEquals(-1, resizeCommand.getColumnWidth(10));
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Test(org.junit.Test)

Example 20 with DataLayerFixture

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

the class MultiColumnResizeCommandTest method getCommonColumnWidth.

@Test
public void getCommonColumnWidth() {
    MultiColumnResizeCommand resizeCommand = new MultiColumnResizeCommand(new DataLayerFixture(), new int[] { 1, 2 }, 100);
    assertEquals(100, resizeCommand.getCommonColumnWidth());
    assertEquals(100, resizeCommand.getColumnWidth(1));
}
Also used : DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Test(org.junit.Test)

Aggregations

DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)57 Test (org.junit.Test)28 Before (org.junit.Before)27 BaseDataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.BaseDataLayerFixture)11 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)7 Rectangle (org.eclipse.swt.graphics.Rectangle)7 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)6 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)6 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)5 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)3 LayerCommandFixture (org.eclipse.nebula.widgets.nattable.test.fixture.command.LayerCommandFixture)3 ColumnGroupModelFixture (org.eclipse.nebula.widgets.nattable.test.fixture.group.ColumnGroupModelFixture)3 Properties (java.util.Properties)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)2 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)2 RowHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.RowHideShowLayer)2