Search in sources :

Example 6 with ListDataProvider

use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.

the class SelectionUtilsTest method testGetEmptyListOnNoSelection.

@Test
public void testGetEmptyListOnNoSelection() {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    DataLayer dataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, false);
    assertNotNull(selected);
    assertEquals(0, selected.size());
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Test(org.junit.Test)

Example 7 with ListDataProvider

use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.

the class SelectionUtilsTest method testGetSingleItemsOnFullRowSelection.

@Test
public void testGetSingleItemsOnFullRowSelection() {
    List<RowDataFixture> listFixture = RowDataListFixture.getList(10);
    IRowDataProvider<RowDataFixture> bodyDataProvider = new ListDataProvider<RowDataFixture>(listFixture, new ReflectiveColumnPropertyAccessor<RowDataFixture>(RowDataListFixture.getPropertyNames()));
    DataLayer dataLayer = new DataLayer(bodyDataProvider);
    SelectionLayer selectionLayer = new SelectionLayer(dataLayer);
    selectionLayer.selectRow(0, 3, false, false);
    List<RowDataFixture> selected = SelectionUtils.getSelectedRowObjects(selectionLayer, bodyDataProvider, true);
    assertNotNull(selected);
    assertEquals(1, selected.size());
    assertEquals(listFixture.get(3), selected.get(0));
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Test(org.junit.Test)

Example 8 with ListDataProvider

use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.

the class RowSelectionTraversalTest 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<RowDataFixture>(RowDataListFixture.getList(10), new ReflectiveColumnPropertyAccessor<RowDataFixture>(propertyNames));
    this.selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
    this.selectionLayer.setSelectionModel(new RowSelectionModel<RowDataFixture>(this.selectionLayer, bodyDataProvider, new IRowIdAccessor<RowDataFixture>() {

        @Override
        public Serializable getRowId(RowDataFixture rowObject) {
            return rowObject.getSecurity_id();
        }
    }));
    this.viewportLayer = new ViewportLayer(this.selectionLayer);
}
Also used : IRowIdAccessor(org.eclipse.nebula.widgets.nattable.data.IRowIdAccessor) ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) Before(org.junit.Before)

Example 9 with ListDataProvider

use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.

the class ViewportIntegrationTest method shouldInitWithNoScroll.

@Test
public void shouldInitWithNoScroll() {
    List<String> contents = new ArrayList<>(Arrays.asList("one", "two", "three", "four", "five"));
    IDataProvider bodyDataProvider = new ListDataProvider<>(contents, new IColumnAccessor<String>() {

        @Override
        public Object getDataValue(String rowObject, int columnIndex) {
            return rowObject;
        }

        @Override
        public void setDataValue(String rowObject, int columnIndex, Object newValue) {
        // ignore
        }

        @Override
        public int getColumnCount() {
            return 1;
        }
    });
    SelectionLayer selectionLayer = new SelectionLayer(new DataLayer(bodyDataProvider));
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    IDataProvider colDataProvider = new DummyColumnHeaderDataProvider(bodyDataProvider);
    ColumnHeaderLayer colHeader = new ColumnHeaderLayer(new DataLayer(colDataProvider), viewportLayer, selectionLayer);
    IDataProvider rowDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    RowHeaderLayer rowHeaderLayer = new RowHeaderLayer(new DataLayer(rowDataProvider), viewportLayer, selectionLayer);
    CornerLayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(colDataProvider, rowDataProvider)), rowHeaderLayer, colHeader);
    GridLayer grid = new GridLayer(viewportLayer, colHeader, rowHeaderLayer, cornerLayer);
    // create the table with no scrollbars
    NatTable natTable = new NatTable(new Shell(), SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.DOUBLE_BUFFERED, grid);
    // this caused a NPE for scrollbar initialization
    natTable.setSize(600, 600);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ArrayList(java.util.ArrayList) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) DummyColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DummyColumnHeaderDataProvider) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) Shell(org.eclipse.swt.widgets.Shell) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) Test(org.junit.Test)

Example 10 with ListDataProvider

use of org.eclipse.nebula.widgets.nattable.data.ListDataProvider in project nebula.widgets.nattable by eclipse.

the class _509_SortHeaderLayerExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and
    // setting the ViewportLayer as underlying layer. But in this case using
    // the ViewportLayer
    // directly as body layer is also working.
    List<PersonWithAddress> data = PersonService.getPersonsWithAddress(10);
    IColumnPropertyAccessor<PersonWithAddress> accessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IDataProvider bodyDataProvider = new ListDataProvider<>(data, accessor);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(bodyDataLayer);
    ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
    SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    ILayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, viewportLayer, selectionLayer);
    ConfigRegistry configRegistry = new ConfigRegistry();
    SortHeaderLayer<PersonWithAddress> sortHeaderLayer = new SortHeaderLayer<>(columnHeaderLayer, new PersonWithAddressSortModel(data));
    // build the row header layer
    IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
    DataLayer rowHeaderDataLayer = new DefaultRowHeaderDataLayer(rowHeaderDataProvider);
    ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, viewportLayer, selectionLayer);
    // build the corner layer
    IDataProvider cornerDataProvider = new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider);
    DataLayer cornerDataLayer = new DataLayer(cornerDataProvider);
    ILayer cornerLayer = new CornerLayer(cornerDataLayer, rowHeaderLayer, sortHeaderLayer);
    // build the grid layer
    GridLayer gridLayer = new GridLayer(viewportLayer, sortHeaderLayer, rowHeaderLayer, cornerLayer);
    // turn the auto configuration off as we want to add custom
    // configurations
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // enable sorting on single click on the column header
    natTable.addConfiguration(new SingleClickSortConfiguration());
    natTable.configure();
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) ColumnHideShowLayer(org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) PersonWithAddress(org.eclipse.nebula.widgets.nattable.dataset.person.PersonWithAddress) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) SortHeaderLayer(org.eclipse.nebula.widgets.nattable.sort.SortHeaderLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Aggregations

ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)73 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)64 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)57 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)46 ViewportLayer (org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer)34 HashMap (java.util.HashMap)31 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)31 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)31 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)30 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)30 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)29 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)27 DefaultCornerDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider)25 RowHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer)25 CornerLayer (org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer)24 GridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer)24 DefaultRowHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider)23 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)21 DefaultRowHeaderDataLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer)21 GridLayout (org.eclipse.swt.layout.GridLayout)19