Adding a Radio Control to a FIM Custom Workflow UI

Following on from the last post about adding a CheckBox, here’s how I added a RadioButtonList to a custom workflow UI.

Note: I have also uploaded a version of this to the Technet Wiki: How to Add a RadioButtonList to a FIM Custom Workflow UI

Here I’m adding a control which allows me to set a Logging Level. I then use the value Me.LoggingLevel in my code to decide which messages to write to the event log.

Define the property in the Activity code

The radio control will return a string value so I need to define the property in the Activity code.

    '''  Identifies the target attribute
    Public Shared LoggingLevelProperty As DependencyProperty = DependencyProperty.Register("LoggingLevel", GetType(System.String), GetType(MyActivity))
    <Description("Please specify the target attribute")> _
    <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
    <Browsable(True)> _
    Public Property LoggingLevel() As String
            Return DirectCast(MyBase.GetValue(MyActivity.LoggingLevelProperty), [String])
        End Get
        Set(ByVal value As String)
            MyBase.SetValue(MyActivity.LoggingLevelProperty, value)
        End Set
    End Property


UI code functions

Add the following functions to your UI code:

#Region "Radio Functions"
    Private Function AddTableRowRadioList(ByVal labelText As [String], ByVal controlID As [String], _
                                          ByVal radioOptions As String(), _
                                          ByVal defaultValue As [String]) As TableRow
        Dim row As New TableRow()
        Dim labelCell As New TableCell()
        Dim controlCell As New TableCell()
        Dim label As New Label()
        Dim radioList As New RadioButtonList()
        Dim item As String

        label.Text = labelText
        label.CssClass = MyBase.LabelCssClass

        radioList.ID = controlID
        For Each item In radioOptions
            radioList.Items.Add(New ListItem(item, item))
        radioList.SelectedValue = defaultValue
        radioList.RepeatDirection = RepeatDirection.Horizontal
        Return row
    End Function

    Private Function GetRadioSelection(ByVal radioListID As String) As String
        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
        Return radioList.SelectedValue
    End Function

    Private Sub SetRadioSelection(ByVal radioListID As String, ByVal radioSelection As String)
        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
        If radioList IsNot Nothing Then
            radioList.SelectedValue = radioSelection
            radioList.SelectedValue = radioList.Items.Item(0).Text
        End If
    End Sub

    Private Sub SetRadioListReadOnlyOption(ByVal radioListID As String, ByVal [readOnly] As Boolean)
        Dim radioList As RadioButtonList = DirectCast(Me.FindControl(radioListID), RadioButtonList)
        radioList.Enabled = Not [readOnly]
    End Sub

    Protected Overrides Sub CreateChildControls()
        Dim controlLayoutTable As Table
        controlLayoutTable = New Table()

        'Width is set to 100% of the control size
        controlLayoutTable.Width = Unit.Percentage(100.0)
        controlLayoutTable.BorderWidth = 0
        controlLayoutTable.CellPadding = 2
        ' The following lines add the Radio Control
        Dim loggingOptions As String() = {"Normal", "Verbose"}
        controlLayoutTable.Rows.Add(Me.AddTableRowRadioList("Logging Level:", "txtLoggingLevel", loggingOptions, "Normal"))

    End Sub

#End Region


Modify the default methods of the UI code

Finally modify the default metods of the UI code to handle the value.

    Public Overrides Function GenerateActivityOnWorkflow(ByVal workflow As SequentialWorkflow) As Activity
        If Not Me.ValidateInputs() Then
            Return Nothing
        End If
        Dim MyActivity As New MyActivity()
        MyActivity.LoggingLevel = Me.GetRadioSelection("txtLoggingLevel")
        Return MyActivity
    End Function

    Public Overrides Sub LoadActivitySettings(ByVal activity As Activity)
        Dim MyActivity As MyActivity = TryCast(activity, MyActivity)
        If MyActivity IsNot Nothing Then
            Me.SetRadioSelection("txtLoggingLevel", MyActivity.LoggingLevel)
        End If
    End Sub

    Public Overrides Function PersistSettings() As ActivitySettingsPartData
        Dim data As New ActivitySettingsPartData()
        data("LoggingLevel") = Me.GetRadioSelection("txtLoggingLevel")
        Return data
    End Function

    Public Overrides Sub RestoreSettings(ByVal data As ActivitySettingsPartData)
        If data IsNot Nothing Then
            Me.SetRadioSelection("txtLoggingLevel", DirectCast(data("LoggingLevel"), String))
        End If
    End Sub

    Public Overrides Sub SwitchMode(ByVal mode As ActivitySettingsPartMode)
        Dim [readOnly] As Boolean = (mode = ActivitySettingsPartMode.View)
        Me.SetRadioListReadOnlyOption("txtLoggingLevel", [readOnly])
    End Sub


Leave a Reply

Your email address will not be published. Required fields are marked *