Search in sources :

Example 1 with TurnViewportOnCommand

use of net.sourceforge.nattable.print.command.TurnViewportOnCommand in project translationstudio8 by heartsome.

the class HsMultiActiveCellEditor method synchronizeRowHeight.

public static void synchronizeRowHeight() {
    if (parent == null || sourceEditor == null || !sourceEditor.isValid() || targetEditor == null || !targetEditor.isValid()) {
        return;
    }
    if (sourceRowIndex != targetRowIndex) {
        // 垂直模式
        StyledTextCellEditor focusCell = getFocusCellEditor();
        if (sourceEditor.getCellEditor() == focusCell) {
            // edit source
            int srcHeight = sourceEditor.computeSize().y;
            int srcColPosition = sourceEditor.getColumnPosition();
            int srcRowPosition = sourceEditor.getRowPosition();
            int srcRowIndex = sourceEditor.getRowIndex();
            Rectangle srcBounds = parent.getBoundsByPosition(srcColPosition, srcRowPosition);
            srcHeight += 3;
            if (srcBounds != null && srcBounds.height != srcHeight) {
                Rectangle srcEditorBounds = sourceEditor.getEditorBounds();
                //					int preSrcH = srcEditorBounds.height;
                srcEditorBounds.height = srcHeight;
                int cellStartY = srcBounds.y;
                int cellEndY = cellStartY + srcHeight;
                Rectangle tgtEditorBounds = targetEditor.getEditorBounds();
                int srcAndTgtEndY = cellEndY + tgtEditorBounds.height;
                Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
                int clientAreaEndY = clientArea.y + clientArea.height;
                if (srcAndTgtEndY > clientAreaEndY) {
                    srcEditorBounds.height = clientAreaEndY - tgtEditorBounds.height - cellStartY - 3;
                }
                CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
                DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
                comlayer.doCommand(new TurnViewportOffCommand());
                dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(srcRowIndex), srcEditorBounds.height);
                comlayer.doCommand(new TurnViewportOnCommand());
                //					sourceEditor.setEditorBounds(srcEditorBounds, true);
                //					tgtEditorBounds.y = tgtEditorBounds.y + (srcEditorBounds.height - preSrcH);
                //					targetEditor.setEditorBounds(tgtEditorBounds, true);
                recalculateCellsBounds();
            }
        } else {
            // edit target
            int tgtHeight = targetEditor.computeSize().y;
            int tgtColPosition = targetEditor.getColumnPosition();
            int tgtRowPosition = targetEditor.getRowPosition();
            int tgtRowIndex = targetEditor.getRowIndex();
            Rectangle bounds = parent.getBoundsByPosition(tgtColPosition, tgtRowPosition);
            tgtHeight += 3;
            if (bounds != null && bounds.height != tgtHeight) {
                Rectangle tgtBounds = targetEditor.getEditorBounds();
                tgtBounds.height = tgtHeight;
                int cellStartY = tgtBounds.y;
                int cellEndY = cellStartY + tgtBounds.height;
                Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
                int clientAreaEndY = clientArea.y + clientArea.height;
                if (cellEndY > clientAreaEndY) {
                    tgtBounds.height = clientAreaEndY - cellStartY;
                }
                CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
                DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
                comlayer.doCommand(new TurnViewportOffCommand());
                dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(tgtRowIndex), tgtBounds.height);
                comlayer.doCommand(new TurnViewportOnCommand());
                //					targetEditor.setEditorBounds(tgtBounds, true);
                recalculateCellsBounds();
            }
        }
    } else {
        // 水平模式
        int srcHeight = sourceEditor.computeSize().y;
        int tgtHeight = targetEditor.computeSize().y;
        int newHeight = srcHeight > tgtHeight ? srcHeight : tgtHeight;
        int colPosition = sourceEditor.getColumnPosition();
        int rowPosition = sourceEditor.getRowPosition();
        int rowIndex = sourceEditor.getRowIndex();
        Rectangle bounds = parent.getBoundsByPosition(colPosition, rowPosition);
        newHeight += 3;
        if (bounds != null && bounds.height == newHeight) {
            return;
        }
        // 加上编辑模式下,StyledTextCellEditor的边框
        Rectangle srcBounds = sourceEditor.getEditorBounds();
        Rectangle tgtBounds = targetEditor.getEditorBounds();
        srcBounds.height = newHeight;
        tgtBounds.height = newHeight;
        int cellStartY = srcBounds.y;
        int cellEndY = cellStartY + srcBounds.height;
        Rectangle clientArea = parent.getClientAreaProvider().getClientArea();
        int clientAreaEndY = clientArea.y + clientArea.height;
        if (cellEndY > clientAreaEndY) {
            srcBounds.height = clientAreaEndY - cellStartY;
            tgtBounds.height = srcBounds.height;
        }
        CompositeLayer comlayer = LayerUtil.getLayer(parent, CompositeLayer.class);
        DataLayer dataLayer = LayerUtil.getLayer(parent, DataLayer.class);
        comlayer.doCommand(new TurnViewportOffCommand());
        dataLayer.setRowHeightByPosition(dataLayer.getRowPositionByIndex(rowIndex), tgtBounds.height);
        comlayer.doCommand(new TurnViewportOnCommand());
        //			HorizontalViewportLayer viewLayer = LayerUtil.getLayer(parent, HorizontalViewportLayer.class);
        //			int newRowPosition = viewLayer.getRowPositionByIndex(rowIndex) + 1;
        //			if (newRowPosition != rowPosition) {
        //				sourceEditor.setRowPosition(newRowPosition);
        //				targetEditor.setRowPosition(newRowPosition);
        //				Rectangle newSrcBounds = parent.getBoundsByPosition(colPosition, newRowPosition);
        //				newSrcBounds.height = srcBounds.height;
        //				Rectangle newTgtBounds = parent.getBoundsByPosition(targetEditor.getColumnIndex(), newRowPosition);
        //				sourceEditor.setEditorBounds(newSrcBounds, true);
        //				targetEditor.setEditorBounds(newTgtBounds, true);
        //			} else {
        //				sourceEditor.setEditorBounds(srcBounds, true);
        //				targetEditor.setEditorBounds(tgtBounds, true);
        recalculateCellsBounds();
    //			}
    }
}
Also used : DataLayer(net.sourceforge.nattable.layer.DataLayer) TurnViewportOnCommand(net.sourceforge.nattable.print.command.TurnViewportOnCommand) Rectangle(org.eclipse.swt.graphics.Rectangle) CompositeLayer(net.sourceforge.nattable.layer.CompositeLayer) TurnViewportOffCommand(net.sourceforge.nattable.print.command.TurnViewportOffCommand)

