Search in sources :

Example 11 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class BlinkingGridExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    final String[] propertyNames = RowDataListFixture.getPropertyNames();
    final Map<String, String> propertyToLabelMap = RowDataListFixture.getPropertyToLabelMap();
    ConfigRegistry configRegistry = new ConfigRegistry();
    // Body
    LinkedList<BlinkingRowDataFixture> rowData = new LinkedList<>();
    EventList<BlinkingRowDataFixture> eventList = GlazedLists.eventList(rowData);
    ObservableElementList<BlinkingRowDataFixture> observableElementList = new ObservableElementList<>(eventList, GlazedLists.beanConnector(BlinkingRowDataFixture.class));
    IColumnPropertyAccessor<BlinkingRowDataFixture> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    this.bodyDataProvider = new ListDataProvider<>(observableElementList, columnPropertyAccessor);
    final DataLayer bodyLayer = new DataLayer(this.bodyDataProvider);
    GlazedListsEventLayer<BlinkingRowDataFixture> glazedListsEventLayer = new GlazedListsEventLayer<>(bodyLayer, observableElementList);
    BlinkLayer<BlinkingRowDataFixture> blinkingLayer = new BlinkLayer<>(glazedListsEventLayer, this.bodyDataProvider, new IRowIdAccessor<BlinkingRowDataFixture>() {

        @Override
        public Serializable getRowId(BlinkingRowDataFixture rowObject) {
            return rowObject.getSecurity_description();
        }
    }, columnPropertyAccessor, configRegistry);
    registerBlinkingConfigCells(configRegistry);
    insertRowData(glazedListsEventLayer, this.bodyDataProvider);
    // Column header
    final DefaultColumnHeaderDataProvider defaultColumnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    // Row header
    final DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(this.bodyDataProvider);
    // Corner
    final DefaultCornerDataProvider cornerDataProvider = new DefaultCornerDataProvider(defaultColumnHeaderDataProvider, rowHeaderDataProvider);
    // Grid
    GridLayer gridLayer = new DefaultGridLayer(blinkingLayer, new DefaultColumnHeaderDataLayer(defaultColumnHeaderDataProvider), new DefaultRowHeaderDataLayer(rowHeaderDataProvider), new DataLayer(cornerDataProvider));
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.setConfigRegistry(configRegistry);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.configure();
    return natTable;
}
Also used : Serializable(java.io.Serializable) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) GlazedListsEventLayer(org.eclipse.nebula.widgets.nattable.extension.glazedlists.GlazedListsEventLayer) ObservableElementList(ca.odell.glazedlists.ObservableElementList) 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) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) LinkedList(java.util.LinkedList) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) BlinkingRowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.BlinkingRowDataFixture) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) BlinkLayer(org.eclipse.nebula.widgets.nattable.blink.BlinkLayer)

Example 12 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class Derived_or_computed_column_data method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    List<Person> myList = new ArrayList<>();
    myList.add(new Person("Homer", "Simpson", "Sargeant", 1234567890L));
    myList.add(new Person("Waylon", "Smithers", "Admiral", 6666666666L));
    myList.add(new Person("Bart", "Smithers", "General", 9125798342L));
    myList.add(new Person("Nelson", "Muntz", "Private", 0000000001L));
    myList.add(new Person("John", "Frink", "Lieutenant", 3141592654L));
    String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
    final IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    // Add derived 'fullName' column
    final IColumnPropertyAccessor<Person> derivedColumnPropertyAccessor = new IColumnPropertyAccessor<Person>() {

        @Override
        public Object getDataValue(Person rowObject, int columnIndex) {
            if (columnIndex < columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getDataValue(rowObject, columnIndex);
            } else if (columnIndex == columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getDataValue(rowObject, 0) + " " + columnPropertyAccessor.getDataValue(rowObject, 1);
            } else {
                return null;
            }
        }

        @Override
        public void setDataValue(Person rowObject, int columnIndex, Object newValue) {
            columnPropertyAccessor.setDataValue(rowObject, columnIndex, newValue);
        }

        @Override
        public int getColumnCount() {
            return columnPropertyAccessor.getColumnCount() + 1;
        }

        @Override
        public String getColumnProperty(int columnIndex) {
            if (columnIndex < columnPropertyAccessor.getColumnCount()) {
                return columnPropertyAccessor.getColumnProperty(columnIndex);
            } else if (columnIndex == columnPropertyAccessor.getColumnCount()) {
                return "fullName";
            } else {
                return null;
            }
        }

        @Override
        public int getColumnIndex(String propertyName) {
            if ("fullName".equals(propertyName)) {
                return columnPropertyAccessor.getColumnCount() + 1;
            } else {
                return columnPropertyAccessor.getColumnIndex(propertyName);
            }
        }
    };
    final IDataProvider listDataProvider = new ListDataProvider<>(myList, derivedColumnPropertyAccessor);
    // Column header data provider includes derived properties
    IDataProvider columnHeaderDataProvider = new IDataProvider() {

        @Override
        public Object getDataValue(int columnIndex, int rowIndex) {
            return derivedColumnPropertyAccessor.getColumnProperty(columnIndex);
        }

        @Override
        public void setDataValue(int columnIndex, int rowIndex, Object newValue) {
        // noop
        }

        @Override
        public int getColumnCount() {
            return derivedColumnPropertyAccessor.getColumnCount();
        }

        @Override
        public int getRowCount() {
            return 1;
        }
    };
    ILayer layer = new DefaultGridLayer(listDataProvider, columnHeaderDataProvider);
    return new NatTable(parent, layer);
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) ArrayList(java.util.ArrayList) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) IColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 13 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class Get_and_set_selected_objects method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    Person homer = new Person("Homer", "Simpson", "Sargeant", 1234567890L);
    Person smithers = new Person("Waylon", "Smithers", "Admiral", 6666666666L);
    Person bart = new Person("Bart", "Smithers", "General", 9125798342L);
    Person nelson = new Person("Nelson", "Muntz", "Private", 0000000001L);
    Person frink = new Person("John", "Frink", "Lieutenant", 3141592654L);
    List<Person> myList = new ArrayList<>();
    myList.add(homer);
    myList.add(smithers);
    myList.add(bart);
    myList.add(nelson);
    myList.add(frink);
    String[] propertyNames = { "firstName", "lastName", "rank", "serialNumber" };
    IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
    IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(myList, columnPropertyAccessor);
    DefaultGridLayer gridLayer = new DefaultGridLayer(bodyDataProvider, new DefaultColumnHeaderDataProvider(propertyNames));
    NatTable natTable = new NatTable(parent, gridLayer);
    ISelectionProvider selectionProvider = new RowSelectionProvider<>(gridLayer.getBodyLayer().getSelectionLayer(), bodyDataProvider, // Provides rows where any cell in the row is selected
    false);
    selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            System.out.println("Selection changed:");
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            @SuppressWarnings("rawtypes") Iterator it = selection.iterator();
            while (it.hasNext()) {
                System.out.println("  " + it.next());
            }
        }
    });
    // Programmatically select a few rows
    selectionProvider.setSelection(new StructuredSelection(new Person[] { homer, smithers, nelson }));
    // I changed my mind. Select a few other rows
    selectionProvider.setSelection(new StructuredSelection(new Person[] { bart, frink }));
    return natTable;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RowSelectionProvider(org.eclipse.nebula.widgets.nattable.selection.RowSelectionProvider) ReflectiveColumnPropertyAccessor(org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) Iterator(java.util.Iterator) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 14 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class TableDecorationConfiguration method createNatTable.

