Search in sources :

Example 26 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class TickUpdateCommandHandler method doCommand.

public boolean doCommand(TickUpdateCommand command) {
    PositionCoordinate[] selectedPositions = selectionLayer.getSelectedCells();
    IConfigRegistry configRegistry = command.getConfigRegistry();
    // Tick update for multiple cells in selection 
    if (selectedPositions.length > 1) {
        ICellEditor lastSelectedCellEditor = EditUtils.lastSelectedCellEditor(selectionLayer, configRegistry);
        // Can all cells be updated ?
        if (EditUtils.isEditorSame(selectionLayer, configRegistry, lastSelectedCellEditor) && EditUtils.allCellsEditable(selectionLayer, configRegistry)) {
            for (PositionCoordinate position : selectedPositions) {
                updateSingleCell(command, position);
            }
        }
    } else {
        // Tick update for single selected cell
        updateSingleCell(command, selectionLayer.getLastSelectedCellPosition());
    }
    return true;
}
Also used : IConfigRegistry(net.sourceforge.nattable.config.IConfigRegistry) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor)

Example 27 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class KeyEditAction method run.

public void run(NatTable natTable, KeyEvent event) {
    Character character = null;
    if (LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character) || event.character == ' ') {
        character = Character.valueOf(event.character);
    }
    if (character != null) {
        int[] selectedRowIndexs = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows();
        if (selectedRowIndexs.length == 0) {
            return;
        }
        Arrays.sort(selectedRowIndexs);
        int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
        ViewportLayer viewportLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        // 先记录下可见区域的范围
        int originRowPosition = viewportLayer.getOriginRowPosition();
        // 总行数
        int rowCount = viewportLayer.getRowCount();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            rowIndex = rowIndex * 2;
        }
        if (rowIndex < originRowPosition || rowIndex > originRowPosition + rowCount || HsMultiActiveCellEditor.getTargetEditor() == null) {
            HsMultiActiveCellEditor.commit(true);
            PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
            if (!editor.isHorizontalLayout()) {
                natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
            } else {
                if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                    p.columnPosition = editor.getTgtColumnIndex();
                }
                natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
            }
            HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
            StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
            if (cellEditor != null && cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
                cellEditor.insertCanonicalValue(character);
            }
        }
    } else if ((event.character == SWT.CR) && event.stateMask == SWT.NONE) {
        HsMultiActiveCellEditor.commit(true);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
        } else {
            if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                p.columnPosition = editor.getTgtColumnIndex();
            }
            natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 28 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate in project translationstudio8 by heartsome.

the class HsMultiActiveCellEditor method activateCellEditors.

/**
	 * @param cellEditors
	 */
public static void activateCellEditors(HsMultiCellEditor srcCellEditor, HsMultiCellEditor tgtCellEditor, NatTable natTable) {
    parent = natTable;
    sourceEditor = srcCellEditor;
    sourceRowIndex = srcCellEditor.getRowIndex();
    sourceRowPosition = srcCellEditor.getRowPosition();
    targetEditor = tgtCellEditor;
    targetRowIndex = tgtCellEditor.getRowIndex();
    targetRowPosition = tgtCellEditor.getRowPosition();
    sourceEditor.activeCurrentEditor(natTable);
    targetEditor.activeCurrentEditor(natTable);
    SelectionLayer sLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
    PositionCoordinate p = sLayer.getLastSelectedCellPosition();
    int colPosition = p.columnPosition;
    if (colPosition == targetEditor.getColumnIndex()) {
        targetEditor.forceFocus();
    } else if (colPosition == sourceEditor.getColumnIndex()) {
        sourceEditor.forceFocus();
    }
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Aggregations

PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)28 SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)5 ArrayList (java.util.ArrayList)4 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)4 CellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)3 ILayer (net.sourceforge.nattable.layer.ILayer)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)3 Point (org.eclipse.swt.graphics.Point)3 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)2 ActiveCellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.ActiveCellRegion)2 Range (net.sourceforge.nattable.coordinate.Range)2 LabelStack (net.sourceforge.nattable.layer.LabelStack)2 IRegion (org.eclipse.jface.text.IRegion)2 MessageFormat (java.text.MessageFormat)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1