Search in sources :

Example 66 with XLIFFEditorImplWithNatTable

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

the class FileAnalysisHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    model = new FAModel();
    faItemId = event.getParameter("faItemId");
    allTUSize = 0;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    shell = window.getShell();
    IFile multiTempIFile = null;
    IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("net.heartsome.cat.common.ui.navigator.view");
    ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
    if (HandlerUtil.getActivePart(event) instanceof IViewPart) {
        ISelection currentSelection = (StructuredSelection) viewPart.getSite().getSelectionProvider().getSelection();
        if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof IStructuredSelection) {
            IStructuredSelection structuredSelection = (IStructuredSelection) currentSelection;
            @SuppressWarnings("unchecked") Iterator<Object> selectIt = structuredSelection.iterator();
            while (selectIt.hasNext()) {
                Object object = selectIt.next();
                if (object instanceof IFile) {
                    IFile selectFile = (IFile) object;
                    String fileExtension = selectFile.getFileExtension();
                    // 如果后缀名不是xlf,那么就进行提示
                    if (fileExtension == null || !CommonFunction.validXlfExtension(fileExtension)) {
                        boolean isSure = MessageDialog.openConfirm(shell, Messages.getString("qa.all.dialog.warning"), MessageFormat.format(Messages.getString("qa.all.tip.notXliff"), new Object[] { selectFile.getFullPath() }));
                        if (!isSure) {
                            return null;
                        }
                    }
                    selectIFiles.add(selectFile);
                } else if (object instanceof IContainer) {
                    IContainer selectContainer = (IContainer) object;
                    try {
                        ResourceUtils.getXliffs(selectContainer, selectIFiles);
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error(Messages.getString("qa.handlers.FileAnalysisHandler.log1"), e);
                    }
                }
            }
        }
    } else if (HandlerUtil.getActivePart(event) instanceof IEditorPart) {
        // 如果左边未选择品质检查的类型,那么,获取nattable中打开的文件
        IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        if (activeEditor != null && !activeEditor.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.BatchQAHandler.tip2"));
            return null;
        }
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) activeEditor;
        isMultiFile = nattable.isMultiFile();
        multiTempIFile = ((FileEditorInput) nattable.getEditorInput()).getFile();
        if (isMultiFile) {
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String multiFileStr : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(multiFileStr));
            }
        } else {
            selectIFiles.add(multiTempIFile);
        }
    } else {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip3"));
        return null;
    }
    CommonFunction.removeRepeateSelect(selectIFiles);
    if (selectIFiles.size() <= 0) {
        MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip1"));
        return null;
    }
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : selectIFiles) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    selectIFiles.removeAll(lstFiles);
    if (selectIFiles.size() == 0) {
        return null;
    }
    // 判断要分析的文件是否是属于同一个项目中的.
    IProject project = selectIFiles.get(0).getProject();
    if (selectIFiles.size() >= 2) {
        for (int i = 1; i < selectIFiles.size(); i++) {
            if (selectIFiles.get(i).getProject() != project) {
                MessageDialog.openWarning(shell, Messages.getString("qa.all.dialog.warning"), Messages.getString("qa.handlers.FileAnalysisHandler.tip2"));
                return null;
            }
        }
    }
    model.setAnalysisIFileList(selectIFiles);
    model.setShell(shell);
    model.setMultiFile(isMultiFile);
    if (isMultiFile) {
        model.setMultiTempIFile(multiTempIFile);
    }
    // 文件分析框的框名
    title = model.getAnalysisItemMap().get(faItemId).get(QAConstant.FA_ITEM_NAME);
    FileAnalysisDialog dialog = new FileAnalysisDialog(shell, model, title, faItemId);
    int result = dialog.open();
    if (result == IDialogConstants.OK_ID) {
        analysisFile(title);
    }
    return null;
}
Also used : IViewPart(org.eclipse.ui.IViewPart) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FileAnalysisDialog(net.heartsome.cat.ts.ui.qa.dialogs.FileAnalysisDialog) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) List(java.util.List) IContainer(org.eclipse.core.resources.IContainer) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) IProject(org.eclipse.core.resources.IProject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FAModel(net.heartsome.cat.ts.core.qa.FAModel) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 67 with XLIFFEditorImplWithNatTable

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

the class NumberOrTagConsisQAHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    boolean isMultiFile = false;
    IFile multiTempIFile = null;
    IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
    // 改为布局
    if (editorPart != null && editorPart instanceof XLIFFEditorImplWithNatTable) {
        String qaItem = event.getParameter("qaItemId");
        XLIFFEditorImplWithNatTable nattable = (XLIFFEditorImplWithNatTable) editorPart;
        ArrayList<IFile> selectIFiles = new ArrayList<IFile>();
        FileEditorInput input = (FileEditorInput) nattable.getEditorInput();
        // 首先判断是否是合并打开的文件
        if (nattable.isMultiFile()) {
            isMultiFile = true;
        }
        if (isMultiFile) {
            multiTempIFile = input.getFile();
            List<String> multiFilesList = new XLFHandler().getMultiFiles(multiTempIFile);
            for (String filePath : multiFilesList) {
                selectIFiles.add(ResourceUtils.fileToIFile(filePath));
            }
        } else {
            selectIFiles.add(input.getFile());
        }
        QAModel model = new QAModel();
        IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        shell = window.getShell();
        // 先调用方法,查看品质检查结果视图是否处于显示状态,如果是显示的,就删除数据
        IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        IViewPart view = workbenchPage.findView(QAResultViewPart.ID);
        if (view != null) {
            // 运行时,将结果视图中列表的数据清除
            ((QAResultViewPart) view).clearTableData();
        }
        QAResult qaResult = new QAResult();
        // 存储品质检查的检查项
        // model.setBatchQAItemIdList(getBatchQAItems());
        // 存储品质检查的检查时不包括的文本段
        model.setNotInclude(getNotIncludePara());
        // 给品质检查结果视图发出通告,本次检查对象为合并打开文件
        qaResult.firePropertyChange(isMultiFile, new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        if (isMultiFile) {
            model.setMuliFiles(true);
            model.setMultiOper(new MultiFilesOper(selectIFiles.get(0).getProject(), selectIFiles, multiTempIFile));
        } else {
            model.setMuliFiles(false);
        }
        boolean isNumberQA = false;
        if (QAConstant.QA_NUMBER.equals(qaItem)) {
            isNumberQA = true;
        } else if (QAConstant.QA_TAG.equals(qaItem)) {
            isNumberQA = false;
        }
        List<String> fileList = new ArrayList<String>();
        for (IFile iFIle : selectIFiles) {
            fileList.add(iFIle.getLocation().toOSString());
        }
        qaResult.setFilePathList(fileList);
        HsMultiActiveCellEditor.commit(true);
        beginQA(selectIFiles, model, isNumberQA, qaResult);
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IViewPart(org.eclipse.ui.IViewPart) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) QAResult(net.heartsome.cat.ts.ui.qa.model.QAResult) QAResultViewPart(net.heartsome.cat.ts.ui.qa.views.QAResultViewPart) QAModel(net.heartsome.cat.ts.ui.qa.model.QAModel) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 68 with XLIFFEditorImplWithNatTable

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

the class JumpToNextHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof XLIFFEditorImplWithNatTable) {
        String jumpToNext = event.getParameter("JumpNextSegment");
        if (jumpToNext == null) {
            return null;
        }
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        int[] selectedRows = xliffEditor.getSelectedRows();
        if (selectedRows.length < 1) {
            return null;
        }
        Arrays.sort(selectedRows);
        int lastSelectRow = selectedRows[selectedRows.length - 1];
        XLFHandler handler = xliffEditor.getXLFHandler();
        int nextRow = -1;
        Shell shell = HandlerUtil.getActiveShell(event);
        if (jumpToNext.equalsIgnoreCase("JumpNextNonTranslation")) {
            // 下一未翻译文本段
            nextRow = handler.getNextUntranslatedSegmentIndex(lastSelectRow);
            if (nextRow == -1) {
                MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg1"));
                return null;
            }
        } else if (jumpToNext.equalsIgnoreCase("JumpNextQuestion")) {
            // 下一带疑问文本段
            nextRow = handler.getNextQuestionSegmentIndex(lastSelectRow);
            if (nextRow == -1) {
                MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg2"));
                return null;
            }
        } else if (jumpToNext.equalsIgnoreCase("JumpNextNote")) {
            // 下一带标注文本段
            nextRow = handler.getNextNoteSegmentIndex(lastSelectRow);
            if (nextRow == -1) {
                MessageDialog.openInformation(shell, Messages.getString("handler.JumpToNextHandler.msgTitle"), Messages.getString("handler.JumpToNextHandler.msg3"));
                return null;
            }
        }
        xliffEditor.jumpToRow(nextRow);
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) Shell(org.eclipse.swt.widgets.Shell) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 69 with XLIFFEditorImplWithNatTable

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

the class LockRepeatedSegmentHandler method execute.

@Override
public Object execute(final ExecutionEvent event, final List<IFile> iFileList) {
    list = iFileList;
    tmMatcher = new TmMatcher();
    isCancel = false;
    continuee = true;
    isLocked = false;
    if (list == null || list.isEmpty()) {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("translation.LockRepeatedSegmentHandler.msg1"));
            return null;
        }
        return null;
    }
    try {
        window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    } catch (ExecutionException e1) {
        LOGGER.error("", e1);
        e1.printStackTrace();
    }
    // 首先验证是否是合并打开的文件 --robert
    if (isEditor) {
        IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(list.get(0)), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
        if (editorRefe.length <= 0) {
            return null;
        }
        nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
        // 针对合并打开
        if (nattable.isMultiFile()) {
            list = ResourceUtils.filesToIFiles(nattable.getMultiFileList());
        }
    }
    // 添加验证 peason
    List<IFile> lstFiles = new ArrayList<IFile>();
    XLFValidator.resetFlag();
    for (IFile iFile : list) {
        if (!XLFValidator.validateXliffFile(iFile)) {
            lstFiles.add(iFile);
        }
    }
    XLFValidator.resetFlag();
    if (!(list instanceof ArrayList)) {
        list = new ArrayList<IFile>(list);
    }
    list.removeAll(lstFiles);
    if (list.size() == 0) {
        return null;
    }
    CommonFunction.removeRepeateSelect(list);
    final LockRepeatedSegmentDialog dialog = new LockRepeatedSegmentDialog(shell, list, Messages.getString("translation.LockRepeatedSegmentHandler.dialog"));
    if (dialog.open() == LockRepeatedSegmentDialog.OK) {
        isLockInnerRepeatedSegment = dialog.isLockInnerRepeatedSegment();
        isLockTM100Segment = dialog.isLockTM100Segment();
        isLockTM101Segment = dialog.isLockTM101Segment();
        if (!dialog.isLockInnerRepeatedSegment() && !dialog.isLockTM100Segment() && !dialog.isLockTM101Segment()) {
            // “锁定内部”、“锁定100%”、“锁定101%”都未选中。
            return null;
        }
        if (!isEditor) {
            // 如果针对单个文件, 先验证是否有合并打开的
            MultiFilesOper oper = new MultiFilesOper(list.get(0).getProject(), (ArrayList<IFile>) list);
            // 如果有合并打开的文件,那么将这种转换成针对编辑器的方式处理
            if (oper.validExist()) {
                final IFile multiTempIFile = oper.getMultiFilesTempIFile(true);
                IEditorReference[] editorRefe = window.getActivePage().findEditors(new FileEditorInput(multiTempIFile), XLIFF_EDITOR_ID, IWorkbenchPage.MATCH_INPUT | IWorkbenchPage.MATCH_ID);
                // 如果这几个文件没有合并打开,
                if (editorRefe.length > 0) {
                    nattable = (XLIFFEditorImplWithNatTable) editorRefe[0].getEditor(true);
                    continuee = false;
                }
            }
        }
        // 开始进行处理
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    int totalWork = dialog.isLockInnerRepeatedSegment() ? list.size() : 0;
                    totalWork = (dialog.isLockTM100Segment() || dialog.isLockTM101Segment()) ? totalWork * 2 : totalWork;
                    monitor.beginTask(Messages.getString("translation.LockRepeatedSegmentHandler.task1"), totalWork);
                    // 修改结果显示为是否成功
                    final LockRepeatedSegmentResultDialog lrsrd = new LockRepeatedSegmentResultDialog(shell, list);
                    // 是否进行外部匹配
                    boolean checkTM = false;
                    curProject = list.get(0).getProject();
                    // 锁定外部完全匹配与外部上下文匹配
                    if ((dialog.isLockTM100Segment() || dialog.isLockTM101Segment())) {
                        // 如果是针对编辑器,那么将里面的文件进行统一处理
                        if (isEditor) {
                            LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                            // 用户指定退出操作
                            if (lts == null && isCancel) {
                                return;
                            }
                            lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
                            lrsrd.setLockedContextResult(lts.getLockedContextResult());
                            lrsrd.setTuNumResult(lts.getTuNumResult());
                            checkTM = true;
                        } else {
                            if (continuee) {
                                Map<String, Integer> lockedFullMatchResultMap = new HashMap<String, Integer>();
                                Map<String, Integer> lockedContextMatchResultMap = new HashMap<String, Integer>();
                                Map<String, Integer> lockedTuNumResultMap = new HashMap<String, Integer>();
                                for (int i = 0; i < list.size(); i++) {
                                    IFile iFile = list.get(i);
                                    LockTMSegment lts = lockTMSegment(Arrays.asList(iFile), dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                                    if (lts == null && isCancel) {
                                        return;
                                    }
                                    // 返回的为空,是解析异常的文件被删除了。
                                    if (lts != null) {
                                        lockedFullMatchResultMap.putAll(lts.getLockedFullMatchResult());
                                        lockedContextMatchResultMap.putAll(lts.getLockedContextResult());
                                        lockedTuNumResultMap.putAll(lts.getTuNumResult());
                                    } else {
                                        i--;
                                    }
                                }
                                lrsrd.setLockedFullMatchResult(lockedFullMatchResultMap);
                                lrsrd.setLockedContextResult(lockedContextMatchResultMap);
                                lrsrd.setTuNumResult(lockedTuNumResultMap);
                                checkTM = true;
                            } else {
                                LockTMSegment lts = lockTMSegmentOFEditor(list, dialog.isLockTM100Segment(), dialog.isLockTM101Segment(), monitor);
                                if (lts == null && isCancel) {
                                    return;
                                }
                                lrsrd.setLockedFullMatchResult(lts.getLockedFullMatchResult());
                                lrsrd.setLockedContextResult(lts.getLockedContextResult());
                                lrsrd.setTuNumResult(lts.getTuNumResult());
                                checkTM = true;
                            }
                        }
                    }
                    // 锁定内部重复
                    if (dialog.isLockInnerRepeatedSegment()) {
                        SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, list.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                        HashMap<String, Integer> lockedInnerRepeatedResault = new HashMap<String, Integer>();
                        HashMap<String, Integer> tuNumResult = null;
                        if (!checkTM) {
                            tuNumResult = new HashMap<String, Integer>();
                        }
                        Map<String, int[]> resMap = lockInnerRepeatedSegment(list, subMonitor, checkTM);
                        for (IFile iFile : list) {
                            String filePath = ResourceUtils.iFileToOSPath(iFile);
                            int[] res = resMap.get(filePath);
                            if (!checkTM) {
                                int countTU = res[0];
                                tuNumResult.put(filePath, countTU);
                            }
                            int countLockedInnerRepeatedSegment = res[1];
                            lockedInnerRepeatedResault.put(filePath, countLockedInnerRepeatedSegment);
                        }
                        lrsrd.setLockedInnerRepeatedResault(lockedInnerRepeatedResault);
                        if (!checkTM) {
                            lrsrd.setTuNumResult(tuNumResult);
                        }
                    }
                    Display.getDefault().asyncExec(new Runnable() {

                        public void run() {
                            IEditorPart editor = HandlerUtil.getActiveEditor(event);
                            if (editor != null && editor instanceof XLIFFEditorImplWithNatTable) {
                                XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
                                xliffEditor.reloadXliff();
                            }
                            // lrsrd.open();
                            if (hasWrongResults(list, lrsrd)) {
                                MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
                            } else {
                                MessageDialog.openInformation(shell, Messages.getString("translation.LockRepeatedSegmentHandler.msgTitle"), Messages.getString("dialog.LockRepeatedSegmentResultDialog.locksuccesful"));
                            }
                            lrsrd.close();
                            HsMultiActiveCellEditor.refrushCellsEditAbility();
                        }
                    });
                } finally {
                    monitor.done();
                }
            }
        };
        try {
            new ProgressMonitorDialog(shell).run(true, true, runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IEditorReference(org.eclipse.ui.IEditorReference) ExecutionException(org.eclipse.core.commands.ExecutionException) MultiFilesOper(net.heartsome.cat.ts.ui.util.MultiFilesOper) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) LockRepeatedSegmentDialog(net.heartsome.cat.ts.lockrepeat.dialog.LockRepeatedSegmentDialog) LockRepeatedSegmentResultDialog(net.heartsome.cat.ts.lockrepeat.dialog.LockRepeatedSegmentResultDialog) IEditorPart(org.eclipse.ui.IEditorPart) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ExecutionException(org.eclipse.core.commands.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TmMatcher(net.heartsome.cat.ts.tm.match.TmMatcher) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 70 with XLIFFEditorImplWithNatTable

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

the class KeyEditAction method run.

public void run(NatTable natTable, KeyEvent event) {
    Character character = null;
    if (LetterOrDigitKeyEventMatcher.isLetterOrDigit(event.character) || event.character == ' ') {
        character = Character.valueOf(event.character);
    }
    if (character != null) {
        int[] selectedRowIndexs = XLIFFEditorImplWithNatTable.getCurrent().getSelectedRows();
        if (selectedRowIndexs.length == 0) {
            return;
        }
        Arrays.sort(selectedRowIndexs);
        int rowIndex = selectedRowIndexs[selectedRowIndexs.length - 1];
        ViewportLayer viewportLayer = LayerUtil.getLayer(natTable, ViewportLayer.class);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        // 先记录下可见区域的范围
        int originRowPosition = viewportLayer.getOriginRowPosition();
        // 总行数
        int rowCount = viewportLayer.getRowCount();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            rowIndex = rowIndex * 2;
        }
        if (rowIndex < originRowPosition || rowIndex > originRowPosition + rowCount || HsMultiActiveCellEditor.getTargetEditor() == null) {
            HsMultiActiveCellEditor.commit(true);
            PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
            if (!editor.isHorizontalLayout()) {
                natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
            } else {
                if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                    p.columnPosition = editor.getTgtColumnIndex();
                }
                natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
            }
            HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
            StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor();
            if (cellEditor != null && cellEditor.getCellType().equals(NatTableConstant.TARGET)) {
                cellEditor.insertCanonicalValue(character);
            }
        }
    } else if ((event.character == SWT.CR) && event.stateMask == SWT.NONE) {
        HsMultiActiveCellEditor.commit(true);
        SelectionLayer selectionLayer = LayerUtil.getLayer(natTable, SelectionLayer.class);
        PositionCoordinate p = selectionLayer.getLastSelectedCellPosition();
        XLIFFEditorImplWithNatTable editor = XLIFFEditorImplWithNatTable.getCurrent();
        if (!editor.isHorizontalLayout()) {
            natTable.doCommand(new SelectCellCommand(selectionLayer, editor.getTgtColumnIndex(), p.rowPosition / 2 * 2, false, false));
        } else {
            if (p.columnPosition != editor.getSrcColumnIndex() && p.columnPosition != editor.getTgtColumnIndex()) {
                p.columnPosition = editor.getTgtColumnIndex();
            }
            natTable.doCommand(new SelectCellCommand(selectionLayer, p.columnPosition, p.rowPosition, false, false));
        }
        HsMultiCellEditorControl.activeSourceAndTargetCell(editor);
    }
}
Also used : XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) SelectionLayer(net.sourceforge.nattable.selection.SelectionLayer) SelectCellCommand(net.sourceforge.nattable.selection.command.SelectCellCommand) PositionCoordinate(net.sourceforge.nattable.coordinate.PositionCoordinate) ViewportLayer(net.sourceforge.nattable.viewport.ViewportLayer) StyledTextCellEditor(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)

Aggregations

XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)71 IEditorPart (org.eclipse.ui.IEditorPart)53 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)36 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)27 ArrayList (java.util.ArrayList)16 IFile (org.eclipse.core.resources.IFile)13 FileEditorInput (org.eclipse.ui.part.FileEditorInput)11 StyledTextCellEditor (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.StyledTextCellEditor)9 Shell (org.eclipse.swt.widgets.Shell)9 NattableUtil (net.heartsome.cat.ts.ui.xliffeditor.nattable.utils.NattableUtil)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 IViewPart (org.eclipse.ui.IViewPart)8 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IEditorReference (org.eclipse.ui.IEditorReference)7 HashMap (java.util.HashMap)6 IEditorInput (org.eclipse.ui.IEditorInput)6 ISelection (org.eclipse.jface.viewers.ISelection)5 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)5