Search in sources :

Example 11 with IColumn

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

the class JaretTable method drawTableArea.

/**
     * Draw the main table area including fixed rows and columns.
     * 
     * @param gc gc
     * @param width width of the area
     * @param height height of the area
     */
private void drawTableArea(GC gc, int width, int height) {
    _colInfoCache.clear();
    boolean colCacheFilled = false;
    Rectangle clipSave = gc.getClipping();
    // iterate over all rows in the row info cache
    for (RowInfo rowInfo : getRowInfos()) {
        int y = rowInfo.y;
        IRow row = rowInfo.row;
        int rHeight = _tvs.getRowHeight(row);
        int yclip = y;
        if (rowInfo.fixed && yclip < _fixedRowRect.y) {
            yclip = _fixedRowRect.y;
        } else if (!rowInfo.fixed && yclip < _tableRect.y) {
            yclip = _tableRect.y;
        }
        int x = 0;
        // fixed columns
        if (_fixedColumns > 0) {
            x = _fixedColRect.x;
            for (int cIdx = 0; cIdx < _fixedColumns; cIdx++) {
                IColumn col = _cols.get(cIdx);
                int colwidth = _tvs.getColumnWidth(col);
                if (!colCacheFilled) {
                    _colInfoCache.add(new ColInfo(col, x, colwidth));
                }
                // clipping is extended by 1 for border drawing
                gc.setClipping(x, yclip, colwidth + 1, rHeight + 1);
                Rectangle area = new Rectangle(x, y, colwidth, rHeight);
                drawCell(gc, area, row, col);
                x += colwidth;
            }
        }
        // columns in normal table area
        x = _tableRect.x - _firstColPixelOffset;
        int cIdx = _firstColIdx;
        while (x < getWidth() && cIdx < _cols.size()) {
            IColumn col = _cols.get(cIdx);
            int colwidth = _tvs.getColumnWidth(col);
            if (!colCacheFilled) {
                _colInfoCache.add(new ColInfo(col, x, colwidth));
            }
            int xx = x > _tableRect.x ? x : _tableRect.x;
            int clipWidth = x > _tableRect.x ? colwidth : colwidth - _firstColPixelOffset;
            // clipping is extended by 1 for border drawing
            gc.setClipping(xx, yclip, clipWidth + 1, rHeight + 1);
            Rectangle area = new Rectangle(x, y, colwidth, rHeight);
            drawCell(gc, area, row, col);
            x += colwidth;
            cIdx++;
        }
        colCacheFilled = true;
    }
    // filter result is no rows
    if (!colCacheFilled) {
        // fixed cols
        int x = 0;
        if (_fixedColumns > 0) {
            for (int i = 0; i < _fixedColumns; i++) {
                IColumn col = _cols.get(i);
                int colwidth = _tvs.getColumnWidth(col);
                _colInfoCache.add(new ColInfo(col, x, colwidth));
                x += colwidth;
            }
        }
        x = -_firstColPixelOffset;
        x += _tableRect.x;
        int cIdx = _firstColIdx;
        while (x < getWidth() && cIdx < _cols.size()) {
            IColumn col = _cols.get(cIdx);
            int colwidth = _tvs.getColumnWidth(col);
            _colInfoCache.add(new ColInfo(col, x, colwidth));
            x += colwidth;
            cIdx++;
        }
    }
    // draw extra lines to separate fixed areas
    if (_fixedColRect != null && _fixedColumns > 0) {
        int maxY = _fixedColRect.y + _fixedColRect.height - 1;
        if (_rows != null && _rows.size() > 0) {
            IRow lastRow = _rows.get(_rows.size() - 1);
            Rectangle bounds = getRowBounds(lastRow);
            if (bounds != null) {
                maxY = bounds.y + bounds.height;
            }
        }
        gc.setClipping(new Rectangle(0, 0, width, height));
        int fx = _fixedColRect.x + _fixedColRect.width - 1;
        gc.drawLine(fx, _fixedRowRect.y, fx, maxY);
        gc.setClipping(clipSave);
    }
    if (_fixedRowRect != null && _fixedRows > 0) {
        int maxX = _fixedRowRect.x + _fixedRowRect.width - 1;
        if (_cols != null && _cols.size() > 0) {
            IColumn lastCol = _cols.get(_cols.size() - 1);
            int mx = xForCol(lastCol) + _tvs.getColumnWidth(lastCol);
            maxX = mx;
        }
        gc.setClipping(new Rectangle(0, 0, width, height));
        int fy = _fixedRowRect.y + _fixedRowRect.height - 1;
        gc.drawLine(_fixedRowRect.x, fy, maxX, fy);
        gc.setClipping(clipSave);
    }
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point)

