Search in sources :

Example 1 with IJaretTableCell

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

the class DefaultCCPStrategy method cutOrCopy.

/**
     * Do the actual copy or cut operation.
     * 
     * @param table table
     * @param cut if set to true cells we be emptied
     */
protected void cutOrCopy(JaretTable table, boolean cut) {
    IJaretTableSelection selection = table.getSelectionModel().getSelection();
    Clipboard cb = getClipboard();
    if (!selection.isEmpty()) {
        Set<IJaretTableCell> cells = selection.getAllSelectedCells(table.getTableModel());
        int minx = -1;
        int maxx = -1;
        int miny = -1;
        int maxy = -1;
        // line is the outer map
        Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
        for (IJaretTableCell cell : cells) {
            Point p = table.getCellDisplayIdx(cell);
            Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
            if (lineMap == null) {
                lineMap = new HashMap<Integer, IJaretTableCell>();
                cellMap.put(p.y, lineMap);
            }
            if (miny == -1 || p.y < miny) {
                miny = p.y;
            }
            if (maxy == -1 || p.y > maxy) {
                maxy = p.y;
            }
            lineMap.put(p.x, cell);
            if (minx == -1 || p.x < minx) {
                minx = p.x;
            }
            if (maxx == -1 || p.x > maxx) {
                maxx = p.x;
            }
        }
        StringBuilder buf = new StringBuilder();
        if (_includeHeadersInCopy) {
            for (int x = minx; x <= maxx; x++) {
                String headerLabel = table.getColumn(x).getHeaderLabel();
                buf.append(headerLabel);
                buf.append(COPY_DELIMITER);
            }
            buf.append("\n");
        }
        for (int y = miny; y <= maxy; y++) {
            Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
            // empty lines are ommitted
            if (lineMap != null) {
                for (int x = minx; x <= maxx; x++) {
                    IJaretTableCell cell = lineMap.get(x);
                    String value = null;
                    if (cell != null) {
                        Object val = cell.getColumn().getValue(cell.getRow());
                        value = val != null ? val.toString() : null;
                        if (cut) {
                            emptyCell(cell);
                        }
                    }
                    if (value != null) {
                        buf.append(value);
                    }
                    buf.append(COPY_DELIMITER);
                }
                buf.append("\n");
            }
        }
        TextTransfer textTransfer = TextTransfer.getInstance();
        cb.setContents(new Object[] { buf.toString() }, new Transfer[] { textTransfer });
    }
}
Also used : HashMap(java.util.HashMap) IJaretTableSelection(de.jaret.util.ui.table.model.IJaretTableSelection) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Clipboard(org.eclipse.swt.dnd.Clipboard) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) HashMap(java.util.HashMap) Map(java.util.Map) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 2 with IJaretTableCell

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

the class DefaultCellStyleProvider method propertyChange.

/**
     * {@inheritDoc} Listens to all styles and fires style changed for every location a style is used in.
     */
public void propertyChange(PropertyChangeEvent event) {
    ICellStyle style = (ICellStyle) event.getSource();
    List<IJaretTableCell> locs = getStyleLocations(style);
    for (IJaretTableCell loc : locs) {
        fireCellStyleChanged(loc.getRow(), loc.getColumn(), (ICellStyle) style);
    }
}
Also used : IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell)

Example 3 with IJaretTableCell

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

the class JaretTable method getSelectedRectangle.

/**
     * Retrieve the index rectangle of selected cells.
     * 
     * @return rectangel made from the indizes of the selected cells if a rectangular area is selected (all cells)
     */
private Rectangle getSelectedRectangle() {
    IJaretTableSelection selection = getSelectionModel().getSelection();
    if (!selection.isEmpty() && _selectedIdxRectangle == null) {
        Set<IJaretTableCell> cells = selection.getAllSelectedCells(getTableModel());
        int minx = -1;
        int maxx = -1;
        int miny = -1;
        int maxy = -1;
        // line is the outer map
        Map<Integer, Map<Integer, IJaretTableCell>> cellMap = new HashMap<Integer, Map<Integer, IJaretTableCell>>();
        for (IJaretTableCell cell : cells) {
            Point p = getCellDisplayIdx(cell);
            Map<Integer, IJaretTableCell> lineMap = cellMap.get(p.y);
            if (lineMap == null) {
                lineMap = new HashMap<Integer, IJaretTableCell>();
                cellMap.put(p.y, lineMap);
            }
            if (miny == -1 || p.y < miny) {
                miny = p.y;
            }
            if (maxy == -1 || p.y > maxy) {
                maxy = p.y;
            }
            lineMap.put(p.x, cell);
            if (minx == -1 || p.x < minx) {
                minx = p.x;
            }
            if (maxx == -1 || p.x > maxx) {
                maxx = p.x;
            }
        }
        // check if all cells are selected
        boolean everythingSelected = true;
        for (int y = miny; y <= maxy && everythingSelected; y++) {
            Map<Integer, IJaretTableCell> lineMap = cellMap.get(y);
            if (lineMap != null) {
                for (int x = minx; x <= maxx; x++) {
                    IJaretTableCell cell = lineMap.get(x);
                    if (cell == null) {
                        everythingSelected = false;
                        break;
                    }
                }
            } else {
                everythingSelected = false;
                break;
            }
        }
        if (everythingSelected) {
            _selectedIdxRectangle = new Rectangle(minx, miny, maxx - minx + 1, maxy - miny + 1);
        } else {
            _selectedIdxRectangle = null;
        }
    }
    return _selectedIdxRectangle;
}
Also used : HashMap(java.util.HashMap) IJaretTableSelection(de.jaret.util.ui.table.model.IJaretTableSelection) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IJaretTableCell(de.jaret.util.ui.table.model.IJaretTableCell) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with IJaretTableCell

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

the class JaretTable method selectRight.

/**
     * Enlarge selection to the right.
     */
private void selectRight() {
    IJaretTableCell cell = getFocussedCell();
    if (_lastSelectType == SelectType.CELL && 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();
        }
        focusRight();
        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 > _cols.size() - 1) {
            colIdx = _cols.size() - 1;
        }
        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 5 with IJaretTableCell

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

the class JaretTable method handleFill.

/**
     * Handle the end of a fill drag.
     * 
     */
private void handleFill() {
    if (_fillDragStrategy != null) {
        if (_horizontalFillDrag) {
            // horizontal base rect
            for (int i = _firstFillDragSelect.x; i < _firstFillDragSelect.x + _firstFillDragSelect.width; i++) {
                IJaretTableCell firstCell = getCellForIdx(i, _firstFillDragSelect.y);
                List<IJaretTableCell> cells = getSelectedCellsVertical(i);
                cells.remove(firstCell);
                _fillDragStrategy.doFill(this, firstCell, cells);
            }
        } else {
            // vertical base rect
            for (int i = _firstFillDragSelect.y; i < _firstFillDragSelect.y + _firstFillDragSelect.height; i++) {
                IJaretTableCell firstCell = getCellForIdx(_firstFillDragSelect.x, i);
                List<IJaretTableCell> cells = getSelectedCellsHorizontal(i);
                cells.remove(firstCell);
                _fillDragStrategy.doFill(this, firstCell, cells);
            }
        }
    }
}
Also used : 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