wow ... Virtualization

************************************************************
codes to be put under the class SharedBusinessRules
************************************************************

Public Overrides Function SupportsVirtualization(controllerName As String) As Boolean

Select Case controllerName

Case "" 'exceptions (case sensitive)
Return False

Case Else 'by default, use virtualization
Return True

End Select

End Function

Public Overrides Sub VirtualizeController(controllerName As String, navigator As XPathNavigator, resolver As XmlNamespaceManager)
'** Tested on COT 8.7.4.0 UNLIMITED
'** refer to project's app > controllers XML files for through understandings

'** get each FIELD
Dim fields As XPathNodeIterator = navigator.Select("/c:dataController/c:fields/c:field", resolver)
While fields.MoveNext
Dim currentField As XPathNavigator = fields.Current
Dim fieldName As String = getAttr(currentField, "name")
Dim fieldType As String = getAttr(currentField, "type")
'example of how to update
Call updateAttr(currentField, "label", "Boonchoo: " & fieldName)
End While

'** get each ACTION
Dim actions As XPathNodeIterator = navigator.Select("/c:dataController/c:actions/c:actionGroup/c:action", resolver)
While actions.MoveNext
Dim currentAction As XPathNavigator = actions.Current
Dim actionID As String = getAttr(currentAction, "id")
Dim actionCommandName As String = getAttr(currentAction, "commandName")
Dim actionCommandArgument As String = getAttr(currentAction, "commandArgument")
If actionCommandName = "Select" And actionCommandArgument = "editForm1" Then
Call updateAttr(currentAction, "headerText", "Boonchoo ACTION from BR")
End If
End While

'** get each VIEW
Dim views As XPathNodeIterator = navigator.Select("/c:dataController/c:views/c:view", resolver)
While views.MoveNext

Dim currentView As XPathNavigator = views.Current
Dim viewID As String, viewType As String
viewID = getAttr(currentView, "id")
viewType = getAttr(currentView, "type")

'Grid v.s. Form have different paths, see {controller name}.xml for details**
'map corresponding path by view type
Dim viewFieldsPath As String
Select Case viewType
Case "Grid"
viewFieldsPath = "/c:dataController/c:views/c:view[@id='" & viewID & "']/c:dataFields/c:dataField"
Case "Form"
'all fields are retrieved no matter categories
viewFieldsPath = "/c:dataController/c:views/c:view[@id='" & viewID & "']/c:categories/c:category/c:dataFields/c:dataField"
End Select

'** get each DATAFIELD
Dim viewFields As XPathNodeIterator = navigator.Select(viewFieldsPath, resolver)
Dim viewFieldName As String
While viewFields.MoveNext
Dim currentViewField As XPathNavigator = viewFields.Current
viewFieldName = getAttr(currentViewField, "fieldName")
End While
End While

End Sub

Private Function getAttr(xp As XPathNavigator, attr As String) As String
getAttr = xp.GetAttribute(attr, String.Empty)
End Function

Private Sub updateAttr(xp As XPathNavigator, attr As String, val As String)
If xp.MoveToAttribute(attr, String.Empty) Then
xp.SetValue(val)
Else
xp.CreateAttribute(String.Empty, attr, String.Empty, val)
End If
End Sub

************************************************************
Procedures
************************************************************

1) try to adjust attribute(s) on the IDE


2) browse to ensure if changes are correct as you may want


3) open the project with a visual studio
and goto app > controllers > {the controller name you adjust}.xml
to see how IDE changes are translated into XML


4) try to adjust the corresponding portion in the VirtualizeController


5) browse again to see the new result(s)


btw, i really love this feature !!!
super thanks ... COT team
1 person likes
this idea
+1
Reply