private void createNatTable(Composite parent, boolean paintDecorationDependent) {
    String[] propertyNames = { "columnOneNumber", "columnTwoNumber", "columnThreeNumber", "columnFourNumber", "columnFiveNumber", "columnSixNumber", "columnSevenNumber", "columnEightNumber" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("columnOneNumber", "C 1");
    propertyToLabelMap.put("columnTwoNumber", "C 2");
    propertyToLabelMap.put("columnThreeNumber", "C 3");
    propertyToLabelMap.put("columnFourNumber", "C 4");
    propertyToLabelMap.put("columnFiveNumber", "C 5");
    propertyToLabelMap.put("columnSixNumber", "C 6");
    propertyToLabelMap.put("columnSevenNumber", "C 7");
    propertyToLabelMap.put("columnEightNumber", "C 8");
    DefaultGridLayer gridLayer = new DefaultGridLayer(createNumberValuesList(), propertyNames, propertyToLabelMap);
    DataLayer bodyDataLayer = (DataLayer) gridLayer.getBodyDataLayer();
    bodyDataLayer.setDefaultRowHeight(40);
    bodyDataLayer.setDefaultColumnWidth(40);
    final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
    bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
    registerColumnLabels(columnLabelAccumulator);
    NatTable natTable = new NatTable(parent, gridLayer, false);
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    natTable.addConfiguration(new TableDecorationConfiguration(paintDecorationDependent));
    natTable.configure();
    GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
}
Also used : DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) HashMap(java.util.HashMap) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnOverrideLabelAccumulator(org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)

Example 15 with DefaultGridLayer

use of org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer in project nebula.widgets.nattable by eclipse.

the class ListDataProviderPerformanceTest method performanceOfListDataProvider.

// Bench marked ~ 65 milliseconds. Intel 2GHZ, 2GB Ram
@Test
public void performanceOfListDataProvider() throws Exception {
    List<RowDataFixture> largeList = RowDataListFixture.getList(26000);
    Assert.assertTrue(largeList.size() > 25000);
    this.layer = new DefaultGridLayer(largeList, RowDataListFixture.getPropertyNames(), RowDataListFixture.getPropertyToLabelMap());
}
Also used : RowDataFixture(org.eclipse.nebula.widgets.nattable.dataset.fixture.data.RowDataFixture) DefaultGridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer) Test(org.junit.Test)

Aggregations

DefaultGridLayer (org.eclipse.nebula.widgets.nattable.grid.layer.DefaultGridLayer)29 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)17 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)17 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)16 HashMap (java.util.HashMap)11 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)10 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)10 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)9 ColumnOverrideLabelAccumulator (org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator)9 Test (org.junit.Test)8 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)7 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)7 ReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ReflectiveColumnPropertyAccessor)5 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)4 ExtendedPersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress)4 ArrayList (java.util.ArrayList)3 IClientAreaProvider (org.eclipse.nebula.widgets.nattable.util.IClientAreaProvider)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Before (org.junit.Before)3 ObservableElementList (ca.odell.glazedlists.ObservableElementList)2