Search in sources :

Example 11 with IJaretTableCell

use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.

the class JaretTable method ensureSelectionContainsRegion.

/**
     * Ensures the selection contains the cells in the rectangle given by firstIdxRect, *Idx. If the rectangle given by
     * first*, last* is larger than the other rectangle is is ensured that the additional cells are not in the
     * selection.
     * 
     * @param firstIdxRect rectangle containing the indizes of the originating rect
     * @param colIdx new end x index for the selected rectangle
     * @param rowIdx new end y index for teh selecetd rectangle
     * @param lastCellSelectX may be -1 for no last selection
     * @param lastCellSelectY may be -1 for no last selection
     */
private void ensureSelectionContainsRegion(Rectangle firstIdxRect, int colIdx, int rowIdx, int lastCellSelectX, int lastCellSelectY) {
    int firstx = Math.min(firstIdxRect.x, colIdx);
    int endx = Math.max(firstIdxRect.x + firstIdxRect.width - 1, colIdx);
    int firsty = Math.min(firstIdxRect.y, rowIdx);
    int endy = Math.max(firstIdxRect.y + firstIdxRect.height - 1, rowIdx);
    for (int x = firstx; x <= endx; x++) {
        for (int y = firsty; y <= endy; y++) {
            IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
            if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
                _selectionModel.addSelectedCell(cell);
            }
        }
    }
    // last sel rect
    if (lastCellSelectX != -1 && lastCellSelectY != -1) {
        int lfx = Math.min(firstIdxRect.x, lastCellSelectX);
        int lex = Math.max(firstIdxRect.x + firstIdxRect.width - 1, lastCellSelectX);
        int lfy = Math.min(firstIdxRect.y, lastCellSelectY);
        int ley = Math.max(firstIdxRect.y + firstIdxRect.height - 1, lastCellSelectY);
        for (int x = lfx; x <= lex; x++) {
            for (int y = lfy; y <= ley; y++) {
                if (!(x >= firstx && x <= endx && y >= firsty && y <= endy)) {
                    IJaretTableCell cell = new JaretTableCellImpl(rowForIdx(y), colForIdx(x));
                    _selectionModel.remSelectedCell(cell);
                }
            }
        }
    }
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Example 12 with IJaretTableCell

use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.

the class JaretTable method selectLeft.

/**
     * Enlarge selection to the left.
     */
private void selectLeft() {
    IJaretTableCell cell = getFocussedCell();
    if (_lastSelectType == SelectType.CELL && cell != null) {
        if (cell != null) {
            int cx = getColumnIdx(cell.getColumn());
            int cy = getRowIdx(cell.getRow());
            if (_lastKeySelect == null) {
                _lastKeySelect = new Point(-1, -1);
            }
            if (_firstKeySelect == null) {
                _firstKeySelect = new Point(cx, cy);
                _selectionModel.clearSelection();
            }
            focusLeft();
            cell = getFocussedCell();
            cx = getColumnIdx(cell.getColumn());
            cy = getRowIdx(cell.getRow());
            ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x, _lastKeySelect.y);
            _lastSelectType = SelectType.CELL;
            _lastKeySelect = new Point(cx, cy);
        }
    } else if (_lastSelectType == SelectType.COLUMN && (_lastColSelectIdx != -1 || _lastKeyColSelectIdx != -1)) {
        if (_firstKeyColSelectIdx == -1) {
            _firstKeyColSelectIdx = _lastColSelectIdx;
        }
        int colIdx = _lastKeyColSelectIdx != -1 ? _lastKeyColSelectIdx - 1 : _firstKeyColSelectIdx - 1;
        if (colIdx < 0) {
            colIdx = 0;
        }
        ensureSelectionContainsColRegion(_firstKeyColSelectIdx, colIdx, _lastKeyColSelectIdx);
        _lastKeyColSelectIdx = colIdx;
    }
}
Also used : IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 13 with IJaretTableCell

use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.

the class DefaultSelectionProvider method getISelection.

/**
     * {@inheritDoc}. Returns a structured selection containig rows and columns and cells that have been selected.
     */
