Author Topic: Proper way of adding diagram objects WITHOUT needing to call ReloadDiagram()  (Read 13525 times)

MichPaule

  • EA User
  • **
  • Posts: 65
  • Karma: +0/-0
    • View Profile
EA 16.1.1627 (64 bit)

I have to create diagram objects on diagrams which at this point in time might be in the "modified" state.
When following the often recommended approach to call ReloadDiagram() after adding the diagram object unexpected behavior happens: The modifications of the diagram are reverted and the user is annoyed  :-[
The internal commands of EA (e.g. Show part) can do the trick but I fail to replicate the same behavior using scripts.
One of my latest attempts:
Code: [Select]
Set dgmob = dgm.DiagramObjects.AddNew("", "")
dgmob.ElementID = ele.ElementID
If (dgmob.Update() = False) Then Call Repository.WriteOutput("Script", "Update failed: " & dgmob.GetLastError(), 0)
Call dgm.DiagramObjects.Refresh()
If (dgm.Update() = False) Then Call Repository.WriteOutput("Script", "Diagram Update failed: " & dgm.GetLastError(), 0)
No error but also no visible element.
Manually reloading the diagram will finally show it!
I'm out of ideas now...
Any help would be appreciated very much! :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
In order to show the changes in the diagram to the user, you need to reload it.

The diagram object you are working on, and the one shown in the GUI are two different objects.
If you want to avoid loosing the current changes on the diagram, save it before reloading. (Repository.SaveDiagram)

Geert

PS. there is no need to call DiagramObjects.Refresh(), or Dgm.Update() when you are only adding a diagramobject.

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
In this case, I would think about how to handle the "modified" state.
You could test first on whether the diagram is in that state and if so, then ask to either save or cancel.
In pseudo code:

IF diagram Modified
   THEN Ask how to proceed (Save or Cancel)
      IF Proceed
         THEN Save Diagram
         ELSE Exit script
Continue script...

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
I'm not sure if there is a way to know if the diagram is in a "modified" state.

Geert

MichPaule

  • EA User
  • **
  • Posts: 65
  • Karma: +0/-0
    • View Profile
I'm not sure if there is a way to know if the diagram is in a "modified" state.
According to this post there seems to be no way  :'(

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Maybe then just always ask the user to check whether the diagram is in a 'safe' state...
Similar to asking "Are you sure?" when deleting something.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Maybe then just always ask the user to check whether the diagram is in a 'safe' state...
Similar to asking "Are you sure?" when deleting something.
I've considered that in similar circumstances, and I decided against it and simply always save the diagram without asking.

The popup box might be more annoying then sometimes saving a diagram when the user didn't want it saved.

Geert

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
I wasn't very satisfied, so I tried another approach as indicated by this post (https://sparxsystems.com/forums/smf/index.php?topic=1455.0).
It uses the repository method IsTabOpen().
This method returns "2" when the current diagram is open and not changed.
It returns "0" if the diagram is modified because the name is prepended with "*" which doesn't match with the original name of the diagram.

There is however a drawback as it is not completely reliable. It also returns "0" when the name of the diagram contains a digit... Is this a bug?

The VBS script I used to test is a diagram VBScript which only works on (and thus tests) the current diagram.
When the result is TRUE, I think it is save to do the automatic updates.
If the result is FALSE, then prompt and ask the user.

The VBScript contains the following code:

Code: [Select]
dim currentDiagram as EA.Diagram
set currentDiagram = Repository.GetCurrentDiagram()

dim diagramName
dim diagramIsTabOpen
dim diagramCheckModifiedResult

diagramName = CStr( currentDiagram.Name )
diagramIsTabOpen = Repository.IsTabOpen( diagramName )
diagramCheckModifiedResult = "Repository.IsTabOpen(" & diagramName & ") results: " & diagramIsTabOpen & "!!!"

if ( diagramIsTabOpen ) then
Session.Prompt "Result TRUE " & diagramCheckModifiedResult, promptOK
else
Session.Prompt "Result FALSE " & diagramCheckModifiedResult, promptOK
end if

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Additional remark:
There seems to be a different behaviour between the EA Fat and SaaS clients.

For the first test, I used the EA SaaS client Version 16.1.1625 - 64 bit - Ultimate Edition.
For a second test, I used a EA Fat client Version 16.1.1621 - 64 bit - Unified Edition.

In the second test, both reloaded and modified diagrams returned "2" when checking for the name of the diagram.
There was however a difference when checking ( "*" & diagramName ).
The EA Fat client returned a "2" for the modified diagram too.
So in this case, the test should be on ( "*" & diagramName ), which makes the test a bit unreliable.

Again the result of a bug in the IsTabOpen() method?

MichPaule

  • EA User
  • **
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Wow, awesome findings.
I appreciate sharing with us.
For now I followed Geerts advice to always save and then reload the diagram.
Let's see what the users will say about it...
Thanks a lot to all of you!

Michael

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Additional remark:
There seems to be a different behaviour between the EA Fat and SaaS clients.
There's no such thing as a SaaS client. There is only the fat client.

What you consider the SaaS client is probably the fat client installed on a server somewhere, and served as Remote Desktop/Citrix/Terminal software.

The software still all runs on that server machine, so the difference you are observing must be related to something else.

Geert

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Quote
There's no such thing as a SaaS client. There is only the fat client.
You are right Geert, should have named the two versions correctly.

Quote
so the difference you are observing must be related to something else

That's why I also included the versions I used:

Quote
For the first test, I used the EA SaaS client Version 16.1.1625 - 64 bit - Ultimate Edition.
For a second test, I used a EA Fat client Version 16.1.1621 - 64 bit - Unified Edition.

I do not have an indication on what the other configurations are installed on the clients, like probably the .NET version, etc.