Book a Demo

Author Topic: API for Methods option "Show Behavior in Diagram"  (Read 3848 times)

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
API for Methods option "Show Behavior in Diagram"
« on: December 03, 2008, 06:41:33 pm »
Hi @ all!  :)

Does someone of you know if there is any API for showing the Behavior of a Method in a Diagram? In the documentation I found only the possibility to get accessto the Behavior field itself but not the possibility to show it.
If there is none I will request this feature because it cost a lot of time to check this option for every method and maybe uncheck again...  :-/

Thanks for your help!  :)

Daniel

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: API for Methods option "Show Behavior in Diagr
« Reply #1 on: December 04, 2008, 12:42:00 am »
Hi Daniel,

It has been a while since I tried this, so the details are a bit vague.

I think you need to explicitly tell EA to display the behavior, either directly or by enabling a partition on the element.

When EA does this via the UI, I think it stores the setting in one of the PDATA fields of the DiagramObject. For elements, it is possible to read these via the MiscData attributes, but not to set them. There is no such thing for DiagramObjects. To make matters worse, the Style attribute is write-only (i.e. you cannot use it to inspect the current state) and does not let you address the settings you need.

So, where does that leave you?

I think you need to open the database itself. If you are not using the Desktop Edition of EA (and perhaps if you are) you can do this by creating a connection to outside of EA (even in the same program). Remember to open the second connection with shared access if you want EA to be able to use the model at the same time (or if you also have it open through EA in your code). You can use the Repository.ConnectionString property to get a workable string, but remember to remove the EA prefix.

Now find the correct DiagramObject record in the t_diagramobjects table. Read the ObjectStyle field.

[Some notes: In an EAP file this is a Text field with a maximum length of 255. Other repositories might be more forgiving, but if you will (ever) transfer to an EAP file you must respect this limit. Jet sets Unicode Compression to Yes for text fields; this should not usually affect your application but it might be worth noting. This field can be null, so you should be prepared to gracefully handle this possibility.]

The field contents are a list of settings - these are not documented, so don't ask me - that control a variety of display options. The settings are semicolon delimited. Most (but not all) settings are only present when they are not set to the default value (or the 'off' setting). They might show up if they have been set, and later restored to default values. You will need to add the settings you need, then save the record. After that you will need to refresh or reload the diagram, package, or model in EA if you want to see your changes in real time. See the API documentation for how to handle that.

To learn the correct syntax you need to do some experimentation. Create a diagram by hand. On the diagram set up an element with behavior showing, as you would want your application to render it. Now close the model and open it with MS Access (or any other tool that allows you to read the schema). Check out the field contents. It will be pretty obvious which settings you need.

HTH, David
No, you can't have it!

dagraf

  • EA Novice
  • *
  • Posts: 19
  • Karma: +0/-0
    • View Profile
Re: API for Methods option "Show Behavior in Diagr
« Reply #2 on: December 09, 2008, 07:50:13 pm »
Hi David,
thank you very much for your help! :-) The hint with Access was very helpful.
The solution is quite simple for my problem. There is the possibility to show behavior of a Method with set a string like "ShowBeh=1;" in the StyleEx attribute. To disable you have to set "ShowBeh=0;".

Here is my
Code: [Select]
public Behavior(EA.Repository repository, string objectGUID, int show)
{
    EA.Element element = repository.GetElementByGuid(objectGUID);
    EA.Collection methods = element.Methods;

    string searchString_0 = "ShowBeh=0;";
    string searchString_1 = "ShowBeh=1;";
    string insertString = "ShowBeh=" + Convert.ToString(show) + ";";

    for (short i = 0; i < methods.Count; i++)
    {
        EA.Method method = (EA.Method)methods.GetAt(i);
        string styleEx = method.StyleEx;

        if (styleEx.Contains(searchString_0))
        {
            method.StyleEx = styleEx.Replace(searchString_0, insertString);
        }
        else if(styleEx.Contains(searchString_1))
        {
            method.StyleEx = styleEx.Replace(searchString_1, insertString);
        }
        else
        {
            method.StyleEx = styleEx.Insert(0, insertString);
        }
        /* Update modified method */
        method.Update();
    }
    /* Update ... */
    element.Update();
    /* ... and refresh modified elements */
    element.Refresh();
}


Because the entry in the help about this StyleEx attribute of a Method is wrong I sent out an bug report.

Daniel  ;)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: API for Methods option "Show Behavior in Diagr
« Reply #3 on: December 09, 2008, 11:41:01 pm »
Hi again Daniel,

First, thanks for sending in the report. Roy et al continue to do legion duty on updating the documentation, but they cannot resolve issues they don't know about. Given that the documentation was well over 1200 pages when Roy came into the picture, the onus falls on us (the user community) to report these things.

Also, thanks for keeping the rest of us in the loop. I have seen a few cases where these 'magic' fields could be tweaked, but by no means have I seen them all.

FWIW...

Once upon a time - before EA 7.x was even dreamed of - there was an attempt to split off the EA API documentation and create a 'real' SDK. This thing went to beta status, and appeared to be primarily or entirely documentation based. It seemed that we'd (finally) see most (or at least more) of the 'magic' fields and constants documented. As the SDK used the (then) current API documentation as its core, it remained familiar to EA developers.

Sadly the SDK did not survive as an entity in itself. The good news is that Sparx preserved the effort (and resulting improvements) by reintegrating it into the core documentation set, replacing the API section. You see this reflected today in the section title.

Perhaps a suggestion or two - actually, many suggestions or two [sorry, I couldn't resist] many(s) - would encourage Sparx to revisit the SDK (in whatever form) and finish the job of documenting the details. This is a large undertaking, both initially and over time, as many of the details are subject to change. Still, given that there has not been a substantive change to the EA schema since version 4.0, perhaps the maintenance overhead can be contained.

Remember, this can only happen if we users express enough interest.

David
No, you can't have it!