3

This is my first SO question. I hope i provide enough details.
I have an EMF Model with a class called ScopeContainer, which has two containment References as ELists of Different Types.

I have generated the

  • model
  • model.edit and
  • model.editor

codes with the Genmodel

I am trying to show the contents of one of those lists in a org.eclipse.jface.viewers.TableViewer with only one Column.

This can't be a org.eclipse.swt.widgets.List since i want to be able to edit those entries.

TableViewer viewer;
AdapterFactory adapterFactory = storage.getDomain().getAdapterFactory();
AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
AdapterFactoryContentProvider contentProvider = new AdapterFactoryContentProvider(adapterFactory);

viewer.setLabelProvider(labelProvider);
viewer.setContentProvider(contentProvider);
viewer.setInput(project.getScopecontainer().getFilters());

When I set the input as the the ScopeContainer Object. I can see all the objects in both lists When i set the input as the EList<Filter> the Table is empty. What do i have to do to set the Input of the TableViewer as EList?

Fuhry
  • 43
  • 7

3 Answers3

3

A simple solution would be to override AdapterFactoryContentProvider.getElements() to return an array of Filter elements (derived from the EList<Filter> input).

erdal.karaca
  • 693
  • 1
  • 4
  • 20
  • Thank you for your answer. I provide the code I implemented as an Answer. I am greatful for suggestions. – Fuhry Apr 08 '19 at 07:48
1

As suggested I overrode the getElements Method Like this:

public class EListContentProvider<T> extends AdapterFactoryContentProvider{

    public EListContentProvider(AdapterFactory adapterFactory) {
        super(adapterFactory);
    }

    @Override
    public Object[] getElements(Object inputElement) {
        Object[] arr = null;
        if(inputElement instanceof EList) {
            arr = ((EList<T>) inputElement).toArray();
        }
        return arr;
    }
}
Fuhry
  • 43
  • 7
0

You should check the class org.eclipse.jface.viewers.ArrayContentProvider or the class org.eclipse.jface.databinding.viewers.ObservableListContentProvider, depending on if your list is supposed to change or not.

Those content providers do exactly what you are asking for: manage a collection input for a table or a viewer.