Property Visibility Extensions for DSL

A set of highly reusable components for empowering the domain class instance to control the visibility of its properties in the property grid

About this extension

Most of the times, we would have to control visibility of the properties in the property grid by deciding which property is to be shown on which scenario and in which display mode. Even though Microsoft has beautifully architected the DSL Tools framework, they have left the end users in the midst of the ocean by giving no clues about controlling the runtime behavior of the property grid visibility by means of any reusable software components.

The classic solution for addressing this is sub classing by writing customized TypeDescriptor, TypeConverter, PropertyDescriptor and TypeDescriptionProvider for each domain class and each domain property.

Even though sub classing the type descriptor and related components provides the complete control on the preconfigured property visibility, it is not a very brilliant idea to do so, since maintaining hundreds of different implementations of these components in an enterprises level product is not that productive and developer friendly. Unfortunately no reusable components are available for addressing the dynamic property behavior.

Property Visibility Extensions for DSL Tools V10 is a class library that provides a set of highly reusable components with the capability of changing the visibility behavior of the domain properties in the property grid without sub classing. It has a set of type descriptors, type converters, custom attributes, enumerations and interfaces for empowering the registered domain class to control the visibility of a domain property during runtime.

Most of the components in Property Visibility Extensions are making use of the interface dependency injection and decorator pattern for handling the property visibility. The domain class will act as the visibility decorator and decides what should be the state of each property through the implemented interfaces.

The components in Property Visibility Extensions are designed to be very powerful so as to override the visibility behavior defined in DSL Designer using attribute discovery and attribute injection. For an example, consider you have set a domain property to be read only or hidden or both; you can make it editable during runtime..

Exploring the visibility handling in DSL

When we set Is UI Read Only or Is Browsable in DSL, a few attributes are created in the generated code for hadling them as follows.

[global::System.ComponentModel.ReadOnly(true)]
[global::System.ComponentModel.Browsable(false)] 

TypeDescriptor discovers these attributes on run-time and pass them to the constructor of the PropertyDescriptor. The PropertyDescriptor instance makes use of these attributes to handle the visibility.

So creating a new instance of PropertyDescriptor after adding/removing respective visibility attributes based on our business requirement alone will work great without breaking the existing architecture apartment. Apart from the above attributes, we would remove the Editor attribute for read only or hidden attributes. Another catch is, a hidden property need not have a PropertyDescriptor at all.

This approach took me in writing Property Visibility Extensions for DSL

Design Concepts

The major components of the Property Visibility Extensions are
  1. ModelTypeDescriptionProvider - Instantiates the TypeDescriptionProvider for the registered type. This can be registered for a model element on compile time for any classes inheriting from model element class and it can be also registered in package initialization.
  2. ModelTypeDescriptor - Provides the property descriptors for the properties based on the configured behavior.
  3. PropertyBehaviorAttribute - Compile time registration of the dynamic display behavior of a property based on the value of another property. ModelTypeDescriptor will evaluate the state of the domain class with the registered behaviors using attribute discovery and controls the visibility of the properties by adding or removing the visibility attributes.
  4. AdvancedModelTypeDescriptor - Empowers the domain class to control the property visibility behavior using interfaces. The domain class must implement IPropertyVisibilityDecorator, IRolePlayerVisibilityDecorator or IRolePlayerProviderDecorator in any combination according to the requirements. The purpose of each interface and their usage is explained in the users' manual in brief.
  5. DisplayMode - Enumeration for the visibility of the property on behavior match. Values are Default, Editable, ReadOnly and Hidden.
  6. ExtendedStringConverter - Empowers the instance of the domain class to control the standard value collection for the properties of string data type. The domain class must implement IStandardValueProvider interface.
  7. RolePlayerDescriptor - Empowers the instance of the domain class to control the list of opposite domain roles of 1 or 0-1 multiplicity. The domain class should implement the IRolePlayerProviderDecorator interface.

Runtime Behavior

  • ModelTypeDescriptor will find the property behavior attributes and compare the state with the instance of the domain class. The default property descriptor is created by adding or removing the visibility attributes (ReadOnly, Browsable and Editor) according to the matching configurations.
  • AdvancedModelTypeDescriptor will query the instance of the domain class for the visibility using the available interfaces and the default property descriptors are created by adding or removing the visibility attributes (ReadOnly, Browsable and Editor) according to the provided configurations.
  • ExtendedStringConverter will query the instance of the domain class using the IStandardValueProvider interface and the details will be passed to the caller.
  • RolePlayerDescriptor will query the instance of the domain class using IRolePlayerProviderDecorator interface and get the opposite domain role players with 1 or 0-1 multiplicity to which the instance can create relations.

Limitations

  • Multilevel dependency in behavior is not addressed for ModelTypeDescriptor. Use AdvancedModelTypeDescriptor instead.
  • Caching of the Property Descriptors are not supported so as to support the dynamic behavior of the component.
Note:
  • The source code, users' manual and sample are available for download in the downloads tab. Please review them and post me your comments
  • The content of this wiki is under development. Please check back soon for updates.

Last edited Jul 26, 2010 at 2:29 AM by kiranchand, version 16

Comments

No comments yet.