Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » What is the best way to add tree node for an optional xml child element?
What is the best way to add tree node for an optional xml child element? [message #1494834] Mon, 01 December 2014 20:07 Go to next message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
Consider xml:
<my-node>
  <my-optional-child required-attribute="x">
     <my-optional-grandchild required-attribute="y"/>
  </my-optional-child>
</my-node>

Element <my-optional-child> is optional in <my-node> and element <my-optional-grandchild> is optional in <my-optional-child>. Once one or both of these elements are present, attribute 'required-attribute' must be set.

In interface MyNode I added ImpliedElementProperty PROP_MY_OPTIONAL_CHILD.
In editor definition (.sdef file) I described node as
	<node>
		<id>MyOptionalChildNode</id>
		<property>MyOptionalChild</property>
...
       </node>

and included it to children of MyNode tree node.
The same approach is implemented for my-optional-grandchild.

Editor works fine when child nodes are available in xml. When I remove them, nodes in tree remain, which is ok as a handle to add the child element just by editing its form.
What is bad, is that when there are no child elements in xml, nodes in tree and forms display a validation error about missing required attribute.

The node in xml can be hidden by
<visible-when>${RequiredAttribute != null}</visible-when>
Then everything is ok but one: I do not have the handle to add the child element.

I tried to add a form section to parent node as such a handle. But again, it displays a validation error when the child element is missing.

What is the best practice to treat this case?
Re: What is the best way to add tree node for an optional xml child element? [message #1495870 is a reply to message #1494834] Tue, 02 December 2014 15:37 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Based on the semantics you have described, an implied element property isn't the best choice. You should use a regular element property, then in sdef you add the associated node using the node factory construct, just like you would for a list property.
Re: What is the best way to add tree node for an optional xml child element? [message #1497288 is a reply to message #1495870] Wed, 03 December 2014 18:05 Go to previous messageGo to next message
Slava Kabanovich is currently offline Slava KabanovichFriend
Messages: 8
Registered: December 2014
Junior Member
Thank you very much, it works just as I like it.

I wonder, why my previous attempts to implement it this way failed. I really tried node factory for a non-list property before, but always got definition errors, and finally decided that node factory is only for list properties. I cannot remember what I did wrong, maybe I failed to use <case> element, which could seem redundant due to lack of choice.
Re: What is the best way to add tree node for an optional xml child element? [message #1497448 is a reply to message #1497288] Wed, 03 December 2014 20:48 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
Are you using the sdef editor or editing sdef by hand?
Previous Topic:How to programmatically add elements to a Sapphire list?
Next Topic:How to declare and set an integer field in Sapphire?
Goto Forum:
  


Current Time: Wed Nov 14 00:17:50 GMT 2018

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

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

Back to the top