Search in sources :

Example 71 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class MatchViewPart method reLoadMatches.

public void reLoadMatches(IXliffEditor editor, int rowIndex) {
    // 修复 Bug #3064 编辑匹配--更换记忆库后再编辑原记忆库匹配,出现异常.刷新问题
    // handler.getTransUnit(rowId);
    TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
    if (transUnit == null) {
        return;
    }
    XLFHandler handler = editor.getXLFHandler();
    if (handler == null) {
        return;
    }
    IProject prj = null;
    if (editor instanceof IEditorPart) {
        IEditorPart p = (IEditorPart) editor;
        FileEditorInput input = (FileEditorInput) p.getEditorInput();
        prj = input.getFile().getProject();
    }
    if (prj == null) {
        return;
    }
    String rowId = handler.getRowId(rowIndex);
    TransUnitInfo2TranslationBean tuInfoBean = getTuInfoBean(transUnit, handler, rowId);
    executeMatch(editor, rowId, transUnit, tuInfoBean, prj);
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IProject(org.eclipse.core.resources.IProject) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 72 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class MatchViewPart method manualExecSimpleTranslation.

public void manualExecSimpleTranslation(int rowIndex, IXliffEditor editor, ISimpleMatcher simpleMatcher) {
    if (rowIndex == -1) {
        return;
    }
    // handler.getTransUnit(rowId);
    TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
    if (transUnit == null) {
        return;
    }
    XLFHandler handler = editor.getXLFHandler();
    if (handler == null) {
        return;
    }
    IProject prj = null;
    if (editor instanceof IEditorPart) {
        IEditorPart p = (IEditorPart) editor;
        FileEditorInput input = (FileEditorInput) p.getEditorInput();
        prj = input.getFile().getProject();
    }
    if (prj == null) {
        return;
    }
    String rowId = handler.getRowId(rowIndex);
    TransUnitInfo2TranslationBean tuInfo = getTuInfoBean(transUnit, handler, rowId);
    TranslationTaskData data = new TranslationTaskData(simpleMatcher, transUnit, tuInfo, editor, rowIndex, prj);
    synchronized (manualTranslationTaskContainer) {
        manualTranslationTaskContainer.pushTranslationTask(data);
        manualTranslationTaskContainer.notify();
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IProject(org.eclipse.core.resources.IProject) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 73 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class MatchViewPart method manualExecComplexTranslation.

public void manualExecComplexTranslation(int rowIndex, IXliffEditor editor, IComplexMatch complexMatcher) {
    if (rowIndex == -1) {
        return;
    }
    // handler.getTransUnit(rowId);
    TransUnitBean transUnit = editor.getRowTransUnitBean(rowIndex);
    if (transUnit == null) {
        return;
    }
    XLFHandler handler = editor.getXLFHandler();
    if (handler == null) {
        return;
    }
    IProject prj = null;
    if (editor instanceof IEditorPart) {
        IEditorPart p = (IEditorPart) editor;
        FileEditorInput input = (FileEditorInput) p.getEditorInput();
        prj = input.getFile().getProject();
    }
    if (prj == null) {
        return;
    }
    String rowId = handler.getRowId(rowIndex);
    TransUnitInfo2TranslationBean tuInfo = getTuInfoBean(transUnit, handler, rowId);
    TranslationTaskData data = new TranslationTaskData(complexMatcher, transUnit, tuInfo, editor, rowIndex, prj);
    synchronized (manualTranslationTaskContainer) {
        manualTranslationTaskContainer.pushTranslationTask(data);
        manualTranslationTaskContainer.notify();
    }
}
Also used : TransUnitBean(net.heartsome.cat.ts.core.bean.TransUnitBean) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEditorPart(org.eclipse.ui.IEditorPart) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler) IProject(org.eclipse.core.resources.IProject) TransUnitInfo2TranslationBean(net.heartsome.cat.ts.tm.bean.TransUnitInfo2TranslationBean)

Example 74 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project translationstudio8 by heartsome.

the class XLIFFEditorImplWithNatTable method saveAs.

/**
	 * 另存文件
	 * @param newInput
	 * @param oldFile
	 * @param monitor
	 *            ;
	 */
private void saveAs(IEditorInput newInput, File oldFile, IProgressMonitor monitor) {
    if (newInput == null || oldFile == null) {
        return;
    }
    boolean success = false;
    try {
        if (newInput instanceof FileEditorInput) {
            IFile newFile = (IFile) newInput.getAdapter(IFile.class);
            if (newFile != null) {
                FileInputStream fis = new FileInputStream(oldFile);
                BufferedInputStream bis = new BufferedInputStream(fis);
                if (newFile.exists()) {
                    newFile.setContents(bis, false, true, monitor);
                } else {
                    newFile.create(bis, true, monitor);
                }
                bis.close();
                fis.close();
            }
        } else if (newInput instanceof FileStoreEditorInput) {
            FileStoreEditorInput storeEditorInput = (FileStoreEditorInput) newInput;
            File newFile = new File(storeEditorInput.getURI());
            copyFile(oldFile, newFile);
        }
        success = true;
    } catch (CoreException e) {
        LOGGER.error("", e);
        final IStatus status = e.getStatus();
        if (status == null || status.getSeverity() != IStatus.CANCEL) {
            String title = Messages.getString("editor.XLIFFEditorImplWithNatTable.msgTitle1");
            String msg = MessageFormat.format(Messages.getString("editor.XLIFFEditorImplWithNatTable.msg2"), e.getMessage());
            MessageDialog.openError(getSite().getShell(), title, msg);
        }
    } catch (FileNotFoundException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (IOException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } finally {
        if (success) {
            setInput(newInput);
        }
    }
    if (monitor != null) {
        monitor.setCanceled(!success);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileInputStream(java.io.FileInputStream) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 75 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput in project tdi-studio-se by Talend.

the class Problems method computeCompilationUnit.

@SuppressWarnings("restriction")
private static List<Problem> computeCompilationUnit(IFile file, ProblemType type, Item item) throws CoreException {
    ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(item);
    // FIXME, only for standard job first, also for JobLaunchShortcut.launch
    if (itemType == null || !itemType.equals(ERepositoryObjectType.PROCESS)) {
        return Collections.emptyList();
    }
    List<Problem> compilProblems = new ArrayList<Problem>();
    final ICompilationUnit unit = JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(new FileEditorInput(file), false);
    if (unit != null) {
        CompilationUnit ast = unit.reconcile(ASTProvider.SHARED_AST_LEVEL, ICompilationUnit.FORCE_PROBLEM_DETECTION, null, null);
        IProblem[] problems = ast.getProblems();
        if (problems != null) {
            for (IProblem p : problems) {
                String[] arguments = p.getArguments();
                int id = p.getID();
                String message = p.getMessage();
                int sourceLineNumber = p.getSourceLineNumber();
                int sourceStart = p.getSourceStart();
                int sourceEnd = p.getSourceEnd();
                String uniName = null;
                IPath location = file.getLocation();
                if (location != null) {
                    String path = location.toString();
                    uniName = setErrorMark(path, sourceLineNumber);
                }
                ProblemStatus status = ProblemStatus.WARNING;
                if (p.isError()) {
                    status = ProblemStatus.ERROR;
                }
                TalendProblem tp = new TalendProblem(status, item, null, message, sourceLineNumber, uniName, sourceStart, sourceEnd, type);
                compilProblems.add(tp);
            }
        }
    }
    return compilProblems;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPath(org.eclipse.core.runtime.IPath) TalendProblem(org.talend.core.model.process.TalendProblem) ArrayList(java.util.ArrayList) IProblem(org.eclipse.jdt.core.compiler.IProblem) ProblemStatus(org.talend.core.model.process.Problem.ProblemStatus) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Problem(org.talend.core.model.process.Problem) IProblem(org.eclipse.jdt.core.compiler.IProblem) TalendProblem(org.talend.core.model.process.TalendProblem) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Aggregations

FileEditorInput (org.eclipse.ui.part.FileEditorInput)87 IFile (org.eclipse.core.resources.IFile)55 CoreException (org.eclipse.core.runtime.CoreException)31 IEditorPart (org.eclipse.ui.IEditorPart)29 PartInitException (org.eclipse.ui.PartInitException)24 ArrayList (java.util.ArrayList)20 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)19 IXliffEditor (net.heartsome.cat.ts.ui.editors.IXliffEditor)18 IEditorReference (org.eclipse.ui.IEditorReference)17 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)16 IEditorInput (org.eclipse.ui.IEditorInput)16 FileStoreEditorInput (org.eclipse.ui.ide.FileStoreEditorInput)15 IProject (org.eclipse.core.resources.IProject)13 File (java.io.File)11 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)11 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ExecutionException (org.eclipse.core.commands.ExecutionException)9 List (java.util.List)7