Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » add multiple items to ModelElementList property
add multiple items to ModelElementList property [message #710256] Thu, 04 August 2011 21:16 Go to next message
Danny Ju is currently offline Danny JuFriend
Messages: 14
Registered: July 2009
Junior Member
one of the property of my model is a ModelElementList,
public ModelElementList<ICreationTemplate> getTemplates()

The property is presented as a list which user click and select.
When user selects one item in UI, I would add dependent items in the SAME
list to the model. What is best way to do this?

I tried a ModelPropertyListener, but seem not working properly:

public class TemplatesValueChangeListener extends ModelPropertyListener {
public void handlePropertyChangedEvent(ModelPropertyChangeEvent event) {
...
//find dependent items and try add to list.
ICreationTemplate c = model.getTemplates().addNewElement();
c.setName( allTemplates.get(name).name );
...

This causes a new item added to UI briefly at the end then removed by Sapphire.

That must be a better way...
Re: add multiple items to ModelElementList property [message #710266 is a reply to message #710256] Thu, 04 August 2011 21:27 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
I am not sure why the listener approach isn't working, but I don't think it is the best approach in any regard. The biggest issue with a listener is that you can't really identify an add action among other possible causes of list change.

I can think of two ways to accomplish what you are after:

1. Do this in the UI by overriding the default Sapphire.Add action handler. You would have to contribute a new handler and filter out the one provided by the system.

2. Do this in the binding. Only possible if there is a resource used with this model element. See ListBindingImpl.add() or StandardXmlListBindingImpl.addUnderlyingObject().

In both of this cases you would be operating in the code path specific to the add action.

- Konstantin
Re: add multiple items to ModelElementList property [message #710387 is a reply to message #710266] Fri, 05 August 2011 00:46 Go to previous message
Danny Ju is currently offline Danny JuFriend
Messages: 14
Registered: July 2009
Junior Member
It turns out adding the listener to the ModelElementList property is definitely
not the right way to handle the use case like this:
the listener is triggered by
ModelElementList.addNewElement(),
when user click the checkbox in UI (or by client call), adding an empty node to list,
with the name property, which I needed to find its dependencies, is not yet set.

What I did was to register the listener to the element (ICreationTemplate) itself,
to get notified when the name is set, and update the list (the parent of the element).

This approach works for me since user can only add/remove item from the list, not change the name property of the element. The listener will be triggered only when they adds.


Previous Topic:asynchronous model change
Next Topic:Underlying Control
Goto Forum:
  


Current Time: Thu Apr 25 20:12:51 GMT 2024

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

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

Back to the top