读取 Eclipse 状态行
我正在构建一个 Eclipse RCP 应用程序并通过以下方式在共享状态行中设置文本:
IStatusLineManager statusLine =
getWindowConfigurer().getActionBarConfigurer().getStatusLineManager();
statusLine.setMessage("some status text");
我想知道是否有办法读回共享状态行中显示的当前文本?我注意到您可以使用 StatusLineContributionItem 执行此操作,但对于共享状态行似乎并非如此。
提前致谢。
I'm building an Eclipse RCP application and setting text in the shared status line via:
IStatusLineManager statusLine =
getWindowConfigurer().getActionBarConfigurer().getStatusLineManager();
statusLine.setMessage("some status text");
I'm wondering if there is a way to read back the current text displayed in the shared status line? I notice you can do so with StatusLineContributionItem's but doesn't seem so with the shared status line.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
恶心的方式:
依赖于 StatusLine 类的实现不变 - 因此请谨慎操作:
StatusLineManager.getControl() 返回一个 StatusLine (受包保护),但它是复合子类,这意味着您可以调用 getChildren() 以及这些子级之一将是包含消息的 CLabel。
但这是非常可怕的。
更好的方法,但更多的工作:
从 StatusLineManager 的文档来看,它说客户端可以子类化以提供不同的布局,因此大概您可以对其进行子类化并提供一种公开最后状态消息的方法。
如果您正在构建 RCP,您应该子类化 WorkbenchWindowAdvisor,它有一个构造函数:
您可以从构造函数中调用:
注意,来自我的 javadocs:
所以您可能想改为研究该扩展点。
工厂对象应该是您自己的 AbstractPresentationFactory (或者实际上是 WorkbenchPresentationFactory)的子类,
重写此方法:
返回您自己的 StatusLineManager 子类。
注意:我使用的是 Eclipse 3.4.2,因此请仔细检查文档以了解您正在使用的版本。
Nasty way:
Relies on the implementation of the StatusLine class not changing - so proceed with caution:
StatusLineManager.getControl() returns a StatusLine (which is package protected), however it subclasses composite, which means you can call getChildren(), and one of these children will be a CLabel containing the message.
This is horrendously hacky though.
Nicer way, but more work:
From the documentation of StatusLineManager it says that clients may subclass to provide different layouts, so presumably you could subclass this and provide a means of exposing the last status message.
If you are building an RCP you should be subclassing WorkbenchWindowAdvisor, which has a constructor:
From the constuctor you could call:
Note, from my javadocs:
So you may want to investigate that extension point instead.
the factory object should be your own subclass of AbstractPresentationFactory (or indeed WorkbenchPresentationFactory),
overriding this method:
to return your own subclass of StatusLineManager.
NOTE: I'm using Eclipse 3.4.2, so double check the docs for the version you are using.
恕我直言,从 UI 读取是不好的做法。 Eclipse 架构是 MVC,这意味着如果您以后需要的话,您的状态应该保存在控制器中。
如果我是你,我会使用扩展点存储状态:
我会更改变量的值而不是直接更改状态行并使用 IValueVariableListener 用于(自动)更新状态行。
IMHO, it is bad practice to read from UI. Eclipse architecture is MVC and that means your status should be saved in controller if you need it for later purpose.
If I were you, I would store the status using extension points:
I will change the value of the variable instead of changing the status line directly and use IValueVariableListener to (automatically) update the status line.