Application Settings. Structure Design

For ease of use in UI, Xafari BC Settings supports multi-level grouping of Setting Units. The structure of the Settings in the UI is shown in the screenshot, this structure consists of a root node, nested groups and finite elements - Setting Units that provide access to the values.

app_settings_3

To determine the Settings structure, the developer needs to expand the Application|Xafari|Settings node with a set of corresponding interfaces. This is a standard approach to extend the Application Model. For general information you should familiarize yourself with the Extend and Customize the Application Model in Code topic.

You can examine described sample in the Xafari Northwind demo. Values of Settings are used as default values when creating the appropriate entities. The structure of the Settings is schematically represented by the following list:

  • Root
    • Classifiers
      • Product
        • Category
        • ShortName
      • Supplier
        • HomePage
        • Region
      • Territory
        • Code
        • TerritoryName
    • Documents
      • Order
        • Employee
        • ShippedDate

This structure is implemented by the following code:

  • c#
  • VB

public interface IModelNorthwindSettings
{
  Documents Documents { get; }
  Classifiers Classifiers { get; }
}
public interface Documents : IModelBCSettingsGroup
{
  Order Order { get; }
}
public interface Order : IModelBCSettingsGroup
{
  IModelKeyEmployeeObject Employee { get; }
  IModelKeyDateTime ShippedDate { get; }
}
public interface Classifiers : IModelBCSettingsGroup
{
  Product Product { get; }
  Territory Territory { get; }
  Supplier Supplier { get; }
}
public interface Product : IModelBCSettingsGroup
{
  IModelKeyCategoryObject Category { get; }
  IModelKeyString ShortName { get; }
}
public interface Territory : IModelBCSettingsGroup
{
  IModelKeyString TerritoryName { get; }
  IModelKeyString Code { get; }
}
public interface Supplier : IModelBCSettingsGroup
{
  IModelKeyString HomePage { get; }
  IModelKeyString Region { get; }
}
public interface IModelKeyEmployeeObject : IModelBCSettingsObjectItem<Employee>
{
}
[DomainLogic(typeof(IModelKeyEmployeeObject))]
public class IModelKeyEmployeeObjectLogic : IModelBCSettingsXPObjectItemLogic<Employee, IModelKeyEmployeeObject>
{
  public IModelKeyEmployeeObjectLogic(IModelKeyEmployeeObject instance)
    : base(instance)
  {
  }
}
public interface IModelKeyCategoryObject : IModelBCSettingsObjectItem<Category>
{
}
[DomainLogic(typeof(IModelKeyCategoryObject))]
public class IModelKeyCategoryObjectLogic : IModelBCSettingsXPObjectItemLogic<Category, IModelKeyCategoryObject>
{
  public IModelKeyCategoryObjectLogic(IModelKeyCategoryObject instance)
    : base(instance)
  {
  }
}

Public Interface IModelNorthwindSettings
  ReadOnly Property Documents As Documents
  ReadOnly Property Classifiers As Classifiers
End Interface
Public Interface Documents
  Inherits IModelBCSettingsGroup
  ReadOnly Property Order As Order
End Interface
Public Interface Order
  Inherits IModelBCSettingsGroup
  ReadOnly Property Employee As IModelKeyEmployeeObject
  ReadOnly Property ShippedDate As IModelKeyDateTime
End Interface
Public Interface Classifiers
  Inherits IModelBCSettingsGroup
  ReadOnly Property Product As Product
  ReadOnly Property Territory As Territory
  ReadOnly Property Supplier As Supplier
End Interface
Public Interface Product
  Inherits IModelBCSettingsGroup
  ReadOnly Property Category As IModelKeyCategoryObject
  ReadOnly Property ShortName As IModelKeyString
End Interface
Public Interface Territory
  Inherits IModelBCSettingsGroup
  ReadOnly Property TerritoryName As IModelKeyString
  ReadOnly Property Code As IModelKeyString
End Interface
Public Interface Supplier
  Inherits IModelBCSettingsGroup
  ReadOnly Property HomePage As IModelKeyString
  ReadOnly Property Region As IModelKeyString
End Interface
Public Interface IModelKeyEmployeeObject
  Inherits IModelBCSettingsObjectItem(Of Employee)
End Interface
<DomainLogic(GetType(IModelKeyEmployeeObject))> _
Public Class IModelKeyEmployeeObjectLogic
  Implements IModelBCSettingsXPObjectItemLogic(Of Employee, IModelKeyEmployeeObject)
  Public Sub New(ByVal instance As IModelKeyEmployeeObject)
    MyBase.New(instance)
  End Sub
End Class
Public Interface IModelKeyCategoryObject
  Inherits IModelBCSettingsObjectItem(Of Category)
End Interface
<DomainLogic(GetType(IModelKeyCategoryObject))> _
Public Class IModelKeyCategoryObjectLogic
  Implements IModelBCSettingsXPObjectItemLogic(Of Category, IModelKeyCategoryObject)
  Public Sub New(ByVal instance As IModelKeyCategoryObject)
    MyBase.New(instance)
  End Sub
End Class

As you can see, to determine the structure of groups (folders), it is necessary to use the base IModelBCSettingsGroup interface. A group can includes Setting Items or references to other groups. Setting Items are declared as nodes of the special type in the Application Model. The type of the Setting Item may be both a reference or correspond to a standard c# type. The table below lists a standard types and corresponding IModelKey types:

Built-in C# type

Setting Item Type

bool

IModelKeyBool

bool?

IModelKeyBoolNull

int

IModelKeyInt

string

IModelKeyString

DateTime

IModelKeyDateTime

DateTime?

IModelKeyDateTimeNull

Guid

IModelKeyGuid

double

IModelKeyDouble

double?

IModelKeyDoubleNull

For the Setting Items of reference type (including persistent), it is required to define a separate typed nodes and implement Domain Logic, see, for example, IModelKeyEmployeeObject in the code above.

There are several additional parameters to customize a Settings Item, for this purpose use appropriate attributes when declaring Setting Item:

  • c#
  • VB

public interface Territory : IModelBCSettingsGroup
{
  [ModelDefault("AllowWrite", "false")]
  [ModelDefault("Value", "Default value with code.")]
  IModelKeyString TerritoryName { get; }
  [ModelDefault("ToolTip", "ToolTip with code.")]
  IModelKeyString Code { get; }
  [Obsolete]
  IModelKeyString ObsoleteKey { get; }
  [Browsable(false)]
  IModelKeyString HiddenKey { get; }
}

Public Interface Territory
  Inherits IModelBCSettingsGroup
  <ModelDefault("AllowWrite", "false")> _
<ModelDefault("Value", "Default value with code.")> _
ReadOnly Property TerritoryName As IModelKeyString
  <ModelDefault("ToolTip", "ToolTip with code.")> _
ReadOnly Property Code As IModelKeyString
  <Obsolete> _
ReadOnly Property ObsoleteKey As IModelKeyString
  <Browsable(False)> _
ReadOnly Property HiddenKey As IModelKeyString
End Interface

ModelDefaultAttribute sets default values of the Setting Unit object to be generated on the basis of Settings Item. Available parameters are listed below:

  • Tooltip
  • AllowWrite
  • Value

ObsoleteAttribute is an indication that the Setting Item is obsolete and no longer used. The use of the attribute deletes an item from the common settings list in the UI.

BrowsableAttribute deletes an item from the common list settings in the UI.