Search in sources :

Example 51 with FileEditorInput

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

the class DataSourceHelper method setDataSource.

/**
	 * 设置数据源
	 * @param editorInput
	 * @param dataSource
	 * @return ;
	 */
public boolean setDataSource(IEditorInput editorInput, T dataSource) {
    if (editorInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
        IFile file = fileEditorInput.getFile();
        return setDataSource(file, dataSource);
    } else if (editorInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
        map.put(generateKey(fileStoreEditorInput), dataSource);
        return true;
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 52 with FileEditorInput

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

the class DataSourceHelper method getDataSource.

/**
	 * 获取数据源
	 * @param editorInput
	 * @return ;
	 */
@SuppressWarnings("unchecked")
public T getDataSource(IEditorInput editorInput) {
    if (editorInput instanceof FileEditorInput) {
        if (editorInput instanceof FileEditorInput) {
            FileEditorInput fileEditorInput = (FileEditorInput) editorInput;
            IFile file = fileEditorInput.getFile();
            return this.getDataSource(file);
        }
    } else if (editorInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
        Object obj = map.get(generateKey(fileStoreEditorInput));
        if (dataSourceClass.isInstance(obj)) {
            return (T) obj;
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 53 with FileEditorInput

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

the class DataSourceHelper method copyDataSource.

/**
	 * 从 oldInput 复制数据源到 newInput
	 * @param oldInput
	 * @param newInput
	 * @return ;
	 */
@SuppressWarnings("unchecked")
public static boolean copyDataSource(IEditorInput oldInput, IEditorInput newInput) {
    if (oldInput instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) oldInput;
        IFile file = fileEditorInput.getFile();
        try {
            Collection<Object> values = file.getSessionProperties().values();
            for (Object value : values) {
                DataSourceHelper helper = new DataSourceHelper(value.getClass());
                helper.setDataSource(newInput, value);
            }
            return true;
        } catch (CoreException e) {
            e.printStackTrace();
            return false;
        }
    } else if (oldInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) oldInput;
        for (Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            if (key.startsWith(fileStoreEditorInput.getURI().toString() + " ")) {
                Object value = map.get(key);
                DataSourceHelper helper = new DataSourceHelper(value.getClass());
                helper.setDataSource(newInput, value);
            }
        }
        return true;
    }
    return false;
}
Also used : Entry(java.util.Map.Entry) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Example 54 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput 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 55 with FileEditorInput

use of org.eclipse.ui.part.FileEditorInput 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)

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