Search in sources :

Example 31 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class FillHandlePasteCommandHandler method doCommand.

@Override
public boolean doCommand(ILayer targetLayer, FillHandlePasteCommand command) {
    if (this.clipboard.getCopiedCells() != null) {
        int pasteColumn = -1;
        int pasteRow = -1;
        int pasteWidth = this.clipboard.getCopiedCells().length;
        int pasteHeight = this.clipboard.getCopiedCells()[0].length;
        Rectangle handleRegion = this.selectionLayer.getFillHandleRegion();
        if (handleRegion != null) {
            pasteColumn = handleRegion.x;
            pasteRow = handleRegion.y;
            pasteWidth = handleRegion.width;
            pasteHeight = handleRegion.height;
        } else {
            PositionCoordinate coord = this.selectionLayer.getSelectionAnchor();
            pasteColumn = coord.getColumnPosition();
            pasteRow = coord.getRowPosition();
        }
        int pasteStartColumn = pasteColumn;
        int rowStartAdjustment = 0;
        if (command.direction == MoveDirectionEnum.UP) {
            rowStartAdjustment = pasteHeight % this.clipboard.getCopiedCells().length;
        }
        int columnStartAdjustment = 0;
        if (command.direction == MoveDirectionEnum.LEFT) {
            columnStartAdjustment = pasteWidth % this.clipboard.getCopiedCells()[0].length;
        }
        for (int i = 0; i < pasteHeight; i++) {
            ILayerCell[] cells = this.clipboard.getCopiedCells()[(i + rowStartAdjustment) % this.clipboard.getCopiedCells().length];
            for (int j = 0; j < pasteWidth; j++) {
                ILayerCell cell = cells[(j + columnStartAdjustment) % this.clipboard.getCopiedCells()[0].length];
                Object cellValue = getPasteValue(cell, command, pasteColumn, pasteRow);
                if (EditUtils.isCellEditable(this.selectionLayer, command.configRegistry, new PositionCoordinate(this.selectionLayer, pasteColumn, pasteRow))) {
                    this.selectionLayer.doCommand(new UpdateDataCommand(this.selectionLayer, pasteColumn, pasteRow, cellValue));
                }
                pasteColumn++;
                if (pasteColumn >= this.selectionLayer.getColumnCount()) {
                    break;
                }
            }
            pasteRow++;
            pasteColumn = pasteStartColumn;
        }
    }
    return true;
}
Also used : Rectangle(org.eclipse.swt.graphics.Rectangle) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 32 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class FilterRowHeaderCompositeTest method shouldHandleClearFilterCommand.

@Test
public void shouldHandleClearFilterCommand() throws Exception {
    Assert.assertEquals(13, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 1, 2, "ford"));
    Assert.assertEquals(1, this.filterList.size());
    this.layerUnderTest.doCommand(new ClearFilterCommand(this.layerUnderTest, 1));
    Assert.assertEquals(13, this.filterList.size());
    this.listener.containsInstanceOf(RowStructuralRefreshEvent.class);
}
Also used : ClearFilterCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 33 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class FilterRowDataLayerTest method shouldHandleClearFilterCommand.

@Test
public void shouldHandleClearFilterCommand() throws Exception {
    assertEquals(13, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 1, 0, "ford"));
    assertEquals(1, this.filterList.size());
    this.layerUnderTest.doCommand(new ClearFilterCommand(this.layerUnderTest, 1));
    assertEquals(13, this.filterList.size());
    this.listener.containsInstanceOf(RowStructuralRefreshEvent.class);
}
Also used : ClearFilterCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 34 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class FilterRowDataLayerTest method shouldHandleTheClearAllFiltersCommand.

@Test
public void shouldHandleTheClearAllFiltersCommand() throws Exception {
    assertEquals(13, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 1, 0, "ford"));
    assertEquals(1, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 0, 0, "XXX"));
    assertEquals(0, this.filterList.size());
    this.layerUnderTest.doCommand(new ClearAllFiltersCommand());
    assertEquals(13, this.filterList.size());
    this.listener.containsInstanceOf(RowStructuralRefreshEvent.class);
}
Also used : ClearAllFiltersCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Example 35 with UpdateDataCommand

use of org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand in project nebula.widgets.nattable by eclipse.

the class FilterRowHeaderCompositeTest method shouldHandleTheClearAllFiltersCommand.

@Test
public void shouldHandleTheClearAllFiltersCommand() throws Exception {
    Assert.assertEquals(13, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 1, 2, "ford"));
    Assert.assertEquals(1, this.filterList.size());
    this.layerUnderTest.doCommand(new UpdateDataCommand(this.layerUnderTest, 0, 2, "XXX"));
    Assert.assertEquals(0, this.filterList.size());
    this.layerUnderTest.doCommand(new ClearAllFiltersCommand());
    Assert.assertEquals(13, this.filterList.size());
    this.listener.containsInstanceOf(RowStructuralRefreshEvent.class);
}
Also used : ClearAllFiltersCommand(org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand) UpdateDataCommand(org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand) Test(org.junit.Test)

Aggregations

UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)63 Test (org.junit.Test)52 RowDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowDeleteEvent)10 DiscardDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.DiscardDataChangesCommand)7 SaveDataChangesCommand (org.eclipse.nebula.widgets.nattable.datachange.command.SaveDataChangesCommand)6 Person (org.eclipse.nebula.widgets.nattable.dataset.person.Person)6 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)5 Date (java.util.Date)4 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ColumnDeleteEvent (org.eclipse.nebula.widgets.nattable.layer.event.ColumnDeleteEvent)4 RowInsertEvent (org.eclipse.nebula.widgets.nattable.layer.event.RowInsertEvent)4 StructuralRefreshCommand (org.eclipse.nebula.widgets.nattable.command.StructuralRefreshCommand)3 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)2 DataUpdateEvent (org.eclipse.nebula.widgets.nattable.edit.event.DataUpdateEvent)2 ClearAllFiltersCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearAllFiltersCommand)2 ClearFilterCommand (org.eclipse.nebula.widgets.nattable.filterrow.command.ClearFilterCommand)2 CellVisualChangeEvent (org.eclipse.nebula.widgets.nattable.layer.event.CellVisualChangeEvent)2