Search in sources :

Example 1 with LayerCell

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;
}
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 2 with LayerCell

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;
}
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 3 with LayerCell

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);
}
Also used : TurnViewportOnCommand(net.sourceforge.nattable.print.command.TurnViewportOnCommand) LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) IOException(java.io.IOException) IOException(java.io.IOException)

Example 4 with LayerCell

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;
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Range(net.sourceforge.nattable.coordinate.Range)

Example 5 with LayerCell

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 });
}
Also used : LayerCell(net.sourceforge.nattable.layer.cell.LayerCell) Clipboard(org.eclipse.swt.dnd.Clipboard) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Aggregations

LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)24 Rectangle (org.eclipse.swt.graphics.Rectangle)8 ICellPainter (net.sourceforge.nattable.painter.cell.ICellPainter)4 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)3 IDisplayConverter (net.sourceforge.nattable.data.convert.IDisplayConverter)3 IStyle (net.sourceforge.nattable.style.IStyle)3 IDataValidator (net.sourceforge.nattable.data.validate.IDataValidator)2 UpdateDataCommand (net.sourceforge.nattable.edit.command.UpdateDataCommand)2 ICellEditor (net.sourceforge.nattable.edit.editor.ICellEditor)2 CellStyleProxy (net.sourceforge.nattable.style.CellStyleProxy)2 Point (org.eclipse.swt.graphics.Point)2 NavException (com.ximpleware.NavException)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 InnerTagBean (net.heartsome.cat.common.innertag.InnerTagBean)1 XliffInnerTagFactory (net.heartsome.cat.common.innertag.factory.XliffInnerTagFactory)1 NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)1