What is the best way to add tree node for an optional xml child element? [message #1494834] |
Mon, 01 December 2014 20:07  |
Eclipse User |
|
|
|
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 #1497288 is a reply to message #1495870] |
Wed, 03 December 2014 18:05   |
Eclipse User |
|
|
|
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.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03112 seconds