Skip to main content



      Home
Home » Archived » Sapphire » Reading nodes' labels using Sapphire Expression Language
Reading nodes' labels using Sapphire Expression Language [message #783824] Thu, 26 January 2012 09:32 Go to next message
Eclipse UserFriend
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 05:13 Go to previous messageGo to next message
Eclipse UserFriend
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 14:04 Go to previous messageGo to next message
Eclipse UserFriend
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 16:07 Go to previous messageGo to next message
Eclipse UserFriend
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 14:55 Go to previous messageGo to next message
Eclipse UserFriend
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 16:02 Go to previous messageGo to next message
Eclipse UserFriend
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 16:34 Go to previous messageGo to next message
Eclipse UserFriend
Simple enough.
Thanks!
Re: Reading nodes' labels using Sapphire Expression Language [message #819433 is a reply to message #819360] Mon, 12 March 2012 19:01 Go to previous messageGo to next message
Eclipse UserFriend
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 19:32 Go to previous messageGo to next message
Eclipse UserFriend
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 13:09 Go to previous messageGo to next message
Eclipse UserFriend
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 14:55 Go to previous messageGo to next message
Eclipse UserFriend
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 15:13 Go to previous messageGo to next message
Eclipse UserFriend
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 452 times)
Re: Reading nodes' labels using Sapphire Expression Language [message #820142 is a reply to message #820129] Tue, 13 March 2012 15:39 Go to previous messageGo to next message
Eclipse UserFriend
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 15:52 Go to previous messageGo to next message
Eclipse UserFriend
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 16:13 Go to previous messageGo to next message
Eclipse UserFriend
...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 16:33 Go to previous message
Eclipse UserFriend
Very cool.
Previous Topic:Refreshing a FunctionResult
Next Topic:Activating general actions only via a key binding
Goto Forum:
  


Current Time: Wed Jul 02 21:13:28 EDT 2025

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

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

Back to the top