Search in sources :

Example 6 with IJaretTableCell

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

the class JaretTable method getSelectedCellsVertical.

/**
     * Get all cells that are selected at the x idx given.
     * 
     * @param x x idx
     * @return list of selecetd cells with x idx == x
     */
private List<IJaretTableCell> getSelectedCellsVertical(int x) {
    List<IJaretTableCell> cells = new ArrayList<IJaretTableCell>();
    List<IJaretTableCell> s = getSelectionModel().getSelection().getSelectedCells();
    for (IJaretTableCell cell : s) {
        Point p = getCellDisplayIdx(cell);
        if (p.x == x) {
            cells.add(cell);
        }
    }
    return cells;
}
Also used : ArrayList(java.util.ArrayList) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Example 7 with IJaretTableCell

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

the class JaretTable method getToolTipText.

/**
     * Supply tooltip text for a position in the table.
     * 
     * @param x x coordinate
     * @param y y coordinate
     * @return tooltip text or <code>null</code>
     */
private String getToolTipText(int x, int y) {
    IJaretTableCell cell = getCell(x, y);
    if (cell != null) {
        Rectangle bounds = getCellBounds(cell);
        ICellRenderer renderer = getCellRenderer(cell.getRow(), cell.getColumn());
        if (renderer != null) {
            String tt = renderer.getTooltip(this, bounds, cell.getRow(), cell.getColumn(), x, y);
            if (tt != null) {
                return tt;
            }
        }
    }
    return null;
}
Also used : ICellRenderer(de.jaret.util.ui.table.renderer.ICellRenderer) Rectangle(org.eclipse.swt.graphics.Rectangle) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell)

Example 8 with IJaretTableCell

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

the class JaretTable method selectDown.

/**
     * Enlarge selection downwards.
     */
private void selectDown() {
    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();
            }
            focusDown();
            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 > _rows.size() - 1) {
            rowIdx = _rows.size() - 1;
        }
        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 9 with IJaretTableCell

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

the class JaretTable method getSelectedCellsHorizontal.

/**
     * Get all cells that are selected at the y idx given.
     * 
     * @param y y idx
     * @return list of selecetd cells at idx y == y
     */
private List<IJaretTableCell> getSelectedCellsHorizontal(int y) {
    List<IJaretTableCell> cells = new ArrayList<IJaretTableCell>();
    List<IJaretTableCell> s = getSelectionModel().getSelection().getSelectedCells();
    for (IJaretTableCell cell : s) {
        Point p = getCellDisplayIdx(cell);
        if (p.y == y) {
            cells.add(cell);
        }
    }
    return cells;
}
Also used : ArrayList(java.util.ArrayList) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Point(org.eclipse.swt.graphics.Point)

Example 10 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 first*, *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 firstCellSelectX begin x index of selected cell rectangle
     * @param firstCellSelectY begin y index of selected cell rectangle
     * @param colIdx end x index of selected cell rectangle
     * @param rowIdx end y index of selected cell rectangle
     * @param lastCellSelectX may be -1 for no last selection
     * @param lastCellSelectY may be -1 for no last selection
     */
private void ensureSelectionContainsRegion(int firstCellSelectX, int firstCellSelectY, int colIdx, int rowIdx, int lastCellSelectX, int lastCellSelectY) {
    int firstx = Math.min(firstCellSelectX, colIdx);
    int endx = Math.max(firstCellSelectX, colIdx);
    int firsty = Math.min(firstCellSelectY, rowIdx);
    int endy = Math.max(firstCellSelectY, 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) {
        int lfx = Math.min(firstCellSelectX, lastCellSelectX);
        int lex = Math.max(firstCellSelectX, lastCellSelectX);
        int lfy = Math.min(firstCellSelectY, lastCellSelectY);
        int ley = Math.max(firstCellSelectY, 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)

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