Search in sources :

Example 21 with IColumn

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

the class JaretTablePrinter method print.

public void print(JaretTablePrintConfiguration configuration) {
    _printingRect = new Rectangle(pixelForCmX(_borderLeft), pixelForCmY(_borderTop), _pageWidth, _pageHeight);
    _headerRenderer = _table.getHeaderRenderer().getPrintRenderer(_printer);
    Point pages = calculatePageCount(configuration);
    int pagesx = pages.x;
    int pagesy = pages.y;
    _printer.startJob(configuration.getName() != null ? configuration.getName() : "jarettable");
    GC gc = new GC(_printer);
    Font oldfont = gc.getFont();
    FontData fontdata = new FontData("Arial", (int) (8.0 * _scale), SWT.NULL);
    Font printerFont = new Font(_printer, fontdata);
    gc.setFont(printerFont);
    for (int px = 0; px < pagesx; px++) {
        int startx = (int) ((px * _pageWidth) / (_scaleX * _scale));
        IColumn column = _table.getColumnForAbsX(startx);
        int offx = startx - _table.getAbsBeginXForColumn(column);
        int beginColIdx = _table.getColIdxForAbsX(startx);
        // System.out.println("PX "+px+" startx "+startx+" offx "+offx+" beginColIdx "+beginColIdx);
        int rIdx = 0;
        for (int py = 0; py < pagesy; py++) {
            int y = 0;
            String footerText = configuration.getFooterText() != null ? configuration.getFooterText() : "";
            footerText += "(" + (px + 1) + "/" + pagesx + "," + (py + 1) + "/" + pagesy + ")";
            _printer.startPage();
            int starty = (int) (py * ((_pageHeight - _footerHeight - (configuration.getRepeatHeader() ? scaleY(_table.getHeaderHeight()) : 0)) / (_scaleY * _scale)));
            // _table.getRowIdxForAbsY(starty);
            rIdx = py == 0 ? 0 : rIdx;
            Rectangle clipSave = gc.getClipping();
            if (starty == 0 || configuration.getRepeatHeader()) {
                // draw header
                // draw headers table area
                int x = -offx;
                int cIdx = beginColIdx;
                while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount() && (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
                    IColumn col = _table.getColumn(cIdx);
                    int colwidth = _table.getTableViewState().getColumnWidth(col);
                    int xx = x > 0 ? x : 0;
                    int clipWidth = x > 0 ? colwidth : colwidth - offx;
                    if (!_headerRenderer.disableClipping()) {
                        gc.setClipping(scaleX(xx) + pixelForCmX(_borderLeft), pixelForCmY(_borderTop), scaleX(clipWidth), scaleY(_table.getHeaderHeight()));
                        gc.setClipping(gc.getClipping().intersection(_printingRect));
                    }
                    drawHeader(gc, scaleX(x) + pixelForCmX(_borderLeft), scaleX(colwidth), col);
                    x += colwidth;
                    cIdx++;
                }
                y += _table.getHeaderHeight();
                gc.setClipping(clipSave);
            }
            // normal table area
            gc.setClipping(_printingRect);
            while (scaleY(y) < _pageHeight && rIdx < _table.getRowCount() && (configuration.getRowLimit() == -1 || rIdx <= configuration.getRowLimit())) {
                IRow row = _table.getRow(rIdx);
                int rHeight = _table.getTableViewState().getRowHeight(row);
                // do not draw a row that does not fit on th page
                if (scaleY(y) + scaleY(rHeight) > _pageHeight) {
                    break;
                }
                int x = -offx;
                int cIdx = beginColIdx;
                while (scaleX(x) < _pageWidth && cIdx < _table.getColumnCount() && (configuration.getColLimit() == -1 || cIdx <= configuration.getColLimit())) {
                    IColumn col = _table.getColumn(cIdx);
                    int colwidth = _table.getTableViewState().getColumnWidth(col);
                    Rectangle area = new Rectangle(scaleX(x) + pixelForCmX(_borderLeft), scaleY(y) + pixelForCmY(_borderTop), scaleX(colwidth), scaleY(rHeight));
                    drawCell(gc, area, row, col);
                    x += colwidth;
                    cIdx++;
                }
                y += rHeight;
                rIdx++;
            }
            gc.setClipping(clipSave);
            drawFooter(gc, footerText);
            _printer.endPage();
        }
    }
    _printer.endJob();
    printerFont.dispose();
    gc.setFont(oldfont);
    gc.dispose();
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font)

