Search in sources :

Example 11 with IEditorPart

use of org.eclipse.ui.IEditorPart 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 12 with IEditorPart

use of org.eclipse.ui.IEditorPart 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 13 with IEditorPart

use of org.eclipse.ui.IEditorPart 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 14 with IEditorPart

use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.

the class MergeNextHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
    if (selectedRowIds.size() < 1) {
        return null;
    }
    String rowId = selectedRowIds.get(selectedRowIds.size() - 1);
    XLFHandler handler = xliffEditor.getXLFHandler();
    int rowIndex = handler.getRowIndex(rowId);
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    if (rowIndex == handler.countEditableTransUnit() - 1) {
        // 是最后一行
        MessageDialog.openWarning(window.getShell(), "", "不存在下一文本段,不能合并。");
        return null;
    }
    String rowId2 = handler.getRowId(rowIndex + 1);
    if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
        MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
        return null;
    }
    String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
    String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
    if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
        MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
        return null;
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 15 with IEditorPart

use of org.eclipse.ui.IEditorPart in project translationstudio8 by heartsome.

the class MergePreviousHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    List<String> selectedRowIds = xliffEditor.getSelectedRowIds();
    if (selectedRowIds.size() < 1) {
        return null;
    }
    String rowId = selectedRowIds.get(0);
    XLFHandler handler = xliffEditor.getXLFHandler();
    int rowIndex = handler.getRowIndex(rowId);
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    if (rowIndex == 0) {
        // 是第一行
        MessageDialog.openWarning(window.getShell(), "", "不存在上一文本段,不能合并。");
        return null;
    }
    String rowId2 = handler.getRowId(rowIndex - 1);
    if (handler.isApproved(rowId) || handler.isApproved(rowId2)) {
        MessageDialog.openWarning(window.getShell(), "", "已批准文本段,不能合并。");
        return null;
    }
    String fileName1 = RowIdUtil.getFileNameByRowId(rowId);
    String fileName2 = RowIdUtil.getFileNameByRowId(rowId2);
    if (fileName1 == null || fileName2 == null || !fileName1.equals(fileName2)) {
        MessageDialog.openWarning(window.getShell(), "", "文本段不在同一个文件内,不能合并。");
        return null;
    }
    //		IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
    //		try {
    //			operationHistory.execute(new MergeSegmentOperation("Merge Segment", xliffEditor, handler,
    //					rowIndex - 1), null, null);
    //		} catch (ExecutionException e) {
    //			e.printStackTrace();
    //		}
    // 选中上一行
    SelectionLayer selectionLayer = LayerUtil.getLayer(xliffEditor.getTable(), SelectionLayer.class);
    selectionLayer.selectRow(0, rowIndex - 1, false, false);
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Aggregations

IEditorPart (org.eclipse.ui.IEditorPart)401 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)137 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)127 PartInitException (org.eclipse.ui.PartInitException)73 IFile (org.eclipse.core.resources.IFile)58 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)53 IEditorReference (org.eclipse.ui.IEditorReference)52 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)45 ArrayList (java.util.ArrayList)43 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)41 IEditorInput (org.eclipse.ui.IEditorInput)37 IViewPart (org.eclipse.ui.IViewPart)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)33 Test (org.junit.Test)31 ISelection (org.eclipse.jface.viewers.ISelection)30 FileEditorInput (org.eclipse.ui.part.FileEditorInput)29 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)27 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)26 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)26 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)24