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));
}
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);
}
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);
}
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));
}
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));
}
Aggregations