Author Topic: [Java-API] How to move Elements between Packages?  (Read 3158 times)

real-time-systems

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
[Java-API] How to move Elements between Packages?
« on: December 11, 2007, 04:37:46 am »
Hello,

the Project Browser window has the ability to move elements from one package into another package.
It would be nice, if this can be done with the Java API.
Unfortunately i can not find any method to move an element from a collection of one package into the collection of another package.

org.sparx.Package.GetElements() returns a collection (org.sparx.Collection).
The only method to extened a collection is AddNew(String name, String type).
It seems to me that i have to remove the element from the original package and must create a new element within the destination package.

Is there any other way to move elements?
Thanks a lot!

thomaskilian

  • Guest
Re: [Java-API] How to move Elements between Packag
« Reply #1 on: December 11, 2007, 04:56:21 am »
I think it's simply by setting the ParentID to the other package's ID.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: [Java-API] How to move Elements between Packag
« Reply #2 on: December 11, 2007, 08:07:19 am »
However, if you've got an instance of either collection (the previous or new owner's Packages collection) you might be wise to call Refresh(), so the package entry in each collection is updated. Otherwise you run the risk of not finding the package in the new collection or much worse, your code might still think it 'sees' the package in the old collection.
No, you can't have it!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8030
  • Karma: +118/-20
    • View Profile
Re: [Java-API] How to move Elements between Packag
« Reply #3 on: December 11, 2007, 01:04:37 pm »
Quote
I think it's simply by setting the ParentID to the other package's ID.

Actually, ParentID relates to the object ID of another element.  PackageID is what you want to change to move an element to another package.  (You would then Refresh any collections that you have around that should either have the element removed or added.)