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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations