Smart Design. Example

This topic illustrates how to use Xafari Smart Design to manage the Views generation. We will consistently decorate the XafarSmartDesignObject business class with special attributes to see how they affect the process of generating the Views.

Note

You can view the code used in this lesson in the Xafari.FeatureCenter|XafariSmartDesignGenerator|XafarSmartDesignObject.cs file of the Feature Center demo installed with Xafari. By default, the Feature Center application is installed in %PUBLIC%\Documents\Xafari Framework vXX.X.XXXX Demos\Feature Center.

The code snippet below shows the XafarSmartDesignObject business class definition:

  • c#
  • VB

public class XafariViewLayoutGeneratorObject : ObjectBase
{
  public XafariViewLayoutGeneratorObject(Session session)
    : base(session)
  {
  }
  private byte _byte;
  private decimal _decimal;
  private double _double;
  private float _float;
  private Int32 _integer;
  private Int64 _long;
  private string _string;
  public byte Byte
  {
    get
    {
      return this._byte;
    }
    set
    {
      SetPropertyValue("Byte", ref this._byte, value);
    }
  }
  public decimal Decimal
  {
    get
    {
      return this._decimal;
    }
    set
    {
      SetPropertyValue("Decimal", ref this._decimal, value);
    }
  }
  public double Double
  {
    get
    {
      return this._double;
    }
    set
    {
      SetPropertyValue("Double", ref this._double, value);
    }
  }
  public float Float
  {
    get
    {
      return this._float;
    }
    set
    {
      SetPropertyValue("Float", ref this._float, value);
    }
  }
  public Int32 Integer
  {
    get
    {
      return this._integer;
    }
    set
    {
      SetPropertyValue("Integer", ref this._integer, value);
    }
  }
  public Int64 Long
  {
    get
    {
      return this._long;
    }
    set
    {
      SetPropertyValue("Long", ref this._long, value);
    }
  }
  public string String
  {
    get
    {
      return this._string;
    }
    set
    {
      SetPropertyValue("String", ref this._string, value);
    }
  }
  [NonPersistent]
  public XPCollection<XafarSmartDesignObject> Objects
  {
    get
    {
      return new XPCollection<XafarSmartDesignObject>(this.Session, null, new SortProperty[] { });
    }
  }
}

Public Class XafariViewLayoutGeneratorObject
  Inherits ObjectBase
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Private __byte As Byte
  Private __decimal As decimal
  Private __double As double
  Private __float As Single
  Private __integer As Int32
  Private __long As Int64
  Private __string As String
  Public Property [Byte] As Byte
    Get
      Return Me.__byte
    End Get
    Set
      SetPropertyValue("Byte", Me.__byte, value)
    End Set
  End Property
  Public Property [Decimal] As decimal
    Get
      Return Me.__decimal
    End Get
    Set
      SetPropertyValue("Decimal", Me.__decimal, value)
    End Set
  End Property
  Public Property [Double] As double
    Get
      Return Me.__double
    End Get
    Set
      SetPropertyValue("Double", Me.__double, value)
    End Set
  End Property
  Public Property Float As Single
    Get
      Return Me.__float
    End Get
    Set
      SetPropertyValue("Float", Me.__float, value)
    End Set
  End Property
  Public Property [Integer] As Int32
    Get
      Return Me.__integer
    End Get
    Set
      SetPropertyValue("Integer", Me.__integer, value)
    End Set
  End Property
  Public Property [Long] As Int64
    Get
      Return Me.__long
    End Get
    Set
      SetPropertyValue("Long", Me.__long, value)
    End Set
  End Property
  Public Property [String] As String
    Get
      Return Me.__string
    End Get
    Set
      SetPropertyValue("String", Me.__string, value)
    End Set
  End Property
  <NonPersistent> _
Public ReadOnly Property Objects As XPCollection(Of XafarSmartDesignObject)
    Get
      Return New XPCollection(Of XafarSmartDesignObject)(Me.Session, Nothing, New SortProperty() { })
    End Get
  End Property
End Class

To apply the Smart Design features, add the XafariModule and XafariSmartDesignModule modules to the project.

Apply the SmartDesignStrategy attribute to the class in order to activate XafariSmartDesignStrategy:

  • c#
  • VB

[SmartDesignStrategy(typeof(XafariSmartDesignStrategy))]
public class XafariViewLayoutGeneratorObject : ObjectBase
{//...
}

<SmartDesignStrategy(GetType(XafariSmartDesignStrategy))> _
Public Class XafariViewLayoutGeneratorObject
  Inherits ObjectBase
  '...
End Class

To create additional Views with a specific custom layout, use the CreateListView and CreateDetailView attributes, and set the Id and Layout properties as follows:

  • example

//List View with four columns: Byte, Decimal, Double, Float; it will be DefaultTreeListView:
 [CreateListView(Id = "XafariSmartDesignGeneratorObject_Code1_ListView", Layout = "Byte;Decimal;Double;Float", IsDefaultTreeListView = true)]
 //Lookup List View with three columns: Integer, Long, String:
 [CreateListView(Id = "XafariSmartDesignGeneratorObject_Code1_LookupListView", Layout = "Integer;Long;String", ListViewType = ListViewType.LookupListView)]
 //Detail View with three single properties (String, Integer, Double) and three groups and Objects collection property
 [CreateDetailView(Id = "XafariSmartDesignGeneratorObject_Code1_DetailView", Layout = "String;Integer;Double;" +
                                                                                       "GroupByte[Byte,Byte,Byte];" +
                                                                                       "GroupDecimal[Decimal,Decimal,Decimal];" +
                                                                                       "GroupFloat[Float,Float,Float];Objects")]
 //List View with three columns: Integer;Long;String; it will be DefaultGridListView:
 [CreateListView(Id = "XafariSmartDesignGeneratorObject_Code2_ListView", Layout = "Integer;Long;String", IsDefaultGridListView = true)]
 //Lookup List View with four columns: Byte;Decimal;Double;Float:
 [CreateListView(Id = "XafariSmartDesignGeneratorObject_Code2_LookupListView", Layout = "Byte;Decimal;Double;Float", ListViewType = ListViewType.LookupListView)]
 //Detail View with String property, Objects collection property and one group (Byte, Integer):
 [CreateDetailView(Id = "XafariSmartDesignGeneratorObject_Code2_DetailView", Layout = "String;Group[Byte,Integer];Objects")]

 [SmartDesignStrategy(typeof(XafariSmartDesignStrategy))]
 public class XafariViewLayoutGeneratorObject : ObjectBase
 {
  //...
 }

To create an extra List View for the Objects collection property, decorate this property with the CreateListView attribute as shown in the code sample below:

  • c#
  • VB

public class XafariViewLayoutGeneratorObject : ObjectBase
{
  //...
  [CreateListView(Layout = "String;Byte", ListViewType = ListViewType.LookupListView)]
  public XPCollection<XafariViewLayoutGeneratorObject> Objects
  {
    get
    {
      return new XPCollection<XafariViewLayoutGeneratorObject>(this.Session, null, new SortProperty[] { });
    }
  }
}

Public Class XafariViewLayoutGeneratorObject
  Inherits ObjectBase
  '...
  <CreateListView(Layout := "String;Byte", ListViewType := ListViewType.LookupListView)> _
Public ReadOnly Property Objects As XPCollection(Of XafariViewLayoutGeneratorObject)
    Get
      Return New XPCollection(Of XafariViewLayoutGeneratorObject)(Me.Session, Nothing, New SortProperty() { })
    End Get
  End Property
End Class

Apply the VisibleIn...View attributes to all appropriate properties in order to specify their visibility in the default Views:

  • c#
  • VB

