Search in sources :

Example 36 with XLFHandler

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

the class AbstractExportHandler method getXlfBean.

private XliffBean getXlfBean(IFile file) {
    XliffBean bean = null;
    XLFHandler xlfHandler = new XLFHandler();
    Map<String, Object> result = xlfHandler.openFile(file.getLocation().toOSString());
    Object obj = result.get(Constant.RETURNVALUE_RESULT);
    if (obj != null && (Integer) obj == Constant.RETURNVALUE_RESULT_SUCCESSFUL) {
        bean = xlfHandler.getXliffInfo().get(file.getLocation().toOSString()).get(0);
    }
    return bean;
}
Also used : XliffBean(net.heartsome.cat.ts.core.bean.XliffBean) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 37 with XLFHandler

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

the class ShowPreviousUnapprovedHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    int[] selectedRows = xliffEditor.getSelectedRows();
    if (selectedRows.length < 1) {
        return null;
    }
    Arrays.sort(selectedRows);
    int firstSelectedRow = selectedRows[0];
    XLFHandler handler = xliffEditor.getXLFHandler();
    int row = handler.getPreviousUnapprovedSegmentIndex(firstSelectedRow);
    if (row != -1) {
        xliffEditor.jumpToRow(row);
    } else {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openWarning(window.getShell(), "", "不存在上一未批准文本段。");
    }
    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 38 with XLFHandler

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

the class ShowPreviousUntranslatableHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    int[] selectedRows = xliffEditor.getSelectedRows();
    if (selectedRows.length < 1) {
        return null;
    }
    Arrays.sort(selectedRows);
    int firstSelectedRow = selectedRows[0];
    XLFHandler handler = xliffEditor.getXLFHandler();
    int row = handler.getPreviousUntranslatableSegmentIndex(firstSelectedRow);
    if (row != -1) {
        xliffEditor.jumpToRow(row);
    } else {
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openWarning(window.getShell(), "", "不存在上一不可翻译文本段。");
    }
    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 39 with XLFHandler

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

the class LockSegmentHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    // 这是之前的实现方式,这是锁定文本段。锁定全部文本段,锁定可编辑文本段的共同 handler,--robert 2012-05-02
    // String lockSegment = event.getParameter("lockSegment");
    // if (lockSegment == null) {
    // return null;
    // }
    // State state = event.getCommand().getState(RegistryToggleState.STATE_ID);
    // boolean isSelect = (Boolean) (state.getValue());
    // state.setValue(!isSelect);
    // IEditorPart editor = HandlerUtil.getActiveEditor(event);
    // if (editor instanceof XLIFFEditorImplWithNatTable) {
    // XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
    //
    // // 批准可编辑文本段时要初始化 rowIds ,批准所有文本段则不需要
    // if (lockSegment.equals("lockDuplicateSegment")) {
    // // TODO 解决如何高效获取重复文本段后再做
    //
    // } else {
    // ArrayList<String> rowIds = null;
    // if (lockSegment.equals("lockEditableSegment")) {
    // rowIds = xliffEditor.getXLFHandler().getRowIds();
    // } else if (lockSegment.equals("lockAllSegment")) {
    // rowIds = null;
    // }
    // NattableUtil util = new NattableUtil(xliffEditor);
    // util.lockTransUnits(rowIds, !isSelect);
    // // 改变单元格编辑器模式为“只读”
    // util.changeCellEditorMode(rowIds, null);
    // // TODO 入库
    //
    // }
    //
    // }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        ArrayList<String> rowIds = (ArrayList<String>) xliffEditor.getSelectedRowIds();
        ArrayList<String> needLockRowIds = new ArrayList<String>();
        // 先判断所有的选择文本段的是否锁定状态
        for (String rowId : rowIds) {
            if (!handler.isLocked(rowId)) {
                needLockRowIds.add(rowId);
            }
        }
        NattableUtil util = NattableUtil.getInstance(xliffEditor);
        // 如果都是锁定状态的,那么把它们都变成未锁定
        if (needLockRowIds.size() <= 0) {
            util.lockTransUnits(rowIds, false);
        } else {
            util.lockTransUnits(needLockRowIds, true);
        // 改变单元格编辑器模式为“只读”
        // util.changeCellEditorMode(rowIds, null);
        }
        HsMultiActiveCellEditor.refrushCellsEditAbility();
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) NattableUtil(net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 40 with XLFHandler

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

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