Search in sources :

Example 41 with XLFHandler

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

the class DeleteAllSegmentNoteHandler 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(), "删除确认", "确定要删除所有文本段的全部批注吗?");
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        handler.deleteAllSegmentNote();
    }
    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 42 with XLFHandler

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

the class DeleteSelectionSegmentNotesHandler 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.DeleteSelectionSegmentNotesHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg1"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        List<String> lstRowId = xliffEditor.getSelectedRowIds();
        // 先将应用范围为当前文本段的批注删除
        handler.deleteEditableSegmentNote(lstRowId);
        try {
            HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>();
            for (String rowId : lstRowId) {
                // 删除应用范围为所有文本段的批注
                Vector<NoteBean> noteBeans = xliffEditor.getXLFHandler().getNotes(rowId);
                if (noteBeans != null && noteBeans.size() > 0) {
                    mapNote.put(rowId, noteBeans);
                }
            }
            xliffEditor.getXLFHandler().deleteNote(mapNote);
        } catch (NavException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } finally {
            xliffEditor.refresh();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HashMap(java.util.HashMap) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) IEditorPart(org.eclipse.ui.IEditorPart) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) Vector(java.util.Vector) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 43 with XLFHandler

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

the class NeedReviewSegmentHandler 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> selectedRowIds = xliffEditor.getSelectedRowIds();
        boolean isNeedReview = true;
        //先判断所有的选择文本段的是否锁定状态
        for (String rowId : selectedRowIds) {
            if (!handler.isNeedReview(rowId)) {
                isNeedReview = false;
                break;
            }
        }
        NattableUtil util = NattableUtil.getInstance(xliffEditor);
        util.changIsQuestionState(selectedRowIds, isNeedReview ? "no" : "yes");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 44 with XLFHandler

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

the class UnlockSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart part = HandlerUtil.getActiveEditor(event);
    if (part instanceof XLIFFEditorImplWithNatTable) {
        final XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) part;
        XLFHandler handler = nattable.getXLFHandler();
        handler.unlockSegment();
        nattable.refresh();
        HsMultiActiveCellEditor.refrushCellsEditAbility();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 45 with XLFHandler

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

the class ExportAsTextHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    String elementName = event.getParameter("elementName");
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    Shell shell = activeEditor.getEditorSite().getShell();
    if (activeEditor == null || !(activeEditor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) activeEditor;
    if (xliffEditor.isMultiFile()) {
        MessageDialog.openInformation(shell, "", "当前编辑器打开了多个文件,无法执行该操作。");
    }
    IEditorInput input = xliffEditor.getEditorInput();
    URI uri = null;
    if (input instanceof FileEditorInput) {
        uri = ((FileEditorInput) input).getURI();
    } else if (input instanceof FileStoreEditorInput) {
        uri = ((FileStoreEditorInput) input).getURI();
    } else {
        return null;
    }
    File xliff = new File(uri);
    FileDialog fd = new FileDialog(shell, SWT.SAVE);
    String[] names = { "Plain Text Files [*.txt]", "All Files [*.*]" };
    //$NON-NLS-1$ //$NON-NLS-2$
    String[] extensions = { "*.txt", "*.*" };
    fd.setFilterExtensions(extensions);
    fd.setFilterNames(names);
    //$NON-NLS-1$
    fd.setFileName(xliff.getName() + ".txt");
    String out = fd.open();
    if (out == null) {
        return null;
    }
    XLFHandler handler = xliffEditor.getXLFHandler();
    boolean result = handler.saveAsText(xliff.getAbsolutePath(), out, elementName);
    if (result) {
        IWorkbenchPage page = xliffEditor.getEditorSite().getPage();
        OpenEditorUtil.OpenFileWithSystemEditor(page, out);
    } else {
        MessageDialog.openInformation(shell, "", "文件 “" + out + "” 保存失败!请重试。");
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IEditorPart(org.eclipse.ui.IEditorPart) URI(java.net.URI) Shell(org.eclipse.swt.widgets.Shell) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) IEditorInput(org.eclipse.ui.IEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) 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