Search in sources :

Example 11 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class SummaryRowIntegrationTest method defaultConfigLabelsAreApplied.

@Test
public void defaultConfigLabelsAreApplied() throws Exception {
    LabelStack configLabels = this.natTable.getConfigLabelsByPosition(0, 4);
    List<String> labels = configLabels.getLabels();
    assertEquals(2, labels.size());
    assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 0, labels.get(0));
    assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL, labels.get(1));
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) Test(org.junit.Test)

Example 12 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class LayerAssert method assertLayerEquals.

@SuppressWarnings("boxing")
public static void assertLayerEquals(ILayer expectedLayer, ILayer actualLayer) {
    // Horizontal features
    // Columns
    int expectedColumnCount = expectedLayer.getColumnCount();
    int actualColumnCount = actualLayer.getColumnCount();
    Assert.assertEquals("Column count", expectedColumnCount, actualColumnCount);
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedColumnIndexByPosition = expectedLayer.getColumnIndexByPosition(columnPosition);
        int actualColumnIndexByPosition = actualLayer.getColumnIndexByPosition(columnPosition);
        Assert.assertEquals("Column index by position (" + columnPosition + ")", expectedColumnIndexByPosition, actualColumnIndexByPosition);
    }
    for (int localColumnPosition = 0; localColumnPosition < expectedColumnCount; localColumnPosition++) {
        int expectedLocalToUnderlyingColumnPosition = expectedLayer.localToUnderlyingColumnPosition(localColumnPosition);
        int actualLocalToUnderlyingColumnPosition = actualLayer.localToUnderlyingColumnPosition(localColumnPosition);
        Assert.assertEquals("Local to underlying column position (" + localColumnPosition + ")", expectedLocalToUnderlyingColumnPosition, actualLocalToUnderlyingColumnPosition);
    }
    // for (int underlyingColumnPosition = 0; underlyingColumnPosition <
    // expectedLayer.getColumnCount(); underlyingColumnPosition++) {
    // Assert.assertEquals("Underlying to local column position (" +
    // underlyingColumnPosition + ")",
    // expectedLayer.underlyingToLocalColumnPosition(null,
    // underlyingColumnPosition),
    // actualLayer.underlyingToLocalColumnPosition(null,
    // underlyingColumnPosition));
    // }
    // Width
    int expectedWidth = expectedLayer.getWidth();
    int actualWidth = actualLayer.getWidth();
    Assert.assertEquals("Width", expectedWidth, actualWidth);
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedColumnWidthByPosition = expectedLayer.getColumnWidthByPosition(columnPosition);
        int actualColumnWidthByPosition = actualLayer.getColumnWidthByPosition(columnPosition);
        Assert.assertEquals("Column width by position (" + columnPosition + ")", expectedColumnWidthByPosition, actualColumnWidthByPosition);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        boolean expectedColumnPositionResizable = expectedLayer.isColumnPositionResizable(columnPosition);
        boolean actualColumnPositionResizable = actualLayer.isColumnPositionResizable(columnPosition);
        Assert.assertEquals("Column position resizable (" + columnPosition + ")", expectedColumnPositionResizable, actualColumnPositionResizable);
    }
    for (int x = 0; x < expectedWidth; x++) {
        int expectedColumnPositionByX = expectedLayer.getColumnPositionByX(x);
        int actualColumnPositionByX = actualLayer.getColumnPositionByX(x);
        Assert.assertEquals("Column position by X (" + x + ")", expectedColumnPositionByX, actualColumnPositionByX);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        int expectedStartXOfColumnPosition = expectedLayer.getStartXOfColumnPosition(columnPosition);
        int actualStartXOfColumnPosition = actualLayer.getStartXOfColumnPosition(columnPosition);
        Assert.assertEquals("Start X of column position (" + columnPosition + ")", expectedStartXOfColumnPosition, actualStartXOfColumnPosition);
    }
    // Vertical features
    // Rows
    int expectedRowCount = expectedLayer.getRowCount();
    int actualRowCount = actualLayer.getRowCount();
    Assert.assertEquals("Row count", expectedRowCount, actualRowCount);
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedRowIndexByPosition = expectedLayer.getRowIndexByPosition(rowPosition);
        int actualRowIndexByPosition = actualLayer.getRowIndexByPosition(rowPosition);
        Assert.assertEquals("Row index by position (" + rowPosition + ")", expectedRowIndexByPosition, actualRowIndexByPosition);
    }
    for (int localRowPosition = 0; localRowPosition < expectedRowCount; localRowPosition++) {
        int expectedLocalToUnderlyingRowPosition = expectedLayer.localToUnderlyingRowPosition(localRowPosition);
        int actualLocalToUnderlyingRowPosition = actualLayer.localToUnderlyingRowPosition(localRowPosition);
        Assert.assertEquals("Local to underlying row position (" + localRowPosition + ")", expectedLocalToUnderlyingRowPosition, actualLocalToUnderlyingRowPosition);
    }
    // for (int underlyingRowPosition = 0; underlyingRowPosition <
    // expectedLayer.getRowCount(); underlyingRowPosition++) {
    // Assert.assertEquals("Underlying to local row position (" +
    // underlyingRowPosition + ")",
    // expectedLayer.underlyingToLocalRowPosition(null,
    // underlyingRowPosition),
    // actualLayer.underlyingToLocalRowPosition(null,
    // underlyingRowPosition));
    // }
    // Height
    int expectedHeight = expectedLayer.getHeight();
    int actualHeight = actualLayer.getHeight();
    Assert.assertEquals("Height", expectedHeight, actualHeight);
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedRowHeightByPosition = expectedLayer.getRowHeightByPosition(rowPosition);
        int actualRowHeightByPosition = actualLayer.getRowHeightByPosition(rowPosition);
        Assert.assertEquals("Row height by position (" + rowPosition + ")", expectedRowHeightByPosition, actualRowHeightByPosition);
    }
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        boolean expectedRowPositionResizable = expectedLayer.isRowPositionResizable(rowPosition);
        boolean actualRowPositionResizable = actualLayer.isRowPositionResizable(rowPosition);
        Assert.assertEquals("Row position resizable (" + rowPosition + ")", expectedRowPositionResizable, actualRowPositionResizable);
    }
    for (int y = 0; y < expectedHeight; y++) {
        int expectedRowPositionByY = expectedLayer.getRowPositionByY(y);
        int actualRowPositionByY = actualLayer.getRowPositionByY(y);
        Assert.assertEquals("Row position by Y (" + y + ")", expectedRowPositionByY, actualRowPositionByY);
    }
    for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
        int expectedStartYOfRowPosition = expectedLayer.getStartYOfRowPosition(rowPosition);
        int actualStartYOfRowPosition = actualLayer.getStartYOfRowPosition(rowPosition);
        Assert.assertEquals("Start Y of row position (" + rowPosition + ")", expectedStartYOfRowPosition, actualStartYOfRowPosition);
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            ILayerCell expectedCellByPosition = expectedLayer.getCellByPosition(columnPosition, rowPosition);
            ILayerCell actualCellByPosition = actualLayer.getCellByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Cell by position (" + columnPosition + ", " + rowPosition + ")", expectedCellByPosition, actualCellByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            Rectangle expectedBoundsByPosition = expectedLayer.getBoundsByPosition(columnPosition, rowPosition);
            Rectangle actualBoundsByPosition = actualLayer.getBoundsByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Bounds by position (" + columnPosition + ", " + rowPosition + ")", expectedBoundsByPosition, actualBoundsByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            String expectedDisplayModeByPosition = expectedLayer.getDisplayModeByPosition(columnPosition, rowPosition);
            String actualDisplayModeByPosition = actualLayer.getDisplayModeByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Display mode by position (" + columnPosition + ", " + rowPosition + ")", expectedDisplayModeByPosition, actualDisplayModeByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            LabelStack expectedConfigLabelsByPosition = expectedLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
            LabelStack actualConfigLabelsByPosition = actualLayer.getConfigLabelsByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Config labels by position (" + columnPosition + ", " + rowPosition + ")", expectedConfigLabelsByPosition, actualConfigLabelsByPosition);
        }
    }
    for (int columnPosition = 0; columnPosition < expectedColumnCount; columnPosition++) {
        for (int rowPosition = 0; rowPosition < expectedRowCount; rowPosition++) {
            Object expectedDataValueByPosition = expectedLayer.getDataValueByPosition(columnPosition, rowPosition);
            Object actualDataValueByPosition = actualLayer.getDataValueByPosition(columnPosition, rowPosition);
            Assert.assertEquals("Data value by position (" + columnPosition + ", " + rowPosition + ")", expectedDataValueByPosition, actualDataValueByPosition);
        }
    }
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 13 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderLayerSelectionTest method shouldReturnProvidedLabels.

