'/===================================================================//
'/ Vincent Richard            |                                      //
'/ Technical Support Engineer |                                      //
'/ Rational Software          | Phone:  +31 (0)20 4546 200           //
'/ Beechavenue 30             | Fax:    +31 (0)20 4546 201           //
'/ 1119 PV  Schiphol-Rijk     | email:  vincent.richard@rational.com //
'/ The Netherlands            | http://www.rational.com/support      //
'/===================================================================//

' The shortcut menus that will be dynamically enabled/disabled/checked
Dim ClearStereotype As RoseContextMenuItem
Dim NoneStereotype As RoseContextMenuItem
Dim BoochStereotype As RoseContextMenuItem
Dim GradyStereotype As RoseContextMenuItem
Dim JacobsonStereotype As RoseContextMenuItem
Dim OtherStereotype As RoseContextMenuItem

Option Compare Text

Public Sub OnNewModel(RoseApp As RoseApplication)
    MsgBox "VBContextMenu: OnNewModel"
End Sub

Public Sub OnAppInit(RoseApp As RoseApplication)
    MsgBox "VBContextMenu: OnAppInit"
End Sub

Public Sub OnActivate(RoseApp As RoseApplication)
    MsgBox "VBContextMenu: OnActivate"
    
    ' Find our add-in
    Dim thisAddIn As RoseAddIn
    Set thisAddIn = RoseApp.AddInManager.AddIns.GetFirst("VBContextMenu")
    If Not thisAddIn Is Nothing Then
        MsgBox "VBContextMenu Add-in found"
        Dim tmpMenuItem As RoseContextMenuItem
        Set tmpMenuItem = thisAddIn.AddContextMenuItem(rsClass, "Separator", "")
        Set ClearStereotype = thisAddIn.AddContextMenuItem(rsClass, "Clear Stereotype", "SetStereotypeNone")
        Set tmpMenuItem = thisAddIn.AddContextMenuItem(rsClass, "Submenu Set Stereotype", "")
        Set NoneStereotype = thisAddIn.AddContextMenuItem(rsClass, "None", "SetStereotypeNone")
        Set BoochStereotype = thisAddIn.AddContextMenuItem(rsClass, "Booch", "SetStereotypeBooch")
        Set GradyStereotype = thisAddIn.AddContextMenuItem(rsClass, "Grady", "SetStereotypeGrady")
        Set JacobsonStereotype = thisAddIn.AddContextMenuItem(rsClass, "Jacobson", "SetStereotypeJacobson")
        Set OtherStereotype = thisAddIn.AddContextMenuItem(rsClass, "Other", "Other")
        Set tmpMenuItem = thisAddIn.AddContextMenuItem(rsClass, "endsubmenu", "")
    End If
End Sub

Public Sub OnDeactivate(RoseApp As RoseApplication)
    MsgBox "VBContextMenu: OnDeactivate"
    
    Set ClearStereotype = Nothing
    Set NoneStereotype = Nothing
    Set BoochStereotype = Nothing
    Set GradyStereotype = Nothing
    Set JacobsonStereotype = Nothing
    Set OtherStereotype = Nothing
End Sub

Public Function OnEnableContextMenuItems(RoseApp As RoseApplication, MenuItem As RoseContextMenuItemType) As Boolean
    If MenuItem = rsClass Then
        ClearStereotype.MenuState = rsEnabled
        NoneStereotype.MenuState = rsEnabled
        BoochStereotype.MenuState = rsEnabled
        GradyStereotype.MenuState = rsEnabled
        JacobsonStereotype.MenuState = rsEnabled
        OtherStereotype.MenuState = rsDisabled
        If RoseApp.CurrentModel.GetSelectedClasses.Count = 1 Then
            Stereotype$ = RoseApp.CurrentModel.GetSelectedClasses.GetAt(1).Stereotype
            If Stereotype = "" Then
                ClearStereotype.MenuState = rsDisabled
                NoneStereotype.MenuState = rsDisabledAndChecked
            ElseIf Stereotype = "Grady" Then
                GradyStereotype.MenuState = rsDisabledAndChecked
            ElseIf Stereotype = "Jacobson" Then
                JacobsonStereotype.MenuState = rsDisabledAndChecked
            ElseIf Stereotype = "Booch" Then
                BoochStereotype.MenuState = rsDisabledAndChecked
            Else
                OtherStereotype.MenuState = rsDisabledAndChecked
            End If
        End If
    End If
    OnEnableContextMenuItems = True
End Function

Public Function OnSelectedContextMenuItem(RoseApp As RoseApplication, internalName As String) As Boolean
    If Left(internalName, 13) = "SetStereotype" Then
        Stereotype$ = ""
        If internalName = "SetStereotypeBooch" Then
            Stereotype$ = "Booch"
        ElseIf internalName = "SetStereotypeGrady" Then
            Stereotype$ = "Grady"
        ElseIf internalName = "SetStereotypeJacobson" Then
            Stereotype$ = "Jacobson"
        End If
        Dim allClasses As RoseClassCollection
        Set allClasses = RoseApp.CurrentModel.GetSelectedClasses
        For i% = 1 To allClasses.Count
            allClasses.GetAt(i).Stereotype = Stereotype
        Next i
    End If
    OnSelectedContextMenuItems = True
End Function
