Search in sources :

Example 1 with CellVisualChangeEvent

use of net.sourceforge.nattable.layer.event.CellVisualChangeEvent 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)

Example 2 with CellVisualChangeEvent

use of net.sourceforge.nattable.layer.event.CellVisualChangeEvent in project translationstudio8 by heartsome.

the class ButtonCellPainter method run.

/**
	 * Respond to mouse click. Simulate button press.
	 */
public void run(final NatTable natTable, MouseEvent event) {
    NatEventData eventData = (NatEventData) event.data;
    columnPosClicked = eventData.getColumnPosition();
    rowPosClicked = eventData.getRowPosition();
    recentlyClicked = true;
    new Timer().schedule(getButtonFlashTimerTask(natTable), buttonFlashTime);
    natTable.fireLayerEvent(new CellVisualChangeEvent(natTable, columnPosClicked, rowPosClicked));
    for (IMouseAction listener : clickLiseners) {
        listener.run(natTable, event);
    }
}
Also used : IMouseAction(net.sourceforge.nattable.ui.action.IMouseAction) Timer(java.util.Timer) NatEventData(net.sourceforge.nattable.ui.NatEventData) CellVisualChangeEvent(net.sourceforge.nattable.layer.event.CellVisualChangeEvent)

Example 3 with CellVisualChangeEvent

use of net.sourceforge.nattable.layer.event.CellVisualChangeEvent in project translationstudio8 by heartsome.

the class UpdateDataCommandHandler method doCommand.

@Override
protected boolean doCommand(UpdateDataCommand command) {
    try {
        int columnPosition = command.getColumnPosition();
        int rowPosition = command.getRowPosition();
        dataLayer.getDataProvider().setDataValue(columnPosition, rowPosition, command.getNewValue());
        dataLayer.fireLayerEvent(new CellVisualChangeEvent(dataLayer, columnPosition, rowPosition));
        return true;
    } catch (UnsupportedOperationException e) {
        e.printStackTrace(System.err);
        System.err.println("Failed to update value to: " + command.getNewValue());
        return false;
    }
}
Also used : CellVisualChangeEvent(net.sourceforge.nattable.layer.event.CellVisualChangeEvent)

Aggregations

CellVisualChangeEvent (net.sourceforge.nattable.layer.event.CellVisualChangeEvent)3 Timer (java.util.Timer)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)1 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)1 AutoResizeCurrentRowsCommand (net.heartsome.cat.ts.ui.xliffeditor.nattable.handler.AutoResizeCurrentRowsCommand)1 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)1 NatEventData (net.sourceforge.nattable.ui.NatEventData)1 IMouseAction (net.sourceforge.nattable.ui.action.IMouseAction)1