Search in sources :

Example 6 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.

the class FindReplaceDialog method doReplace.

/**
	 * 替换 ;
	 */
private void doReplace() {
    CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion();
    if (activeCellRegion == null) {
        return;
    }
    StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
    if (cellEditor != null) {
        StyledText text = cellEditor.getSegmentViewer().getTextWidget();
        String sleText = text.getSelectionText();
        String findStr = cmbFind.getText();
        if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
            findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
            findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
            findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
        }
        if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())) {
            Point p = text.getSelection();
            text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText());
        }
    }
}
Also used : CellRegion(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.CellRegion) ActiveCellRegion(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.coordinate.ActiveCellRegion) StyledText(org.eclipse.swt.custom.StyledText) Point(org.eclipse.swt.graphics.Point) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 7 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor 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 8 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.

the class FindReplaceCommandHandler method doCommand.

public boolean doCommand(ILayer targetLayer, FindReplaceCommand findReplaceCommand) {
    findReplaceCommand.convertToTargetLayer(targetLayer);
    ISearchStrategy searchStrategy = findReplaceCommand.getSearchStrategy();
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.addLayerListener(findReplaceCommand.getSearchEventListener());
    }
    PositionCoordinate anchor = selectionLayer.getSelectionAnchor();
    if (anchor.columnPosition < 0 || anchor.rowPosition < 0) {
        anchor = new PositionCoordinate(selectionLayer, 0, 0);
    }
    searchStrategy.setContextLayer(targetLayer);
    Object dataValueToFind = null;
    if ((dataValueToFind = findReplaceCommand.getSearchText()) == null) {
        dataValueToFind = selectionLayer.getDataValueByPosition(anchor.columnPosition, anchor.rowPosition);
    }
    ICellSearchStrategy cellSearchStrategy = findReplaceCommand.getCellSearchStrategy();
    searchStrategy.setCellSearchStrategy(cellSearchStrategy);
    DefaultCellSearchStrategy defaultCellSearchStrategy = null;
    if (cellSearchStrategy instanceof DefaultCellSearchStrategy) {
        defaultCellSearchStrategy = (DefaultCellSearchStrategy) cellSearchStrategy;
    }
    searchResultCellRegion = searchStrategy.executeSearch(dataValueToFind);
    if (searchResultCellRegion != null) {
        PositionCoordinate searchResultCellCoordinate = searchResultCellRegion.getPositionCoordinate();
        int rowPosition = searchResultCellCoordinate.rowPosition;
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        ViewportLayer viewportLayer = LayerUtil.getLayer(editor.getTable(), ViewportLayer.class);
        HsMultiActiveCellEditor.commit(true);
        if (!editor.isHorizontalLayout()) {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition / 2 * 2, false, false));
        } else {
            viewportLayer.doCommand(new SelectCellCommand(selectionLayer, searchResultCellCoordinate.columnPosition, rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
        HsMultiActiveCellEditor.setCellEditorForceFocusByIndex(searchResultCellCoordinate.columnPosition, rowPosition);
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
        if (cellEditor != null) {
            String dataValue = cellEditor.getSegmentViewer().getDocument().get();
            if (dataValue != null) {
                int startOffset = -1;
                if (defaultCellSearchStrategy != null) {
                    startOffset = defaultCellSearchStrategy.getStartOffset();
                }
                defaultCellSearchStrategy.setStartOffset(startOffset);
                String findString = dataValueToFind.toString();
                if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) {
                    findString = findString.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n");
                    findString = findString.replaceAll("\\t", Constants.TAB_CHARACTER + "​");
                    findString = findString.replaceAll(" ", Constants.SPACE_CHARACTER + "​");
                }
                IRegion region = defaultCellSearchStrategy.executeSearch(findString, dataValue);
                if (region != null) {
                    HsMultiActiveCellEditor.setSelectionText(cellEditor, region.getOffset(), region.getLength());
                }
                defaultCellSearchStrategy.setStartOffset(-1);
            }
        }
    }
    selectionLayer.fireLayerEvent(new FindReplaceEvent(searchResultCellRegion));
    if (findReplaceCommand.getSearchEventListener() != null) {
        selectionLayer.removeLayerListener(findReplaceCommand.getSearchEventListener());
    }
    return true;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ICellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ICellSearchStrategy) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) FindReplaceEvent(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.event.FindReplaceEvent) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) IRegion(org.eclipse.jface.text.IRegion) DefaultCellSearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.DefaultCellSearchStrategy) ISearchStrategy(net.heartsome.cat.ts.ui.xliffeditor.nattable.search.strategy.ISearchStrategy) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 9 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.

