Search in sources :

Example 21 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class PreMachineTransUitls method executeTranslation.

public static void executeTranslation(List<IFile> list, final Shell shell) {
    HsMultiActiveCellEditor.commit(true);
    try {
        if (list.size() == 0) {
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg1"));
            return;
        }
        List<IFile> lstFiles = new ArrayList<IFile>();
        XLFValidator.resetFlag();
        for (IFile iFile : list) {
            if (!XLFValidator.validateXliffFile(iFile)) {
                lstFiles.add(iFile);
            }
        }
        XLFValidator.resetFlag();
        list = new ArrayList<IFile>(list);
        list.removeAll(lstFiles);
        if (list.size() == 0) {
            return;
        }
        final IProject project = list.get(0).getProject();
        final List<String> filesWithOsPath = ResourceUtils.IFilesToOsPath(list);
        final XLFHandler xlfHandler = new XLFHandler();
        Map<String, Object> resultMap = xlfHandler.openFiles(filesWithOsPath);
        if (resultMap == null || Constant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) resultMap.get(Constant.RETURNVALUE_RESULT)) {
            // 打开文件失败。			
            MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg2"));
            return;
        }
        Map<String, List<XliffBean>> map = xlfHandler.getXliffInfo();
        final PreMachineTransParameters parameters = new PreMachineTransParameters();
        PreMachineTranslationDialog dialog = new PreMachineTranslationDialog(shell, map, parameters);
        if (dialog.open() == Window.OK) {
            if (project == null) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg3"));
                return;
            }
            if (filesWithOsPath == null || filesWithOsPath.size() == 0) {
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.msg4"));
                return;
            }
            final List<IFile> lstFile = list;
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    PreMachineTranslation pt = new PreMachineTranslation(xlfHandler, filesWithOsPath, project, parameters);
                    try {
                        final List<PreMachineTranslationCounter> result = pt.executeTranslation(monitor);
                        Display.getDefault().syncExec(new Runnable() {

                            public void run() {
                            //PreMachineTranslationResultDialog dialog = new PreMachineTranslationResultDialog(shell, result);
                            //dialog.open();
                            }
                        });
                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
                        result.clear();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (CoreException e) {
                        logger.error("", e);
                        e.printStackTrace();
                    } finally {
                        pt.clearResources();
                    }
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                            for (IFile file : lstFile) {
                                FileEditorInput editorInput = new FileEditorInput(file);
                                IEditorPart editorPart = page.findEditor(editorInput);
                                // 选择所有语言
                                XLFHandler handler = null;
                                if (editorPart != null && editorPart instanceof IXliffEditor) {
                                    // xliff 文件已用 XLIFF 编辑器打开
                                    IXliffEditor xliffEditor = (IXliffEditor) editorPart;
                                    handler = xliffEditor.getXLFHandler();
                                    handler.resetCache();
                                    VTDGen vg = new VTDGen();
                                    String path = ResourceUtils.iFileToOSPath(file);
                                    if (vg.parseFile(path, true)) {
                                        handler.getVnMap().put(path, vg.getNav());
                                        xliffEditor.refresh();
                                    }
                                }
                            }
                        }
                    });
                }
            };
            try {
                new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
                MessageDialog.openInformation(shell, Messages.getString("pretranslation.PreTransUitls.msgTitle"), Messages.getString("pretranslation.PreTransUitls.result.msg"));
            } catch (InvocationTargetException e) {
                logger.error("", e);
            } catch (InterruptedException e) {
                logger.error("", e);
            }
        }
    } finally {
        HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.getCurrent());
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) PreMachineTransParameters(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTransParameters) PreMachineTranslationDialog(net.heartsome.cat.ts.machinetranslation.dialog.PreMachineTranslationDialog) ArrayList(java.util.ArrayList) List(java.util.List) PreMachineTranslationCounter(net.heartsome.cat.ts.machinetranslation.bean.PreMachineTranslationCounter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) VTDGen(com.ximpleware.VTDGen) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 22 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method getAllOpenedIFile.

/**
	 * 获取所有已经被打开的文件
	 * @return
	 */
private Map<IFile, IEditorPart> getAllOpenedIFile() {
    Map<IFile, IEditorPart> openedIfileMap = new HashMap<IFile, IEditorPart>();
    IEditorReference[] referenceArray = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    for (IEditorReference reference : referenceArray) {
        IEditorPart editor = reference.getEditor(true);
        // 如果这是一个 nattable 编辑器
        if (XLIFF_EDITOR_ID.equals(editor.getSite().getId())) {
            IXliffEditor xlfEditor = (IXliffEditor) editor;
            if (xlfEditor.isMultiFile()) {
                for (File file : xlfEditor.getMultiFileList()) {
                    openedIfileMap.put(ResourceUtils.fileToIFile(file.getAbsolutePath()), editor);
                }
            } else {
                openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
            }
        } else {
            // 其他情况,直接将文件丢进去就行了
            openedIfileMap.put(((FileEditorInput) editor.getEditorInput()).getFile(), editor);
        }
    }
    return openedIfileMap;
}
Also used : IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) HashMap(java.util.HashMap) IEditorPart(org.eclipse.ui.IEditorPart) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 23 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class MultiFilesOper method getAllOpenedIFiles.

