use of net.sourceforge.nattable.layer.cell.LayerCell 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.layer.cell.LayerCell 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.layer.cell.LayerCell in project translationstudio8 by heartsome.
the class ExcelExporter method export.
/**
* Create an HTML table suitable for Excel.
*
* @param outputStream
* to write the output to
* @param positionRectangle
* of the layer to export
* @throws IOException
*/
public void export(final Shell shell, final OutputStream outputStream, final Rectangle positionRectangle) throws IOException {
final ExcelExportProgessBar progressBar = new ExcelExportProgessBar(shell);
Runnable exporter = new Runnable() {
public void run() {
try {
int startRow = positionRectangle.y;
int endRow = startRow + positionRectangle.height;
progressBar.open(startRow, endRow);
writeHeader(outputStream);
outputStream.write(asBytes("<body><table border='1'>"));
for (int rowPosition = startRow; rowPosition <= endRow; rowPosition++) {
progressBar.setSelection(rowPosition);
outputStream.write(asBytes("<tr>\n"));
int startColumn = positionRectangle.x;
int endColumn = startColumn + positionRectangle.width;
for (int colPosition = startColumn; colPosition <= endColumn; colPosition++) {
LayerCell cell = layer.getCellByPosition(colPosition, rowPosition);
outputStream.write(asBytes("\t" + getCellAsHTML(cell) + "\n"));
}
outputStream.write(asBytes("</tr>\n"));
}
outputStream.write(asBytes("</table></body></html>"));
} catch (Exception e) {
logError(e);
} finally {
try {
outputStream.close();
} catch (IOException e) {
logError(e);
}
// These must be fired at the end of the thread execution
layer.setClientAreaProvider(originalClientAreaProvider);
layer.doCommand(new TurnViewportOnCommand());
progressBar.dispose();
}
}
};
// Run with the SWT display so that the progress bar can paint
shell.getDisplay().asyncExec(exporter);
}
use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.
the class CopyDataCommandHandler method assembleCopiedDataStructure.
protected LayerCell[][] assembleCopiedDataStructure() {
final Set<Range> selectedRows = selectionLayer.getSelectedRows();
final int rowOffset = columnHeaderLayer != null ? columnHeaderLayer.getRowCount() : 0;
// Add offset to rows, remember they need to include the column header as a row
final LayerCell[][] copiedCells = new LayerCell[selectionLayer.getSelectedRowCount() + rowOffset][1];
if (columnHeaderLayer != null) {
copiedCells[0] = assembleColumnHeaders(selectionLayer.getSelectedColumns());
}
for (Range range : selectedRows) {
for (int rowPosition = range.start; rowPosition < range.end; rowPosition++) {
copiedCells[(rowPosition - range.start) + rowOffset] = assembleBody(rowPosition);
}
}
return copiedCells;
}
use of net.sourceforge.nattable.layer.cell.LayerCell in project translationstudio8 by heartsome.
the class CopyDataToClipboardSerializer method serialize.
public void serialize() {
final Clipboard clipboard = command.getClipboard();
final String cellDelimeter = command.getCellDelimeter();
final String rowDelimeter = command.getRowDelimeter();
final TextTransfer textTransfer = TextTransfer.getInstance();
final StringBuilder textData = new StringBuilder();
int currentRow = 0;
for (LayerCell[] cells : copiedCells) {
int currentCell = 0;
for (LayerCell cell : cells) {
final String delimeter = ++currentCell < cells.length ? cellDelimeter : "";
if (cell != null) {
textData.append(cell.getDataValue() + delimeter);
} else {
textData.append(delimeter);
}
}
if (++currentRow < copiedCells.length) {
textData.append(rowDelimeter);
}
}
clipboard.setContents(new Object[] { textData.toString() }, new Transfer[] { textTransfer });
}
Aggregations