Search in sources :

Example 1 with AutoResizeCurrentRowsCommand

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand in project translationstudio8 by heartsome.

the class UpdateDataOperation method execute.

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    Object newValue = command.getNewValue() == null ? new UpdateDataBean() : command.getNewValue();
    if (((UpdateDataBean) newValue).getText().equals(((UpdateDataBean) oldValue).getText())) {
        // 值相同,则取消操作
        // 修改行在当前一屏显示的几行中的相对位置
        int currentRow = command.getRowPosition() + 1;
        table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow }, table.getConfigRegistry()));
        return Status.CANCEL_STATUS;
    }
    return refreshNatTable(newValue, false);
}
Also used : AutoResizeCurrentRowsCommand(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand) UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)

Example 2 with AutoResizeCurrentRowsCommand

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand in project translationstudio8 by heartsome.

the class UpdateDataOperation method refreshNatTable.

/**
	 * 更新 NatTable 的 UI
	 * @param value
	 *            单元格保存的值
	 * @param move
	 *            是否移动单元格到指定区域;
	 */
private IStatus refreshNatTable(Object value, boolean move) {
    if (table == null || table.isDisposed()) {
        return Status.CANCEL_STATUS;
    }
    int rowIndex = command.getRowPosition();
    int columnIndex = command.getColumnPosition();
    int columnPosition = viewportLayer.getColumnPositionByIndex(columnIndex);
    int rowPosition = viewportLayer.getRowPositionByIndex(rowIndex);
    // 实质上 DataLayer 层的 index 和 position 是一致的,此方法可以对范围判断
    if (rowIndex == -1 || columnIndex == -1) {
        return Status.CANCEL_STATUS;
    }
    // 修改值并刷新 UI。
    dataLayer.getDataProvider().setDataValue(columnIndex, rowIndex, value);
    dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
    // 修改行在当前一屏显示的几行中的相对位置
    int currentRow = rowPosition + 1;
    table.doCommand(new AutoResizeCurrentRowsCommand(table, new int[] { currentRow }, table.getConfigRegistry()));
    int selectedRow = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows()[0];
    if (value instanceof UpdateDataBean & rowIndex == selectedRow) {
        UpdateDataBean bean = (UpdateDataBean) value;
        StyledTextCellEditor sourceCellEditor = HsMultiActiveCellEditor.getSourceStyledEditor();
        StyledTextCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
        if (sourceCellEditor != null && sourceCellEditor.getRowIndex() == rowIndex && sourceCellEditor.getColumnIndex() == columnIndex) {
            ISegmentViewer segviewer = sourceCellEditor.getSegmentViewer();
            if (segviewer != null) {
                segviewer.setText(bean.getText());
            }
        } else if (targetCellEditor != null && targetCellEditor.getRowIndex() == rowIndex && targetCellEditor.getColumnIndex() == columnIndex) {
            ISegmentViewer segviewer = targetCellEditor.getSegmentViewer();
            if (segviewer != null) {
                segviewer.setText(bean.getText());
            }
        }
    }
    // 先记录下可见区域的范围
    int originRowPosition = viewportLayer.getOriginRowPosition();
    // 总行数
    int rowCount = viewportLayer.getRowCount();
    int row = LayerUtil.convertRowPosition(dataLayer, rowPosition, viewportLayer);
    if (move) {
        // 定位到屏幕第三行的位置
        if (rowPosition < originRowPosition || rowPosition > originRowPosition + rowCount) {
            HsMultiActiveCellEditor.commit(true);
            viewportLayer.doCommand(new SelectCellCommand(viewportLayer, columnPosition, row, false, false));
            HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
        } else {
            XLIFFEditorImplWithNatTable.getCurrent().jumpToRow(rowIndex);
        }
    }
    return Status.OK_STATUS;
}
Also used : AutoResizeCurrentRowsCommand(net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) ISegmentViewer(net.heartsome.cat.ts.ui.innertag.ISegmentViewer) UpdateDataBean(net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) CellVisualChangeEvent(net.sourceforge.nattable.layer.event.CellVisualChangeEvent)

Aggregations

UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)2 AutoResizeCurrentRowsCommand (net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand)2 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 CellVisualChangeEvent (net.sourceforge.nattable.layer.event.CellVisualChangeEvent)1 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)1