Example 2 with TurnViewportOnCommand

use of net.sourceforge.nattable.print.command.TurnViewportOnCommand 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 3 with TurnViewportOnCommand

use of net.sourceforge.nattable.print.command.TurnViewportOnCommand in project translationstudio8 by heartsome.

the class ExportToExcelAction method run.

public void run(NatTable natTable, KeyEvent event) {
    natTable.doCommand(new TurnViewportOffCommand());
    natTable.doCommand(new ExportToExcelCommand(natTable.getConfigRegistry(), natTable.getShell()));
    natTable.doCommand(new TurnViewportOnCommand());
}
Also used : TurnViewportOnCommand(net.sourceforge.nattable.print.command.TurnViewportOnCommand) ExportToExcelCommand(net.sourceforge.nattable.export.excel.command.ExportToExcelCommand) TurnViewportOffCommand(net.sourceforge.nattable.print.command.TurnViewportOffCommand)

Example 4 with TurnViewportOnCommand

use of net.sourceforge.nattable.print.command.TurnViewportOnCommand in project translationstudio8 by heartsome.

the class AutoResizeRowCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, AutoResizeRowsCommand command) {
    // Need to resize selected rows even if they are outside the viewport
    targetLayer.doCommand(new TurnViewportOffCommand());
    int[] rowPositions = ObjectUtils.asIntArray(command.getRowPositions());
    int[] gridRowPositions = convertFromSelectionToGrid(rowPositions);
    int[] gridRowHeights = MaxCellBoundsHelper.getPreferedRowHeights(command.getConfigRegistry(), command.getGC(), gridLayer, gridRowPositions);
    gridLayer.doCommand(new MultiRowResizeCommand(gridLayer, gridRowPositions, gridRowHeights));
    targetLayer.doCommand(new TurnViewportOnCommand());
    return true;
}
Also used : TurnViewportOnCommand(net.sourceforge.nattable.print.command.TurnViewportOnCommand) MultiRowResizeCommand(net.sourceforge.nattable.resize.command.MultiRowResizeCommand) TurnViewportOffCommand(net.sourceforge.nattable.print.command.TurnViewportOffCommand)

