简体   繁体   English

ViewerSupport和ITableColorProvider或ITableFontProvider

[英]ViewerSupport and ITableColorProvider or ITableFontProvider

I'm writing an RCP-Application and trying to use databinding to link the controls of the GUI with the model. 我正在编写RCP应用程序,并尝试使用数据绑定将GUI的控件与模型链接。 This includes for example binding data to a table. 例如,这包括将数据绑定到表。

As far as I understood, org.eclipse.jface.databinding.viewers.ViewerSupport is the recommended method to bind a model to a table viewer. 据我了解,org.eclipse.jface.databinding.viewers.ViewerSupport是将模型绑定到表查看器的推荐方法。 This will however only allow me to put the data as text into the table. 但是,这仅允许我将数据作为文本放入表中。 I'd also like to change the foreground and background color aswell as the font of some cells, depending on other observables. 我还想更改前景色和背景色以及某些单元格的字体,具体取决于其他可观察对象。 I'd also be happy if I could somehow get a ITableFontProvider or ITableColorProvider into what ViewerSupport.bind(...) produces. 如果我能以某种方式将ITableFontProvider或ITableColorProvider插入ViewerSupport.bind(...)生成的内容,我也很高兴。

So far I've not found a nice way to do that. 到目前为止,我还没有找到一种好的方法。 I could copy the contents of ViewerSupport.bind() and override the LabelProvider with my own class. 我可以复制ViewerSupport.bind()的内容,并使用自己的类覆盖LabelProvider。 This seems a bit messy. 这似乎有点混乱。

I could also after calling ViewerSupport.bind retrieve the LabelProvider and replace it with a delegating LabelProvider which also implements ITableFontProvider and ITableColorProvider. 在调用ViewerSupport.bind之后,我还可以检索LabelProvider并用委派的LabelProvider替换它,该实现也实现了ITableFontProvider和ITableColorProvider。 This leaves me creating a lot of methods that do nothing but delegate things to another object. 这使我创建了很多方法,它们除了将事情委托给另一个对象外什么也不做。 Not very elegant aswell. 也不是很优雅。

All of that doesn't seem so nice. 所有这些似乎都不太好。 Any idea how to do it in an elegant way? 任何想法如何以优雅的方式做到这一点? Am I overlooking some factory class to do that? 我可以忽略一些工厂课程吗?

ViewerSupport just provides simplified methods based on the various data binding content and label providers. ViewerSupport仅提供基于各种数据绑定内容和标签提供程序的简化方法。 It is perfectly acceptable to use these content and label providers directly when ViewerSupport does not provide what you want. ViewerSupport无法提供ViewerSupport内容时,直接使用这些内容和标签提供程序是完全可以接受的。

For example, ViewerSupport.bind(StructuredViewer viewer, IObservableList input, IValueProperty[] labelProperties) is just: 例如, ViewerSupport.bind(StructuredViewer viewer, IObservableList input, IValueProperty[] labelProperties)只是:

ObservableListContentProvider contentProvider = new ObservableListContentProvider();
if (viewer.getInput() != null)
    viewer.setInput(null);
viewer.setContentProvider(contentProvider);
viewer.setLabelProvider(new ObservableMapLabelProvider(Properties
        .observeEach(contentProvider.getKnownElements(),
                    labelProperties)));
if (input != null)
    viewer.setInput(input);

So you could just use this code but with a sub-class of ObservableMapLabelProvider with your font and color providers. 因此,您可以只使用此代码,但是将ObservableMapLabelProvider的子类与字体和颜色提供程序一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM