Search in sources :

Example 41 with NatTableFixture

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

the class EditTraversalStrategyLeftRightTest method setUp.

@Before
public void setUp() {
    this.dataLayer = new DataLayerFixture(10, 10, 100, 20);
    this.selectionLayer = new SelectionLayer(this.dataLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.viewportLayer.setRegionName(GridRegion.BODY);
    this.viewportLayer.addConfiguration(new DefaultEditBindings());
    this.viewportLayer.addConfiguration(new DefaultEditConfiguration());
    this.natTable = new NatTableFixture(this.viewportLayer);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 2, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 5, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 6, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 7, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 8, NOT_EDITABLE);
    this.natTable.registerLabelOnColumn(this.dataLayer, 9, NOT_EDITABLE);
}
Also used : DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) Before(org.junit.Before)

Example 42 with NatTableFixture

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

the class EditTraversalStrategyUpDownTest method setUp.

@Before
public void setUp() {
    // only use 10 columns to make the test cases easier
    String[] propertyNames = Arrays.copyOfRange(RowDataListFixture.getPropertyNames(), 0, 10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
    this.dataLayer = new DataLayer(bodyDataProvider, 20, 20);
    this.selectionLayer = new SelectionLayer(this.dataLayer);
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
    this.viewportLayer.setRegionName(GridRegion.BODY);
    this.viewportLayer.addConfiguration(new DefaultEditBindings());
    this.viewportLayer.addConfiguration(new DefaultEditConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true));
            configRegistry.registerConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, new DefaultDataValidator());
            configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new DefaultBooleanDisplayConverter(), DisplayMode.NORMAL, ColumnLabelAccumulator.COLUMN_LABEL_PREFIX + 9);
        }
    });
    this.natTable = new NatTableFixture(this.viewportLayer);
    this.natTable.enableEditingOnAllCells();
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.NEVER_EDITABLE, DisplayMode.EDIT, NOT_EDITABLE);
    this.natTable.getConfigRegistry().registerConfigAttribute(EditConfigAttributes.OPEN_ADJACENT_EDITOR, Boolean.TRUE);
    // register non editable rows
    this.overrider = new RowOverrideLabelAccumulator<>(bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    });
    this.overrider.registerRowOverrides(2, NOT_EDITABLE);
    this.overrider.registerRowOverrides(5, NOT_EDITABLE);
    this.overrider.registerRowOverrides(6, NOT_EDITABLE);
    this.overrider.registerRowOverrides(7, NOT_EDITABLE);
    this.overrider.registerRowOverrides(8, NOT_EDITABLE);
    this.overrider.registerRowOverrides(9, NOT_EDITABLE);
    AggregateConfigLabelAccumulator accumulator = new AggregateConfigLabelAccumulator();
    accumulator.add(this.overrider);
    accumulator.add(new ColumnLabelAccumulator());
    this.dataLayer.setConfigLabelAccumulator(accumulator);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DefaultBooleanDisplayConverter(org.eclipse.nebula.widgets.nattable.data.convert.DefaultBooleanDisplayConverter) NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) DefaultDataValidator(org.eclipse.nebula.widgets.nattable.data.validate.DefaultDataValidator) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DefaultEditBindings(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings) AggregateConfigLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.AggregateConfigLabelAccumulator) IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultEditConfiguration(org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) ColumnLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnLabelAccumulator) Before(org.junit.Before)

Example 43 with NatTableFixture

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

the class PreserveSelectionModelStructuralChangeEventHandlerTest method setup.

@Before
public void setup() {
    this.listFixture = RowDataListFixture.getList(10);
    this.bodyDataProvider = new ListDataProvider<RowDataFixture>(this.listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    GridLayerFixture gridLayer = new GridLayerFixture(this.bodyDataProvider);
    this.nattable = new NatTableFixture(gridLayer, false);
    this.bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    this.selectionLayer = gridLayer.getBodyLayer().getSelectionLayer();
    this.selectionLayer.setSelectionModel(new PreserveSelectionModel<RowDataFixture>(this.selectionLayer, this.bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
}
Also used : IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) 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) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) Before(org.junit.Before)

Example 44 with NatTableFixture

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

the class SelectionModelStructuralChangeEventHandlerTest method shouldClearSelectionOnDataUpdates.

@Test
public void shouldClearSelectionOnDataUpdates() 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());
    listFixture.add(0, RowDataFixture.getInstance("Tata motors", "A"));
    // fire event to trigger structural refresh
    bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(bodyDataLayer));
    assertEquals(0, selectionLayer.getFullySelectedRowPositions().length);
}
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)

Example 45 with NatTableFixture

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

the class SelectionEventsTest method setup.

@Before
public void setup() {
    this.nattable = new NatTableFixture();
    this.listener = new LayerListenerFixture();
    this.nattable.addLayerListener(this.listener);
}
Also used : NatTableFixture(org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture) LayerListenerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture) Before(org.junit.Before)

Aggregations

NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)51 Test (org.junit.Test)29 Before (org.junit.Before)22 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)16 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)13 DummyGridLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DummyGridLayerStack)13 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.LayerListenerFixture)11 RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)8 Properties (java.util.Properties)7 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)7 GridLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.GridLayerFixture)6 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)5 SpanningDataLayer (org.eclipse.nebula.widgets.nattable.layer.SpanningDataLayer)5 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)5 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)5 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)4 DefaultEditBindings (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditBindings)4 DefaultEditConfiguration (org.eclipse.nebula.widgets.nattable.edit.config.DefaultEditConfiguration)4 IUniqueIndexLayer (org.eclipse.nebula.widgets.nattable.layer.IUniqueIndexLayer)4 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)4