Book a Demo

Author Topic: Controlling package order  (Read 5520 times)

Jason Goetz

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Controlling package order
« on: December 14, 2010, 01:41:55 pm »
I have been trying to set the order of my packages through the API with no success. Here is what I am doing:
Code: [Select]

newPackage = (EA.Package)parentPackage.Packages.AddNew("BETA", "Nothing");
newPackage.Update();
parentPackage.Packages.Refresh();

newPackage = (EA.Package)parentPackage.Packages.AddNew("GAMMA", "Nothing");
newPackage.Update();
parentPackage.Packages.Refresh();

newPackage = (EA.Package)parentPackage.Packages.AddNew("ALPHA", "Nothing");
newPackage.Update();
parentPackage.Packages.Refresh();


Once the packages are created and show up in the Explorer, they are not ordered in the order that I created them, but instead are in alphabetical order (ALPHA, BETA, GAMMA). In fact, even the Packages array shows ALPHA as the first element right after I create it and call Packages.Refresh.

I thought that using the property TreePos on each package would help, I assigned TreePos 0 to the first element and TreePos 2 to the last element, and this seemed to help as everything was in the correct order in the array, but when I looked in the EA explorer, everything was still in alphabetical order.

Any idea how I can control the order of my added packages?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling package order
« Reply #1 on: December 14, 2010, 07:55:29 pm »
Jason,

There's a setting somewhere in the options to allow/disallow free ordering.
If it is allowed (and EA takes the treepos into account) you should see the green up/down arrays enabled in your project browser.

Geert

Jason Goetz

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Controlling package order
« Reply #2 on: December 15, 2010, 04:35:17 am »
Thank you for the reply, Geert. I have played with that "allow free ordering" option and the sorting arrows are enabled in the project browser and I can move objects around through the UI. But, I want to be able to do this through the API. TreePos seems to help with sorting the Collections arrays correctly, but the results do not display in the TreePos order in the project browser.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling package order
« Reply #3 on: December 15, 2010, 07:48:41 pm »
Jason,

First thing to do is figure out if the treepos value has been saved after you set it. You can check in the database if the t_object.Tpos column contains the value you've set.
If that is the case, try to reload the model. The GUI often isn't aware of changes like that, so it might need to repaint before you see the correct order.

Geert

Jason Goetz

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Controlling package order
« Reply #4 on: December 16, 2010, 06:33:27 am »
Refreshing the model view did the trick. I thought that refreshing my packages would be all I needed to do, but it was repository.RefreshModelView that did it. Thanks for your help, Geert.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Controlling package order
« Reply #5 on: December 16, 2010, 03:32:08 pm »
Jason,

You mad the classical mistake of thinking that EA.Collection.Refresh something else then it actually does.
In fact, in most cases you won't need EA.Collection, I think I've never needed it in any of my addins.
The Refresh operation will only go back to the database and reload the collection into memory. This is only necessary if you add or remove something from the Collection, and you want to iterate the collection later. If you don't refresh the collection it will not reflect the added or removed elements.
So Refresh should maybe be better named ReloadContentsFromDatabase.

Geert