Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » Reading nodes' labels using Sapphire Expression Language
Reading nodes' labels using Sapphire Expression Language [message #783824] Thu, 26 January 2012 14:32 Go to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Hi,
I'm looking for a way to propagate parts of node labels up the tree for some types of nodes.
I managed to do this with a custom function which determines the type of node it's operating on and gets the required data from the children elements. This works fine, except the parents' labels are not refreshed when their children elements are changed.
I started fixing this by adding listeners but this seems to be a bit overkill.
Is it possible to access a node's label from the expression in the
parent's label? (And as a bonus, have dependent labels refresh automatically?)
Thanks,
Roded
Re: Reading nodes' labels using Sapphire Expression Language [message #784299 is a reply to message #783824] Fri, 27 January 2012 10:13 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Some alterations to my model solved this for me.
Thanks.
Re: Reading nodes' labels using Sapphire Expression Language [message #786725 is a reply to message #784299] Mon, 30 January 2012 19:04 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
There is no built in facility to access child node labels when computing parent node label. A custom function is a good way to achieve that objective. Sapphire functions are required to listen on their inputs in order to know when to refresh their result (this happens in function result implementation), so it sounds like you were on the right track there...

- Konstantin
Re: Reading nodes' labels using Sapphire Expression Language [message #786817 is a reply to message #786725] Mon, 30 January 2012 21:07 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Nice to know.
Thanks for the clearing up.
Re: Reading nodes' labels using Sapphire Expression Language [message #819306 is a reply to message #786817] Mon, 12 March 2012 18:55 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
I'm revisiting the custom function solution with a different requirement, and I could use some advice.
I have the following model tree:
Row
----Field (name: fieldA)
----Field (name: specialFieldB)
----Field (name: fieldC)
--------SubField (value: propagated)

(A row can contain multiple Fields, and a Field can contain a single Value element, or none).

A certain Field under a Row can have special meaning, that that field is significant is indicated by its "name" property.
I'd like the Row element's tree label to contain the special Field's SubField property's value.
For this purpose, I've created a custom function which finds the relevant propagated SubField value and added a call to it from the Row node's label.
My difficulty arises from the fact that the user can change the name of the Fields making a "special" field not so special anymore, can delete the Field's SubField or can change the SubField propagated value. When events like these occur, it's a bit of a issue to manage the FunctionResult listeners which are meant to refresh the Row's label.
(Hope the above makes sense.)

This all makes me doubt this is the correct solution to the issue..
Is it possible to listen on element changes + all changes under it recursively so I could manage only one listener?
Any advice would be much appreciated.
Thanks,
Roded
Re: Reading nodes' labels using Sapphire Expression Language [message #819342 is a reply to message #819306] Mon, 12 March 2012 20:02 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
You can use paths with certain wildcards when registering ModelPropertyListener. For instance "Foo/*" means listen to property Foo and all child properties beneath it, or just "*" means listen to all properties of the current model element and all of their child properties.

- Konstantin
Re: Reading nodes' labels using Sapphire Expression Language [message #819360 is a reply to message #819342] Mon, 12 March 2012 20:34 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Simple enough.
Thanks!
Re: Reading nodes' labels using Sapphire Expression Language [message #819433 is a reply to message #819360] Mon, 12 March 2012 23:01 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
I'm experiencing some unexpected behavior (Stack overflows)..

In FunctionResult.evaluate():
rowModelElement.addListener(new ModelPropertyListener() {
    public void handlePropertyChangedEvent(final ModelPropertyChangeEvent event) {
        event.getModelElement().removeListener(this, new ModelPath("Fields/*"));
        refresh();
    }
}, new ModelPath("Fields/*")); 

The row model element has the following property:
// *** Fields ***
@Type(base = IField.class)
@Label(standard = "Fields")
@XmlListBinding(mappings = @XmlListBinding.Mapping(element = "field", type = IField.class))
ListProperty PROP_FIELDS = new ListProperty(TYPE, "Fields");
ModelElementList<IField> getFields();

Anything wrong here?
Thanks
Re: Reading nodes' labels using Sapphire Expression Language [message #819449 is a reply to message #819433] Mon, 12 March 2012 23:32 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
My guess is that it's a combination of the refresh() call in handlePropertyChangeEvent() and removeListener() being called on the wrong element. Try calling it on rowModelElement instead.

Also, you don't need to explicitly construct ModelPath objects. Just call addListener/removeListener with a string path.

- Konstantin
Re: Reading nodes' labels using Sapphire Expression Language [message #820052 is a reply to message #819449] Tue, 13 March 2012 17:09 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Tried calling removeListener on the rowModelElement and the SOF persisted.
There's an issue I don't completely understand with the PropogationListener when adding the listener.
handlePropertyChangedEvent() is called with a null event.
I managed it as follows (hope my intuition is correct):
dataSourceRow.addListener(new ModelPropertyListener() {
    public void handlePropertyChangedEvent(final ModelPropertyChangeEvent event) {
        if (event != null) {
	    refresh();
	    dataSourceRow.removeListener(this, "Fields/*");
	}
    }
}, "Fields/*");
Re: Reading nodes' labels using Sapphire Expression Language [message #820118 is a reply to message #820052] Tue, 13 March 2012 18:55 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Could you post however much of SOF stack you got? I need to see where it is looping. I would guess we will need to take a deeper look at your model. Is there recursive content inside Fields property?
Re: Reading nodes' labels using Sapphire Expression Language [message #820129 is a reply to message #820118] Tue, 13 March 2012 19:13 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
Sure.
Each field can contain a type which can contain more of itself. It's not possible for a Field to contain another Field.

I actually don't need to listen on "Fields/*". Just listening on "Fields" + every field's Name would be enough.
Thanks.
  • Attachment: sof.txt
    (Size: 239.59KB, Downloaded 429 times)
Re: Reading nodes' labels using Sapphire Expression Language [message #820142 is a reply to message #820129] Tue, 13 March 2012 19:39 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Ok. Looking at the stack trace wasn't that useful. At this point, I am not sure that I can help you unless you can create a repro that I can run to trigger the problem.

- Konstantin
Re: Reading nodes' labels using Sapphire Expression Language [message #820149 is a reply to message #820142] Tue, 13 March 2012 19:52 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Actually... it looks like you are calling addListener() during the evaluate() call, so you are likely registering far more listener instances than you need. Listeners should be added during FunctionResult init() call.
Re: Reading nodes' labels using Sapphire Expression Language [message #820165 is a reply to message #820149] Tue, 13 March 2012 20:13 Go to previous messageGo to next message
Roded Bahat is currently offline Roded BahatFriend
Messages: 152
Registered: August 2011
Senior Member
...and disposed of in dispose().
That fixed it all.
I'll carry on fixing all my other functions now Smile
Thanks a lot.
Re: Reading nodes' labels using Sapphire Expression Language [message #820176 is a reply to message #820165] Tue, 13 March 2012 20:33 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Very cool.
Previous Topic:Refreshing a FunctionResult
Next Topic:Activating general actions only via a key binding
Goto Forum:
  


Current Time: Wed Sep 25 19:11:31 GMT 2024

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

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

Back to the top