Book a Demo

Author Topic: Slash before port labels at component instances  (Read 7184 times)

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Slash before port labels at component instances
« on: June 03, 2013, 08:38:43 pm »
Hi guys,

I'm trying to instantiate a Component as an Instance into a diagram. As usual the Structural Elements window pops up where I can choose the ports of the component to be displayed at the instance. My ports are stereotyped to give them a new color. In the Structural Elements window the port is still correctly stereotyped. As soon as I finish this window, the port
1) is not stereotyped anymore
2) has a label "/ portname" which is not the name specified in properties (this field is empty for the instantiated port)


top: how it is intantiated
bottom: how it should be

Questions:

1) The slash is to my knowledge sign for a derived property. How can I at least suppress this label and just display the original name instead?
2) Why is the stereotype not inherited from the Component?

Please take into consideration, that I have to do these things automatically at the the instantiation - preferably by profile means, if not possible through addin.

Thanks in advance!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Slash before port labels at component instance
« Reply #2 on: June 03, 2013, 10:15:49 pm »
Ah, I see, it's also just an instance, but how can I technically achieve my aims in EA?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Slash before port labels at component instance
« Reply #3 on: June 03, 2013, 11:24:30 pm »
I guess you need to write an add-in that catches the OnPostNew event and act accordingly.

q.

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Slash before port labels at component instance
« Reply #4 on: June 04, 2013, 08:50:09 am »
This is my code so far:
Code: [Select]
       public bool EA_OnPostNewElement(EA.Repository rep, EA.EventProperties info)
        {
            EA.Element elem = rep.GetElementByID(info.Get(0).Value);
            if (elem.Stereotype == "ComponentInstance")
            {
                EA_UtilityClass.AssociateWithClassifiersCompositeDiagram(rep, elem);
                stereotypePortInstances(rep, elem);
                return true;
            }
            return false;
        }

        private void stereotypePortInstances(EA.Repository rep, EA.Element compInstance)
        {
            EA.Element classifier = rep.GetElementByID(compInstance.ClassifierID);
            EA.Collection embeddedElements = classifier.EmbeddedElements;
            for (short i = 0; i < embeddedElements.Count; i++)
            {
                EA.Element eElement = (EA.Element)embeddedElements.GetAt(i);
                if (eElement.Type.Equals("Port"))
                {
                    String setPortInstanceStereotypes = "UPDATE t_object SET Stereotype='" + eElement.Stereotype + "', Name='"+eElement.Name+"' WHERE Object_Type='Port' AND Classifier_guid='"+eElement.ElementGUID+"'";
                    rep.Execute(setPortInstanceStereotypes);
                }
            }
            compInstance.Update();
            compInstance.Refresh();
        }

Unfortunately, the OnPostNewElement routine ends before the user can choose the Ports from the "Structural Elements" window, so the stereotypes are only assigned at the next instantiation of the component and when the diagram is reloaded.

1) Is there any way to get a callback when the Structural Elements dialog closes?
2) Is there a preferable solution dealing with these delayed events in general, since catching OnNotifyContextItemModified seems not the best way for it?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Slash before port labels at component instance
« Reply #5 on: June 04, 2013, 10:16:13 am »
Some others might have a solution out of the box. I haven't. I can only confirm that fiddling around in these areas usually is a PITA.

q.

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Slash before port labels at component instance
« Reply #6 on: June 04, 2013, 07:04:22 pm »
Do you occasionally know, what happens in the DB, when the Structural Elements dialog is closed? I wasn't able to figure it out!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Slash before port labels at component instance
« Reply #7 on: June 04, 2013, 08:17:07 pm »
I'm not sure what you expect. The only thing that happens in the DB is that it receives a SQL with some INSERT statement. Everything else happens inside EA.

q.

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Slash before port labels at component instance
« Reply #8 on: June 04, 2013, 08:22:47 pm »
Well, I thought about writing an observer which observes the relevant fields in DB and triggering an event when the ports are inserted in the appropriate table.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Slash before port labels at component instance
« Reply #9 on: June 04, 2013, 08:31:11 pm »
Tough! If you are at a level to write triggers, you should observe what goes to t_object when creating elements. I haven't been that deep in the matters since it was not necessary. As said I'd expect an INSERT to happen. But it might be that there will be some ALTER following.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Slash before port labels at component instance
« Reply #10 on: June 07, 2013, 03:58:16 pm »
I don't think an observer on the database is the way to go.

I would rather try an OnContextItem... event.
So you could make sure you store the information you require in the OnPostNewElement, and then use that information in the OnContextItem... event to do whatever you need.

It's not ideal, but not too difficult either.

Geert

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Slash before port labels at component instance
« Reply #11 on: June 07, 2013, 05:00:59 pm »
Unfortunately, sometimes your mind is blocked when you think about solving a prolem like this. Then some approaches like fiddeling with bypassing the given API arise, which lead to direct data manipulation.

Fortunately, after sleeping a night about it I did the only thing which is appropriate in this case: "If some approach is not suitable for the requirements or violates basic principles, rethink your design" (1st year university)

What I came up with is a function which just uses the onPreNewElement as Trigger and builds the complete component including all ports from scratch. Obviously, you are able then to stereotype them and give them a custom name, which makes the slash label!