java - Eclipse插件开发: How to inform view that content has changed?

标签 java eclipse eclipse-plugin jface

我正在开发我的第一个 Eclipse 插件。为此,我使用了一个具有简单 View 的示例。我添加了一个 IStructuredContentProvider 来为 View 提供内容。第一次加载时它可以工作,但是当我更改内容时, View 不会更新。我该怎么办?

这是我的 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).

关于java - Eclipse插件开发: How to inform view that content has changed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8519439/

相关文章:

java - 我可以将可执行 JAR 文件部署到 Azure PaaS 吗?

重启后 Eclipse 语法着色重置

Eclipse RCP 的 Maven 原型(prototype)

java - WAR 中的无状态 ejb > 打包到 EAR > 本地 ejb 调用

java - 在eclipse中调试带有源代码的jar文件

android - 项目没有 project.properties 文件。更改android项目路径

java - 如何从 Git 中删除 ".project"文件?

eclipse - 如何让 Pygame 与 Pydev 一起工作?

java - 哪种静态分析工具用于扫描从一种方法到另一种方法的数据流?

java - JSP include,前后导入代码