Search in sources :

Example 1 with TagDisplayConverter

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.TagDisplayConverter in project translationstudio8 by heartsome.

the class CellDisplayValueSearchUtil method findCell.

static CellRegion findCell(final ILayer layer, final IConfigRegistry configRegistry, final PositionCoordinate[] cellsToSearch, final Object valueToMatch, final ICellSearchStrategy cellSearchStrategy) {
    final List<PositionCoordinate> cellCoordinates = Arrays.asList(cellsToSearch);
    // Find cell
    CellRegion targetCoordinate = null;
    String stringValue = valueToMatch.toString();
    final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
    for (int cellIndex = 0; cellIndex < cellCoordinates.size(); cellIndex++) {
        final PositionCoordinate cellCoordinate = cellCoordinates.get(cellIndex);
        final int columnPosition = cellCoordinate.columnPosition;
        final int rowPosition = cellCoordinate.rowPosition;
        // Convert cell's data
        if (displayConverter instanceof TagDisplayConverter) {
            LayerCell cell = new LayerCell(cellCoordinate.getLayer(), cellCoordinate.getColumnPosition(), cellCoordinate.getRowPosition());
            ((TagDisplayConverter) displayConverter).setCell(cell);
        }
        final Object dataValue = displayConverter.canonicalToDisplayValue(layer.getDataValueByPosition(columnPosition, rowPosition));
        // Compare with valueToMatch
        if (dataValue instanceof String) {
            String dataValueString = dataValue.toString();
            IRegion region;
            if ((region = cellSearchStrategy.executeSearch(stringValue, dataValueString)) != null) {
                targetCoordinate = new CellRegion(cellCoordinate, region);
                break;
            }
            ((DefaultCellSearchStrategy) cellSearchStrategy).setStartOffset(-1);
        }
    }
    return targetCoordinate;
}
Also used : CellRegion(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) TagDisplayConverter(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.TagDisplayConverter) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

TagDisplayConverter (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.TagDisplayConverter)1 CellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion)1 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)1 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 IRegion (org.eclipse.jface.text.IRegion)1