One of the organisations I support in using Enterprise Architect was encountering problems with deleting elements from a repository. Sometimes modellers deleted elements by accident and in other cases where teams are modelling it was not clear that an element was still used.
However there is a model manager who is maintaining the repository content so from an organisational point of view this problem shoud be easy to solve. He suggested that a Wastebin should solve the problem. This wastebin should have the same functionality als the wastebin in Windows. When somebody deletes an element or package it is not deleted but moved to a certain location in the repository.
Since the organisation is using the IDEA AddOn we decided to develop a function in the AddOn, which is developed in VB.Net. It turned out to be relative easy. There is an adaption necessary in the AddIN Predelete event and an extra class (not necessary but for us a best practice) is added. Below you see the two code snippets.
Function EA_OnPreDeleteElement(Repository As EA.Repository, _
Info As EA.EventProperties) As Boolean
Return WasteBin.WasteBinElement(Repository, Info.Get(0).Value)
Function EA_OnPreDeletePackage(Repository As EA.Repository, _
Info As EA.EventProperties) As Boolean
Return WasteBin.WasteBinPackage(Repository, Info.Get(0).Value)
This piece of code is returning a true or false to deleted the selected package or not. When it is a regular user, the element is moved before the delete and therefore a false is returned. When somebody is authorized and the element is in the WasteBin package the element can be deleted so a true is returned.
In the code snippet below you see the code of the WasteBin class
Public Class WasteBinPublic Shared Function WasteBinElement(Repository As EA.Repository, strEntityId As String) As BooleanDim oElement As EA.ElementDim intPackage_id As Int32 = GetWasteBinPackage_id()TryIf intPackage_id <> -999 ThenoElement = Repository.GetElementByID(Convert.ToInt32(strEntityId))If oElement.PackageID <> intPackage_id ThenRepository.EnableUIUpdates = FalseoElement.PackageID = intPackage_idoElement.Update()Repository.EnableUIUpdates = TrueReturn FalseElseReturn DeleteFromWasteBin(Repository)End IfEnd IfReturn TrueCatch ex As ExceptionDLA2EAHelper.Error2Log(ex)End TryReturn FalseEnd FunctionPrivate Shared Function DeleteFromWasteBin(Repository As EA.Repository) As BooleanIf Repository.IsSecurityEnabled = False Or DLA2EAHelper.IsUserGroupMember(Repository, "Administrators") ThenReturn TrueElseReturn FalseEnd IfEnd FunctionPublic Shared Function WasteBinPackage(Repository As EA.Repository, strEntityId As String) As BooleanDim oPackage As EA.PackageDim intPackage_id As Int32 = GetWasteBinPackage_id()TryIf intPackage_id <> -999 ThenoPackage = Repository.GetPackageByID(Convert.ToInt32(strEntityId))If oPackage.ParentID <> intPackage_id ThenRepository.EnableUIUpdates = FalseoPackage.ParentID = intPackage_idoPackage.Update()Repository.EnableUIUpdates = TrueReturn FalseElseReturn DeleteFromWasteBin(Repository)End IfEnd IfReturn TrueCatch ex As ExceptionDLA2EAHelper.Error2Log(ex)End TryReturn FalseEnd FunctionShared Function GetWasteBinPackage_id() As Int32Dim oDef As New IDEADefinitions()Dim strPackage_id As StringDim intPackage_id As Int32 = -999strPackage_id = oDef.GetSettingValue("WasteBinPackage_id")If strPackage_id.Length > 0 ThenintPackage_id = Convert.ToInt32(strPackage_id)End IfReturn intPackage_idEnd FunctionEnd Class
In the code we check first if the element is in the wastebin package or not, if not the element is moved to the wastebin. If the element or the package is in the wastebin then an authorization check is done. If the user is authorized then the element is permanent removed from the repository
This routine is part of the IDEA AddOn. This Open Source tool can be downloaded from http://eaxpertise.nl/ideanl.aspx. When you want to include it in a ModelAddIn this is probably a relatively small modification.