我用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 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器