Search in sources :

Example 31 with RowDataFixture

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.

the class RowSelectionIntegrationTest method setup.

@Before
public void setup() {
    IConfigRegistry configRegistry = new ConfigRegistry();
    // 10 rows in fixture
    this.eventListFixture = GlazedLists.eventList(RowDataListFixture.getList(10));
    GlazedListsGridLayer<RowDataFixture> gridLayer = new GlazedListsGridLayer<>(this.eventListFixture, RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap(), configRegistry);
    this.nattable = new NatTableFixture(gridLayer, false);
    this.nattable.setConfigRegistry(configRegistry);
    this.selectionLayer = gridLayer.getBodyLayerStack().getSelectionLayer();
    this.bodyDataProvider = gridLayer.getBodyDataProvider();
    this.selectionProvider = new RowSelectionProvider<>(this.selectionLayer, this.bodyDataProvider);
    this.nattable.addConfiguration(new DefaultSortConfiguration());
    // Enable preserve selection on data update
    this.selectionLayer.setSelectionModel(new RowSelectionModel<>(this.selectionLayer, this.bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    // Enable test mode - events can be fired outside the Display thread
    gridLayer.getGlazedListsEventLayer().setTestMode(true);
    this.nattable.configure();
}
Also used : IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.DefaultSortConfiguration) NatTableFixture(org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.NatTableFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Before(org.junit.Before)

Example 32 with RowDataFixture

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.

the class FilterListDataProviderTest method testAddVisibleData.

@Test
public void testAddVisibleData() {
    RowDataFixture temp = RowDataListFixture.getList().get(8);
    this.values.add(8, temp);
    // now the AbstractFilterListDataProvider row count should be 10 again
    Assert.assertEquals(11, this.dataProvider.getRowCount());
    // as there is one invisible object before this position, the visible
    // row position is 7 again
    Assert.assertEquals(this.values.get(8), this.dataProvider.getRowObject(7));
    Assert.assertEquals(this.values.get(9), this.dataProvider.getRowObject(8));
    Assert.assertEquals(this.values.get(11), this.dataProvider.getRowObject(9));
}
Also used : RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Test(org.junit.Test)

Example 33 with RowDataFixture

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture 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 34 with RowDataFixture

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture in project nebula.widgets.nattable by eclipse.

the class PreserveSelectionModelStructuralChangeEventHandlerTest method shouldRetainRowSelectionOnMove.

@Test
public void shouldRetainRowSelectionOnMove() throws Exception {
    assertEquals(0, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(0, this.selectionLayer.getSelectedRowCount());
    this.nattable.doCommand(new SelectRowsCommand(this.nattable, 1, 1, false, false));
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    // Ford motor at top and selected
    assertEquals("B Ford Motor", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    RowDataFixture ford = getSelected();
    // move selected to the bottom
    this.listFixture.remove(ford);
    this.listFixture.add(ford);
    // fire event to trigger structural refresh
    this.bodyDataLayer.fireLayerEvent(new StructuralRefreshEvent(this.bodyDataLayer));
    // Tata motors at top but Ford motors still selected
    assertEquals("A Alphabet Co.", this.nattable.getDataValueByPosition(2, 1).toString());
    assertEquals("B Ford Motor", getSelected().getSecurity_description());
    assertEquals(1, this.selectionLayer.getFullySelectedRowPositions().length);
    assertEquals(1, this.selectionLayer.getSelectedRowCount());
    assertEquals(this.listFixture.size() - 1, this.selectionLayer.getFullySelectedRowPositions()[0]);
}
Also used : StructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.StructuralRefreshEvent) RowStructuralRefreshEvent(org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) SelectRowsCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand) Test(org.junit.Test)

Example 35 with RowDataFixture

use of org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture 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)

Aggregations

RowDataFixture (org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture)46 Test (org.junit.Test)24 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)18 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)13 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)13 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)13 Before (org.junit.Before)13 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)12 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)10 IRowIdAccessor (org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor)8 NatTableFixture (org.eclipse.nebula.widgets.nattable.test.fixture.NatTableFixture)8 LayerListenerFixture (org.eclipse.nebula.widgets.nattable.extension.glazedlists.fixture.LayerListenerFixture)6 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)5 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)5 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 RowStructuralRefreshEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowStructuralRefreshEvent)5 SelectRowsCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRowsCommand)5 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)4