Search in sources :

Example 11 with ColumnInsertEvent

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());
}
Also used : UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Test(org.junit.Test)

Example 12 with ColumnInsertEvent

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());
}
Also used : RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) TurnViewportOffCommand(org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand) Test(org.junit.Test)

Example 13 with ColumnInsertEvent

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());
}
Also used : RenameColumnHeaderCommand(org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Test(org.junit.Test)

Example 14 with ColumnInsertEvent

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());
}
Also used : ColumnDeleteEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent) ColumnReorderLayer(org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) Test(org.junit.Test)

Example 15 with ColumnInsertEvent

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;
}
Also used : ListDataProvider(org.eclipse.nebula.widgets.nattable.data.ListDataProvider) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) HeaderMenuConfiguration(org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration) DefaultCornerDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) Button(org.eclipse.swt.widgets.Button) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DefaultRowHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultRowHeaderDataLayer) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) ColumnInsertEvent(org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent) Composite(org.eclipse.swt.widgets.Composite) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DefaultRowHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider) RowHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.RowHeaderLayer) CornerLayer(org.eclipse.nebula.widgets.nattable.grid.layer.CornerLayer) SingleClickSortConfiguration(org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration) GridLayer(org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer) DefaultBodyLayerStack(org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ColumnInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnInsertEvent)15 Test (org.junit.Test)13 DefaultBodyLayerStack (org.eclipse.nebula.widgets.nattable.layer.stack.DefaultBodyLayerStack)7 ColumnHideShowLayer (org.eclipse.nebula.widgets.nattable.hideshow.ColumnHideShowLayer)4 MultiColumnHideCommand (org.eclipse.nebula.widgets.nattable.hideshow.command.MultiColumnHideCommand)4 ColumnReorderLayer (org.eclipse.nebula.widgets.nattable.reorder.ColumnReorderLayer)4 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)4 RenameColumnHeaderCommand (org.eclipse.nebula.widgets.nattable.columnRename.RenameColumnHeaderCommand)3 ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2 TurnViewportOffCommand (org.eclipse.nebula.widgets.nattable.print.command.TurnViewportOffCommand)2 SingleClickSortConfiguration (org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration)2 HeaderMenuConfiguration (org.eclipse.nebula.widgets.nattable.ui.menu.HeaderMenuConfiguration)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2