John Smith
John Smith

Reputation: 787

Reloading Eclipse view

I have a plugin with a view that creates a tableviewer based on different files found in the selected project (the workspace has more than one project loaded). My problem is that when I try to reload the view the information remains the same as on the first run after Eclipse started.

What should I do in order to reload the content provider everytime I reload the view ?

Upvotes: 0

Views: 115

Answers (2)

John Smith
John Smith

Reputation: 787

This is how my partVisible looks:

public void partVisible(IWorkbenchPartReference partRef) {
    // TODO Auto-generated method stub
    if (partRef.getId().equals("view id taken from extensions"))
       {

        getWorkspacePath();
        viewer.remove(TableContent.INSTANCE.getRow());
        viewer.setInput(TableContent.INSTANCE.updateContentProvider());
        viewer.refresh();

       }
}

The path is updated (i've displayed the path in the view) but the content of the table isn't....updateContentProvider contains the call of the functions that need to parse some files in the selected project....

Upvotes: 0

greg-449
greg-449

Reputation: 111142

To be told about which part is active you need to use IPartListener2. Make your ViewPart implement IPartListener2.

Set up the listener in the createPartControl:

@Override
public void createPartControl(final Composite parent)
{
  ....

  getSite().getWorkbenchWindow().getPartService().addPartListener(this);
}

Remove the listener in dispose:

@Override
public void dispose()
{
  super.dispose();

  ...

  getSite().getWorkbenchWindow().getPartService().removePartListener(this);
}

You will have to implement the various methods of IPartListener, most of these don't need to do anything, the partVisible method is called when your view (or any other part) is shown:

@Override
public void partVisible(final IWorkbenchPartReference ref)
{
  if (ref.getId().equals("your view id"))
   {
     // Your view has become visible ... add code here to update the table
   }
}

Upvotes: 1

Related Questions