Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » Sapphire » InitialValue vs DefaultValue and persistence
InitialValue vs DefaultValue and persistence [message #1635852] Thu, 26 February 2015 00:49 Go to next message
Jason Pell is currently offline Jason PellFriend
Messages: 55
Registered: February 2011
Member
Hi,

I have a field which is backed by an enumeration. It must have a value in the XML that gets written. I would like to ensure that a default value is specified in the UI and that even if no one changes that value it gets written out.

I tried using @InitialValue but it seems to have no impact on what is selected in the UI and also does not appear in the xml anyway.

This DuplicateConfig is referenced from the root element object:

@Label( standard = "Duplicate Config" )
@Type( base = DuplicateConfig.class )
@XmlBinding( path = "DuplicateConfig" )	
    
ImpliedElementProperty PROP_DUPLICATE_CONFIG = new ImpliedElementProperty( TYPE, "DuplicateConfig" );
DuplicateConfig getDuplicateConfig();


Should I just use a @DefaultValue and a custom XML binder? Or is there something fundamental I am not understanding.

public interface DuplicateConfig extends Element {
	ElementType TYPE = new ElementType(DuplicateConfig.class);

	@Type( base = DuplicateMatching.class )
	@XmlBinding(path = "duplicateMatching")
	@Label(standard = "Duplicate Matching")
	@InitialValue( text = "IgnoreNumericSuffix" )
	ValueProperty PROP_DUPLICATE_MATCHING = new ValueProperty(TYPE, "DuplicateMatching");

	Value<DuplicateMatching> getDuplicateMatching();
	void setDuplicateMatching(String value);
	void setDuplicateMatching(DuplicateMatching value);
	
	@Label( standard = "Ignore Fqns" )
	@XmlListBinding( path = "" )
	@Type( base = IgnoreFqn.class )
    ListProperty PROP_IGNORE_FQNS = new ListProperty( TYPE, "IgnoreFqns" );
    ElementList<IgnoreFqn> getIgnoreFqns();
}


Edit - I also tried to add a @CustomXmlValueBinding but the write method is never called. I am not sure how to override the @CustomXmlElementBinding at the parent level to ensure a value gets written.

[Updated on: Thu, 26 February 2015 03:25]

Report message to a moderator

Re: InitialValue vs DefaultValue and persistence [message #1635974 is a reply to message #1635852] Thu, 26 February 2015 02:14 Go to previous messageGo to next message
Jason Pell is currently offline Jason PellFriend
Messages: 55
Registered: February 2011
Member
So I added a hack to my Editor class to write out the default value, but its so nasty and I want to know if there is a way to add this code only to certain Elements.

@Override
	protected Element createModel() {
		GeneratorConfig config = GeneratorConfig.TYPE.instantiate(new RootXmlResource(
				new XmlEditorResourceStore(this, this.sourcePage)));
		
		setDefaultValues(config);
		
		return config;
	}
	
	private void setDefaultValues(Element element) {
		for( Property property : element.properties( "*" ) ) {
			 if( property instanceof Element ) {
				 setDefaultValues((Element) property);
			 } else if( property instanceof Value ) {
				 Value<?> value = (Value<?>) property;
				 
				 if (value.content() == null && value.getDefaultContent() != null) {
					 value.write(value.getDefaultContent());
				 }
			 }
		}
	}

[Updated on: Thu, 26 February 2015 10:44]

Report message to a moderator

Re: InitialValue vs DefaultValue and persistence [message #1636032 is a reply to message #1635974] Thu, 26 February 2015 02:52 Go to previous message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 1077
Registered: July 2009
Senior Member
The @InitialValue facility is closest to what you are trying to achieve, but since applying the initial value modifies the model you have to trigger it explicitly. Try calling root.initialize() after creating your model in the editor.
Previous Topic:Custom list binding
Next Topic:Combining root-node style and normal property editors on one page
Goto Forum:
  


Current Time: Tue Mar 19 06:10:11 GMT 2024

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

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

Back to the top