Sparx Systems Forum

Enterprise Architect => General Board => Topic started by: Monsieur on November 28, 2014, 01:12:02 am

Title: Block link / relationship between 2 objects
Post by: Monsieur on November 28, 2014, 01:12:02 am
Hello all!

I have created my own profile, toolbox, diagram (as now encouraged in the new EA). [smiley=beer.gif] [smiley=beer.gif]
My profile is composed of a few elements (my packages, my elements, my connectors) by extending the correspondent metaclass.
Today i can create the links however I want whatever I want, where ever i want, and that’s my problem!!

Does anyone know how to restrain one link to 2 object types (or stereotype?)
One solution seems to be to use OCL (at is now done in the EA11.1) to do it, as it is used by the "Model Validation" (MRxxxxx)

I don’t know if I made myself clear :-[ . but I can give more explication s :D

ps: i also want to restrain the type of object that i can put under a package (for example only requirement under a "requirement" typed package)
 
ps2: Today I work on EA9.3 (booooooooo) and i am testing EA11.1 (corporate) in order to upgrade (maybe?) if the new feature has a real interest.

ps3: I am a newbie at customizing EA. Please be as detailed as you can be!
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on November 28, 2014, 02:07:35 am
OCL wont help you further since EA does not interpret it but only checks the syntax. The only way I see for you is to create an add-in and subscribe to the EA_On... events.

q.
Title: Re: Block link / relationship between 2 objects
Post by: philchudley on November 28, 2014, 02:29:49 am
If you are creating an MDG then you can add Quicklinker "rules" for your diagram(s) element(s)

It's a little tedious and will need some fine tuning to get it perfect, but it can be made to work

Details are in the Help or User Guide

Of course the use of a Quicklinker just populates a menu with what is valid, it cannot enforce a correct link.

For that, as has been posted previously you need a script (which can monitor the event of the connector being created and take appropriate action, or a script / add-in that validates the model after it has been corrected.

Cheers

Phil
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on November 28, 2014, 02:32:04 am
Quote
OCL wont help you further since EA does not interpret it but only checks the syntax. The only way I see for you is to create an add-in and subscribe to the EA_On... events.

q.

It should be a way (maybe an other than OCL).


I'll give you an example of what i want (scenario in EA11.1):

If i place myself in a requirement diagram and I create 2 objects from different types (could be from different toolboxes) and I try to create a link whose not compliant with the 2 objects EA propose me as a pop up a compliant link. if i click on the diagram (as the compliant links doesn't suit me) then a pop up inform me "The requested connection is not UML compliant"
I tried between a requirement and a package with a link from "metatmodel relationship" on a requirement diagram (all default EA).


I wish to have that kind of restriction on my custom diagram/elements/packages/....

This kind of restriction is needfull to keep the user to respect the metamodel, that's why i need it.

Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on November 28, 2014, 02:47:30 am
Quote
If you are creating an MDG then you can add Quicklinker "rules" for your diagram(s) element(s)

It's a little tedious and will need some fine tuning to get it perfect, but it can be made to work

Details are in the Help or User Guide

Of course the use of a Quicklinker just populates a menu with what is valid, it cannot enforce a correct link.

For that, as has been posted previously you need a script (which can monitor the event of the connector being created and take appropriate action, or a script / add-in that validates the model after it has been corrected.

Cheers

Phil

Thanks Phil, I’ll look into the quicklinker rules ASAP hoping that will block incorrect moves of the user (for example wrong use of the link, or wrong direction or ...)
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on November 28, 2014, 10:59:16 am
The quick linker will not really constrain possible links. It just offers the most convenient ones in a context. To actually constraint things you need to write an add-in.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on November 28, 2014, 07:45:48 pm
Quote
The quick linker will not really constrain possible links. It just offers the most convenient ones in a context. To actually constraint things you need to write an add-in.

q.

Is there a way to constrain possible link the way at is in the little scenario of my previous post? [smiley=rolleyes.gif] :question :question

Is it mandatory to use an Add in?
If so, do someone have a few website to recommend in order for me to make my first add in (something easy :-/) ? [smiley=vrolijk_26.gif]
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on November 28, 2014, 10:23:36 pm
Addins are the only way to go in your case. Refer to Geert Bellekens blog post about writing an add-in (and my Scripting book if you want to get a quick start with the API).

q.
Title: Re: Block link / relationship between 2 objects
Post by: Geert Bellekens on November 28, 2014, 10:59:36 pm
Quote
Quote
The quick linker will not really constrain possible links. It just offers the most convenient ones in a context. To actually constraint things you need to write an add-in.

q.

Is there a way to constrain possible link the way at is in the little scenario of my previous post? [smiley=rolleyes.gif] :question :question

Is it mandatory to use an Add in?
If so, do someone have a few website to recommend in order for me to make my first add in (something easy :-/) ? [smiley=vrolijk_26.gif]

This page: Writing EA Addins (http://bellekens.com/writing-ea-add-ins/) lists all you need to know to get started.

Geert
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on November 28, 2014, 11:50:38 pm
Quote
Quote
Quote
The quick linker will not really constrain possible links. It just offers the most convenient ones in a context. To actually constraint things you need to write an add-in.

q.

Is there a way to constrain possible link the way at is in the little scenario of my previous post? [smiley=rolleyes.gif] :question :question

Is it mandatory to use an Add in?
If so, do someone have a few website to recommend in order for me to make my first add in (something easy :-/) ? [smiley=vrolijk_26.gif]

This page: Writing EA Addins (http://bellekens.com/writing-ea-add-ins/) lists all you need to know to get started.

Geert

Ty Geert
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on February 05, 2015, 09:48:53 pm
LITTLE UP (or down?)

I never made the quicklinker work... I must be really bad :-[  .
Here are my columns... i don't know if they are the right ones:
Source Element Type      Source ST filter      Target Element Type      Target ST Filter      Diagram Filter      New Element Type      New Element ST      New Link Type      New Link ST      New Link Direction      New Link Caption      New Link &amp       Element Caption      Create Link      Create Element      Disallow Self connector      Exclusiveto ST Filter + No inherit from metatype      Menu Group      Complexity Level      Target Must Be Parent      Embed element      Preceeds Separator LEAF      Preceeds Separator GROUP

Can some one send me his xls, so i try?
Or maybe give a little help on the process (like a step by step tutorial)?

I know i am asking a lot, but that be very helpfull... i am a bit desperate about this  :'(   :-/



Ps: Querty, i am reading your books, what is the t_connectorconstraint table? Could it help me to restrain the link to 2 objecttype? using sourceelement(or better sourceStereotype) and destelement (DestStereotype)?
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 05, 2015, 11:02:34 pm
Yep, the QL is a PITA. It took me ages to get it work. Start with a single connector and vary the parameters. Takes a lot of time.

The table you're asking for is likely heritage. Even in the Example Model provided by Sparx it contains nothing.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Eve on February 06, 2015, 08:44:46 am
t_connectorcontstraint = Constraints page of connector properties.
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 06, 2015, 09:23:49 am
Quote
t_connectorcontstraint = Constraints page of connector properties.
Hmm. That leads to the question: where is this page? I just searched a looong moment for the settings menu (yes, this is the "where is my menu in the new EA release"-question). But could not find a related entry.

q.
Title: Re: Block link / relationship between 2 objects
Post by: RoyC on February 06, 2015, 09:50:43 am
Connector properties - double-click on a connector and select the Constraints page or tab.
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 06, 2015, 10:03:24 am
Thanks. That made be a bit wiser today  :D Still so many places in EA where I have almost never been.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on February 06, 2015, 09:51:34 pm
Quote
t_connectorcontstraint = Constraints page of connector properties.

Can I use this to only create links that verifies certain condition?

Using something like this?:
sourceElement = "Need"
destElement = "Need"





NB
I had a thought of our 2 favorites EA admins : Simon and Roy <=> Tweedledum et Tweedledee  :-* :-* :-*  ;D
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 06, 2015, 10:16:03 pm
Well, this constraint is implicit. All connectors have source and target. You can add things like "only exists if" or "multiplicity depends on" etc. But as my above comment suggests I never in my life have ever used a connector constraint. I'm quite sure its use is more or less academic.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on February 07, 2015, 12:31:43 am
Quote
Well, this constraint is implicit. All connectors have source and target. You can add things like "only exists if" or "multiplicity depends on" etc. But as my above comment suggests I never in my life have ever used a connector constraint. I'm quite sure its use is more or less academic.

q.

Tried this :
(http://snag.gy/OkOKK.jpg)

Does not seem to do anything...

NB :  Need is my own stereotype defined by extending requirement with MDG.
Tried with "Requirement", does not seem to do much more...  :'(
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 07, 2015, 12:38:58 am
Any constraint is always meant to be read by a human. An OCL constraint can be read by a machine, but EA does only check the syntax of the OCL statement and does not execute it.

What you can do is to write an add-in that checks constraints on a programmatically basis.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Monsieur on February 07, 2015, 01:04:13 am
Quote
Any constraint is always meant to be read by a human. An OCL constraint can be read by a machine, but EA does only check the syntax of the OCL statement and does not execute it.

What you can do is to write an add-in that checks constraints on a programmatically basis.

q.

So your advice is to take your book (and it's interesting even i whished it to go a little deeper) and create a script that for every link check if source / typeoflink / destination match. And if not, delete the link.
Not really dynamic.
Can we log what we delete? (create a .txt somewhere, and buffer>txt)
Title: Re: Block link / relationship between 2 objects
Post by: qwerty on February 07, 2015, 01:56:29 am
Rather you should take a look at Geerts blog about writing an add-in in 10 minutes ;)

You could turn on the audit log. That logs such changes.

I have done something similar in the past. It's not that difficult.

q.
Title: Re: Block link / relationship between 2 objects
Post by: Gary on February 11, 2015, 12:18:27 am
Back to the beginning question about connectors.
I wrote an add-in to do exactly what you want to do. Mine stops modellers from using Realize between requirements.

Use Geerts tutorial (thanks Geert very useful) to create an add-in. The method you want to put your code in is "EA_OnPreNewConnector". The following is the code i wrote:

/*
            EA.EventProperties Info Contains the following EventProperty objects for the connector
            to be created:
            (0)Type: Astring value corresponding to Connector.Type
            (1)Subtype: Astring value corresponding to Connector.Subtype
            (2)Stereotype: Astring value corresponding to Connector.Stereotype
            (3)ClientID: Along value corresponding to Connector.ClientID
            (4)SupplierID: Along value corresponding to Connector.SupplierID
            (5)DiagramID: Along value corresponding to Connector.DiagramID
             */
            bool result = true;
            //create objects to hold the diagram,client and supplier
            EA.IDualDiagram diag = Repository.GetDiagramByID(Info.Get("DiagramID").Value);
            EA.Element client = Repository.GetElementByID(Info.Get("ClientID").Value);
            EA.Element supplier = Repository.GetElementByID(Info.Get("SupplierID").Value);
            
            
                         /*this rule checks relisation is only used between a class and an interface
                         *or between interfaces on a block or class diagram*/
                        if (Info.Get(0).Value == "Realisation" || Info.Get(0).Value == "Realization")
                        {

                            
                            // Check that connection is only between a block/class and an interface or interface to interface
                            if ("Logical" == diag.Type && ("Class" == client.Type || "Interface" == client.Type) && "Interface" == supplier.Type)
                            {
                                                              
                                result = true;
                            }
                            else
                            {
                                MessageBox.Show("Connecor only valid between a block/class and an interface \n or interface to interface", "Invalid Connector Usage",
                                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                result = false;
                            }
                        }

Hope this helps

Gary
Title: Re: Block link / relationship between 2 objects
Post by: Geert Bellekens on February 11, 2015, 12:46:21 am
If you are a bit weary to write your own add-in, or you have too many hurdles to overcome to get that approved, you can achieve the same thing with EA-Matic (http://bellekens.com/ea-matic/) and the built-in scripting feature.

EA-Matic forwards the EA_OnPreNewConnector event to the scripting environment, where you can write your own validation.

Geert

PS. Yes I'm selling a commercial add-in now :D