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;
}
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);
}
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;
}
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);
}
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());
}
Aggregations