Search in sources :

Example 86 with PositionCoordinate

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

the class CompositeFreezeLayer method loadState.

@Override
public void loadState(String prefix, Properties properties) {
    String property = properties.getProperty(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION);
    PositionCoordinate topLeftPosition = null;
    if (property != null) {
        StringTokenizer tok = new StringTokenizer(property, IPersistable.VALUE_SEPARATOR);
        String columnPosition = tok.nextToken();
        String rowPosition = tok.nextToken();
        topLeftPosition = new PositionCoordinate(this.freezeLayer, Integer.valueOf(columnPosition), Integer.valueOf(rowPosition));
    }
    property = properties.getProperty(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION);
    PositionCoordinate bottomRightPosition = null;
    if (property != null) {
        StringTokenizer tok = new StringTokenizer(property, IPersistable.VALUE_SEPARATOR);
        String columnPosition = tok.nextToken();
        String rowPosition = tok.nextToken();
        bottomRightPosition = new PositionCoordinate(this.freezeLayer, Integer.valueOf(columnPosition), Integer.valueOf(rowPosition));
    }
    // only restore a freeze state if there is one persisted
    if (topLeftPosition != null && bottomRightPosition != null) {
        if (topLeftPosition.columnPosition == -1 && topLeftPosition.rowPosition == -1 && bottomRightPosition.columnPosition == -1 && bottomRightPosition.rowPosition == -1) {
            FreezeHelper.unfreeze(this.freezeLayer, this.viewportLayer);
        } else {
            FreezeHelper.freeze(this.freezeLayer, this.viewportLayer, topLeftPosition, bottomRightPosition);
        }
    }
    super.loadState(prefix, properties);
}
Also used : StringTokenizer(java.util.StringTokenizer) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 87 with PositionCoordinate

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

the class FreezeCommandHandler method handleFreezeCommand.

/**
 * Performs freeze actions dependent on the coordinates specified by the
 * given {@link IFreezeCoordinatesProvider} and the configuration flags. If
 * a freeze state is already active it is checked if this state should be
 * overriden or toggled. Otherwise the freeze state is applied.
 *
 * @param coordinatesProvider
 *            The {@link IFreezeCoordinatesProvider} to retrieve the freeze
 *            coordinates from
 * @param toggle
 *            whether to unfreeze if the freeze layer is already in a frozen
 *            state
 * @param override
 *            whether to override a current frozen state.
 */
