Search in sources :

Example 6 with XLFHandler

use of net.heartsome.cat.ts.core.file.XLFHandler 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 7 with XLFHandler

use of net.heartsome.cat.ts.core.file.XLFHandler 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 8 with XLFHandler

use of net.heartsome.cat.ts.core.file.XLFHandler 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)

Example 9 with XLFHandler

use of net.heartsome.cat.ts.core.file.XLFHandler in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method getFilesByFileEditorInput.

/**
	 * 通过 FileEditorInput 得到当前要打开的文件
	 * @param input
	 *            FileEditorInput 对象
	 * @return ;
	 * @throws CoreException
	 */
private List<File> getFilesByFileEditorInput(FileEditorInput input) throws CoreException {
    List<File> files = null;
    IFile file = (IFile) input.getAdapter(IFile.class);
    if (file == null) {
        throw new CoreException(new Status(Status.WARNING, net.heartsome.cat.ts.ui.xliffeditor.nattable.Activator.PLUGIN_ID, Messages.getString("editor.XLIFFEditorImplWithNatTable.msg5")));
    } else {
        if ("xlp".equals(file.getFileExtension()) && ".TEMP".equals(file.getParent().getName())) {
            List<String> multiFiles = new XLFHandler().getMultiFiles(file);
            files = new ArrayList<File>();
            File mergerFile;
            for (String multiFileLC : multiFiles) {
                if (CommonFunction.validXlfExtensionByFileName(multiFileLC)) {
                    mergerFile = new File(multiFileLC);
                    files.add(mergerFile);
                }
            }
        } else {
            files = Arrays.asList(new File(input.getURI()));
        }
    }
    return files;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 10 with XLFHandler

use of net.heartsome.cat.ts.core.file.XLFHandler 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

XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)63 IEditorPart (org.eclipse.ui.IEditorPart)45 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)36 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)24 ArrayList (java.util.ArrayList)21 IFile (org.eclipse.core.resources.IFile)16 FileEditorInput (org.eclipse.ui.part.FileEditorInput)16 List (java.util.List)14 IProject (org.eclipse.core.resources.IProject)13 ExecutionException (org.eclipse.core.commands.ExecutionException)11 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 CoreException (org.eclipse.core.runtime.CoreException)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Shell (org.eclipse.swt.widgets.Shell)8 IViewPart (org.eclipse.ui.IViewPart)8 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)6 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)6