Search in sources :

Example 26 with PositionCoordinate

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

the class CompositeFreezeLayer method saveState.

// Persistence
@Override
public void saveState(String prefix, Properties properties) {
    PositionCoordinate coord = this.freezeLayer.getTopLeftPosition();
    properties.setProperty(prefix + FreezeLayer.PERSISTENCE_TOP_LEFT_POSITION, coord.columnPosition + IPersistable.VALUE_SEPARATOR + coord.rowPosition);
    coord = this.freezeLayer.getBottomRightPosition();
    properties.setProperty(prefix + FreezeLayer.PERSISTENCE_BOTTOM_RIGHT_POSITION, coord.columnPosition + IPersistable.VALUE_SEPARATOR + coord.rowPosition);
    super.saveState(prefix, properties);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 27 with PositionCoordinate

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

the class FreezeHelper method resetViewport.

/**
 * Helper method to reset the origin coordinates of the viewport. Is needed
 * to perform an unfreeze or to override a current frozen state.
 *
 * @param freezeLayer
 *            The FreezeLayer of the grid to perform the freeze action.
 * @param viewportLayer
 *            The ViewportLayer of the grid to perform the freeze action.
 */
public static void resetViewport(FreezeLayer freezeLayer, ViewportLayer viewportLayer) {
    PositionCoordinate topLeftPosition = freezeLayer.getTopLeftPosition();
    viewportLayer.resetOrigin(viewportLayer.getScrollableLayer().getStartXOfColumnPosition(Math.max(0, topLeftPosition.columnPosition)), viewportLayer.getScrollableLayer().getStartYOfRowPosition(Math.max(0, topLeftPosition.rowPosition)));
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate)

Example 28 with PositionCoordinate

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

the class FreezeSelectionStrategy method getTopLeftPosition.

@Override
public PositionCoordinate getTopLeftPosition() {
    PositionCoordinate lastSelectedCellPosition = this.selectionLayer.getLastSelectedCellPosition();
    if (lastSelectedCellPosition == null) {
        return null;
    }
    ILayerCell lastSelectedCell = this.selectionLayer.getCellByPosition(lastSelectedCellPosition.columnPosition, lastSelectedCellPosition.rowPosition);
    int columnPosition = this.viewportLayer.getScrollableLayer().getColumnPositionByX(this.viewportLayer.getOrigin().getX());
    if (columnPosition > 0 && columnPosition >= lastSelectedCellPosition.columnPosition) {
        if (!this.include) {
            columnPosition = lastSelectedCellPosition.columnPosition - 1;
        } else {
            columnPosition = lastSelectedCellPosition.columnPosition + lastSelectedCell.getColumnSpan() - 1;
        }
    }
    int rowPosition = this.viewportLayer.getScrollableLayer().getRowPositionByY(this.viewportLayer.getOrigin().getY());
    if (rowPosition > 0 && rowPosition >= lastSelectedCellPosition.rowPosition) {
        if (!this.include) {
            rowPosition = lastSelectedCellPosition.rowPosition - 1;
        } else {
            rowPosition = lastSelectedCellPosition.rowPosition - lastSelectedCell.getRowSpan() - 1;
        }
    }
    return new PositionCoordinate(this.freezeLayer, columnPosition, rowPosition);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 29 with PositionCoordinate

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

the class HierarchicalTreeLayer method handleLayerEvent.

@Override
public void handleLayerEvent(ILayerEvent event) {
    if (event instanceof IStructuralChangeEvent) {
        IStructuralChangeEvent structuralChangeEvent = (IStructuralChangeEvent) event;
        if (structuralChangeEvent.isVerticalStructureChanged()) {
            // recalculate node row indexes
            // build a new collection of nodes to avoid duplication clashes
            // as nodes are equal per column and row index
            int negativeIndex = -1;
            Set<HierarchicalTreeNode> updatedCollapsedNodes = new HashSet<HierarchicalTreeNode>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                int newRowIndex = findTopRowIndex(node.columnIndex, node.rowObject);
                // the underlying collection
                if (newRowIndex >= 0) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, newRowIndex, this.underlyingList.get(newRowIndex)));
                } else if (this.retainRemovedRowObjectNodes) {
                    updatedCollapsedNodes.add(new HierarchicalTreeNode(node.columnIndex, negativeIndex, node.rowObject));
                    negativeIndex--;
                }
            }
            this.collapsedNodes.clear();
            this.collapsedNodes.addAll(updatedCollapsedNodes);
            // recalculate hidden rows based on updated collapsed nodes
            Set<Integer> updatedHiddenRows = new HashSet<Integer>();
            for (HierarchicalTreeNode node : this.collapsedNodes) {
                updatedHiddenRows.addAll(getChildIndexes(node.columnIndex, node.rowIndex));
            }
            getHiddenRowIndexes().clear();
            getHiddenRowIndexes().addAll(updatedHiddenRows);
        }
    } else if (event instanceof SearchEvent) {
        PositionCoordinate coord = ((SearchEvent) event).getCellCoordinate();
        if (coord != null) {
            Integer foundIndex = coord.getLayer().getRowIndexByPosition(coord.rowPosition);
            if (getHiddenRowIndexes().contains(foundIndex)) {
                if (this.expandOnSearch) {
                    // not collapsible
                    for (int level = this.nodeColumnMapping.size() - 2; level >= 0; level--) {
                        ILayerCell nodeCell = coord.getLayer().getCellByPosition(this.nodeColumnMapping.get(level), coord.rowPosition);
                        int colIdx = coord.getLayer().getColumnIndexByPosition(nodeCell.getOriginColumnPosition());
                        int rowIdx = coord.getLayer().getRowIndexByPosition(nodeCell.getOriginRowPosition());
                        if (this.collapsedNodes.contains(new HierarchicalTreeNode(colIdx, rowIdx, null))) {
                            expandOrCollapse(colIdx, rowIdx);
                        }
                    }
                } else {
                    // only make the single row visible again
                    getHiddenRowIndexes().remove(foundIndex);
                }
            }
            invalidateCache();
            fireLayerEvent(new ShowRowPositionsEvent(this, Arrays.asList(foundIndex)));
        }
    }
    super.handleLayerEvent(event);
}
Also used : IStructuralChangeEvent(org.eclipse.nebula.widgets.nattable.layer.event.IStructuralChangeEvent) PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) SearchEvent(org.eclipse.nebula.widgets.nattable.search.event.SearchEvent) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) ShowRowPositionsEvent(org.eclipse.nebula.widgets.nattable.hideshow.event.ShowRowPositionsEvent) HashSet(java.util.HashSet)

