I'm trying to allow my users to run an action from within my Sapphire editor.
I'd like this action to receive parameters from the user by property editors in the same editor.
My initial intuition was to add the parameters as transient properties to the relevant element and allow editing them via a property editor, this however isn't the solution it seems.
I then tired to use regular value properties and disable all data binding to the model with a custom XML binder. This seemed like a good idea till I realized that passing the properties' values to the action handler doesn't work (also causes some issues with the PossibleValuesService).
Any pointers would be much appreciated.
As you've discovered transient properties cannot be presented in UI. Transient properties allow you to attach arbitrary objects to the model without conforming to Sapphire's requirements, but as a consequence you loose ability to persist the content of these properties and ability to present them in UI.
For gathering user input in an action, I recommend using a separate model instance instead of your editor's model. The action's model can then be bound to memory resource (as opposed to XML resource) and you will not need to deal with any binding issues. Just call MyActionModel.TYPE.instantiate() (using the zero-arg constructor) in your action handler. Once you've gathered user's input, you can do what you need done to the editor's model and dispose of the action's model.
Hi, Sounds like a good idea.
But I could still use some more details (or an exmaple if available).
How do I include a Property Editor of a different model in a composite used to edit properties of my editor's model?
What I'm trying might be a bit unorthadox and it could very well change in the future,
but my current requirement is, in some elements' editor page, to show the user 2 more property editors (which have nothing to do with the model) and an action link.
The action link will do some processing based on the 2 "transient" and print the output to the console.
Hope I'm clear enough, if not I'd be glad explain further.
Ok. If you are trying to show these properties together with your actual editor properties on the same screen, the easiest thing to do is to keep it all in one model. Make them value properties and use the solution you found with a custom binding that keeps state in a member variable. Doesn't need to be a static variable since the binding object's lifecycle matches the element.
Using a static variable isn't working as I though it would (having the same values for all properties in the editor of the same name).
The notifyPropertyChangeListeners is changing it back I suspect.
You need to tell Sapphire if there is a relationship between properties such that when one changes, the other changes as well. You can do this using the @DependsOn annotation. See examples in samples project.
Not sure I follow you in this case.
My problem is that when binding FieldA in my editor to a static variable, different occurences of property editors of FieldA in my editor retain their different values instead of having all property editors of FieldA change when changing any one of them (static behaviour I suppose).
It's not a major issue, but would be nice to figure out how to make the property editors all bind to the same static model.
Sapphire model needs to know when to re-read property value from the resource. It isn't re-read on every access. Using @DependsOn between linked properties is one way to trigger a refresh. Another way is to write a smarter binding that knows when this static field changes and triggers refresh call on the bound property.
Assuming that you are doing it from your custom binding implementation, you can access the model element associated with that binding instance using element() method. There is a one to one relationship between a binding and a model element. So, you would setup a singleton data provider with a listener mechanism, each binding instance would listen on this data provider. When it changes, the binding calls refresh on its model element. In this manner, you will accomplish refresh on all active model elements.