Eclipse调用ViewPart saveState on View关闭 [英] Eclipse call ViewPart saveState on View close

查看:181
本文介绍了Eclipse调用ViewPart saveState on View关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse插件,它使用一个ViewPart扩展视图。 ViewPart有一个saveState方法,需要一个IMemento。
我添加了我的代码到saveState和相应的init-Method和它的工作。不幸的是,仅当整个工作区关闭时才调用saveState。我的看法并不是非常重要,我期望它能够在整个时间内开放。因此,如果在查看关闭时调用saveState,那么这将是很酷的。



我发现一个视图部件侦听器是对视图关闭的反应的意思,但是我不得到是IMemento来自哪里。在哪里可以获得工作空间关闭时使用的纪念品对象?或者如果视图被重新打开,我必须存储我自己的Memento对象以使viewPart在init() - 方法中使用它?

  @Override 
public void saveState(IMemento memento){
super.saveState(memento);
memento = memento.createChild(MEMENTO_GUI_STATE);
memento.putBoolean(MEMENTO_IS_FLAT,!isHierarchicalModeActive());
memento.putBoolean(MEMENTO_IS_CATEGORY_MODE_ACTIVE,comboViewer.isVisible());
}

这是我的saveState - 我可以告诉我的看法,视图关闭?

解决方案

看看这个问题


存储视图状态是以两个公共方法取决于
是否要在工作台会话之间或
调用视图之间存储设置。这些设施中的第一个是直接在IViewPart上找到
。当工作台关闭时,方法
saveState在所有打开的视图中被调用。



持久化视图状态的另一种机制是JFace
IDialogSettings设施。
视图save / init机制上的对话框设置的优点在于,您可以控制何时设置
持久化。仅当您的视图在工作台关闭时打开
时才调用saveState方法,因此当用户关闭视图时,不存储视图
状态。
另一方面的对话框设置可以随时更改并保持。


转到另一个问题 Eclipse文档本身用于设置机制。


I have a Eclipse plugin that uses a view which extends ViewPart. ViewPart has a saveState Method which requires an IMemento. I added my code to saveState and the corresponding init-Method and it works. Unfortunately, saveState is only called if the entire workspace is shutting down. My view is not of such great importance that I can expect it to be opened the entire time. Hence, it would be cool if saveState would be called on view closure.

I found a view-part listener as mean to react on view closure, but what I do not get is where the IMemento comes from. Where do I get the memento object that is used on workspace closure? Or where do I have to store my own Memento object to make the viewPart use it in the init()-method if the view is (re)opened?

@Override
public void saveState(IMemento memento) {
    super.saveState(memento);
    memento = memento.createChild(MEMENTO_GUI_STATE);
    memento.putBoolean(MEMENTO_IS_FLAT, !isHierarchicalModeActive());
    memento.putBoolean(MEMENTO_IS_CATEGORY_MODE_ACTIVE, comboViewer.isVisible());
}

this is my saveState - can I tell my view somehow tell to call it every time the view closes?

解决方案

Take a look at this question in the Eclipse FAQ:

Storing view state is done in two commons ways, depending on whether you want to store settings between workbench sessions or across invocations of your view. The first of these facilities is found directly on IViewPart. When the workbench is shut down, the method saveState is called on all open views.

Another mechanism for persisting view state is the JFace IDialogSettings facility. The advantage of dialog settings over the view save/init mechanism is that you can control when settings are persisted. The saveState method is called only if your view is open when the workbench shuts down, so it is not useful for storing view state when the view is closed by the user. Dialog settings, on the other hand, can be changed and persisted whenever you want.

Go to this other question or to the Eclipse documentation itself for the settings mechanism.

这篇关于Eclipse调用ViewPart saveState on View关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