Search in sources :

Example 1 with ColumnPositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate in project nebula.widgets.nattable by eclipse.

the class LayerCommandUtil method convertColumnPositionToTargetContext.

public static ColumnPositionCoordinate convertColumnPositionToTargetContext(ColumnPositionCoordinate columnPositionCoordinate, ILayer targetLayer) {
    if (columnPositionCoordinate != null) {
        ILayer layer = columnPositionCoordinate.getLayer();
        if (layer == targetLayer) {
            return columnPositionCoordinate;
        }
        int columnPosition = columnPositionCoordinate.getColumnPosition();
        int underlyingColumnPosition = layer.localToUnderlyingColumnPosition(columnPosition);
        if (underlyingColumnPosition < 0) {
            return null;
        }
        Collection<ILayer> underlyingLayers = layer.getUnderlyingLayersByColumnPosition(columnPosition);
        if (underlyingLayers != null) {
            for (ILayer underlyingLayer : underlyingLayers) {
                if (underlyingLayer != null) {
                    ColumnPositionCoordinate convertedColumnPositionCoordinate = convertColumnPositionToTargetContext(new ColumnPositionCoordinate(underlyingLayer, underlyingColumnPosition), targetLayer);
                    if (convertedColumnPositionCoordinate != null) {
                        return convertedColumnPositionCoordinate;
                    }
                }
            }
        }
    }
    return null;
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer)

Example 2 with ColumnPositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate in project nebula.widgets.nattable by eclipse.

the class ColumnReorderCommand method convertToTargetLayer.

@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
    ColumnPositionCoordinate targetFromColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(this.fromColumnPositionCoordinate, targetLayer);
    ColumnPositionCoordinate targetToColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(this.toColumnPositionCoordinate, targetLayer);
    if (targetFromColumnPositionCoordinate != null && targetToColumnPositionCoordinate != null) {
        this.fromColumnPositionCoordinate = targetFromColumnPositionCoordinate;
        this.toColumnPositionCoordinate = targetToColumnPositionCoordinate;
        return true;
    } else {
        return false;
    }
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)

Example 3 with ColumnPositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SelectRegionCommand method convertToTargetLayer.

@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
    PositionCoordinate sourceCoordinate = new PositionCoordinate(this.sourceLayer, this.region.x, this.region.y);
    PositionCoordinate targetCoordinate = LayerCommandUtil.convertPositionToTargetContext(sourceCoordinate, targetLayer);
    if (targetCoordinate != null) {
        this.sourceLayer = targetCoordinate.getLayer();
        this.region.x = targetCoordinate.columnPosition;
        this.region.y = targetCoordinate.rowPosition;
        if (this.anchorColumnPosition >= 0) {
            ColumnPositionCoordinate sourceColumn = new ColumnPositionCoordinate(this.sourceLayer, this.anchorColumnPosition);
            ColumnPositionCoordinate targetColumn = LayerCommandUtil.convertColumnPositionToTargetContext(sourceColumn, targetLayer);
            this.anchorColumnPosition = targetColumn.getColumnPosition();
        }
        if (this.anchorRowPosition >= 0) {
            RowPositionCoordinate sourceRow = new RowPositionCoordinate(this.sourceLayer, this.anchorRowPosition);
            RowPositionCoordinate targetRow = LayerCommandUtil.convertRowPositionToTargetContext(sourceRow, targetLayer);
            this.anchorRowPosition = targetRow.getRowPosition();
        }
        return true;
    }
    return false;
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Example 4 with ColumnPositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate in project nebula.widgets.nattable by eclipse.

the class SelectRowsCommand method convertToTargetLayer.

@Override
public boolean convertToTargetLayer(ILayer targetLayer) {
    ColumnPositionCoordinate targetColumnPositionCoordinate = LayerCommandUtil.convertColumnPositionToTargetContext(this.columnPositionCoordinate, targetLayer);
    if (targetColumnPositionCoordinate != null && targetColumnPositionCoordinate.getColumnPosition() >= 0 && super.convertToTargetLayer(targetLayer)) {
        this.columnPositionCoordinate = targetColumnPositionCoordinate;
        this.rowPositionCoordinateToMoveIntoViewport = LayerCommandUtil.convertRowPositionToTargetContext(this.rowPositionCoordinateToMoveIntoViewport, targetLayer);
        return true;
    }
    return false;
}
Also used : ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)

Example 5 with ColumnPositionCoordinate

use of org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate in project nebula.widgets.nattable by eclipse.

the class ViewportSelectColumnGroupCommandHandler method doCommand.

@Override
protected boolean doCommand(ViewportSelectColumnGroupCommand command) {
    int start = -1;
    int span = -1;
    // if a column group group is configured, we inspect the row position
    if (this.columnGroupGroupHeaderLayer != null && command.getNatTableRowPosition() == 0) {
        start = this.columnGroupGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
        span = this.columnGroupGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
    } else {
        start = this.columnGroupHeaderLayer.getStartPositionOfGroup(command.getColumnPosition());
        span = this.columnGroupHeaderLayer.getColumnSpan(command.getColumnPosition());
    }
    // the SelectRegionCommand needs to be executed on the underlying layer
    // this way the row range from 0 to MAX works, which otherwise breaks
    // when selecting a column group on scrolled state
    ILayer underlyingLayer = this.viewportLayer.getUnderlyingLayerByPosition(0, 0);
    ColumnPositionCoordinate underlyingStart = LayerCommandUtil.convertColumnPositionToTargetContext(new ColumnPositionCoordinate(this.viewportLayer, start), underlyingLayer);
    SelectRegionCommand regionCommand = new SelectRegionCommand(underlyingLayer, underlyingStart.getColumnPosition(), 0, span, Integer.MAX_VALUE, command.isWithShiftMask(), command.isWithControlMask());
    // set the anchor row position to the first row in the viewport
    RowPositionCoordinate underlyingRow = LayerCommandUtil.convertRowPositionToTargetContext(new RowPositionCoordinate(this.viewportLayer, 0), underlyingLayer);
    regionCommand.setAnchorRowPosition(underlyingRow.rowPosition);
    underlyingLayer.doCommand(regionCommand);
    return true;
}
Also used : SelectRegionCommand(org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand) ColumnPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate) ILayer(org.eclipse.nebula.widgets.nattable.layer.ILayer) RowPositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)

Aggregations

ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)6 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)2 ArrayList (java.util.ArrayList)1 PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)1 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)1