use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayerTest method getConfigLabelsByPosition.
@Test
public void getConfigLabelsByPosition() throws Exception {
DataLayer underlyingLayer = new DataLayerFixture();
this.columnReorderLayer = new ColumnReorderLayer(underlyingLayer);
ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(underlyingLayer);
registerCellStyleAccumulators(underlyingLayer, columnLabelAccumulator);
columnLabelAccumulator.registerColumnOverrides(4, "INDEX_4_LABEL");
List<String> labelsForIndex4 = this.columnReorderLayer.getConfigLabelsByPosition(4, 0).getLabels();
assertEquals(2, labelsForIndex4.size());
assertEquals("INDEX_4_LABEL", labelsForIndex4.get(0));
assertEquals("EVEN_BODY", labelsForIndex4.get(1));
// 0 1 2 3 4 - see DataLayerFixture
this.columnReorderLayer.reorderColumnPosition(0, 5);
// Index: 1 2 3 4 0 Width: 100 35 100 80 150
labelsForIndex4 = this.columnReorderLayer.getConfigLabelsByPosition(3, 0).getLabels();
assertEquals(2, labelsForIndex4.size());
assertEquals("INDEX_4_LABEL", labelsForIndex4.get(0));
assertEquals("EVEN_BODY", labelsForIndex4.get(1));
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class SummaryRowIntegrationTest method defaultConfigLabelsAreAdded.
@Test
public void defaultConfigLabelsAreAdded() throws Exception {
ColumnOverrideLabelAccumulator labelAcc = new ColumnOverrideLabelAccumulator(this.layerStackWithSummary);
labelAcc.registerColumnOverrides(0, "myLabel");
((ViewportLayer) this.layerStackWithSummary).setConfigLabelAccumulator(labelAcc);
LabelStack configLabels = this.natTable.getConfigLabelsByPosition(0, 4);
List<String> labels = configLabels.getLabels();
assertEquals(3, labels.size());
assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_COLUMN_CONFIG_LABEL_PREFIX + 0, labels.get(0));
assertEquals(SummaryRowLayer.DEFAULT_SUMMARY_ROW_CONFIG_LABEL, labels.get(1));
assertEquals("myLabel", labels.get(2));
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class TickUpdateCommandHandlerTest method registerCellStyleAccumulators.
private void registerCellStyleAccumulators(DataLayer bodyDataLayer) {
AggregateConfigLabelAccumulator aggregrateConfigLabelAccumulator = new AggregateConfigLabelAccumulator();
this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(new DataLayerFixture());
aggregrateConfigLabelAccumulator.add(this.columnLabelAccumulator, new AlternatingRowConfigLabelAccumulator());
bodyDataLayer.setConfigLabelAccumulator(aggregrateConfigLabelAccumulator);
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class NatTableFixture method getColumnLabelAccumulator.
private ColumnOverrideLabelAccumulator getColumnLabelAccumulator(DataLayer dataLayer) {
if (this.columnLabelAccumulator == null) {
this.columnLabelAccumulator = new ColumnOverrideLabelAccumulator(dataLayer);
dataLayer.setConfigLabelAccumulator(this.columnLabelAccumulator);
}
return this.columnLabelAccumulator;
}
use of org.eclipse.nebula.widgets.nattable.layer.cell.ColumnOverrideLabelAccumulator in project nebula.widgets.nattable by eclipse.
the class _5016_DataChangeLayerExample 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");
IColumnPropertyAccessor<Person> columnPropertyAccessor = new ReflectiveColumnPropertyAccessor<>(propertyNames);
final List<Person> data = PersonService.getPersons(10);
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<>(data, columnPropertyAccessor);
DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
final ColumnOverrideLabelAccumulator columnLabelAccumulator = new ColumnOverrideLabelAccumulator(bodyDataLayer);
bodyDataLayer.setConfigLabelAccumulator(columnLabelAccumulator);
registerColumnLabels(columnLabelAccumulator);
// add a DataChangeLayer that tracks data changes but directly updates
// the underlying data model
DataChangeLayer dataChangeLayer = new DataChangeLayer(bodyDataLayer, new PointKeyHandler(), false);
// we register a special command handler to perform custom changes on
// save
dataChangeLayer.registerCommandHandler(new SaveDataChangesCommandHandler(dataChangeLayer) {
@Override
public boolean doCommand(ILayer targetLayer, SaveDataChangesCommand command) {
if (MessageDialog.openQuestion(parent.getShell(), "Save data", "Do you really want to save to database?")) {
// you would implement the storage to database here
System.out.println("We save the data to the database");
return super.doCommand(targetLayer, command);
}
return true;
}
});
ColumnReorderLayer columnReorderLayer = new ColumnReorderLayer(dataChangeLayer);
ColumnHideShowLayer columnHideShowLayer = new ColumnHideShowLayer(columnReorderLayer);
SelectionLayer selectionLayer = new SelectionLayer(columnHideShowLayer);
ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
// 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 DataLayer(rowHeaderDataProvider, 40, 20), 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);
NatTable natTable = new NatTable(parent, gridLayer, false);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new EditorConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable) {
@Override
protected PopupMenuBuilder createCornerMenu(NatTable natTable) {
return super.createCornerMenu(natTable).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Discard changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new DiscardDataChangesCommand());
}
});
}
}).withMenuItemProvider(new IMenuItemProvider() {
@Override
public void addMenuItem(NatTable natTable, Menu popupMenu) {
MenuItem export = new MenuItem(popupMenu, SWT.PUSH);
export.setText("Save changes");
export.setEnabled(true);
export.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
natTable.doCommand(new SaveDataChangesCommand());
}
});
}
});
}
});
natTable.configure();
return natTable;
}
Aggregations