Book a Demo

Author Topic: prevent name change of package  (Read 6580 times)

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
prevent name change of package
« on: February 15, 2013, 08:53:14 pm »
How can I prevent the user from changing the name of a package ?

what I noticed
EA_OnNotifyContextItemModified is triggered 3 times !

what I tried
(this technique works for an EA.Element)

In EA_OnNotifyContextItemModified
- I change the package.element.name to the correct value
- I do an package.element.update();

-> the package.name is changed anyway !!

I also tried with package.Name in stead of thru the package.element
But then I get EA_OnNotifyContextItemModified  triggers on the element as well.

Debuggingthe happenings
I put a breakpoint on my reset of the name, in the midst of the EA_OnNotifyContextItemModified method

BUT ....... I noticed that the name of the package is already changed in the tree, visible on the UI !!!

proceeding with my reset has no effect what so ever.

I'm stuck  - without a clue :'(

gr and thanks in advance











Reg.

Danny

Sunshine

  • EA Practitioner
  • ***
  • Posts: 1353
  • Karma: +121/-10
  • Its the results that count
    • View Profile
Re: prevent name change of package
« Reply #1 on: February 18, 2013, 07:47:59 am »
You could try locking the package using security to prevent users changing package. Can do this via menu Project>Security> Enable Security. Then add users and by logging on as one user you can lock the package. All of the package fields are locked through  :(. So not sure if that's desirable in your circumstances.
Happy to help
:)

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: prevent name change of package
« Reply #2 on: February 18, 2013, 09:07:19 am »
Hi Danny,

You could block the property dialog for these packages if that is acceptable, using EA_OnContextItemDoubleClicked:

Function EA_OnContextItemDoubleClicked(repo, GUID, ot)
      if ot = 5 then
            EA_OnContextItemDoubleClicked = true
      end if
end function

In addition the following event handler will block a change in the name of the package if a user tries to change it in place in the project browser, -without additional events being triggered- (??!!)

Sub EA_OnNotifyContextItemModified(repo,GUID, ot)
      if ot = 5 then
            dim pck as EA.Package
            set pck = GetPackageByGuid(GUID)
            if pck.element.name <> "sss" then
                  pck.element.name = "sss"
                  pck.element.Update
            end if
      end if
end sub

« Last Edit: February 18, 2013, 09:12:04 am by pmaessen »

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Re: prevent name change of package
« Reply #3 on: February 18, 2013, 06:48:52 pm »
Thanks for the responses
@ Sunshine : I don't want to lock all fields - so that won't work.
@Paulus :
1. Preventing the dialog is cumbersome because as responded to Shunshine some fields need to be editable, meaning I need to provide a replacement dialog ?

2. EA_OnNotifyContextItemModified gets triggered 3 times ! (when going thru the dialog)

If I put a "Repository.WriteOutput" on the EA_OnNotifyContextItemModified, doing nothing else but writing a line to the output I get 3 lines written for 3 times the EA_OnNotifyContextItemModified is triggered.
(Same thing happens when debugging of course)


3. As you suggested, if I 'in place' edit the package name in the browser (without opening the dialog) the EA_OnNotifyContextItemModified only gets triggered 1 time.

-> in this case my reset works  !!



So going thru the dialog exhibits some weird behavior - I'm going to investigate this further

But suggestions are still very welcome :)

thanks again

Reg.

Danny

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: prevent name change of package
« Reply #4 on: February 18, 2013, 10:15:26 pm »
OK, one last suggestion: if it is not possible to prevent the change from wihtin EA_OnNotifyContextItemModified you might try to trigger a timed event from within EA_OnNotifyContextItemModified and undo the namechange from there.

Not ideal but this should work for all cases.

best regards,

Paulus

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: prevent name change of package
« Reply #5 on: February 19, 2013, 11:42:57 pm »
I think you best make sure to store the name of the package in EA_OnContextItemChanged and then in EA_OnNotifyContextItemModified compare it to what you have recorded. If it's different then you change it back to what it was.

Make sure you let the GUI know that you have changed the element.

Geert