java-Eclipse插件开发:如何通知视图内容已更改?
作者:互联网
我正在开发我的第一个Eclipse插件.为此,我使用了一个具有简单视图的示例.我添加了一个IStructuredContentProvider来为视图提供内容.第一次加载时它可以工作,但是当我更改内容时,视图不会更新.我该怎么办?
这是我的IStructuredContentProvider:
public class ViewContentProvider implements IStructuredContentProvider {
private List<Project> projects = new ArrayList<Project>();
private void addProject(Project project) {
if (!projects.contains(project)) {
projects.add(project);
}
}
public void addProjects(List<Project> projects) {
for (Project project : projects) {
addProject(project);
}
}
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
@Override
public void dispose() {
}
@Override
public Object[] getElements(Object parent) {
return projects.toArray();
}
}
解决方法:
这来自于inputChanged()方法的描述:
A typical use for this method is registering the content provider as a listener to changes on the new input (using model-specific means), and deregistering the viewer from the old input. In response to these change notifications, the content provider should update the viewer (see the add, remove, update and refresh methods on the viewers).
标签:jface,eclipse,eclipse-plugin,java 来源: https://codeday.me/bug/20191101/1987205.html