Search in sources :

Example 1 with ILayerCommand

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

the class ReorderColumnCommandTest method testReorderColumnCommand.

@Test
public void testReorderColumnCommand() {
    int fromColumnPosition = 4;
    int toColumnPosition = 1;
    ILayerCommand reorderColumnCommand = new ColumnReorderCommand(this.columnReorderLayer, fromColumnPosition, toColumnPosition);
    this.columnReorderLayer.doCommand(reorderColumnCommand);
    Assert.assertEquals(0, this.columnReorderLayer.getColumnIndexByPosition(0));
    Assert.assertEquals(4, this.columnReorderLayer.getColumnIndexByPosition(1));
    Assert.assertEquals(1, this.columnReorderLayer.getColumnIndexByPosition(2));
    Assert.assertEquals(2, this.columnReorderLayer.getColumnIndexByPosition(3));
    Assert.assertEquals(3, this.columnReorderLayer.getColumnIndexByPosition(4));
}
Also used : ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand) Test(org.junit.Test)

Example 2 with ILayerCommand

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

the class ReorderRowCommandTest method testReorderRowCommand.

@Test
public void testReorderRowCommand() {
    int fromRowPosition = 4;
    int toRowPosition = 1;
    ILayerCommand reorderRowCommand = new RowReorderCommand(this.rowReorderLayer, fromRowPosition, toRowPosition);
    this.rowReorderLayer.doCommand(reorderRowCommand);
    Assert.assertEquals(0, this.rowReorderLayer.getRowIndexByPosition(0));
    Assert.assertEquals(4, this.rowReorderLayer.getRowIndexByPosition(1));
    Assert.assertEquals(1, this.rowReorderLayer.getRowIndexByPosition(2));
    Assert.assertEquals(2, this.rowReorderLayer.getRowIndexByPosition(3));
    Assert.assertEquals(3, this.rowReorderLayer.getRowIndexByPosition(4));
}
Also used : ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand) Test(org.junit.Test)

Example 3 with ILayerCommand

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

the class ChooseColumnsFromCategoriesCommandHandler method itemsMoved.

/**
 * Moves the columns up or down by firing commands on the dialog.
 *
 * Individual columns are moved using the {@link ColumnReorderCommand}
 * Contiguously selected columns are moved using the
 * {@link MultiColumnReorderCommand}
 *
 * @param direction
 *            the direction to move
 * @param selectedPositions
 *            the column positions to move
 */
@Override
public void itemsMoved(MoveDirectionEnum direction, List<Integer> selectedPositions) {
    List<List<Integer>> fromPositions = PositionUtil.getGroupedByContiguous(selectedPositions);
    List<Integer> toPositions = getDestinationPositions(direction, fromPositions);
    for (int i = 0; i < fromPositions.size(); i++) {
        boolean multipleColumnsMoved = fromPositions.get(i).size() > 1;
        ILayerCommand command = null;
        if (!multipleColumnsMoved) {
            int fromPosition = fromPositions.get(i).get(0).intValue();
            int toPosition = toPositions.get(i);
            command = new ColumnReorderCommand(this.columnHideShowLayer, fromPosition, toPosition);
        } else if (multipleColumnsMoved) {
            command = new MultiColumnReorderCommand(this.columnHideShowLayer, fromPositions.get(i), toPositions.get(i));
        }
        this.columnHideShowLayer.doCommand(command);
    }
    refreshDialog();
}
Also used : MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ArrayList(java.util.ArrayList) List(java.util.List) ColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand) MultiColumnReorderCommand(org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand) ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand)

Example 4 with ILayerCommand

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

the class DimensionallyDependentLayer method doCommand.

// Commands
@Override
public boolean doCommand(ILayerCommand command) {
    // Invoke command handler(s) on the Dimensionally dependent layer
    ILayerCommand clonedCommand = command.cloneCommand();
    if (super.doCommand(clonedCommand)) {
        return true;
    }
    // that no other regions are affected
    if (!(command instanceof AbstractRegionCommand)) {
        clonedCommand = command.cloneCommand();
        if (this.horizontalLayerDependency.doCommand(clonedCommand)) {
            return true;
        }
        clonedCommand = command.cloneCommand();
        if (this.verticalLayerDependency.doCommand(clonedCommand)) {
            return true;
        }
    }
    return this.baseLayer.doCommand(command);
}
Also used : AbstractRegionCommand(org.eclipse.nebula.widgets.nattable.command.AbstractRegionCommand) ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand)

Example 5 with ILayerCommand

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

the class CompositeLayer method doCommandOnChildLayers.

protected boolean doCommandOnChildLayers(ILayerCommand command) {
    for (int layoutX = 0; layoutX < this.layoutXCount; layoutX++) {
        for (int layoutY = 0; layoutY < this.layoutYCount; layoutY++) {
            ILayer childLayer = this.childLayerLayout[layoutX][layoutY];
            ILayerCommand childCommand = command.cloneCommand();
            if (childLayer.doCommand(childCommand)) {
                return true;
            }
        }
    }
    return false;
}
Also used : Point(org.eclipse.swt.graphics.Point) ILayerCommand(org.eclipse.nebula.widgets.nattable.command.ILayerCommand)

Aggregations

ILayerCommand (org.eclipse.nebula.widgets.nattable.command.ILayerCommand)11 Test (org.junit.Test)6 ColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.ColumnReorderCommand)2 LayerCommandFixture (org.eclipse.nebula.widgets.nattable.test.fixture.command.LayerCommandFixture)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AbstractRegionCommand (org.eclipse.nebula.widgets.nattable.command.AbstractRegionCommand)1 MultiColumnReorderCommand (org.eclipse.nebula.widgets.nattable.reorder.command.MultiColumnReorderCommand)1 ClearAllSelectionsCommand (org.eclipse.nebula.widgets.nattable.selection.command.ClearAllSelectionsCommand)1 Point (org.eclipse.swt.graphics.Point)1