读取 Eclipse 状态行

发布于 2024-10-20 04:08:06 字数 334 浏览 3 评论 0原文

我正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流云如水 2024-10-27 04:08:06

恶心的方式:
依赖于 StatusLine 类的实现不变 - 因此请谨慎操作:

StatusLineManager.getControl() 返回一个 StatusLine (受包保护),但它是复合子类,这意味着您可以调用 getChildren() 以及这些子级之一将是包含消息的 CLabel。

但这是非常可怕的。

更好的方法,但更多的工作:

从 StatusLineManager 的文档来看,它说客户端可以子类化以提供不同的布局,因此大概您可以对其进行子类化并提供一种公开最后状态消息的方法。

如果您正在构建 RCP,您应该子类化 WorkbenchWindowAdvisor,它有一个构造函数:

  public WorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) ...

您可以从构造函数中调用:

   configurer.setPresentationFactory(factory);

注意,来自我的 javadocs:

   Deprecated. the presentation factory is now obtained via extension point and a preference on org.eclipse.ui specifying which one to use; see IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID

所以您可能想改为研究该扩展点。

工厂对象应该是您自己的 AbstractPresentationFactory (或者实际上是 WorkbenchPresentationFactory)的子类,
重写此方法:

  public IStatusLineManager createStatusLineManager() {
    return new StatusLineManager();
}

返回您自己的 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:

  public WorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) ...

From the constuctor you could call:

   configurer.setPresentationFactory(factory);

Note, from my javadocs:

   Deprecated. the presentation factory is now obtained via extension point and a preference on org.eclipse.ui specifying which one to use; see IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID

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:

  public IStatusLineManager createStatusLineManager() {
    return new StatusLineManager();
}

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.

随风而去 2024-10-27 04:08:06

恕我直言,从 UI 读取是不好的做法。 Eclipse 架构是 MVC,这意味着如果您以后需要的话,您的状态应该保存在控制器中。

如果我是你,我会使用扩展点存储状态:

  • org.eclipse.core.variables.dynamicVariables,或
  • org.eclipse.core.variables.valueVariables

我会更改变量的值而不是直接更改状态行并使用 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:

  • org.eclipse.core.variables.dynamicVariables, or
  • org.eclipse.core.variables.valueVariables

I will change the value of the variable instead of changing the status line directly and use IValueVariableListener to (automatically) update the status line.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文