Search in sources :

Example 1 with StyledTextCellEditor

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

the class DeleteAllSegmentTranslationsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg3"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        try {
            XLFHandler handler = xliffEditor.getXLFHandler();
            int count = xliffEditor.getAllRowCount();
            int[] selectedRows = new int[count];
            for (int i = 0; i < count; i++) {
                selectedRows[i] = i;
            }
            List<Integer> rows = new ArrayList<Integer>();
            boolean exitFlag = false;
            for (int i = 0; i < selectedRows.length; i++) {
                String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
                if (null != tgt) {
                    if (tgt.equals("no")) {
                        exitFlag = true;
                        continue;
                    }
                }
                rows.add(selectedRows[i]);
            }
            if (rows.size() != 0) {
                int columnIndex = xliffEditor.getTgtColumnIndex();
                StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
                if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
                    cellEditor.getSegmentViewer().getTextWidget().forceFocus();
                }
                int[] updateRows = new int[rows.size()];
                for (int i = 0; i < rows.size(); i++) {
                    int ri = rows.get(i);
                    updateRows[i] = ri;
                }
                xliffEditor.updateCells(updateRows, columnIndex, "");
                if (exitFlag) {
                    MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 2 with StyledTextCellEditor

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

the class DeleteSelectionSegmentTranslationsHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg1"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        try {
            XLFHandler handler = xliffEditor.getXLFHandler();
            int[] selectedRows = xliffEditor.getSelectedRows();
            List<Integer> rows = new ArrayList<Integer>();
            boolean exitFlag = false;
            for (int i = 0; i < selectedRows.length; i++) {
                String tgt = handler.getCaseTgtContent(handler.getRowId(selectedRows[i]));
                if (null != tgt) {
                    if (tgt.equals("no")) {
                        exitFlag = true;
                        continue;
                    }
                }
                rows.add(selectedRows[i]);
            }
            if (rows.size() != 0) {
                int columnIndex = xliffEditor.getTgtColumnIndex();
                StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor();
                if (cellEditor != null && cellEditor.getColumnIndex() == columnIndex) {
                    cellEditor.getSegmentViewer().getTextWidget().forceFocus();
                }
                int[] updateRows = new int[rows.size()];
                for (int i = 0; i < rows.size(); i++) {
                    int ri = rows.get(i);
                    updateRows[i] = ri;
                }
                xliffEditor.updateCells(updateRows, columnIndex, "");
                if (exitFlag) {
                    MessageDialog.openInformation(xliffEditor.getSite().getShell(), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentTranslationsHandler.msg2"));
                }
            }
        } catch (Exception e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 3 with StyledTextCellEditor

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

the class DeleteToEndOrToTagHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        String deleteType = event.getParameter("DeleteContent");
        if (deleteType == null) {
            return null;
        }
        StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
        if (cellEditor == null || !cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
            return null;
        }
        if (!cellEditor.isEditable()) {
            // cellEditor.showUneditableMessage();
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteToEndOrToTagHandler.msgTitle"), cellEditor.getEditableManager().getUneditableMessage());
            return null;
        }
        StyledText styledText = cellEditor.getSegmentViewer().getTextWidget();
        int offset = styledText.getCaretOffset();
        Point p = styledText.getSelection();
        if (p != null) {
            int len = styledText.getText().length();
            String preText = "";
            String nextText = "";
            SegmentViewer viewer = (SegmentViewer) cellEditor.getSegmentViewer();
            if (offset > 0) {
                preText = styledText.getText(0, offset - 1);
                preText = viewer.convertDisplayTextToOriginalText(preText);
            }
            // 删除标记前所有内容
            if (deleteType.equals("DeleteToTag") && offset < len) {
                nextText = styledText.getText(offset, len - 1);
                Matcher matcher = PATTERN.matcher(nextText);
                if (matcher.find()) {
                    int index = matcher.start();
                    nextText = nextText.substring(index);
                } else {
                    // 选择删除标记前所有内容时,如果当前光标之后没有标记,则删除光标之后的所有内容
                    nextText = "";
                }
            }
            nextText = viewer.convertDisplayTextToOriginalText(nextText);
            String newText = preText + nextText;
            Hashtable<String, String> map = new Hashtable<String, String>();
            // Fix Bug #2883 删除光标后内容--同时选择多个文本段进行操作时,界面出错 By Jason
            // for (String rowId : xliffEditor.getSelectedRowIds()) {
            // map.put(rowId, newText);
            // }
            int index = cellEditor.getRowIndex();
            String rowId = xliffEditor.getXLFHandler().getRowId(index);
            map.put(rowId, newText);
            xliffEditor.updateSegments(map, xliffEditor.getTgtColumnIndex(), null, null);
            // 定位光标
            styledText.setCaretOffset(offset);
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) StyledText(org.eclipse.swt.custom.StyledText) SegmentViewer(net.heartsome.cat.ts.ui.innertag.SegmentViewer) Matcher(java.util.regex.Matcher) Hashtable(java.util.Hashtable) IEditorPart(org.eclipse.ui.IEditorPart) Point(org.eclipse.swt.graphics.Point) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) Point(org.eclipse.swt.graphics.Point)

Example 4 with StyledTextCellEditor

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

the class ChangeSourceEditableHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        ICellEditor cellEditor = xliffEditor.getTable().getConfigRegistry().getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, XLIFFEditorImplWithNatTable.SOURCE_EDIT_CELL_LABEL);
        if (cellEditor == null || !(cellEditor instanceof StyledTextCellEditor)) {
            return null;
        }
        HsMultiActiveCellEditor.commit(false);
        StyledTextCellEditor sce = (StyledTextCellEditor) cellEditor;
        EditableManager editableManager = sce.getEditableManager();
        //			SourceEditMode nextMode = editableManager.getSourceEditMode().getNextMode();
        SourceEditMode nextMode = getSourceEditMode(editableManager);
        editableManager.setSourceEditMode(nextMode);
        //			element.setIcon(Activator.getImageDescriptor(nextMode.getImagePath()));
        if (!sce.isClosed()) {
            editableManager.judgeEditable();
            //				更新全局 Action 的可用状态,主要是更新编辑-删除功能的可用状态。
            sce.getActionHandler().updateActionsEnableState();
        }
        sce.addClosingListener(listener);
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SourceEditMode(net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.SourceEditMode) EditableManager(net.heartsome.cat.ts.ui.xliffeditor.nattable.celleditor.EditableManager) ICellEditor(net.sourceforge.nattable.edit.editor.ICellEditor) IEditorPart(org.eclipse.ui.IEditorPart) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Example 5 with StyledTextCellEditor

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

