RAP:如何访问ViewPart中的对象 [英] RAP: How to access Object in ViewPart
本文介绍了RAP:如何访问ViewPart中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从其他地方访问视图
的对象
?
how do I access to an Object
of a View
from somewhere else?
(以下代码只是勾勒出我想做的事)
(Following code is just to sketch what i want to do)
public class View extends ViewPart {
public static final String ID = "view";
private static List list;
public View() {
}
@Override
public void createPartControl(Composite parent) {
list = new List(parent, SWT.BORDER);
}
@Override
public void setFocus() {
}
public static void addToList(String string) {
list.add(string);
}
}
现在我希望能够使用 View.addToList( Message)
在应用程序中的任何位置。
Now I want be able to use View.addToList("Message")
anywhere in the application.
推荐答案
使用以下命令代码段,并将 [ID]
替换为您在 plugin.xml
中为视图指定的ID。
Use the following code snippet, and replace [ID]
with the id you specified for your view in plugin.xml
.
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView( [ID] );
该ID通常为 com.domain.something.viewName的形式
,可以在您的视图贡献下找到。
The id is usually in the form of com.domain.something.viewName
and can be found under your view contribution.
这篇关于RAP:如何访问ViewPart中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文