Search in sources :

Example 16 with PositionCoordinate

use of net.sourceforge.nattable.coordinate.PositionCoordinate 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 17 with PositionCoordinate

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

the class MoveRowSelectionCommandHandler method moveLastSelectedUp.

@Override
protected void moveLastSelectedUp(int stepSize, boolean withShiftMask, boolean withControlMask) {
    if (selectionLayer.hasRowSelection()) {
        PositionCoordinate lastSelectedCell = selectionLayer.getCellPositionToMoveFrom(withShiftMask, withControlMask);
        int newSelectedRowPosition = stepSize >= 0 ? lastSelectedCell.rowPosition - stepSize : 0;
        if (newSelectedRowPosition < 0) {
            newSelectedRowPosition = 0;
        }
        selectionLayer.selectRow(lastSelectedCell.columnPosition, newSelectedRowPosition, withShiftMask, withControlMask);
    }
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 18 with PositionCoordinate

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

the class MoveRowSelectionCommandHandler method moveLastSelectedDown.

@Override
protected void moveLastSelectedDown(int stepSize, boolean withShiftMask, boolean withControlMask) {
    if (selectionLayer.hasRowSelection()) {
        PositionCoordinate lastSelectedCell = selectionLayer.getCellPositionToMoveFrom(withShiftMask, withControlMask);
        int newSelectedRowPosition = stepSize >= 0 ? lastSelectedCell.rowPosition + stepSize : selectionLayer.getRowCount() - 1;
        if (newSelectedRowPosition >= selectionLayer.getRowCount()) {
            newSelectedRowPosition = selectionLayer.getRowCount() - 1;
        }
        selectionLayer.selectRow(lastSelectedCell.columnPosition, newSelectedRowPosition, withShiftMask, withControlMask);
    }
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate)

Example 19 with PositionCoordinate

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

the class SelectionLayer method getSelectedCells.

public PositionCoordinate[] getSelectedCells() {
    int[] selectedColumnPositions = getSelectedColumns();
    Set<Range> selectedRowPositions = getSelectedRows();
    List<PositionCoordinate> selectedCells = new LinkedList<PositionCoordinate>();
    for (int columnPositionIndex = 0; columnPositionIndex < selectedColumnPositions.length; columnPositionIndex++) {
        final int columnPosition = selectedColumnPositions[columnPositionIndex];
        for (Range rowIndexRange : selectedRowPositions) {
            for (int rowPositionIndex = rowIndexRange.start; rowPositionIndex < rowIndexRange.end; rowPositionIndex++) {
                if (selectionModel.isCellPositionSelected(columnPosition, rowPositionIndex)) {
                    selectedCells.add(new PositionCoordinate(this, columnPosition, rowPositionIndex));
                }
            }
        }
    }
    return selectedCells.toArray(new PositionCoordinate[0]);
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) Range(net.sourceforge.nattable.coordinate.Range) LinkedList(java.util.LinkedList)

Example 20 with PositionCoordinate

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

the class FindReplaceCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, FindReplaceCommand findReplaceCommand) {
    findReplaceCommand.convertToTargetLayer(targetLayer);
    ISearchStrategy searchStrategy = findReplaceCommand.getSearchStrategy();
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.addLayerListener(findReplaceCommand.getSearchEventListener());
    }
    PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
    if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
        anchor = new PositionCoordinate(selectionLayer, 0, 0);
    }
    searchStrategy.setContextLayer(targetLayer);
    Object dataValueToFind = null;
    if ((dataValueToFind = findReplaceCommand.getSearchText()) == null) {
        dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
    }
    ICellSearchStrategy cellSearchStrategy = findReplaceCommand.getCellSearchStrategy();
    searchStrategy.setCellSearchStrategy(cellSearchStrategy);
    DefaultCellSearchStrategy defaultCellSearchStrategy = null;
    if (cellSearchStrategy instanceof DefaultCellSearchStrategy) {
        defaultCellSearchStrategy = (DefaultCellSearchStrategy) cellSearchStrategy;
    }
    searchResultCellRegion = searchStrategy.executeSearch(dataValueToFind);
    if (searchResultCellRegion != null) {
        PositionCoordinate searchResultCellCoordinate = searchResultCellRegion.getPositionCoordinate();
        int rowPosition = searchResultCellCoordinate.rowPosition;
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        ViewportLayer viewportLayer = LayerUtil.getLayer(editor.getTable(), ViewportLayer.class);
        HsMultiActiveCellEditor.commit(true);
        if (!editor.isHorizontalLayout()) {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition / 2 * 2, false, false));
        } else {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
        HsMultiActiveCellEditor.setCellEditorForceFocusByIndex(searchResultCellCoordinate.columnPosition, rowPosition);
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
        if (cellEditor != null) {
            String dataValue = cellEditor.getSegmentViewer().getDocument().get();
            if (dataValue != null) {
                int startOffset = -1;
                if (defaultCellSearchStrategy != null) {
                    startOffset = defaultCellSearchStrategy.getStartOffset();
                }
                defaultCellSearchStrategy.setStartOffset(startOffset);
                String findString = dataValueToFind.toString();
                if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
                    findString = findString.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
                    findString = findString.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
                    findString = findString.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
                }
                IRegion region = defaultCellSearchStrategy.executeSearch(findString, dataValue);
                if (region != null) {
                    HsMultiActiveCellEditor.setSelectionText(cellEditor, region.getOffset(), region.getLength());
                }
                defaultCellSearchStrategy.setStartOffset(-1);
            }
        }
    }
    selectionLayer.fireLayerEvent(new FindReplaceEvent(searchResultCellRegion));
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.removeLayerListener(findReplaceCommand.getSearchEventListener());
    }
    return true;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ICellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ICellSearchStrategy) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) FindReplaceEvent(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.event.FindReplaceEvent) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) IRegion(org.eclipse.jface.text.IRegion) DefaultCellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.DefaultCellSearchStrategy) ISearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ISearchStrategy) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

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