Design of Control Tables

From Heureka Wiki
Revision as of 09:53, 21 May 2010 by Fkl (talk | contribs) (Created page with '== Introduction == A <tt>ControlTable</tt> is a class whose instances can hold user settings. <tt>ControlTables</tt> are typically presented in a <tt>PropertyGrid</tt>, which me�?�')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

A ControlTable is a class whose instances can hold user settings. ControlTables are typically presented in a PropertyGrid, which means that no user interface has to be built for properties with a simple type.

By adding the sttribute Slu.Heureka.BaseLayer.ConfigurationHandling.ControlTable a class is marked as a ControlTable. The system will automatically discover all ControlTables at startup.

Implementation of Control Tables

Creating a new Control Table

Although not required, it is recommended that ControlTables inherit from UndoablePropertyChangedBase. This base class simplifies implementation of the INotifyPropertyChanged interface, which should be used for classes presented in the PropertyGrid.

To add a property of a simple type, follow this example:

public int CleaningVariation {

   get { return _cleaningVariation; }
   [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
   set
   {
       if (value < 0)
           throw new ArgumentOutOfRangeException("value", "CleaningVar must be >= 0");
       ChangeProperty(ref _cleaningVariation, value);
   }

}

Note the following:

  • NoInlining must be set for the set method, otherwise property changed won't work in release mode
  • Validation can be done before the value is changed
  • UndoablePropertyChangedBase implements ChangeProperty methods with overloads for

Presentation of Control Tables

Since ControlTables are presented in a PropertyGrid, the attributes in System.ComponentModel aids with the presentation of a ControlTable, such as:

Category
Properties with the same Category are grouped in the PropertyGrid
DisplayName
The DisplayName is the name for the property shown in the PropertyGrid.
Description
The Description is shown at the bottom of the PropertyGrid when the property is selected. The description should give a brief help to the user.
DefaultValue
The DefaultValue is the value set when a new instance of a ControlTable is created. Also, the PropertyGrid shows properties with the default value in a normal font, and properties with a changed value in a bold font.
Browsable
The Browsable attribute can be set to false to hide properties in the property grid (unconditionally, to conditionally hide properties see Hiding Properties Conditionally

In addition to this, a number of additional attributes and type converters are available in the Slu.Heureka.BaseLayer.ComponentModel namespace:

ObjectDefaultValues
Allows default values to be set on other types than simple types
PercentTypeConverter
Presents a property with a fraction (e.g. 0.03) to be presented as a percentage (e.g. 3%)

Hiding Properties Conditionally

Using Custom Classes inside a Control Table

Cloning Control Tables

Extending Control Tables

Serialization and Deserialization of Control Tables