the class SplitSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
    if (cellEditor == null) {
        return null;
    }
    if (!cellEditor.getCellType().equals(NatTableConstant.SOURCE)) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    int rowIndex = cellEditor.getRowIndex();
    // 如果是垂直布局,那么 rowIndex 要除以2 --robert
    if (!xliffEditor.isHorizontalLayout()) {
        rowIndex = rowIndex / 2;
    }
    int caretOffset = cellEditor.getRealSplitOffset();
    if (caretOffset < 0) {
        // 文本框已经关闭时
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    // 不能选择多个字符进行分割
    String selText = cellEditor.getSegmentViewer().getTextWidget().getSelectionText();
    if (selText.length() != 0) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg1"));
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    String rowId = handler.getRowId(rowIndex);
    /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 起 */
    String tgt = handler.getCaseTgtContent(rowId);
    if (null != tgt) {
        if (tgt.equals("no")) {
            showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg2"));
            return null;
        }
    }
    int cellTextLength = ((UpdateDataBean) cellEditor.getCanonicalValue()).getText().length();
    if (caretOffset <= 0 || caretOffset >= cellTextLength) {
        showInformation(event, Messages.getString("handler.SplitSegmentHandler.msg3"));
        return null;
    }
    /* burke 修改锁定文本段不能被分割和光标在文本段段首或者段末时,不能进行分割的BUG 添加代码 终 */
    // 关闭Editor
    cellEditor.close();
    IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    try {
        operationHistory.execute(new SplitSegmentOperation("Split Segment", xliffEditor, handler, rowIndex, caretOffset), null, null);
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) IEditorPart(org.eclipse.ui.IEditorPart) SplitSegmentOperation(net.heartsome.cat.ts.ui.xliffeditor.nattable.undoable.SplitSegmentOperation) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor) ExecutionException(org.eclipse.core.commands.ExecutionException) 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