Example 12 with IColumn

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

the class JaretTable method ensureSelectionContainsColRegion.

/**
     * Ensures that the selection contains the columns from firstIdx to colIdx. If the range firstIdx to lastIdx is
     * larger than the region the other columns will be removed from the selection.
     * 
     * @param firstColIdx first selected column index
     * @param colIdx current selected column index
     * @param lastColSelectIdx may be -1 for no last selection
     */
private void ensureSelectionContainsColRegion(int firstColIdx, int colIdx, int lastColSelectIdx) {
    int first = Math.min(firstColIdx, colIdx);
    int end = Math.max(firstColIdx, colIdx);
    for (int i = first; i <= end; i++) {
        IColumn col = colForIdx(i);
        if (!_selectionModel.getSelection().getSelectedColumns().contains(col)) {
            _selectionModel.addSelectedColumn(col);
        }
    }
    if (lastColSelectIdx != -1) {
        int f = Math.min(firstColIdx, lastColSelectIdx);
        int e = Math.max(firstColIdx, lastColSelectIdx);
        for (int i = f; i <= e; i++) {
            if (i < first || i > end) {
                IColumn col = colForIdx(i);
                _selectionModel.remSelectedColumn(col);
            }
        }
    }
}
Also used : IColumn(de.jaret.util.ui.table.model.IColumn) Point(org.eclipse.swt.graphics.Point)

Example 13 with IColumn

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

the class JaretTable method getAbsBeginXForColIdx.

/**
     * Get the absolute begin x for a column.
     * 
     * @param colIdx index of the column (in the displayed columns)
     * @return the absolute x coordinate
     */
public int getAbsBeginXForColIdx(int colIdx) {
    int x = 0;
    for (int idx = 0; idx < colIdx; idx++) {
        IColumn col = _cols.get(idx);
        int colWidth = _tvs.getColumnWidth(col);
        x += colWidth;
    }
    return x;
}
Also used : IColumn(de.jaret.util.ui.table.model.IColumn) Point(org.eclipse.swt.graphics.Point)

Example 14 with IColumn

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

the class JaretTable method setFocus.

/**
     * Set the focussed cell by coordinates.
     * 
     * @param x x coordinate
     * @param y y coordinate
     */
private void setFocus(int x, int y) {
    IRow row = rowForY(y);
    IColumn col = colForX(x);
    if (col != null && row != null) {
        setFocus(row, col);
    }
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn)

Example 15 with IColumn

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

the class JaretTable method setValue.

/**
     * Convenience method for setting a value at a displayed position in the table. NOTE: this method does call the the
     * set method of the model directly, so be aware that the model may protest by throwing a runtime exception or just
     * ignore the new value.
     * 
     * @param colIdx column index
     * @param rowIdx row index
     * @param value value to set
     */
public void setValue(int colIdx, int rowIdx, Object value) {
    IColumn col = getColumn(colIdx);
    IRow row = getRow(rowIdx);
    col.setValue(row, value);
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn)

Aggregations

IColumn (de.jaret.util.ui.table.model.IColumn)33 IRow (de.jaret.util.ui.table.model.IRow)15 Point (org.eclipse.swt.graphics.Point)13 JaretTable (de.jaret.util.ui.table.JaretTable)5 ArrayList (java.util.ArrayList)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Label (org.eclipse.swt.widgets.Label)4 PropCol (de.jaret.util.ui.table.model.PropCol)3 JaretTableActionFactory (de.jaret.util.ui.table.util.action.JaretTableActionFactory)3 MenuManager (org.eclipse.jface.action.MenuManager)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 IAutoFilter (de.jaret.util.ui.table.filter.IAutoFilter)2 IJaretTableCell (de.jaret.util.ui.table.model.IJaretTableCell)2 ITableNode (de.jaret.util.ui.table.model.ITableNode)2 JaretTableCellImpl (de.jaret.util.ui.table.model.JaretTableCellImpl)2 PropListeningTableModel (de.jaret.util.ui.table.model.PropListeningTableModel)2