public class XafarSmartDesignObject : ObjectBase
{
  //...
  [VisibleInListView(true)]
  [VisibleInLookupListView(true)]
  public byte Byte
  {
    get
    {
      return this._byte;
    }
    set
    {
      SetPropertyValue("Byte", ref this._byte, value);
    }
  }
  [VisibleInListView(true)]
  public decimal Decimal
  {
    get
    {
      return this._decimal;
    }
    set
    {
      SetPropertyValue("Decimal", ref this._decimal, value);
    }
  }
  [VisibleInListView(true)]
  [VisibleInLookupListView(true)]
  public double Double
  {
    get
    {
      return this._double;
    }
    set
    {
      SetPropertyValue("Double", ref this._double, value);
    }
  }
  [VisibleInDetailView(true)]
  public float Float
  {
    get
    {
      return this._float;
    }
    set
    {
      SetPropertyValue("Float", ref this._float, value);
    }
  }
  [VisibleInDetailView(true)]
  [VisibleInLookupListView(true)]
  public Int32 Integer
  {
    get
    {
      return this._integer;
    }
    set
    {
      SetPropertyValue("Integer", ref this._integer, value);
    }
  }
  [VisibleInDetailView(true)]
  public Int64 Long
  {
    get
    {
      return this._long;
    }
    set
    {
      SetPropertyValue("Long", ref this._long, value);
    }
  }
  [VisibleInAllView(true)]
  public string String
  {
    get
    {
      return this._string;
    }
    set
    {
      SetPropertyValue("String", ref this._string, value);
    }
  }
  //...
  [VisibleInDetailView(true)]
  public XPCollection<XafarSmartDesignObject> Objects
  {
    get
    {
      return new XPCollection<XafarSmartDesignObject>(this.Session, null, new SortProperty[] { });
    }
  }
}

Public Class XafarSmartDesignObject
  Inherits ObjectBase
  '...
  <VisibleInListView(True)> _
<VisibleInLookupListView(True)> _
Public Property [Byte] As Byte
    Get
      Return Me._byte
    End Get
    Set
      SetPropertyValue("Byte", Me._byte, value)
    End Set
  End Property
  <VisibleInListView(True)> _
Public Property [Decimal] As decimal
    Get
      Return Me._decimal
    End Get
    Set
      SetPropertyValue("Decimal", Me._decimal, value)
    End Set
  End Property
  <VisibleInListView(True)> _
<VisibleInLookupListView(True)> _
Public Property [Double] As double
    Get
      Return Me._double
    End Get
    Set
      SetPropertyValue("Double", Me._double, value)
    End Set
  End Property
  <VisibleInDetailView(True)> _
Public Property Float As Single
    Get
      Return Me._float
    End Get
    Set
      SetPropertyValue("Float", Me._float, value)
    End Set
  End Property
  <VisibleInDetailView(True)> _
<VisibleInLookupListView(True)> _
Public Property [Integer] As Int32
    Get
      Return Me._integer
    End Get
    Set
      SetPropertyValue("Integer", Me._integer, value)
    End Set
  End Property
  <VisibleInDetailView(True)> _
Public Property [Long] As Int64
    Get
      Return Me._long
    End Get
    Set
      SetPropertyValue("Long", Me._long, value)
    End Set
  End Property
  <VisibleInAllView(True)> _
Public Property [String] As String
    Get
      Return Me._string
    End Get
    Set
      SetPropertyValue("String", Me._string, value)
    End Set
  End Property
  '...
  <VisibleInDetailView(True)> _
Public ReadOnly Property Objects As XPCollection(Of XafarSmartDesignObject)
    Get
      Return New XPCollection(Of XafarSmartDesignObject)(Me.Session, Nothing, New SortProperty() { })
    End Get
  End Property
End Class

Build the solution, invoke the Model Editor, and examine the View nodes which are generated according to the aforementioned code.

See the Views appeared in the application.