Example 22 with IColumn

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

the class JaretTable method handleEditorSingleClick.

/**
     * Handle a single mouseclick by passing it to the cell editor if present.
     * 
     * @param x x coordinate of the click
     * @param y y coordinate of the click
     * @return true if the editor handled the click
     */
private boolean handleEditorSingleClick(int x, int y) {
    IRow row = rowForY(y);
    IColumn col = colForX(x);
    if (col != null && row != null) {
        ICellEditor editor = getCellEditor(row, col);
        if (editor != null) {
            Rectangle area = getCellBounds(row, col);
            return editor.handleClick(this, row, col, area, x, y);
        }
    }
    return false;
}
Also used : IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) ICellEditor(de.jaret.util.ui.table.editor.ICellEditor) Rectangle(org.eclipse.swt.graphics.Rectangle)

Example 23 with IColumn

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

the class JaretTable method mouseMoved.

/**
     * Handle mouse move. This is mostly: modifying the appearance of the cursor.
     * 
     * @param x x coordinate of pointer
     * @param y y coordinate of pointer
     * @param stateMask keyStatemask
     */
private void mouseMoved(int x, int y, int stateMask) {
    Display display = Display.getCurrent();
    Shell activeShell = display != null ? display.getActiveShell() : null;
    // check for location over drag marker
    if (_dragMarkerRect != null && _dragMarkerRect.contains(x, y)) {
        if (activeShell != null) {
            // MAYBE other cursor for differentiation?
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEALL));
        }
        return;
    }
    // check for location over lower border of row
    IRow row = rowByBottomBorder(y);
    if (row != null && _rowResizeAllowed && (_tvs.getRowHeigthMode(row) == RowHeightMode.VARIABLE || _tvs.getRowHeigthMode(row) == RowHeightMode.OPTANDVAR) && (!_resizeRestriction || Math.abs(x - _tableRect.x) <= SELDELTA || (_fixedColRect != null && _fixedColRect.contains(x, y)))) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    } else {
        IColumn col = colByRightBorder(x);
        if (col != null && _columnResizeAllowed && _tvs.columnResizingAllowed(col) && (!_resizeRestriction || _headerRect == null || _headerRect.contains(x, y))) {
            if (activeShell != null) {
                activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEW));
            }
            return;
        }
    }
    // check header drag symboling
    if (_headerRect != null && _headerResizeAllowed && Math.abs(_headerRect.y + _headerRect.height - y) <= SELDELTA) {
        if (activeShell != null) {
            activeShell.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
        }
        return;
    }
    if (Display.getCurrent().getActiveShell() != null) {
        Display.getCurrent().getActiveShell().setCursor(Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW));
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IRow(de.jaret.util.ui.table.model.IRow) IColumn(de.jaret.util.ui.table.model.IColumn) Display(org.eclipse.swt.widgets.Display)

Example 24 with IColumn

use of de.jaret.util.ui.table.model.IColumn 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)

Example 25 with IColumn

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

the class JaretTable method updateAutoFilter.

/**
     * Create and/or update autofilters.
     * 
     */
private void updateAutoFilter() {
    if (_autoFilterEnabled) {
        // check combining autofilter
        if (_autoFilter == null) {
            _autoFilter = new AutoFilter(this);
        }
        // create autofilter instances and controls if necessary
        for (IColumn column : _cols) {
            if (_autoFilterMap.get(column) == null) {
                IAutoFilter af = createAutoFilter(column);
                if (af != null) {
                    af.addPropertyChangeListener(_autoFilter);
                    _autoFilterMap.put(column, af);
                }
            }
        }
        // update the filters and register them with the combining internal autofilter row filter
        for (IColumn column : _cols) {
            IAutoFilter af = _autoFilterMap.get(column);
            if (af != null) {
                // might be null in case of errors
                af.update();
            }
        }
    }
}
Also used : DefaultAutoFilter(de.jaret.util.ui.table.filter.DefaultAutoFilter) IAutoFilter(de.jaret.util.ui.table.filter.IAutoFilter) IColumn(de.jaret.util.ui.table.model.IColumn) IAutoFilter(de.jaret.util.ui.table.filter.IAutoFilter)

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