@Test
public void shouldReturnProvidedLabels() {
    ColumnHeaderLayer columnHeaderLayer = (ColumnHeaderLayer) this.gridLayer.getChildLayerByLayoutCoordinate(1, 0);
    columnHeaderLayer.setConfigLabelAccumulator(new IConfigLabelProvider() {

        @Override
        public void accumulateConfigLabels(LabelStack configLabels, int columnPosition, int rowPosition) {
            if (columnPosition == 2) {
                configLabels.addLabel("test");
            }
        }

        @Override
        public Collection<String> getProvidedLabels() {
            Set<String> result = new HashSet<String>();
            result.add("test");
            return result;
        }
    });
    Collection<String> labels = columnHeaderLayer.getProvidedLabels();
    assertEquals(1, labels.size());
    assertEquals("test", labels.iterator().next());
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) Set(java.util.Set) HashSet(java.util.HashSet) IConfigLabelProvider(org.eclipse.nebula.widgets.nattable.layer.cell.IConfigLabelProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) Collection(java.util.Collection) Test(org.junit.Test)

Example 14 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class ColumnHeaderLayerSelectionTest method shouldReturnFullySelectedStyle.

@Test
public void shouldReturnFullySelectedStyle() {
    // Select full column
    this.gridLayer.doCommand(new ViewportSelectColumnCommand(this.gridLayer, 2, false, false));
    ColumnHeaderLayer columnHeaderLayer = (ColumnHeaderLayer) this.gridLayer.getChildLayerByLayoutCoordinate(1, 0);
    // Since I selected using grid coordinates, the column position should
    // be 1 rather than 2
    int columnPosition = this.gridLayer.localToUnderlyingColumnPosition(2);
    final LabelStack labelStack = columnHeaderLayer.getConfigLabelsByPosition(columnPosition, 0);
    assertTrue(labelStack.hasLabel(SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE));
    columnPosition = this.gridLayer.localToUnderlyingColumnPosition(3);
    assertFalse(SelectionStyleLabels.COLUMN_FULLY_SELECTED_STYLE.equals(labelStack));
}
Also used : LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ViewportSelectColumnCommand(org.eclipse.nebula.widgets.nattable.viewport.command.ViewportSelectColumnCommand) Test(org.junit.Test)

