use of org.eclipse.nebula.widgets.nattable.extension.e4.selection.E4SelectionListener in project nebula.widgets.nattable by eclipse.
the class SelectionListenerExample method postConstruct.
@PostConstruct
public void postConstruct(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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
final IRowDataProvider<Person> bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final SelectionLayer selectionLayer = new SelectionLayer(bodyDataLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// create a E4SelectionListener and configure it for providing selection
// on cell selection
E4SelectionListener<Person> esl = new E4SelectionListener<>(service, selectionLayer, bodyDataProvider);
esl.setFullySelectedRowsOnly(false);
esl.setHandleSameRowSelection(false);
selectionLayer.addLayerListener(esl);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), viewportLayer, selectionLayer);
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), viewportLayer, selectionLayer);
// create the corner layer stack
ILayer cornerLayer = new CornerLayer(new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)), rowHeaderLayer, columnHeaderLayer);
// create the grid layer composed with the prior created layer stacks
GridLayer gridLayer = new GridLayer(viewportLayer, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(parent, gridLayer);
natTable.setData("org.eclipse.e4.ui.css.CssClassName", "modern");
parent.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
outputArea = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
outputArea.setEditable(false);
GridDataFactory.fillDefaults().grab(true, false).hint(0, 100).align(SWT.FILL, SWT.BEGINNING).applyTo(outputArea);
showSourceLinks(parent, getClass().getName());
}
Aggregations