2c00L
2c00L

Reputation: 514

Eclipse RCP: TableViewer setInput from another view

I have several views in my RCP project.

In one view I have a TableViewer.

In another view I have a JFrame with a Button.

I want to update the data in the TableViewer using the setInput() method when I press the button in another view.

How do I do this?

EDIT:

Initial input to the table viewer:

tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.setLabelProvider(new TableLabelProvider() );
tableViewer.setInput(TraceData.getTraceData());     // get realtime data

I add the listener to the tableViewer to listen to changes in the GUI

listener = new ISelectionListener() {
    public void selectionChanged(IWorkbenchPart part, ISelection sel) {
       if (!(sel instanceof IStructuredSelection))
          return;
       IStructuredSelection ss = (IStructuredSelection) sel;
       Object o = ss.getFirstElement();
       if (o instanceof Book) // something else in place of Book
          tableViewer.setInput(TraceData.getSavedTraceData());
    }
 };

getSite().getPage().addSelectionListener(listener);

And the problem is how to make it react to a button event in another view? That is how to brodcast the JButton press event and then listen to that event in this TreeViewer.

Upvotes: 0

Views: 884

Answers (1)

Xavier Bouclet
Xavier Bouclet

Reputation: 1012

In my RCP application, I have a View class which is extended by all others. In this View I have :

abstract void refresh();

Now, you have to use the refresh method of the view with the TableViewer.

@Override
public void refresh() {
    tableViewer.setInput(...);
    tableViewer.refresh();
}

And you have to call the refresh method from the button

How to access a view from anotherone.

final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
final IWorkbenchPage page = window.getActivePage();
try {
    if (page.getActivePart() != null) {
    viewTitle = page.getActivePart().getTitle();
    IViewPart view = page.showView(MainView.ID)  //id de la view in plugin.xml
    page.hideView(page.findView(SitesView.ID));
    }

Upvotes: 1

Related Questions