我用GEF框架,结合RCP技术做了一个编辑器,现在编辑的内容无法实现保存。
保存涉及到的代码如下
@Override
public void doSave(IProgressMonitor monitor) {
System.out.println("CCML中的dosave方法开始执行 ");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
createOutputStream(out);
//从编辑器获得编辑文件
IFile file = ((IFileEditorInput) getEditorInput()).getFile();
file.setContents(
new ByteArrayInputStream(out.toByteArray()),
true, // keep saving, even if IFile is out of sync with the Workspace
false, // dont keep history
monitor); // progress monitor
getCommandStack().markSaveLocation();
} catch (CoreException ce) {
ce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void createOutputStream(OutputStream os) throws IOException {
//创建写入指定 OutputStream 的 ObjectOutputStream
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(getModel());
oos.close();
}
麻烦大家知道的指点一二,谢谢。
GEF编辑器的文件如何实现保存功能。结合RCP做的。
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 普通网友 2016-10-07 17:27关注
ide
public void doSave(IProgressMonitor monitor) {
System.out.println("CCML中的dosave方法开始执行 ");
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
createOutputStream(out);
//从编辑器获得编辑文件
IFile file = ((IFileEditorInput) getEditorInput()).getFile();
file.setContents(
new ByteArrayInputStream(out.toByteArray()),
true, // keep saving, even if IFile is out of sync with the Workspace
false, // dont keep history
monitor); // progress monitor
getCommandStack().markSaveLocation();
} catch (CoreException ce) {
ce.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private void createOutputStream(OutputStream os) throws IOException {
//创建写入指定 OutputStream 的 ObjectOutputStream
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(getModel());
oos.close();解决 无用评论 打赏 举报
悬赏问题
- ¥15 vscode问题请教
- ¥50 切换TabTip键盘的输入法
- ¥15 可否在不同线程中调用封装数据库操作的类
- ¥15 微带串馈天线阵列每个阵元宽度计算
- ¥15 keil的map文件中Image component sizes各项意思
- ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
- ¥15 划分vlan后,链路不通了?
- ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
- ¥15 Vue3 大型图片数据拖动排序
- ¥15 Centos / PETGEM