Search in sources :

Example 1 with GridVisibleRange

use of org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange in project translationstudio8 by heartsome.

the class GridVisibleRangeSupport method calculateChange.

private void calculateChange() {
    // FIXME Add back
    if (rangeChangeListener != null) {
        GridVisibleRange range = grid.getVisibleRange();
        ArrayList lOrigItems = new ArrayList();
        lOrigItems.addAll(Arrays.asList(oldRange.getItems()));
        ArrayList lNewItems = new ArrayList();
        lNewItems.addAll(Arrays.asList(range.getItems()));
        Iterator it = lNewItems.iterator();
        while (it.hasNext()) {
            if (lOrigItems.remove(it.next())) {
                it.remove();
            }
        }
        ArrayList lOrigColumns = new ArrayList();
        lOrigColumns.addAll(Arrays.asList(oldRange.getColumns()));
        ArrayList lNewColumns = new ArrayList();
        lNewColumns.addAll(Arrays.asList(range.getColumns()));
        it = lNewColumns.iterator();
        while (it.hasNext()) {
            if (lOrigColumns.remove(it.next())) {
                it.remove();
            }
        }
        if (lOrigItems.size() != 0 || lNewItems.size() != 0 || lOrigColumns.size() != 0 || lNewColumns.size() != 0) {
            RangeChangedEvent evt = new RangeChangedEvent(grid, range);
            evt.addedRows = new GridItem[lNewItems.size()];
            lNewItems.toArray(evt.addedRows);
            evt.removedRows = new GridItem[lOrigItems.size()];
            lOrigItems.toArray(evt.removedRows);
            evt.addedColumns = new GridColumn[lNewColumns.size()];
            lNewColumns.toArray(evt.addedColumns);
            evt.removedColumns = new GridColumn[lOrigColumns.size()];
            lNewColumns.toArray(evt.removedColumns);
            it = rangeChangeListener.iterator();
            while (it.hasNext()) {
                ((VisibleRangeChangedListener) it.next()).rangeChanged(evt);
            }
        }
        oldRange = range;
    }
}
Also used : GridVisibleRange(org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 2 with GridVisibleRange

use of org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange in project translationstudio8 by heartsome.

the class GridCopyEnable method handleVerticalScroll.

void handleVerticalScroll(Event event) {
    GridVisibleRange visibleR = gridTable.getVisibleRange();
    GridItem[] items = visibleR.getItems();
    boolean itemFlg = false;
    for (GridItem item : items) {
        if (focusItem == item) {
            itemFlg = true;
        }
    }
    boolean columnFlg = false;
    GridColumn[] columns = visibleR.getColumns();
    if (columns.length - 1 >= focusColIndex) {
        columnFlg = true;
    }
    if (!itemFlg || !columnFlg) {
        defaultCaret.setVisible(false);
        return;
    }
    defaultCaret.setVisible(true);
    GridColumn col = gridTable.getColumn(focusColIndex);
    GridCellRenderer gcr = col.getCellRenderer();
    int colIndex = gcr.getColumn();
    if (gcr == null || !(gcr instanceof XGridCellRenderer) || !copyAbleColumnIndexs.contains(colIndex)) {
        return;
    }
    XGridCellRenderer cellRender = (XGridCellRenderer) gcr;
    Rectangle cellBounds = focusItem.getBounds(colIndex);
    GC gc = new GC(Display.getDefault());
    TextLayout layout = null;
    try {
        layout = cellRender.getTextLayout(gc, focusItem, colIndex, true, false);
        if (layout == null) {
            gc.dispose();
            return;
        }
        Point point = layout.getLocation(caretOffset, false);
        coordinateOffsetX = cellBounds.x + cellRender.leftMargin;
        coordinateOffsetY = cellBounds.y + cellRender.topMargin + cellRender.textTopMargin;
        defaultCaret.setLocation(point.x + coordinateOffsetX, point.y + coordinateOffsetY);
    } finally {
        if (layout != null) {
            layout.dispose();
        }
        if (gc != null) {
            gc.dispose();
        }
    }
}
Also used : GridVisibleRange(org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) TextLayout(org.eclipse.swt.graphics.TextLayout) GridItem(org.eclipse.nebula.widgets.grid.GridItem) GridCellRenderer(org.eclipse.nebula.widgets.grid.GridCellRenderer) GridColumn(org.eclipse.nebula.widgets.grid.GridColumn) GC(org.eclipse.swt.graphics.GC)

Aggregations

GridVisibleRange (org.eclipse.nebula.widgets.grid.Grid.GridVisibleRange)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 GridCellRenderer (org.eclipse.nebula.widgets.grid.GridCellRenderer)1 GridColumn (org.eclipse.nebula.widgets.grid.GridColumn)1 GridItem (org.eclipse.nebula.widgets.grid.GridItem)1 GC (org.eclipse.swt.graphics.GC)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 TextLayout (org.eclipse.swt.graphics.TextLayout)1