I was trying to use the org.eclipse.core.databinding plugin to bind my TableViewer input change. When I tried to add the binding by below code:

1. TableViewer tableViewer = new TableViewer(parent);
2. IViewerObservableValue<Target> target = ViewerProperties.input(TableViewer.class).observe(tableViewer);
3. UpdateValueStrategy<String, Target> updateValueStrategy = new UpdateValueStrategy<>();
updateValueStrategy.setConverter(...);
4. this.bindingContext.bindValue(target, source, new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_NEVER),
    updateValueStrategy);

But, at line number 2, I'm getting an compiler error that 'The method observe(Viewer) is ambiguous for the type IViewerValueProperty<Viewer,Object>' compiler error.

When I look into the source of IViewerObservableValue, There are 2 methods similar, I tried type casting with Viewer or Object for tableViewer variable passed, but, I'm still getting the error.

 `/**
 * Returns an {@link IViewerObservableValue} observing this value property
 * on the given viewer
 *
 * @param viewer
 *            the source viewer
 * @return an observable value observing this value property on the given
 *         viewer
 */
public IViewerObservableValue<T> observe(Viewer viewer);

/**
 * This method is redeclared to trigger ambiguous method errors that are hidden
 * by a suspected Eclipse compiler bug 536911. By triggering the bug in this way
 * clients avoid a change of behavior when the bug is fixed. When the bug is
 * fixed this redeclaration should be removed.
 */
@Override
public IObservableValue<T> observe(S viewer);`

what I'm doing wrong?

1

There are 1 answers

1
Paul-E On

Sorry Everyone, I have figured it out, We can do by following:

IViewerValueProperty<TableViewer, Target> target = ViewerProperties.<TableViewer, Target>input();
IObservableValue<Target> observe = target.observe(tableViewer);

I had forgot to add generic classes to the input() method call, which would have identified the specific observer(viewer) method. Previously, as I had not provided the generics, the compiler was unable to distinguish between the observe(viewerType) and observe(S).

Thanks, Pal