Popup Container Show Action. Getting Started

This topic provides information on applying the Popup Container Show Action. Before proceeding, it is recommended that you review the Add an Action that Displays a Pop-up Window lesson.

To study this lesson successfully, it is needed to implement two auxiliary classes: PopupContainerShowActionObjects and ShowInPopupListObjects. The Popup Container Show Action should appear on PopupContainerShowActionObjects_DetailView displaying ShowInPopupListObjects within the popup container.

Open the existing XAF solution or create a new one. In the Solution Explorer, right-click the platform-agnostic module project and select Add DevExpress Item|New Item from the context menu. In the invoked DevExpress Templates Gallery select the XPO Business Object template, set the Name property to the "PopupContainerShowActionObjects" value, and click Add. Replace the autogenerated file content with the following code:

  • c#
  • VB

[DefaultClassOptions]
public class PopupContainerShowActionObjects : BaseObject
{
  public PopupContainerShowActionObjects(Session session)
    : base(session)
  {
  }
  public override void AfterConstruction()
  {
    base.AfterConstruction();
  }
  private string _nameProperty;
  private string _logProperty;
  public string NameProperty
  {
    get
    {
      return _nameProperty;
    }
    set
    {
      SetPropertyValue("NameProperty", ref _nameProperty, value);
    }
  }
  [Size(SizeAttribute.Unlimited)]
  [ModelDefault("AllowEdit", "False")]
  public string LogProperty
  {
    get
    {
      return _logProperty;
    }
    set
    {
      SetPropertyValue("LogProperty", ref _logProperty, value);
    }
  }
}

<DefaultClassOptions> _
Public Class PopupContainerShowActionObjects
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Overrides Sub AfterConstruction()
    MyBase.AfterConstruction()
  End Sub
  Private __nameProperty As String
  Private __logProperty As String
  Public Property NameProperty As String
    Get
      Return __nameProperty
    End Get
    Set
      SetPropertyValue("NameProperty", __nameProperty, value)
    End Set
  End Property
  <Size(SizeAttribute.Unlimited)> _
<ModelDefault("AllowEdit", "False")> _
Public Property LogProperty As String
    Get
      Return __logProperty
    End Get
    Set
      SetPropertyValue("LogProperty", __logProperty, value)
    End Set
  End Property
End Class

In the same way, extend the ShowInPopupListObjects class with the following code:

  • c#
  • VB

[DefaultClassOptions]
public class ShowInPopupListObjects : BaseObject
{
  public ShowInPopupListObjects(Session session)
    : base(session)
  {
  }
  public override void AfterConstruction()
  {
    base.AfterConstruction();
  }
  private string _nameProperty;
  public string NameProperty
  {
    get
    {
      return _nameProperty;
    }
    set
    {
      SetPropertyValue("NameProperty", ref _nameProperty, value);
    }
  }
}

<DefaultClassOptions> _
Public Class ShowInPopupListObjects
  Inherits BaseObject
  Public Sub New(ByVal session As Session)
    MyBase.New(session)
  End Sub
  Public Overrides Sub AfterConstruction()
    MyBase.AfterConstruction()
  End Sub
  Private __nameProperty As String
  Public Property NameProperty As String
    Get
      Return __nameProperty
    End Get
    Set
      SetPropertyValue("NameProperty", __nameProperty, value)
    End Set
  End Property
End Class

Then invoke the Add DevExpress Item|New Item dialog, add a new View Controller to the project, and name it PopupContainerShowActionObjectsViewCotroller.

popup_container_show_action_2

Set the Controller's properties as follows: TargetViewType is DetailView and TargetObjectType is PopupContainerShowActionObjects. The image below shows the appropriate Solution Explorer and Properties windows.

popup_container_show_action_3

Build the project, invoke the Module Designer, and drag the XafariModule from the Toolbox to the Modules panel. Rebuild the project.

check_action_4

In the same way, add the XafariWinModule to the WinApplication project and add the XafariWebModule to the WebApplication project.

