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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations