Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF-Databinding] Observe addition/removal changes in multi-value feature of a multi-value feature
[EMF-Databinding] Observe addition/removal changes in multi-value feature of a multi-value feature [message #902114] Wed, 15 August 2012 22:38 Go to next message
Paco Blanco is currently offline Paco BlancoFriend
Messages: 28
Registered: June 2012
Junior Member
Me again... :S

We want to observe element additions/removals from a list of a list of objects (like a double-nested multi-value feature)
We have a Model instance, this one has a multi-value feature, the objects from this feature was shown in a table. They have another multi-value feature inside that I want to observe.

Wrong code:
WritableValue writable = new WritableValue();
writable.setValue(model);
IObservableList observableSubElementList = EMFProperties.list(ModelPackage.Literals.MODEL__SUBELEMENTS).observeDetail(writable);
ObservableListContentProvider ocp = new ObservableListContentProvider();
tableViewer.setContentProvider(ocp);
table.setInput(observableSubElementList);

//One wrong possibility to observe changes in the SubList:
IObservableList observableSubSubElementList = EMFProperties.value(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observeDetail(observableSubElementList);
observableSubSubElementList.addListChangeListener(new IListChangeListener() {
    @Override
    public void handleListChange(ListChangeEvent event) {
          //Do something
    }
});

//Another wrong possibility to observe changes in the SubList:
IObservableList observableSubSubElementMap = EMFProperties.value(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observeDetail(ocp.getKnownElements());
observablePermissionList.addMapChangeListener(new IMapChangeListener() {
     @Override
     public void handleListChange(ListChangeEvent event) {
          //Do something
     }
});


The wrong code only observe changes if one list is replaced by other list (other Java object). It does not observe to the subelement additions or removals in any list.

I think we have to use not ObservableList/Map.value but ObservableList/Map.list:
IObservableList observableSubSubElementList = EMFProperties.list(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS) -> xxxxx -> observableSubElementList

xxxxx can be a method or a group of methods that I cannot find.


Any idea? Or maybe is it not possible?

[Updated on: Wed, 15 August 2012 22:41]

Report message to a moderator

Re: [EMF-Databinding] Observe addition/removal changes in multi-value feature of a multi-value featu [message #902149 is a reply to message #902114] Thu, 16 August 2012 06:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
What you want to do is not supported, the only thing we have since the
last release is that you can observe an index inside a list but this
would mean your first list is has a fixed amount of items.

Tom

Am 16.08.12 00:38, schrieb Paco Blanco:
> Me again... :S
>
> We want to observe element additions/removals from a list of a list of
> objects (like a double-nested multi-value feature)
> We have a Model instance, this one has a multi-value feature, the
> objects from this feature was shown in a table. They have another
> multi-value feature inside that I want to observe.
>
> Wrong code:
>
> WritableValue writable = new WritableValue();
> writable.setValue(model);
> IObservableList observableSubElementList =
> EMFProperties.list(ModelPackage.Literals.MODEL__SUBELEMENTS).observeDetail(writable);
>
> tableViewer.setContentProvider(ocp);
> table.setInput(observableSubElementList);
>
> //One wrong possibility to observe changes in the SubList:
> IObservableList observableSubSubElementList =
> EMFProperties.value(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observeDetail(observableSubElementList);
>
> observableSubSubElementList.addListChangeListener(new
> IListChangeListener() {
> @Override
> public void handleListChange(ListChangeEvent event) {
> //Do something
> }
> });
>
> //Another wrong possibility to observe changes in the SubList:
> IObservableList observableSubSubElementMap =
> EMFProperties.value(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observeDetail(ocp.getKnownElements());
>
> observablePermissionList.addMapChangeListener(new IMapChangeListener() {
> @Override
> public void handleListChange(ListChangeEvent event) {
> //Do something
> }
> });
>
>
> The wrong code only observe changes if one list is replaced by other
> list (other Java object). It does not observe to the subelement
> additions or removals in the lists.
>
> I think we have to use not ObservableList/Map.value but
> ObservableList/Map.list:
> IObservableList observableSubSubElementList =
> EMFProperties.list(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS) ->
> xxxxx -> observableSubElementList
>
> xxxxx can be a method or a group of methods that I cannot find.
>
>
> Any idea? Or maybe is it not possible?
Re: [EMF-Databinding] Observe addition/removal changes in multi-value feature of a multi-value featu [message #902187 is a reply to message #902149] Thu, 16 August 2012 09:26 Go to previous messageGo to next message
Paco Blanco is currently offline Paco BlancoFriend
Messages: 28
Registered: June 2012
Junior Member
Thank for your answer, Tom.
Can you say to me how to do "you can observe an index inside a list but this would mean your first list is has a fixed amount of items"? (with simple code snippet is enough Razz)

BTW, my aprroach to the topic problem is:

private Map<Object, IObservableList> observablePermissionMap = new HashMap<Object,IObservableList>();

method:
..... 
WritableValue writable = new WritableValue();
writable.setValue(model);
IObservableList observableSubElementList = EMFProperties.list(ModelPackage.Literals.MODEL__SUBELEMENTS).observeDetail(writable);
ObservableListContentProvider ocp = new ObservableListContentProvider();
tableViewer.setContentProvider(ocp);
table.setInput(observableSubElementList);

observableSubElementList.addListChangeListener(new IListChangeListener() {
  @Override
  public void handleListChange(ListChangeEvent event) {
    for(final ListDiffEntry entry : event.diff.getDifferences()) {
      if(entry.isAddition()) {
        addObservableToMap((MySubElementClass) entry.getElement());
      } else if(observablePermissionMap.containsKey(entry.getElement())){
        observableList observable = observablePermissionMap.get(entry.getElement());
        observable.dispose();
        observablePermissionMap.remove(entry.getElement());
      }
    }
  }			
});
for(final Object objectToObserve : observableSubElementList) {
  if(!observablePermissionMap.containsKey(objectToObserve)) {
    addObservableToMap((MySubElementClass) objectToObserve);
  }
}
.... 
end method

private void addObservableToMap(final MySubElementClass objectToObserve) {
  IObservableList observable = EMFProperties.list(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observe(objectToObserve);
  observable.addChangeListener(new IChangeListener() {
    @Override
    public void handleChange(ChangeEvent event) {
      //Do something, in my case:
      table.getTableViewer().update(objectToObserve, columnProperties);							
    }							
  });
  observablePermissionMap.put(objectToObserve, observable);
}

[Updated on: Fri, 24 August 2012 13:23]

Report message to a moderator

Re: [EMF-Databinding] Observe addition/removal changes in multi-value feature of a multi-value featu [message #902190 is a reply to message #902187] Thu, 16 August 2012 09:32 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
http://tomsondev.bestsolution.at/2011/05/06/interesting-new-feature-in-emf-databinding/

Tom

Am 16.08.12 11:26, schrieb Paco Blanco:
> Thank for your answer, Tom. Can you say to me how to do "you can observe
> an index inside a list but this would mean your first list is has a
> fixed amount of items"? (with simple code snippet is enough :p)
>
> BTW, my aprroach to this problem is:
>
>
> private Map<Object, IObservableList> observablePermissionMap = new
> HashMap<Object,IObservableList>();
>
> method:
> .... WritableValue writable = new WritableValue();
> writable.setValue(model);
> IObservableList observableSubElementList =
> EMFProperties.list(ModelPackage.Literals.MODEL__SUBELEMENTS).observeDetail(writable);
>
> ObservableListContentProvider ocp = new ObservableListContentProvider();
> tableViewer.setContentProvider(ocp);
> table.setInput(observableSubElementList);
>
> observableSubElementList.addListChangeListener(new IListChangeListener() {
> @Override
> public void handleListChange(ListChangeEvent event) {
> for(final ListDiffEntry entry : event.diff.getDifferences()) {
> if(entry.isAddition()) {
> addObserverToMap((MySubSubElementClass) entry.getElement());
> } else if(observablePermissionMap.containsKey(entry.getElement())){
> observableList observable =
> observablePermissionMap.get(entry.getElement());
> observable.dispose();
> observablePermissionMap.remove(entry.getElement());
> }
> }
> }
> });
> for(final Object objectToObserve : observableSubElementList) {
> if(!observablePermissionMap.containsKey(objectToObserve)) {
> addObserveToUserPermission((MySubSubElementClass) objectToObserve);
> }
> }
> ... end method
>
> private void addObserveToMap(final MySubSubElementClass objectToObserve) {
> IObservableList observable =
> EMFProperties.list(ModelPackage.Literals.SUBELEMENT__SUBSUBELEMENTS).observe(objectToObserve);
>
> observable.addChangeListener(new IChangeListener() {
> @Override
> public void handleChange(ChangeEvent event) {
> //Do something, in my case:
> table.getTableViewer().update(objectToObserve,
> columnProperties);
> }
> });
> observablePermissionMap.put(objectToObserve, observable);
> }
>
Previous Topic:problem converting uml file to ecore and genmodel file
Next Topic:Duplicate overloaded property
Goto Forum:
  


Current Time: Sun Nov 23 06:21:04 GMT 2014

Powered by FUDForum. Page generated in 0.01736 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software