Search code examples
multithreadingdata-bindingeclipse-plugineclipse-rcp

how to bind Eclipse RCP Table View to other thread data


I have just started with Eclipse RCP. I created Eclipse RCP View with TableViewer and WritableList to get data from other thread. But I cannot see any changes. I need only to show content of List that other thread is managing.

public class View extends ViewPart {
private TableViewer viewer; 
private WritableList input;

I also can get error,

org.eclipse.core.runtime.AssertionFailedException: assertion failed: Getter called outside realm of observable org.eclipse.core.databinding.observable.list.WritableList

I know what is UI Thread. I just don't know how to write. Please help with example.

UPDATE. Was not solved, because of lack of time, and missing good and focused tutorial.


Solution

  • I received this error message also with my code. Databinding observables (WritableList, WritableValue...) inherit from ChangeManager, which provides ChangeManager#getRealm and the realm has Realm#exec. Within the runnable provided to exec, the operation runs in the correct thread.

    This line caused the error (Getter called outside realm of observable):

    WritableValue value = getEditor().getWritableValue();
    System.out.println(((RcpEditorModel) value.getValue()).getNumber());
    

    And this prevented the exception:

    WritableValue value = getEditor().getWritableValue();
    value.getRealm().exec(() -> System.out.println(((RcpEditorModel) value.getValue()).getNumber()));
    

    The same will work with WritableList since it also inherits from ChangeManager.