魏爱晨晨1 2016-05-10 12:06 采纳率: 0%
浏览 1147

GEF编辑器的文件如何实现保存功能。结合RCP做的。

  我用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();
}

麻烦大家知道的指点一二,谢谢。
  • 写回答

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 保护模式-系统加载-段寄存器