Search in sources :

Example 71 with ILayerCell

use of org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell 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)

Example 72 with ILayerCell

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnRowDelete.

@Test
public void shouldRemovePartialCellSelectionOnRowDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, true, false));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, true, false));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, true, false));
    assertEquals(4, this.selectionLayer.getSelectedCells().size());
    this.listFixture.remove(0);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new RowDeleteEvent(this.bodyDataLayer, 0));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved up
    for (ILayerCell cell : selectedCells) {
        assertEquals(0, cell.getRowPosition());
    }
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) RowDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 73 with ILayerCell

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldUpdateSelectionOnShiftSelect.

@Test
public void shouldUpdateSelectionOnShiftSelect() {
    // integration test case for drag/shift selection
    // not really a test case for structural changes but important for
    // selection interactions
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 3, 3, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 5, 5, true, false));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(9, selectedCells.size());
    boolean[] found = new boolean[3];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 5 || cell.getColumnPosition() < 2) {
            fail("wrong column position selected: " + cell.getColumnPosition());
        } else {
            found[cell.getColumnPosition() - 2] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + (i + 3) + " not selected", found[i]);
    }
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, true, false));
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(9, selectedCells.size());
    found = new boolean[3];
    for (ILayerCell cell : selectedCells) {
        if (cell.getColumnPosition() >= 3) {
            fail("wrong column position selected: " + cell.getColumnPosition());
        } else {
            found[cell.getColumnPosition()] = true;
        }
    }
    for (int i = 0; i < found.length; i++) {
        assertTrue("columnPosition " + i + " not selected", found[i]);
    }
}
Also used : SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 74 with ILayerCell

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemoveCellSelectionOnColumnDelete.

@Test
public void shouldRemoveCellSelectionOnColumnDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, false, true));
    assertEquals(2, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(0, selectedCells.size());
}
Also used : MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 75 with ILayerCell

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRemovePartialCellSelectionOnColumnDelete.

@Test
public void shouldRemovePartialCellSelectionOnColumnDelete() {
    assertTrue("selection is not empty", this.selectionLayer.getSelectedCells().isEmpty());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 1, 2, false, true));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 1, false, true));
    this.nattable.doCommand(new SelectCellCommand(this.nattable, 2, 2, false, true));
    assertEquals(4, this.selectionLayer.getSelectedCells().size());
    this.nattable.doCommand(new ColumnHideCommand(this.nattable, 1));
    Collection<ILayerCell> selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved to the left
    for (ILayerCell cell : selectedCells) {
        assertEquals(0, cell.getColumnPosition());
    }
    // insert again to verify the column position shift
    this.nattable.doCommand(new ShowAllColumnsCommand());
    // the deselected cells shouldn't get automatically selected again
    selectedCells = this.selectionLayer.getSelectedCells();
    assertEquals(2, selectedCells.size());
    // moved to the right
    for (ILayerCell cell : selectedCells) {
        assertEquals(1, cell.getColumnPosition());
    }
}
Also used : MultiColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand) ColumnHideCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ColumnHideCommand) SelectCellCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand) ShowAllColumnsCommand(org.eclipse.nebula.widgets.nattable.hideshow.command.ShowAllColumnsCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Aggregations

ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)118 Test (org.junit.Test)45 Rectangle (org.eclipse.swt.graphics.Rectangle)23 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)14 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)14 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)11 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)10 LabelStack (org.eclipse.nebula.widgets.nattable.layer.LabelStack)10 Color (org.eclipse.swt.graphics.Color)10 EditCellCommand (org.eclipse.nebula.widgets.nattable.edit.command.EditCellCommand)9 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)9 DataProviderFixture (org.eclipse.nebula.widgets.nattable.test.fixture.data.DataProviderFixture)9 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)5 Point (org.eclipse.swt.graphics.Point)5 HashSet (java.util.HashSet)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)4 IEditableRule (org.eclipse.nebula.widgets.nattable.config.IEditableRule)4 ICellEditor (org.eclipse.nebula.widgets.nattable.edit.editor.ICellEditor)4