the class DeleteAllTagsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        int[] rows = xliffEditor.getSelectedRows();
        if (rows.length == 0) {
            return null;
        }
        HsMultiCellEditor targetCellEditor = HsMultiActiveCellEditor.getTargetEditor();
        StyledTextCellEditor cellEditor = targetCellEditor.getCellEditor();
        if (cellEditor == null || cellEditor.isClosed()) {
            return null;
        }
        if (rows.length == 1) {
            // 清除内部标记
            cellEditor.clearTags();
            return null;
        } else {
            int activeEditRowIndex = targetCellEditor.getRowIndex();
            // 清除内部标记
            cellEditor.clearTags();
            if (!xliffEditor.isHorizontalLayout()) {
                activeEditRowIndex = activeEditRowIndex / 2;
            }
            // non active row
            int[] nonActiveRows = new int[rows.length - 1];
            int i = 0;
            for (int row : rows) {
                if (row == activeEditRowIndex) {
                    continue;
                }
                nonActiveRows[i++] = row;
            }
            List<String> rowIdList = new ArrayList<String>(xliffEditor.getXLFHandler().getRowIds(rows));
            xliffEditor.getXLFHandler().removeAllTags(rowIdList);
            xliffEditor.refresh();
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HsMultiCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.HsMultiCellEditor) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 10 with StyledTextCellEditor

use of net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor in project translationstudio8 by heartsome.

the class CopySourceHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        List<String> rowIds = xliffEditor.getSelectedRowIds();
        boolean locked = false;
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < rowIds.size(); i++) {
            String rowId = rowIds.get(i);
            if (handler.isLocked(rowId)) {
                // 已经批准或者已锁定,则不进行修改。
                locked = true;
                continue;
            }
            String srcContent = handler.getSrcContent(rowId);
            String newValue = srcContent == null ? "" : srcContent;
            map.put(rowId, newValue);
        }
        if (locked) {
            if (!MessageDialog.openConfirm(xliffEditor.getSite().getShell(), Messages.getString("handler.CopySourceHandler.msgTitle"), Messages.getString("handler.CopySourceHandler.msg"))) {
                return null;
            }
        }
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
        if (cellEditor != null) {
            HsMultiActiveCellEditor.setCellEditorForceFocus(cellEditor.getColumnPosition(), cellEditor.getRowPosition());
        }
        xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HashMap(java.util.HashMap) IEditorPart(org.eclipse.ui.IEditorPart) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)11 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)9 IEditorPart (org.eclipse.ui.IEditorPart)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)4 ArrayList (java.util.ArrayList)3 SelectCellCommand (net.sourceforge.nattable.selection.command.SelectCellCommand)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 PositionCoordinate (net.sourceforge.nattable.coordinate.PositionCoordinate)2 ViewportLayer (net.sourceforge.nattable.viewport.ViewportLayer)2 StyledText (org.eclipse.swt.custom.StyledText)2 Point (org.eclipse.swt.graphics.Point)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Matcher (java.util.regex.Matcher)1 ISegmentViewer (net.heartsome.cat.ts.ui.innertag.ISegmentViewer)1 SegmentViewer (net.heartsome.cat.ts.ui.innertag.SegmentViewer)1 UpdateDataBean (net.heartsome.cat.ts.ui.xliffeditor.nattable.UpdateDataBean)1 EditableManager (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager)1 SourceEditMode (net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode)1