Example 15 with LabelStack

use of org.eclipse.nebula.widgets.nattable.layer.LabelStack in project nebula.widgets.nattable by eclipse.

the class CellLabelMouseEventMatcherTest method shouldTakeTheRegionIntoAccountWhileMatching.

@Test
public void shouldTakeTheRegionIntoAccountWhileMatching() throws Exception {
    CellLabelMouseEventMatcher matcher = new CellLabelMouseEventMatcher(GridRegion.COLUMN_HEADER, MouseEventMatcher.LEFT_BUTTON, TEST_LABEL);
    boolean match = matcher.matches(this.natTableFixture, new MouseEvent(SWTUtils.getLeftClickEvent(100, 100, 0, this.natTableFixture)), new LabelStack(GridRegion.BODY));
    Assert.assertFalse(match);
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) LabelStack(org.eclipse.nebula.widgets.nattable.layer.LabelStack) CellLabelMouseEventMatcher(org.eclipse.nebula.widgets.nattable.ui.matcher.CellLabelMouseEventMatcher) Test(org.junit.Test)

Aggregations

LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)80 Test (org.junit.Test)30 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)14 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)13 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)10 HashMap (java.util.HashMap)9 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)9 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)9 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 GridLayout (org.eclipse.swt.layout.GridLayout)9 Composite (org.eclipse.swt.widgets.Composite)9 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)8 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)8 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)8 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)8 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)8