anon
anon

Reputation:

Eclipse plugin development: How to inform view that content has changed?

I'm developing my first Eclipse plugin. For that I used an example that has a simple view. I added a IStructuredContentProvider to provide the view with content. The first time when it is loaded it works, but when I changed the content, the view isn't updated. What should I do?

This is my 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();
    }
}

Upvotes: 3

Views: 1463

Answers (1)

Martti K&#228;&#228;rik
Martti K&#228;&#228;rik

Reputation: 3621

This is from the description of inputChanged() method:

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).

Upvotes: 4

Related Questions