Search in sources :

Example 6 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class SplitSegmentOperation method refreshNatTable.

private void refreshNatTable() {
    SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class);
    int rowPosition = selectionLayer.getRowPositionByIndex(rowIndex);
    selectionLayer.fireLayerEvent(new RowSelectionEvent(selectionLayer, Arrays.asList(new Integer[] { rowPosition, rowPosition + 1 })));
    xliffEditor.autoResizeNotColumn();
    ActiveCellRegion.setActiveCellRegion(null);
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) RowSelectionEvent(net.sourceforge.nattable.selection.event.RowSelectionEvent)

Example 7 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class GridSearchStrategy method executeSearch.

public PositionCoordinate executeSearch(Object valueToMatch) {
    ILayer contextLayer = getContextLayer();
    if (!(contextLayer instanceof SelectionLayer)) {
        throw new RuntimeException("For the GridSearchStrategy to work it needs the selectionLayer to be passed as the contextLayer.");
    }
    SelectionLayer selectionLayer = (SelectionLayer) contextLayer;
    PositionCoordinate selectionAnchor = selectionLayer.getSelectionAnchor();
    boolean hadSelectionAnchor = true;
    if (selectionAnchor.columnPosition < 0 || selectionAnchor.rowPosition < 0) {
        selectionAnchor.columnPosition = 0;
        selectionAnchor.rowPosition = 0;
        hadSelectionAnchor = false;
    }
    int anchorColumnPosition = selectionAnchor.columnPosition;
    int startingRowPosition;
    int[] columnsToSearch = null;
    final int columnCount = selectionLayer.getColumnCount();
    if (searchDirection.equals(ISearchDirection.SEARCH_FORWARD)) {
        int rowPosition = hadSelectionAnchor ? selectionAnchor.rowPosition + 1 : selectionAnchor.rowPosition;
        if (rowPosition > (contextLayer.getRowCount() - 1)) {
            rowPosition = wrapSearch ? 0 : contextLayer.getRowCount() - 1;
        }
        int rowCount = selectionLayer.getRowCount();
        startingRowPosition = rowPosition < rowCount ? rowPosition : 0;
        if (selectionAnchor.rowPosition + 1 >= rowCount && anchorColumnPosition + 1 >= columnCount && hadSelectionAnchor) {
            if (wrapSearch) {
                anchorColumnPosition = 0;
            } else {
                return null;
            }
        } else if (selectionAnchor.rowPosition == rowCount - 1 && anchorColumnPosition < columnCount - 1) {
            anchorColumnPosition++;
        }
        columnsToSearch = getColumnsToSearchArray(columnCount, anchorColumnPosition);
    } else {
        int rowPosition = selectionAnchor.rowPosition - 1;
        if (rowPosition < 0) {
            rowPosition = wrapSearch ? contextLayer.getRowCount() - 1 : 0;
        }
        startingRowPosition = rowPosition > 0 ? rowPosition : 0;
        if (selectionAnchor.rowPosition - 1 < 0 && anchorColumnPosition - 1 < 0 && hadSelectionAnchor) {
            if (wrapSearch) {
                anchorColumnPosition = columnCount - 1;
            } else {
                return null;
            }
        } else if (selectionAnchor.rowPosition == 0 && anchorColumnPosition > 0) {
            anchorColumnPosition--;
        }
        columnsToSearch = getDescendingColumnsToSearchArray(anchorColumnPosition);
    }
    PositionCoordinate executeSearch = searchGrid(valueToMatch, contextLayer, selectionLayer, anchorColumnPosition, startingRowPosition, columnsToSearch);
    return executeSearch;
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) ILayer(net.sourceforge.nattable.layer.ILayer) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 8 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method getSelectedRowIds.

/**
	 * 得到当前选中的行的唯一标识
	 * @return ;
	 */
public List<String> getSelectedRowIds() {
    SelectionLayer selectionLayer = bodyLayer.getSelectionLayer();
    int[] rowPositions = selectionLayer.getFullySelectedRowPositions();
    Set<String> rowIds = handler.getRowIds(rowPositions);
    return new ArrayList<String>(rowIds);
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) ArrayList(java.util.ArrayList)

Example 9 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer in project translationstudio8 by heartsome.

the class RowHeightCalculator method getPreferredRowHeight.

private int getPreferredRowHeight(int rowPosition, IConfigRegistry configRegistry, int clientAreaHeight) {
    int maxHeight = 0;
    ICellPainter painter;
    LayerCell cell;
    SelectionLayer layer = bodyLayer.getSelectionLayer();
    for (int columnPosition = 0; columnPosition < layer.getColumnCount(); columnPosition++) {
        cell = layer.getCellByPosition(columnPosition, rowPosition);
        if (cell != null) {
            painter = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_PAINTER, cell.getDisplayMode(), bodyLayer.getConfigLabelsByPosition(columnPosition, rowPosition).getLabels());
            if (painter != null) {
                int preferedHeight = painter.getPreferredHeight(cell, null, configRegistry);
                maxHeight = (preferedHeight > maxHeight) ? preferedHeight : maxHeight;
            }
        }
    }
    if (maxHeight > clientAreaHeight) {
        return clientAreaHeight;
    }
    return maxHeight;
}
Also used : SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) ICellPainter(net.sourceforge.nattable.painter.cell.ICellPainter)

Example 10 with SelectionLayer

use of net.sourceforge.nattable.selection.SelectionLayer 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)

Aggregations

SelectionLayer (net.sourceforge.nattable.selection.SelectionLayer)11 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)5 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)3 ILayer (net.sourceforge.nattable.layer.ILayer)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)2 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)2 MessageFormat (java.text.MessageFormat)1 ArrayList (java.util.ArrayList)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 HorizontalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.HorizontalViewportLayer)1 VerticalViewportLayer (net.heartsome.cat.ts.ui.xliffeditor.nattable.layer.VerticalViewportLayer)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 DefaultBodyLayerStack (net.sourceforge.nattable.layer.stack.DefaultBodyLayerStack)1 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)1 RowSelectionEvent (net.sourceforge.nattable.selection.event.RowSelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IURIEditorInput (org.eclipse.ui.IURIEditorInput)1