In the Solution Explorer, double-click the PopupContainerShowActionObjectsViewCotroller item to invoke the Controller's Designer, add a PopupContainerShowAction object from the Xafari tab and set its Caption and Id properties to the "PopupContainerShowAction" value. The Image below shows the PopupContainerShowActionObjectsViewCotroller Designer having PopupContainerShowAction.

popup_container_show_action_4

Subscribe to the CustomizePopupWindowParams and Execute Action's events:

popup_container_show_action_5

Modify the PopupContainerShowActionObjectsViewCotroller.cs file, implement the popupContainerShowAction1_CustomizePopupWindowParams event handler as follows:

  • c#
  • VB

public partial class PopupContainerShowActionObjectsViewCotroller : ViewController
{
  //...
  private void popupContainerShowAction1_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
  {
    IObjectSpace objectSpace = Application.CreateObjectSpace();
    e.View = Application.CreateListView(objectSpace, typeof(ShowInPopupListObjects), true);
  }
}

Public Partial Class PopupContainerShowActionObjectsViewCotroller
  Inherits ViewController
  '...
  Private Sub popupContainerShowAction1_CustomizePopupWindowParams(ByVal sender As Object, ByVal e As CustomizePopupWindowParamsEventArgs)
    Dim objectSpace As IObjectSpace = Application.CreateObjectSpace()
    e.View = Application.CreateListView(objectSpace, GetType(ShowInPopupListObjects), True)
  End Sub
End Class

The code above specifies the popup List View that will display the ShowInPopupListObjects records.

Next, add the LogTrace method to the PopupContainerShowActionObjectsViewCotroller class and implement the popupContainerShowAction1_Execute event handler. The Code snippet below demonstrates the class after this changes:      

  • c#
  • VB

public partial class PopupContainerShowActionObjectsViewCotroller : ViewController
{
  //...
  private void LogTrace(string message)
  {
    ((PopupContainerShowActionObjects)View.CurrentObject).LogProperty = message + "\r\n" + ((PopupContainerShowActionObjects)View.CurrentObject).LogProperty;
  }
  private void popupContainerShowAction1_Execute(object sender, PopupWindowShowActionExecuteEventArgs e)
  {
    string parameters = e.PopupWindow.View.SelectedObjects.Cast<ShowInPopupListObjects>().Aggregate("", (current, obj) => current + (obj.NameProperty + " ; "));
    parameters = parameters.Trim().TrimEnd(';');
    LogTrace(string.Format("The 'PopupContainerShowAction' is executed with {0} parameter(s). {1}", e.PopupWindow.View.SelectedObjects.Count, string.IsNullOrEmpty(parameters) ? "" : "\r\n\t\t" + parameters));
  }
  //...
}

Public Partial Class PopupContainerShowActionObjectsViewCotroller
  Inherits ViewController
  '...
  Private Sub LogTrace(ByVal message As String)
    CType(View.CurrentObject, PopupContainerShowActionObjects).LogProperty = message + "" + vbCrLf + "" + CType(View.CurrentObject, PopupContainerShowActionObjects).LogProperty
  End Sub
  Private Sub popupContainerShowAction1_Execute(ByVal sender As Object, ByVal e As PopupWindowShowActionExecuteEventArgs)
    Dim parameters As String = e.PopupWindow.View.SelectedObjects.Cast(Of ShowInPopupListObjects)().Aggregate("", Function(ByVal current, ByVal obj) current + (obj.NameProperty + " ; "))
    parameters = parameters.Trim().TrimEnd(";"C)
    LogTrace(String.Format("The 'PopupContainerShowAction' is executed with {0} parameter(s). {1}", e.PopupWindow.View.SelectedObjects.Count, If(String.IsNullOrEmpty(parameters), "", "" + vbCrLf + "" + vbTab + "" + vbTab + "" + parameters)))
  End Sub
  '...
End Class

To see the result, run the WinForms application, select the Show In Popup List Objects item in the navigation control, and populate the table.

popup_container_show_action_7

Then select the Popup Container Show Action Objects navigation item and click the New Action. In the invoked Detail View, find the PopupContainerShowAction toolbar control and invoke the popup container. Select several objects in the list and click OK.

popup_container_show_action_8

Check to see that the LogProperty value has been changed.

popup_container_show_action_9