/**
	 * 获取当前所打开的所有文件
	 * @return
	 */
public List<IFile> getAllOpenedIFiles() {
    IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
    List<IFile> isOpenedXlfList = new ArrayList<IFile>();
    try {
        IXliffEditor xlfEditor;
        for (int i = 0; i < editorRes.length; i++) {
            if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
                IFile iFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
                //合并打开的情况
                if ("xlp".equals(iFile.getFileExtension())) {
                    xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
                    isOpenedXlfList.addAll(ResourceUtils.filesToIFiles(xlfEditor.getMultiFileList()));
                } else {
                    try {
                        isOpenedXlfList.add(((FileEditorInput) editorRes[i].getEditorInput()).getFile());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return isOpenedXlfList;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) ArrayList(java.util.ArrayList) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException)

Example 24 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class MultiFilesOper method getMultiFilesTempIFile.

/**
	 * 根据指定要合并打开的文件,获取其配置文件
	 * @param selectIFiles
	 * @param isActive	如果找到了符合的合并打开临时文件,是否激活当前nattable编辑器
	 * @return ;
	 */
public IFile getMultiFilesTempIFile(boolean isActive) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorReference[] editorRes = page.getEditorReferences();
    for (int i = 0; i < editorRes.length; i++) {
        if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
            try {
                IXliffEditor xlfEditor = (IXliffEditor) editorRes[i].getEditor(true);
                IFile multiTempFile = ((FileEditorInput) editorRes[i].getEditorInput()).getFile();
                List<File> openedFileList = xlfEditor.getMultiFileList();
                boolean isExist = false;
                if (selectIFiles.size() == openedFileList.size()) {
                    isExist = true;
                    for (IFile iFile : selectIFiles) {
                        if (openedFileList.indexOf(iFile.getFullPath().toFile()) == -1) {
                            continue;
                        }
                    }
                }
                //					}
                if (isActive) {
                    page.activate(editorRes[i].getEditor(true));
                }
                if (isExist) {
                    return multiTempFile;
                }
            } catch (PartInitException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}
Also used : IEditorReference(org.eclipse.ui.IEditorReference) IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor)

Example 25 with IXliffEditor

use of net.heartsome.cat.ts.ui.editors.IXliffEditor in project translationstudio8 by heartsome.

the class TermBaseSearchDialog method InsertGridTgtToEditor.

private void InsertGridTgtToEditor() {
    GridItem[] selection = grid.getSelection();
    if (null == selection || selection.length == 0) {
        return;
    }
    IXliffEditor tempEditor = null;
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof IXliffEditor) {
        IXliffEditor editor = (IXliffEditor) activeEditor;
        tempEditor = editor;
    }
    if (tempEditor == null) {
        return;
    }
    int[] selectedRows = tempEditor.getSelectedRows();
    if (null == selectedRows || selectedRows.length == 0) {
        return;
    }
    int rowIndex = selectedRows[0];
    if (tempEditor == null || rowIndex < 0) {
        return;
    }
    TransUnitBean transUnit = tempEditor.getRowTransUnitBean(rowIndex);
    Hashtable<String, String> tuProp = transUnit.getTuProps();
    if (tuProp != null) {
        String translate = tuProp.get("translate");
        if (translate != null && translate.equalsIgnoreCase("no")) {
            MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg1"));
            return;
        }
    }
    String tarTerm = selection[0].getText(1);
    if (null == tarTerm || tarTerm.isEmpty()) {
        return;
    }
    try {
        tempEditor.insertCell(rowIndex, tempEditor.getTgtColumnIndex(), tarTerm);
    // tempEditor.setFocus(); // 焦点给回编辑器
    } catch (ExecutionException e) {
        if (Constant.RUNNING_MODE == Constant.MODE_DEBUG) {
            e.printStackTrace();
        }
        MessageDialog.openInformation(tempEditor.getSite().getShell(), Messages.getString("view.TerminologyViewPart.msgTitle"), Messages.getString("view.TerminologyViewPart.msg2") + e.getMessage());
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) GridItem(org.eclipse.nebula.widgets.grid.GridItem) IEditorPart(org.eclipse.ui.IEditorPart) ExecutionException(org.eclipse.core.commands.ExecutionException) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) Point(org.eclipse.swt.graphics.Point)

Aggregations

IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)34 IEditorPart (org.eclipse.ui.IEditorPart)24 FileEditorInput (org.eclipse.ui.part.FileEditorInput)18 IFile (org.eclipse.core.resources.IFile)17 IEditorReference (org.eclipse.ui.IEditorReference)10 IViewPart (org.eclipse.ui.IViewPart)10 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)8 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)8 PartInitException (org.eclipse.ui.PartInitException)8 ArrayList (java.util.ArrayList)7 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)7 IProject (org.eclipse.core.resources.IProject)7 CoreException (org.eclipse.core.runtime.CoreException)7 MatchViewPart (net.heartsome.cat.ts.ui.translation.view.MatchViewPart)5 ProjectConfiger (net.heartsome.cat.ts.core.file.ProjectConfiger)4 ISimpleMatcher (net.heartsome.cat.ts.tm.simpleMatch.ISimpleMatcher)4 ExecutionException (org.eclipse.core.commands.ExecutionException)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3