use of org.eclipse.ui.ide.FileStoreEditorInput 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);
}
}
use of org.eclipse.ui.ide.FileStoreEditorInput in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(Messages.getString("editor.XLIFFEditorImplWithNatTable.logger1"));
}
setSite(site);
setInput(input);
List<File> files = null;
if (input instanceof FileStoreEditorInput) {
FileStoreEditorInput editorInput = (FileStoreEditorInput) input;
files = Arrays.asList(new File(editorInput.getURI()));
setPartName(input.getName());
} else if (input instanceof FileEditorInput) {
FileEditorInput editorInput = (FileEditorInput) input;
try {
files = getFilesByFileEditorInput(editorInput);
} catch (CoreException e) {
throw new PartInitException(e.getMessage(), e);
}
if (files != null) {
if (files instanceof ArrayList<?>) {
// “打开项目”的情况,会返回 java.util.ArrayList<?> 对象。
if (files.size() <= 0) {
// 关闭此编辑器。
close();
return;
}
// 设置Editor标题栏的显示名称,否则名称用plugin.xml中的name属性
StringBuffer nameSB = new StringBuffer();
for (File file : files) {
nameSB.append(file.getName() + "、");
}
nameSB.deleteCharAt(nameSB.length() - 1);
String partName = "";
if (nameSB.length() > 17) {
partName = nameSB.substring(0, 17) + "...";
} else {
partName = nameSB.toString();
}
setPartName(partName);
titleToolTip = nameSB.toString();
multiFile = true;
multiFileList = files;
} else {
// 打开文件的一般情况
setPartName(input.getName());
String name = input.getName().toLowerCase();
if (!CommonFunction.validXlfExtensionByFileName(name)) {
// IFile file = (IFile) input.getAdapter(IFile.class);
// 打开正转换对话框
// ConverterCommandTrigger.openConversionDialog(site.getWorkbenchWindow(), file);
// 关闭此编辑器。
close();
return;
}
}
}
}
// if (files == null || !XLFValidator.validateXlifFiles(files)) {
// close(); // 关闭此编辑器。
// return;
// }
openFile(files, input);
}
use of org.eclipse.ui.ide.FileStoreEditorInput 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.ide.FileStoreEditorInput 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.ide.FileStoreEditorInput 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;
}
Aggregations