Search in sources :

Example 1 with IDisplayConverter

use of net.sourceforge.nattable.data.convert.IDisplayConverter in project translationstudio8 by heartsome.

the class CellDisplayValueSearchUtil method findCell.

@SuppressWarnings("unchecked")
static PositionCoordinate findCell(final ILayer layer, final IConfigRegistry configRegistry, final PositionCoordinate[] cellsToSearch, final Object valueToMatch, final Comparator comparator, final boolean caseSensitive) {
    final List<PositionCoordinate> cellCoordinates = Arrays.asList(cellsToSearch);
    // Find cell
    PositionCoordinate targetCoordinate = null;
    String stringValue = caseSensitive ? valueToMatch.toString() : valueToMatch.toString().toLowerCase();
    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
        final IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.NORMAL, layer.getConfigLabelsByPosition(columnPosition, rowPosition).getLabels());
        final Object dataValue = displayConverter.canonicalToDisplayValue(layer.getDataValueByPosition(columnPosition, rowPosition));
        // Compare with valueToMatch
        if (dataValue instanceof Comparable<?>) {
            String dataValueString = caseSensitive ? dataValue.toString() : dataValue.toString().toLowerCase();
            if (comparator.compare(stringValue, dataValueString) == 0 || dataValueString.contains(stringValue)) {
                targetCoordinate = cellCoordinate;
                break;
            }
        }
    }
    return targetCoordinate;
}
Also used : PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter)

Example 2 with IDisplayConverter

use of net.sourceforge.nattable.data.convert.IDisplayConverter in project translationstudio8 by heartsome.

the class HsMultiCellEditorControl method activeCell.

private static HsMultiCellEditor activeCell(ViewportLayer vLayer, XLIFFEditorImplWithNatTable xliffEditor, IConfigRegistry configRegistry, int columnIndex, int rowIndex, int rowPosition, String cellType) {
    NatTable natTable = xliffEditor.getTable();
    int columnPosition = vLayer.getColumnPositionByIndex(columnIndex);
    LayerCell cell = natTable.getCellByPosition(columnPosition, rowPosition);
    if (cell == null) {
        return null;
    }
    Rectangle cellBounds = cell.getBounds();
    List<String> configLabels = cell.getConfigLabels().getLabels();
    if (!xliffEditor.isHorizontalLayout()) {
        if (cellType.equals(NatTableConstant.SOURCE)) {
            configLabels.remove(XLIFFEditorImplWithNatTable.TARGET_EDIT_CELL_LABEL);
        } else if (cellType.equals(NatTableConstant.TARGET)) {
            configLabels.remove(XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
        }
    }
    ILayer layer = cell.getLayer();
    Object originalCanonicalValue = cell.getDataValue();
    IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
    IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
    IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);
    Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));
    int cellStartY = cellBounds.y;
    int cellEndY = cellStartY + cellBounds.height;
    Rectangle clientArea = natTable.getClientAreaProvider().getClientArea();
    int clientAreaEndY = clientArea.y + clientArea.height;
    if (cellEndY > clientAreaEndY) {
        editorBounds.height = clientAreaEndY - cellStartY;
    }
    StyledTextCellEditor cellEditor = (StyledTextCellEditor) configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
    ICellEditHandler editHandler = new HsMultiCellEditorHandler(cellEditor, layer);
    HsMultiCellEditor hsCellEditor = new HsMultiCellEditor(cellType, cellEditor, editHandler, columnPosition, rowPosition, columnIndex, rowIndex, dataValidator, originalCanonicalValue, displayConverter, cellStyle, editorBounds);
    return hsCellEditor;
}
Also used : IDataValidator(net.sourceforge.nattable.data.validate.IDataValidator) ICellEditHandler(net.sourceforge.nattable.edit.ICellEditHandler) ILayer(net.sourceforge.nattable.layer.ILayer) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Rectangle(org.eclipse.swt.graphics.Rectangle) IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter) IStyle(net.sourceforge.nattable.style.IStyle) NatTable(net.sourceforge.nattable.NatTable) CellStyleProxy(net.sourceforge.nattable.style.CellStyleProxy)

Example 3 with IDisplayConverter

use of net.sourceforge.nattable.data.convert.IDisplayConverter 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)

Example 4 with IDisplayConverter

use of net.sourceforge.nattable.data.convert.IDisplayConverter in project translationstudio8 by heartsome.

the class TextPainterWithPadding method convertDataType.

/**
	 * Convert the data value of the cell using the {@link IDisplayConverter} from the {@link IConfigRegistry}
	 */
protected String convertDataType(LayerCell cell, IConfigRegistry configRegistry) {
    IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    if (displayConverter instanceof TagDisplayConverter) {
        ((TagDisplayConverter) displayConverter).setCell(cell);
    }
    String text = displayConverter != null ? (String) displayConverter.canonicalToDisplayValue(cell.getDataValue()) : null;
    return (text == null) ? "" : text;
}
Also used : IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter)

Example 5 with IDisplayConverter

use of net.sourceforge.nattable.data.convert.IDisplayConverter in project translationstudio8 by heartsome.

the class TextPainter method convertDataType.

/**
	 * Convert the data value of the cell using the {@link IDisplayConverter} from the {@link IConfigRegistry}
	 */
protected String convertDataType(LayerCell cell, IConfigRegistry configRegistry) {
    IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    String text = displayConverter != null ? (String) displayConverter.canonicalToDisplayValue(cell.getDataValue()) : null;
    text = (text == null) ? "" : text;
    return text;
}
Also used : IDisplayConverter(net.sourceforge.nattable.data.convert.IDisplayConverter)

Aggregations

IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)7 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)3 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)3 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)3 IStyle (net.sourceforge.nattable.style.IStyle)3 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 ILayer (net.sourceforge.nattable.layer.ILayer)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2 TagDisplayConverter (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.TagDisplayConverter)1 CellRegion (net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion)1 NatTable (net.sourceforge.nattable.NatTable)1 ICellEditHandler (net.sourceforge.nattable.edit.ICellEditHandler)1 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)1 InlineCellEditEvent (net.sourceforge.nattable.edit.event.InlineCellEditEvent)1 MultiCellEditDialog (net.sourceforge.nattable.edit.gui.MultiCellEditDialog)1 ILayerListener (net.sourceforge.nattable.layer.ILayerListener)1 ITickUpdateHandler (net.sourceforge.nattable.tickupdate.ITickUpdateHandler)1 IRegion (org.eclipse.jface.text.IRegion)1 Control (org.eclipse.swt.widgets.Control)1