protected void handleFreezeCommand(IFreezeCoordinatesProvider coordinatesProvider, boolean toggle, boolean override) {
    if (!this.freezeLayer.isFrozen() || override) {
        // the viewport first
        if (this.freezeLayer.isFrozen() && override) {
            FreezeHelper.resetViewport(this.freezeLayer, this.viewportLayer);
        }
        final PositionCoordinate topLeftPosition = coordinatesProvider.getTopLeftPosition();
        final PositionCoordinate bottomRightPosition = coordinatesProvider.getBottomRightPosition();
        FreezeHelper.freeze(this.freezeLayer, this.viewportLayer, topLeftPosition, bottomRightPosition);
    } else if (toggle) {
        // if frozen and toggle = true
        handleUnfreeze();
    }
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 88 with PositionCoordinate

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

the class FreezeSelectionStrategy method getBottomRightPosition.

@Override
public PositionCoordinate getBottomRightPosition() {
    if (this.selectionLayer.getSelectedCells().size() > 1) {
        if (this.selectionLayer.getFullySelectedColumnPositions().length > 0) {
            // if columns are fully selected we will freeze the columns to
            // the left including the selected column with the greatest
            // index
            int columnPosition = 0;
            int[] selColPos = this.selectionLayer.getFullySelectedColumnPositions();
            for (int col : selColPos) {
                columnPosition = Math.max(columnPosition, col);
            }
            return new PositionCoordinate(this.freezeLayer, columnPosition, -1);
        } else if (this.selectionLayer.getFullySelectedRowPositions().length > 0) {
            // if rows are fully selected we will freeze the rows to the top
            // including the selected row with the greatest index
            int rowPosition = 0;
            int[] selRowPos = this.selectionLayer.getFullySelectedRowPositions();
            for (int row : selRowPos) {
                rowPosition = Math.max(rowPosition, row);
            }
            return new PositionCoordinate(this.freezeLayer, -1, rowPosition);
        } else {
            // find the selected cell that is most to the left and to the
            // top of the selection
            int columnPosition = -1;
            int rowPosition = -1;
            PositionCoordinate[] coords = this.selectionLayer.getSelectedCellPositions();
            for (PositionCoordinate coord : coords) {
                if (columnPosition < 0) {
                    columnPosition = coord.columnPosition;
                } else {
                    if (!this.include) {
                        columnPosition = Math.min(columnPosition, coord.columnPosition);
                    } else {
                        columnPosition = Math.max(columnPosition, coord.columnPosition);
                    }
                }
                if (rowPosition < 0) {
                    rowPosition = coord.rowPosition;
                } else {
                    if (!this.include) {
                        rowPosition = Math.min(rowPosition, coord.rowPosition);
                    } else {
                        rowPosition = Math.max(rowPosition, coord.rowPosition);
                    }
                }
            }
            return new PositionCoordinate(this.freezeLayer, !this.include ? columnPosition - 1 : columnPosition, !this.include ? rowPosition - 1 : rowPosition);
        }
    } else {
        PositionCoordinate selectionAnchor = this.selectionLayer.getSelectionAnchor();
        if (selectionAnchor != null) {
            if (!this.include) {
                return new PositionCoordinate(this.freezeLayer, selectionAnchor.columnPosition - 1, selectionAnchor.rowPosition - 1);
            } else {
                ILayerCell selectionAnchorCell = this.selectionLayer.getCellByPosition(selectionAnchor.columnPosition, selectionAnchor.rowPosition);
                return new PositionCoordinate(this.freezeLayer, selectionAnchor.columnPosition + selectionAnchorCell.getColumnSpan() - 1, selectionAnchor.rowPosition + selectionAnchorCell.getRowSpan() - 1);
            }
        }
    }
    return null;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 89 with PositionCoordinate

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

the class SearchDialog method getPosition.

private PositionCoordinate getPosition() {
    if (this.selectionLayer == null) {
        return new PositionCoordinate(null, SelectionLayer.NO_SELECTION, SelectionLayer.NO_SELECTION);
    }
    // The SelectionLayer keeps its anchor even if it has no selection.
    // Seems wrong to me, so here I clear out the anchor.
    PositionCoordinate pos = new PositionCoordinate(this.selectionLayer.getSelectionAnchor());
    if (this.selectionLayer.getSelectedCellPositions().length == 0 && pos.rowPosition != SelectionLayer.NO_SELECTION) {
        this.selectionLayer.clear(false);
        pos = new PositionCoordinate(this.selectionLayer.getSelectionAnchor());
    }
    return pos;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 90 with PositionCoordinate

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

the class CellDisplayValueSearchUtil method getDescendingCellCoordinatesRowFirst.

static List<PositionCoordinate> getDescendingCellCoordinatesRowFirst(ILayer contextLayer, int startingColumnPosition, int startingRowPosition, int width, int height) {
    List<PositionCoordinate> coordinates = new ArrayList<PositionCoordinate>(width * height);
    for (int rowPosition = height; rowPosition >= 0 && startingRowPosition >= 0; rowPosition--) {
        for (int columnPosition = width; columnPosition >= 0 && startingColumnPosition >= 0; columnPosition--) {
            PositionCoordinate coordinate = new PositionCoordinate(contextLayer, startingColumnPosition--, startingRowPosition);
            coordinates.add(coordinate);
        }
        startingRowPosition--;
    }
    return coordinates;
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ArrayList(java.util.ArrayList)

Aggregations

PositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)97 Test (org.junit.Test)55 SelectCellCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectCellCommand)15 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)10 Rectangle (org.eclipse.swt.graphics.Rectangle)9 SelectRegionCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectRegionCommand)7 ArrayList (java.util.ArrayList)5 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)5 SelectionLayer (org.eclipse.nebula.widgets.nattable.selection.SelectionLayer)5 Range (org.eclipse.nebula.widgets.nattable.coordinate.Range)4 ViewportSelectColumnGroupCommand (org.eclipse.nebula.widgets.nattable.group.command.ViewportSelectColumnGroupCommand)4 SearchEvent (org.eclipse.nebula.widgets.nattable.search.event.SearchEvent)4 SelectAllCommand (org.eclipse.nebula.widgets.nattable.selection.command.SelectAllCommand)4 ILayerListener (org.eclipse.nebula.widgets.nattable.layer.ILayerListener)3 HashSet (java.util.HashSet)2 Pattern (java.util.regex.Pattern)2 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 ColumnPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.ColumnPositionCoordinate)2 RowPositionCoordinate (org.eclipse.nebula.widgets.nattable.coordinate.RowPositionCoordinate)2 UpdateDataCommand (org.eclipse.nebula.widgets.nattable.edit.command.UpdateDataCommand)2