Author Topic: Add element to collection  (Read 4771 times)

Aleksandar

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Add element to collection
« on: May 07, 2013, 05:54:17 pm »
Hi,

I have few short questions regarding Enterprise architect.

1. My question is regarding the automation interface. When following the instructions provided on this page: http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/collection.htm in order to add a new element to the collection ( and the .eap file) it does not add the element. I can get data from the elements, modify and even delete them, but adding a new element does not work?

> Call AddNew to add a new item.
> Modify the item as required.
> Call Update on the item to save it to the database.
> Call Refresh on the collection to include it in the current set.

java example:

elements is a collection of all the elements in the model...

      org.sparx.Element elementEa = elements.AddNew("Requirement", "non-functional");
      elementEa.Update();          
      elements.Refresh();
        

2. With the api is it possible to change the id or guid of an element since there are no methods specified in org.sparx for that?


3. One last thing... Is it possible to create a custom element in EA, for example a requirement which will not have the standard properties like difficulty, priority etc.. , but will have others? (normal properties, not tagged values)


Thank you very much,
Alek         

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add element to collection
« Reply #1 on: May 07, 2013, 06:27:59 pm »
Alek,

1. You have to call the AddNew to a collection on an appropriate parent. So something like Package.Elements.AddNew(), otherwise EA doesn't know where to add your new element. (check the documentation on refresh, you don't need that too often)

2. Why would you want to change the ID or GUID of an element? In most cases that is a recipe for disaster (unless you know the database inside an out and you are absolutely sure what you are doing). There is however a hidden backdoor to do anything you want: Repository.Execute(SQLString) will allow you to execute an arbitrary SQL command.

3. Yes you can create custom EA Elements, but most of them are EA.Elements too. They look different in on the GUI, but in the background they all have the same properties. Just look in the database at such an element.

Geert

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Add element to collection
« Reply #2 on: May 07, 2013, 06:59:04 pm »
ad 1) it should be elements.AddNew("non-functional","Requirement")  ;)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Add element to collection
« Reply #3 on: May 07, 2013, 08:27:01 pm »
And to be even more precise: the first parameter is the name (or for a Requirement the Short Description) and the second is the UML element type.

q.

Aleksandar

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Add element to collection
« Reply #4 on: May 07, 2013, 09:41:34 pm »
Thanks a lot for the info everyone :)

Now I can add new classes and requirements to the packages....just need to figure out how to add them to the diagram also...  

About the custom EA Elements, I see now that they all must have those basic properties.... but is it possible just to change the way the properties screen (tab) looks like for them..for example.. just to display name and type (and maybe some additional property, if it's possible to display here, and not in the tagged values tab) ?

Paulus

  • EA User
  • **
  • Posts: 152
  • Karma: +0/-0
    • View Profile
Re: Add element to collection
« Reply #5 on: May 07, 2013, 10:15:31 pm »
Short of writing an add-in that handles events like  EA_OnContextItemDoubleClicked to display a custom property dialog you create from scratch => no there isn't.

And if you still need access to the original EA property dialog => there is no API like Element.ShowPropertyDialog() to do that.

It would be a nice feature to have though.
 
« Last Edit: May 07, 2013, 10:19:21 pm by pmaessen »

Ian Mitchell

  • EA User
  • **
  • Posts: 506
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: Add element to collection
« Reply #6 on: May 07, 2013, 11:14:25 pm »
Have a look at exploringEA.com. Might be useful
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Add element to collection
« Reply #7 on: May 08, 2013, 12:12:10 am »
Quote
And if you still need access to the original EA property dialog => there is no API like Element.ShowPropertyDialog() to do that.

There might not be an official one, but there is a way.
I've managed to do so for my EA Navigator add-in. (except for connectors, I couldn't get it working for connectors)
See Model.cs

Code: [Select]
     /// <summary>
      /// opens the properties dialog for this item
      /// </summary>
      /// <param name="item">the item to open the properties dialog for</param>
      public void openProperties(UML.UMLItem item)
      {
            //get the type string
            string typeString = string.Empty;
            int itemID = 0;
            if (item is Package)
            {
                  typeString = "PKG";
                  itemID = ((Package)item).packageID;
            }
            else if (item is ElementWrapper)
            {
                  typeString = "ELM";
                  itemID = ((ElementWrapper)item).id;
            }
            else if (item is Attribute)
            {
                  typeString = "ATT";
                  itemID = ((Attribute)item).id;
            }
            else if (item is Operation)
            {
                  typeString = "OP";
                  itemID = ((Operation)item).id;
            }
            else if (item is Diagram)
            {
                  typeString = "DGM";
                  itemID = ((Diagram)item).DiagramID;
            }
// TODO: figure out how to open the properties dialog for a connector.      
//            else if (item is ConnectorWrapper)
//            {
//                  //typeString = "CON";
//                  typeString = "MSG";
//                  itemID = ((ConnectorWrapper)item).id;
//            }
            //open the actual dialog
            if (this.mainEAWindow != null
                && typeString != string.Empty
                && itemID != 0)
          {
                  string ret = this.wrappedModel.CustomCommand("CFormCommandHelper", "ProcessCommand", "Dlg=" + typeString + ";id=" + itemID.ToString() + ";hwnd=" + this.mainEAWindow.Handle);
          }
      }

Geert