Example 5 with TurnViewportOnCommand

use of net.sourceforge.nattable.print.command.TurnViewportOnCommand in project translationstudio8 by heartsome.

the class ViewportLayer method doCommand.

@Override
public boolean doCommand(ILayerCommand command) {
    if (command instanceof ClientAreaResizeCommand && command.convertToTargetLayer(this)) {
        ClientAreaResizeCommand clientAreaResizeCommand = (ClientAreaResizeCommand) command;
        ScrollBar hBar = clientAreaResizeCommand.getScrollable().getHorizontalBar();
        ScrollBar vBar = clientAreaResizeCommand.getScrollable().getVerticalBar();
        if (hBarListener == null) {
            hBarListener = new HorizontalScrollBarHandler(this, hBar);
        }
        if (vBarListener == null) {
            vBarListener = new VerticalScrollBarHandler(this, vBar);
        }
        handleGridResize();
        return true;
    } else if (command instanceof TurnViewportOffCommand) {
        viewportOffOriginCol = localToUnderlyingColumnPosition(0);
        viewportOnOriginRow = localToUnderlyingRowPosition(0);
        viewportOff = true;
        return true;
    } else if (command instanceof TurnViewportOnCommand) {
        viewportOff = false;
        setOriginColumnPosition(viewportOffOriginCol);
        setOriginRowPosition(viewportOnOriginRow);
        return true;
    } else if (command instanceof PrintEntireGridCommand) {
        moveCellPositionIntoViewport(0, 0, false);
    }
    return super.doCommand(command);
}
Also used : TurnViewportOnCommand(net.sourceforge.nattable.print.command.TurnViewportOnCommand) ClientAreaResizeCommand(net.sourceforge.nattable.grid.command.ClientAreaResizeCommand) TurnViewportOffCommand(net.sourceforge.nattable.print.command.TurnViewportOffCommand) ScrollBar(org.eclipse.swt.widgets.ScrollBar) PrintEntireGridCommand(net.sourceforge.nattable.print.command.PrintEntireGridCommand)

Aggregations

TurnViewportOnCommand (net.sourceforge.nattable.print.command.TurnViewportOnCommand)9 TurnViewportOffCommand (net.sourceforge.nattable.print.command.TurnViewportOffCommand)7 MultiRowResizeCommand (net.sourceforge.nattable.resize.command.MultiRowResizeCommand)2 IOException (java.io.IOException)1 ExportToExcelCommand (net.sourceforge.nattable.export.excel.command.ExportToExcelCommand)1 ClientAreaResizeCommand (net.sourceforge.nattable.grid.command.ClientAreaResizeCommand)1 CompositeLayer (net.sourceforge.nattable.layer.CompositeLayer)1 DataLayer (net.sourceforge.nattable.layer.DataLayer)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1 PrintCommand (net.sourceforge.nattable.print.command.PrintCommand)1 PrintEntireGridCommand (net.sourceforge.nattable.print.command.PrintEntireGridCommand)1 MultiColumnResizeCommand (net.sourceforge.nattable.resize.command.MultiColumnResizeCommand)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 ScrollBar (org.eclipse.swt.widgets.ScrollBar)1