[英]Eclipse RCP how to get composite parent
I want to create tableviewer in RCP but I don't know how to get "Composite parent". 我想在RCP中创建tableviewer,但不知道如何获取“复合父级”。 I have this code :
我有这个代码:
@PostConstruct
public void createComposite(Composite parent) {
Books.generateBooks();
Map<String, Books> allBooks = Books.returnAllBooks();
List<String> booksList = new ArrayList<String>(allBooks.keySet());
tableViewer = new TableViewer(parent);
for(int i=0; i<booksList.size(); i++) {
tableViewer.add(booksList.get(i));
}
tableViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
if (selection.isEmpty()) return;
BibliotekaSzczegolyPart.createComposite(selection.getFirstElement().toString());
}
});
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL));
}
It creates table view in my part, and add DoubleClickListener in table positions. 它在我的部分中创建表格视图,并在表格位置添加DoubleClickListener。 Now I want to create function createComposite in another class which I want to activate after double click but then I don't have "Composite parent" because it is not @PostConstruct.
现在,我想在另一个要在双击后激活的类中创建函数createComposite,但是我没有“ Composite parent”,因为它不是@PostConstruct。 How to get it?
如何获得?
The best way to do this is to use the event broker to send a event that the other part can listen for. 做到这一点的最佳方法是使用事件代理发送另一个部分可以监听的事件。 That way you don't need a reference to the other part.
这样,您就无需引用其他部分。
To send an event: 发送事件:
@Inject
IEventBroker eventBroker;
String value = .... value you want to send (doesn't have to be a string)
eventBroker.post("/my/topic", value);
To listen for the event include a method like this in the class that wants to listen (assumes the class is created by injection): 要侦听该事件,请在想要侦听的类中包含一个类似这样的方法(假设该类是通过注入创建的):
@Inject
@Optional
public void event(@UIEventTopic("/my/topic") final String value)
{
if (value != null) {
// TODO Handle value
}
}
You may get a call to the method with a value
set to null
while the part is being initialized so check for that. 初始化零件时,您可能会调用方法的
value
设置为null
,因此请检查该值。
The method name can be anything you like. 方法名称可以是您喜欢的任何名称。
@UIEventTopic
forces the event to arrive on the UI thread. @UIEventTopic
强制事件到达UI线程。 Use @EventTopic
if you don't care about the thread. 如果您不关心线程,请使用
@EventTopic
。
The topic name can be whatever you choose but it must contain /
separators as shown. 主题名称可以是您选择的任何名称,但它必须包含
/
分隔符,如图所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.