Book a Demo

Author Topic: Move Operation from one Element to another  (Read 7013 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Move Operation from one Element to another
« on: April 21, 2011, 08:48:50 pm »
I'm writing a tool to move operations from one class to another.
The question: what is the best way to do this.
When using the API I can remove the operation from the source.Methods collection, and then add a new operation to the target.Methods collection, but then I need to copy each and every detail of the operation to the new operation (including parameters, tagged values, etc...).
What I really want to do is just overwrite the Method.ParentID with the ID of the target element.
Sadly this property is readonly :(

The more "dirty" way would be to change the parentID directly in the database. This would avoid the whole copy/paste stuff, and it would keep all references I've put into the model (because the id's would stay the same).

Do any of you see any problems with the "dirty" database approach?

Thanks

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: Move Operation from one Element to another
« Reply #1 on: April 21, 2011, 11:32:46 pm »
In the meantime I tried the dirty database approach:
Code: [Select]
       public override void addOperation(UMLOperation operation)
        {
            //pretty dirty way to actually move the existing operation to this parent.
            ((EAModel)this.model).getWrappedModel().Execute(@"update t_operation
                                             set object_id = " + this.getID().ToString() +
                                             "where OperationID = " + operation.getID());
            ((EAModel)this.model).getWrappedModel().AdviseElementChange(this.getID());
        }
Up until now I don't see any negative side-effects.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Move Operation from one Element to another
« Reply #2 on: April 22, 2011, 12:27:44 am »
Geert,
there is a "rather" easy way to move ops and attrs: Drag from the browser onto the target element in a diagram. This makes identical copies. Then just delete the source.

q.
« Last Edit: April 22, 2011, 12:28:11 am by qwerty »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Move Operation from one Element to another
« Reply #3 on: April 22, 2011, 12:58:33 am »
Quote
Geert,
there is a "rather" easy way to move ops and attrs: Drag from the browser onto the target element in a diagram. This makes identical copies. Then just delete the source.

q.
If you want to move operations, just drag within the browser...  That does a move.  Holding the [Ctrl] key will make a copy.

But if you want to do it programatically your solution seems fine.  (Although I'd insist on naming the method "MoveOperation"  ;))

Paolo
(When I do anything "cute" like this, I always run the model check [Shift+F9] to confirm EA is happy with the changes I made - as I'm sure you do also)
« Last Edit: April 22, 2011, 01:04:31 am by PaoloFCantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Move Operation from one Element to another
« Reply #4 on: April 22, 2011, 03:47:31 am »
Quote
But if you want to do it programatically your solution seems fine.  (Although I'd insist on naming the method "MoveOperation"  ;))
)

Well yeah, maybe, this operation is defined on my EA.Element wrapper, so it kind of makes sense as in that you add an existing operation to this element. (although it also removes the operation from the original Element).

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Move Operation from one Element to another
« Reply #5 on: April 27, 2011, 09:13:42 am »
You may also want to call AdviseElementChange on the original object the method belonged to.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Move Operation from one Element to another
« Reply #6 on: April 27, 2011, 12:41:53 pm »
Thanks Simon,

I indeed added that after I posted the code snippet.

Geert