@SuppressWarnings("unchecked")
protected ISelection getISelection() {
    IJaretTableSelection selection = _table.getSelectionModel().getSelection();
    if (selection != null && !selection.isEmpty()) {
        List list = new ArrayList();
        for (IRow row : selection.getSelectedRows()) {
            list.add(row);
        }
        for (IColumn col : selection.getSelectedColumns()) {
            list.add(col);
        }
        for (IJaretTableCell cell : selection.getSelectedCells()) {
            list.add(cell);
        }
        StructuredSelection sselection = new StructuredSelection(list);
        return sselection;
    }
    return new StructuredSelection();
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) IJaretTableSelection(de.jaret.util.ui.table.model.IJaretTableSelection) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) List(java.util.List) ArrayList(java.util.ArrayList) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell)

Example 14 with IJaretTableCell

use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.

the class JaretTable method selectUp.

/**
     * Enlarge selection upwards.
     */
private void selectUp() {
    IJaretTableCell cell = getFocussedCell();
    if (_lastSelectType == SelectType.CELL && cell != null) {
        if (cell != null) {
            int cx = getColumnIdx(cell.getColumn());
            int cy = getRowIdx(cell.getRow());
            if (_lastKeySelect == null) {
                _lastKeySelect = new Point(-1, -1);
            }
            if (_firstKeySelect == null) {
                _firstKeySelect = new Point(cx, cy);
                _selectionModel.clearSelection();
            }
            focusUp();
            cell = getFocussedCell();
            cx = getColumnIdx(cell.getColumn());
            cy = getRowIdx(cell.getRow());
            ensureSelectionContainsRegion(_firstKeySelect.x, _firstKeySelect.y, cx, cy, _lastKeySelect.x, _lastKeySelect.y);
            _lastSelectType = SelectType.CELL;
            _lastKeySelect = new Point(cx, cy);
        }
    } else if (_lastSelectType == SelectType.ROW && (_lastRowSelectIdx != -1 || _lastKeyRowSelectIdx != -1)) {
        if (_firstKeyRowSelectIdx == -1) {
            _firstKeyRowSelectIdx = _lastRowSelectIdx;
        }
        int rowIdx = _lastKeyRowSelectIdx != -1 ? _lastKeyRowSelectIdx - 1 : _firstKeyRowSelectIdx - 1;
        if (rowIdx < 0) {
            rowIdx = 0;
        }
        ensureSelectionContainsRowRegion(_firstKeyRowSelectIdx, rowIdx, _lastKeyRowSelectIdx);
        _lastKeyRowSelectIdx = rowIdx;
    }
}
Also used : IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 15 with IJaretTableCell

use of de.jaret.util.ui.table.model.IJaretTableCell in project translationstudio8 by heartsome.

the class JaretTable method handleSelection.

/**
     * Handle selection operations.
     * 
     * @param x x
     * @param y y
     * @param stateMask key state mask
     * @param dragging true when dragging
     */
