I am using Sapphire to implement wizard for server adapter. I have specified @DefaultValue annotation on my model which has value binding to IServerWorkingCopy resource. After wizard is shown, I can see default value in grey letters but after I click Finish (and calling IServerWorkingCopy.save) the default value is not stored. I have expected that the annotation will initialise the resource attribute with default value. Or do I have to the initialisation programatically (e.g. resource.setName(model.getName.getDefaultContent))). I have also tried @InitialValue annotation.
The default value is not intended to be stored. It is intended to provide value for when the stored value is null. It sounds like you need @InitialValue. Can you describe what you've tried with @InitialValue?
I'll try:). So for server admin name property, I used @InitialValue(text = "admin"). After the model is instantiated from the resource and it is shown on wizard page, the admin field is empty. The read call from ValuePropertyBinding return (String)null.
There is tooltip that enables me to restore initial value to admin, which works. This triggers ValuePropertyBinding.write and read calls that refreshes the field value. For the admin name, I am using also @Required annotation if this information helps you.
@InitialValue takes effect when the element is considered to be new. When loading from a resource, the element is not new, so initial value is not written. Framework assumes that the value has been explicitly erased.
Why is it important to write the value to the resource? If you always use the model for accessing the resource, then you can use @DefaultValue and it wouldn't matter that the value was never written to the resource.
Yes, that is the issue. Some parts of plugin are still working with resource directly and I want to have all the necessary values stored when the wizard is finished. I have solved it by manual initialization of model values - e.g. model.setProperty(model.getProperty().content()).