I'm in the process of evaluating Sapphire and have a situation where the user will be editing source that is modified during the build. Because of this, I need access to both the input (source) document and the output (target) document (similar to the Maven pom editor: pom.xml and derived pom.xml). Making matters more complicated, the documents have the same structure and the user may edit details in the derived model, but those changes should be stored in the source model (i.e. the source file overrides any automatically generated content). How might I go about doing something like this in Sapphire?
Well... You should be able to leverage DefaultValueService to present values from build-generated file as default values when editing the source file. When the user sets the value, it would be written to the source file. User will also be able to use existing Sapphire facilities to see what the default value is and to revert to it.
The above should be sufficient for value properties, but if you need to default structured content (provide defaults for list or element properties), we don't support that yet in as simple of a manner. There is an open enhancement request, but it's quite a big chunk of work. Sapphire also has the concept of a resource that sits beneath a model element and handles read/write of properties. It is designed such that adopters can provide their own custom implementation of a resource and it is possible to merge content from multiple files at this level.
Thanks for the reply. Could you please provide a link to that enhancement request? With respect to the resources, is it possible to reparent the elements? For example, if the user wishes to modify an attribute on a derived element, would there be a way for me to merge that with the parent structure in the source document? I'm anticipating that this could get really hairy, really fast, but I'm also guessing I don't fully understand the interaction between resources and elements and how I might go about customizing them.
> With respect to the resources, is it possible to reparent the elements?
> For example, if the user wishes to modify an attribute on a derived element,
> would there be a way for me to merge that with the parent structure in the
> source document?
Your resource implementation can be arbitrary complex. The default XML resource holds a DOM element that it reads/writes. Your implementation can hold a DOM element from source file and a DOM element from build file. You can then decide that a property write means that you copy some stuff from one DOM element to another before setting the value. Certainly possible, but not exactly easy. May want to consider using Sapphire to implement a simpler editor first before moving on to more complex scenarios like this one.