Example 30 with PositionCoordinate

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

the class SelectionLayer method getSelectedCellPositions.

public PositionCoordinate[] getSelectedCellPositions() {
    int[] selectedColumnPositions = getSelectedColumnPositions();
    Set<Range> selectedRowPositions = getSelectedRowPositions();
    List<PositionCoordinate> selectedCells = new LinkedList<PositionCoordinate>();
    for (int columnPositionIndex = 0; columnPositionIndex < selectedColumnPositions.length; columnPositionIndex++) {
        final int columnPosition = selectedColumnPositions[columnPositionIndex];
        for (Range rowIndexRange : selectedRowPositions) {
            for (int rowPositionIndex = rowIndexRange.start; rowPositionIndex < rowIndexRange.end; rowPositionIndex++) {
                if (this.selectionModel.isCellPositionSelected(columnPosition, rowPositionIndex)) {
                    selectedCells.add(new PositionCoordinate(this, columnPosition, rowPositionIndex));
                }
            }
        }
    }
    return selectedCells.toArray(new PositionCoordinate[0]);
}
Also used : PositionCoordinate(org.eclipse.nebula.widgets.nattable.coordinate.PositionCoordinate) Range(org.eclipse.nebula.widgets.nattable.coordinate.Range) LinkedList(java.util.LinkedList) Point(org.eclipse.swt.graphics.Point)

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