Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357161 - @DependsOn does not always work between elements in a list
Summary: @DependsOn does not always work between elements in a list
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Sapphire (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Konstantin Komissarchik CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-08 16:59 EDT by Konstantin Komissarchik CLA
Modified: 2021-11-19 09:22 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Komissarchik CLA 2011-09-08 16:59:53 EDT
Suppose you have a model containing a list of elements where properties of these elements declare dependencies to other elements in the list. 

The @DependsOn refreshes work fine if you start from scratch and build up the model, however if you load an existing model, the @DependsOn refreshes are not triggered until you modify the list (adding or removing an element).

Test setup that can be used to repro the problem...

@GenerateImpl
@XmlRootBinding( elementName = "root" )

public interface TestElementRoot extends IModelElement
{
    ModelElementType TYPE = new ModelElementType( TestElementRoot.class );
    
    // *** Children ***
    
    @Type( base = TestElementChild.class )
    @XmlListBinding( mappings = @XmlListBinding.Mapping( element = "child", type = TestElementChild.class ) )

    ListProperty PROP_CHILDREN = new ListProperty( TYPE, "Children" );
    
    ModelElementList<TestElementChild> getChildren();
}

@GenerateImpl

public interface TestElementChild extends IModelElement
{
    ModelElementType TYPE = new ModelElementType( TestElementChild.class );
    
    // *** Id ***
    
    @Required
    @XmlBinding( path = "id" )
    
    ValueProperty PROP_ID = new ValueProperty( TYPE, "Id" );
    
    Value<String> getId();
    void setId( String value );
    
    // *** Reference ***
    
    @XmlBinding( path = "reference" )
    
    ValueProperty PROP_REFERENCE = new ValueProperty( TYPE, "Reference" );
    
    Value<String> getReference();
    void setReference( String value );
    
    // *** Content ***
    
    @DependsOn( { "Reference", "#/Id", "#/Content" } )
    @Service( impl = ContentDefaultValueService.class )
    @XmlBinding( path = "content" )
    
    ValueProperty PROP_CONTENT = new ValueProperty( TYPE, "Content" );
    
    Value<String> getContent();
    void setContent( String value );
}

public final class ContentDefaultValueService extends DefaultValueService
{
    @Override
    public String getDefaultValue()
    {
        final TestElementChild element = nearest( TestElementChild.class );
        final String ref = element.getReference().getText();
        
        if( ref != null )
        {
            final TestElementRoot root = nearest( TestElementRoot.class );
            
            for( TestElementChild child : root.getChildren() )
            {
                if( child != element && ref.equals( child.getId().getText() ) )
                {
                    return child.getContent().getText();
                }
            }
        }
        
        return null;
    }
}
Comment 1 Konstantin Komissarchik CLA 2011-09-09 13:24:36 EDT
Fixed in 0.3.1 and 0.4 code streams.

Test coverage provided by TestModelingMisc0011. In fact, the test suite shows to similar scenarios (testFromEmptyModel and testFromExistingModel). Before the fix, testFromEmptyModel would pass, but testFromExisingModel would fail.
Comment 2 Raj Alagumalai CLA 2011-09-23 05:35:34 EDT
verified with Sapphire build 0.3.1.201109211949
Comment 3 Konstantin Komissarchik CLA 2011-09-23 11:07:38 EDT
Closed.