Search in sources :

Example 1 with GridLayerFixture

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

the class RowSelectionEditUtilsTest method setup.

@Before
public void setup() {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    this.gridLayerStack = new GridLayerFixture(bodyDataProvider);
    this.selectionLayer = this.gridLayerStack.getBodyLayer().getSelectionLayer();
    this.selectionLayer.setSelectionModel(new RowSelectionModel<RowDataFixture>(this.selectionLayer, bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    this.natTable = new NatTableFixture(this.gridLayerStack);
    // Ensure no active editor (static) is present
    // Although deprecated this needs to still work for backwards
    // compatibility
    assertNull(ActiveCellEditorRegistry.getActiveCellEditor());
}
Also used : IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 2 with GridLayerFixture

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

the class ColumnGroupHeaderLayerSelectionTest method setup.

@Before
public void setup() {
    this.dataProvider = new ListDataProvider<>(getNumberValues(), new ReflectiveColumnPropertyAccessor<>("columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber", "columnSixNumber", "columnSevenNumber", "columnEightNumber", "columnNineNumber", "columnTenNumber"));
    this.gridLayer = new GridLayerFixture(this.dataProvider);
    this.model = new ColumnGroupModel();
    // 10 columns in header
    this.columnGroupLayer = new ColumnGroupHeaderLayer(this.gridLayer.getColumnHeaderLayer(), this.gridLayer.getBodyLayer().getSelectionLayer(), this.model, false);
    this.columnGroupLayer.addConfiguration(new DefaultColumnGroupHeaderLayerConfiguration(this.model, true));
    this.gridLayer.getBodyLayer().getViewportLayer().registerCommandHandler(new ViewportSelectColumnGroupCommandHandler(this.gridLayer.getBodyLayer().getViewportLayer(), this.columnGroupLayer));
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_1, 0, 1, 2);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_2, 5, 6);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_3, 8, 9);
    this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1050, 200);
        }
    });
    this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
    this.layerListener = new LayerListenerFixture();
    this.gridLayer.getBodyLayer().addLayerListener(this.layerListener);
}
Also used : IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) DefaultColumnGroupHeaderLayerConfiguration(org.eclipse.nebula.widgets.nattable.group.config.DefaultColumnGroupHeaderLayerConfiguration) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) Shell(org.eclipse.swt.widgets.Shell) ViewportSelectColumnGroupCommandHandler(org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommandHandler) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 3 with GridLayerFixture

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

the class ColumnGroupHeaderLayerTest method setup.

@Before
public void setup() {
    this.gridLayer = new GridLayerFixture();
    this.model = new ColumnGroupModel();
    // 10 columns in header
    this.columnGroupLayer = new ColumnGroupHeaderLayer(this.gridLayer.getColumnHeaderLayer(), this.gridLayer.getBodyLayer().getSelectionLayer(), this.model);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_1, 0, 1);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_2, 5, 6);
    this.columnGroupLayer.addColumnsIndexesToGroup(TEST_GROUP_NAME_3, 8, 9);
    this.gridLayer.setClientAreaProvider(new IClientAreaProvider() {

        @Override
        public Rectangle getClientArea() {
            return new Rectangle(0, 0, 1050, 250);
        }
    });
    this.gridLayer.doCommand(new ClientAreaResizeCommand(new Shell(Display.getDefault(), SWT.V_SCROLL | SWT.H_SCROLL)));
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IClientAreaProvider(org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider) ClientAreaResizeCommand(org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) Before(org.junit.Before)

Example 4 with GridLayerFixture

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithRowStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithRowStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new RowStructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 5 with GridLayerFixture

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnClearingTableWithStructuralRefresh.

@Test
public void shouldClearSelectionOnClearingTableWithStructuralRefresh() throws Exception {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(bodyDataProvider);
    NatTable nattable = new NatTableFixture(gridLayer, false);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    SelectionLayer selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    // test SelectionModel updates
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
    nattable.doCommand(new SelectRowsCommand(nattable, 1, 1, false, false));
    assertEquals(1, selectionLayer.getFullySelectedRowPositions().length);
    // Ford motor at top and selected
    assertEquals("B Ford Motor", nattable.getDataValueByPosition(2, 1).toString());
    Range selection = selectionLayer.getSelectedRowPositions().iterator().next();
    assertEquals("B Ford Motor", listFixture.get(selection.start).getSecurity_description());
    // clear the table
    listFixture.clear();
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    // row count of 1 for NatTable because of header
    assertEquals(1, nattable.getRowCount());
    assertTrue("selection is not empty", selectionLayer.getSelectedCells().isEmpty());
    assertTrue("selection model is not empty", selectionLayer.getSelectionModel().getSelections().isEmpty());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Aggregations

GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)18 Before (org.junit.Before)12 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)6 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)6 Test (org.junit.Test)6 InitializeClientAreaCommandFixture (org.eclipse.nebula.widgets.nattable.test.fixture.InitializeClientAreaCommandFixture)5 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 ClientAreaResizeCommand (org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand)4 Shell (org.eclipse.swt.widgets.Shell)4 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)3 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)3 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)3 DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)3 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)3 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)3 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)3