use of org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent in project nebula.widgets.nattable by eclipse.
the class DataChangeLayerIdIndexTest method shouldUpdateChangeOnColumnInsert.
@Test
public void shouldUpdateChangeOnColumnInsert() {
assertEquals("Simpson", this.dataLayer.getDataValue(1, 2));
this.dataChangeLayer.doCommand(new UpdateDataCommand(this.dataChangeLayer, 1, 2, "Muntz"));
assertEquals("Muntz", this.dataLayer.getDataValue(1, 2));
// simulate column deletion
this.dataLayer.fireLayerEvent(new ColumnInsertEvent(this.dataLayer, 0));
assertFalse("Dirty label set", this.dataChangeLayer.getConfigLabelsByPosition(1, 2).hasLabel(DataChangeLayer.DIRTY));
assertTrue("Dirty label not set", this.dataChangeLayer.getConfigLabelsByPosition(2, 2).hasLabel(DataChangeLayer.DIRTY));
assertFalse("Column 1 is dirty", this.dataChangeLayer.isColumnDirty(1));
assertTrue("Column 2 is not dirty", this.dataChangeLayer.isColumnDirty(2));
assertTrue("Row 2 is not dirty", this.dataChangeLayer.isRowDirty(2));
assertTrue("Cell is not dirty", this.dataChangeLayer.isCellDirty(2, 2));
assertFalse("changed columns are empty", this.dataChangeLayer.changedColumns.isEmpty());
assertFalse("changed rows are empty", this.dataChangeLayer.changedRows.isEmpty());
assertFalse("changes are empty", this.dataChangeLayer.dataChanges.isEmpty());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingMultipleColumn.
@Test
public void shouldUpdateRenamedColumnOnAddingMultipleColumn() {
this.natTableFixture.doCommand(new TurnViewportOffCommand());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
// simulate deletion of a column
this.provider.setColumnCount(this.provider.getColumnCount() + 3);
this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), new Range(1, 4)));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(8, 0).toString());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent in project nebula.widgets.nattable by eclipse.
the class RenameColumnIntegrationTest method shouldUpdateRenamedColumnOnAddingOneColumn.
@Test
public void shouldUpdateRenamedColumnOnAddingOneColumn() {
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
this.natTableFixture.doCommand(new RenameColumnHeaderCommand(this.natTableFixture, 5, TEST_COLUMN_NAME));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(5, 0).toString());
// simulate deletion of a column
this.provider.setColumnCount(this.provider.getColumnCount() + 1);
this.grid.getColumnHeaderDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 0));
assertEquals(TEST_COLUMN_NAME, this.natTableFixture.getDataValueByPosition(6, 0).toString());
assertEquals("Column 5", this.natTableFixture.getDataValueByPosition(5, 0).toString());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent in project nebula.widgets.nattable by eclipse.
the class ColumnStructuralChangeEventIntegrationTest method shouldUpdateReorderOnInsertAndDelete.
@Test
public void shouldUpdateReorderOnInsertAndDelete() {
DefaultBodyLayerStack body = this.grid.getBodyLayer();
ColumnReorderLayer reorderLayer = body.getColumnReorderLayer();
body.doCommand(new ColumnReorderCommand(body, 3, 6));
body.doCommand(new ColumnReorderCommand(body, 3, 5));
assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
this.provider.setColumnCount(7);
this.grid.getBodyDataLayer().fireLayerEvent(new ColumnInsertEvent(this.grid.getBodyDataLayer(), 3));
assertEquals("[0, 1, 2, 3, 6, 5, 4]", reorderLayer.getColumnIndexOrder().toString());
this.provider.setColumnCount(6);
this.grid.getBodyDataLayer().fireLayerEvent(new ColumnDeleteEvent(this.grid.getBodyDataLayer(), 3));
assertEquals("[0, 1, 2, 5, 4, 3]", reorderLayer.getColumnIndexOrder().toString());
}
use of org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent in project nebula.widgets.nattable by eclipse.
the class _304_DynamicColumnExample method createExampleControl.
@Override
public Control createExampleControl(Composite parent) {
// start with 3 columns
this.columns.add("Column_0");
this.columns.add("Column_1");
this.columns.add("Column_2");
this.values.add(createValueRow("Homer"));
this.values.add(createValueRow("Marge"));
this.values.add(createValueRow("Bart"));
this.values.add(createValueRow("Lisa"));
this.values.add(createValueRow("Maggie"));
Composite panel = new Composite(parent, SWT.NONE);
panel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(panel);
Composite gridPanel = new Composite(panel, SWT.NONE);
gridPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(gridPanel);
Composite buttonPanel = new Composite(panel, SWT.NONE);
buttonPanel.setLayout(new GridLayout());
GridDataFactory.fillDefaults().grab(true, true).applyTo(buttonPanel);
ConfigRegistry configRegistry = new ConfigRegistry();
// create the body layer stack
IDataProvider bodyDataProvider = new ListDataProvider<>(this.values, new MyColumnPropertyAccessor());
final DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
DefaultBodyLayerStack bodyLayerStack = new DefaultBodyLayerStack(bodyDataLayer);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new SimpleColumnHeaderDataProvider();
ILayer columnHeaderLayer = new ColumnHeaderLayer(new DataLayer(columnHeaderDataProvider), bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// create the row header layer stack
IDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(bodyDataProvider);
ILayer rowHeaderLayer = new RowHeaderLayer(new DefaultRowHeaderDataLayer(new DefaultRowHeaderDataProvider(bodyDataProvider)), bodyLayerStack.getViewportLayer(), bodyLayerStack.getSelectionLayer());
// 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(bodyLayerStack, columnHeaderLayer, rowHeaderLayer, cornerLayer);
final NatTable natTable = new NatTable(gridPanel, gridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
natTable.addConfiguration(new HeaderMenuConfiguration(natTable));
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
Button addColumnButton = new Button(buttonPanel, SWT.PUSH);
addColumnButton.setText("Add Column");
addColumnButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String newColumn = "Column_" + _304_DynamicColumnExample.this.columns.size();
_304_DynamicColumnExample.this.columns.add(newColumn);
for (Map<String, String> value : _304_DynamicColumnExample.this.values) {
String prefix = value.get("Column_0");
prefix = prefix.substring(0, prefix.indexOf("_"));
value.put(newColumn, prefix + "_" + (_304_DynamicColumnExample.this.columns.size() - 1));
}
bodyDataLayer.fireLayerEvent(new ColumnInsertEvent(bodyDataLayer, _304_DynamicColumnExample.this.columns.size() - 1));
}
});
return panel;
}
Aggregations