private void handleSelection(int x, int y, int stateMask, boolean dragging) {
    // a mouse select always ends a shift-arrow select
    _lastKeySelect = null;
    _firstKeySelect = null;
    _firstKeyColSelectIdx = -1;
    _lastKeyColSelectIdx = -1;
    _firstKeyRowSelectIdx = -1;
    _lastKeyRowSelectIdx = -1;
    IRow row = rowForY(y);
    int rowIdx = row != null ? _rows.indexOf(row) : -1;
    IColumn col = colForX(x);
    int colIdx = getColumnIdx(col);
    // check fill dragging
    if (dragging && _isFillDrag) {
        if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
            if (col != null && row != null) {
                if (_firstCellSelectX == -1) {
                    _firstCellSelectX = colIdx;
                    _firstCellSelectY = rowIdx;
                }
                if (Math.abs(_firstCellSelectX - colIdx) > Math.abs(_firstCellSelectY - rowIdx)) {
                    rowIdx = _firstCellSelectY;
                    row = rowForIdx(rowIdx);
                    _horizontalFillDrag = false;
                } else {
                    colIdx = _firstCellSelectX;
                    col = colForIdx(colIdx);
                    _horizontalFillDrag = true;
                }
                ensureSelectionContainsRegion(_firstFillDragSelect, colIdx, rowIdx, _lastCellSelectX, _lastCellSelectY);
                // ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx,
                // _lastCellSelectX, _lastCellSelectY);
                _lastCellSelectX = colIdx;
                _lastCellSelectY = rowIdx;
                // a newly selected cell will always be the focussed cell (causes scrolling this cell to be
                // completely visible)
                setFocus(row, col);
            }
        }
        return;
    }
    // check row selection
    if (row != null && _selectionModel.isFullRowSelectionAllowed() && (isRowSelection(x, y) || _selectionModel.isOnlyRowSelectionAllowed() || _firstRowSelectIdx != -1)) {
        if (_firstRowSelectIdx == -1) {
            _firstRowSelectIdx = rowIdx;
        }
        if ((stateMask & SWT.CONTROL) != 0) {
            if (!_selectionModel.getSelection().getSelectedRows().contains(row)) {
                _selectionModel.addSelectedRow(row);
            } else {
                _selectionModel.remSelectedRow(row);
            }
            _lastSelectType = SelectType.ROW;
        } else if (dragging) {
            ensureSelectionContainsRowRegion(_firstRowSelectIdx, rowIdx, _lastRowSelectIdx);
            _lastRowSelectIdx = rowIdx;
            _lastSelectType = SelectType.ROW;
        } else {
            _selectionModel.clearSelection();
            _selectionModel.addSelectedRow(row);
            _lastSelectType = SelectType.ROW;
        }
        _lastRowSelectIdx = rowIdx;
        return;
    }
    // check column selection
    if (_selectionModel.isFullColumnSelectionAllowed() && (isColumnSelection(x, y) || _firstColSelectIdx != -1)) {
        if (_firstColSelectIdx == -1) {
            _firstColSelectIdx = colIdx;
        }
        if ((stateMask & SWT.CONTROL) != 0) {
            if (!_selectionModel.getSelection().getSelectedColumns().contains(col)) {
                _selectionModel.addSelectedColumn(col);
            } else {
                _selectionModel.remSelectedColumn(col);
            }
            _lastSelectType = SelectType.COLUMN;
        } else if (dragging) {
            ensureSelectionContainsColRegion(_firstColSelectIdx, colIdx, _lastColSelectIdx);
            _lastColSelectIdx = colIdx;
            _lastSelectType = SelectType.COLUMN;
        } else {
            _selectionModel.clearSelection();
            _selectionModel.addSelectedColumn(col);
            _lastSelectType = SelectType.COLUMN;
        }
        _lastColSelectIdx = colIdx;
        return;
    }
    // check cell selection
    if (_selectionModel.isCellSelectionAllowed() && _tableRect.contains(x, y)) {
        if (col != null && row != null) {
            IJaretTableCell cell = new JaretTableCellImpl(row, col);
            if (_firstCellSelectX == -1) {
                _firstCellSelectX = colIdx;
                _firstCellSelectY = rowIdx;
            }
            if ((stateMask & SWT.CONTROL) != 0) {
                if (!_selectionModel.getSelection().getSelectedCells().contains(cell)) {
                    _selectionModel.addSelectedCell(cell);
                } else {
                    _selectionModel.remSelectedCell(cell);
                }
                _lastSelectType = SelectType.CELL;
            } else if (dragging) {
                ensureSelectionContainsRegion(_firstCellSelectX, _firstCellSelectY, colIdx, rowIdx, _lastCellSelectX, _lastCellSelectY);
                _lastCellSelectX = colIdx;
                _lastCellSelectY = rowIdx;
                _lastSelectType = SelectType.CELL;
            } else {
                _selectionModel.clearSelection();
                _selectionModel.addSelectedCell(cell);
                _lastSelectType = SelectType.CELL;
            }
            // a newly selected cell will always be the focussed cell (causes scrolling this cell to be completely
            // visible)
            setFocus(row, col);
        }
    }
}
Also used : JaretTableCellImpl(de.jaret.util.ui.table.model.JaretTableCellImpl) IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Aggregations

IJaretTableCell (de.jaret.util.ui.table.model.IJaretTableCell)15 Point (org.eclipse.swt.graphics.Point)12 IJaretTableSelection (de.jaret.util.ui.table.model.IJaretTableSelection)3 JaretTableCellImpl (de.jaret.util.ui.table.model.JaretTableCellImpl)3 ArrayList (java.util.ArrayList)3 IColumn (de.jaret.util.ui.table.model.IColumn)2 IRow (de.jaret.util.ui.table.model.IRow)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 ICellRenderer (de.jaret.util.ui.table.renderer.ICellRenderer)1 List (java.util.List)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Clipboard (org.eclipse.swt.dnd.Clipboard)1 TextTransfer (org.eclipse.swt.dnd.TextTransfer)1