# PossibleTypesService

PossibleTypesService enumerates the possible child element types for a list or an element property. Each returned type is required to derive from the property's base type.

In majority of situations, the set of possible types is static and should be configured using @Type annotation. The framework provides an implementation of PossibleTypesService that works with this annotation.

Example

    @Type( base = Shape.class, possible = { Circle.class, Triangle.class, Rectangle.class } )

    ListProperty PROP_SHAPES = new ListProperty( TYPE, "Shapes" );

    ElementList<Shape> getShapes();

When the set of possible types varies due to model extensibility or runtime conditions, a custom implementation of PossibleTypesService can be provided.

Example

    public class ShapesPossibleTypesService extends PossibleTypesService
    {
        @Override
        protected void initPossibleTypesService()
        {
            // Register listeners to invoke refresh() method when the list of possible types
            // may have changed.
        }

        @Override
        protected void compute( final Set<ElementType> types )
        {
            // Compute the set of possible types.
        }

        @Override
        public boolean ordered()
        {
            // Return true if the types supplied in the compute method are already in the intended
            // order. By default, the order is not treated as significant and the possible types are
            // sorted alphabetically by the type name when presented.
        }

        @Override
        public void dispose()
        {
            super.dispose();

            // Remove any listeners that were added during initialization.
        }
    }

    @Type( base = Shape.class )
    @Service( impl = ShapesPossibleTypesService.class )

    ListProperty PROP_SHAPES = new ListProperty( TYPE, "Shapes" );

    ElementList<Shape> getShapes();

If the set of possible types is not specified via @Type annotation or via a custom PossibleTypesService implementation, the set of possible types is defined to be a singleton set composed of the property's base type.

Copyright (c) 2015 Oracle
Content made available under the terms of Eclipse Public License.