Derived Columns with multiple return values

Diagramming issues

Moderator: Moderators

Derived Columns with multiple return values

Postby mvinca-tsi » Mon Jan 09, 2017 7:26 pm

I've setup a Generic Table where I have some derived columns. I have a derived column using Javascript that uses some variables passed into it that looks like this:

Code: Select all
var dirOut = null;
             
if (sourcePortTypeSet.contains( portEvaluating )) dirOut = outObject;       
if (targetPortTypeSet.contains( portEvaluating )) dirOut = inObject;

dirOut;


Is there a way I can return an array or a set so that if both if statement are true, I could return both objects to display in the cell of the table?
mvinca-tsi
Forum Beginner
Forum Beginner
 
Posts: 26
Posts Rating:1
Joined: Wed Apr 23, 2014 7:03 am
Full name: Michael Vinca

Re: Derived Columns with multiple return values

Postby paudzi » Tue Jan 17, 2017 2:18 am

Hello,

I don't know the syntax of the Javascript but theoretically it should be like this:

Code: Select all
var sourceContains = sourcePortTypeSet.contains( portEvaluating );
var targetContains = targetPortTypeSet.contains( portEvaluating );
var result = null;

if ( sourceContains && targetContains)
{
   result = [outObject, inObject];
}
else if ( sourceContains )
{
   result = outObject;
}
else if ( targetContains )
{
   result = inObject;
}
result;


With best regards,
No Magic Customer Support.
paudzi
Customer Support
Customer Support
 
Posts: 52
Posts Rating:5
Joined: Thu Oct 20, 2011 5:50 am

Re: Derived Columns with multiple return values

Postby mvinca-tsi » Tue Jan 17, 2017 11:25 am

Yes, tried that and some other things, but it seems if I return an array, the column in the table is just blank, instead of showing the two items as I would hope for. I'm not really sure what the derived column is expecting to display multiples, or if it supports it.
mvinca-tsi
Forum Beginner
Forum Beginner
 
Posts: 26
Posts Rating:1
Joined: Wed Apr 23, 2014 7:03 am
Full name: Michael Vinca

Re: Derived Columns with multiple return values

Postby paudzi » Wed Jan 25, 2017 3:14 am

I have tried to create a custom column with same behaviour as you do and it worked. As I have already told, I am not familiar with Javascript, so I did it on Groovy script and I have returned a List of two elements instead of Array. Please try to use other kind of collection. Working sample:
Code: Select all
import com.nomagic.magicdraw.core.Project
import com.nomagic.magicdraw.uml.Finder
import com.nomagic.uml2.ext.magicdraw.classes.mdkernel.Element

Project project = Project.getProject(arg1)
Element e1 = Finder.byQualifiedName().find(project, "a1")
Element e2 = Finder.byQualifiedName().find(project, "a2")
List<Element> elements = Arrays.asList(e1, e2)
elements


With best regards,
No Magic Customer Support.
paudzi
Customer Support
Customer Support
 
Posts: 52
Posts Rating:5
Joined: Thu Oct 20, 2011 5:50 am

Re: Derived Columns with multiple return values

Postby mvinca-tsi » Wed Jan 25, 2017 7:05 am

I had previously tried Array and Set. This time I tried List, but that didn't work either. (Although I may have not been doing it right.)

I was hesitant to change the scripting language, because MagicDraw deletes all my parameter definitions when you change the Language. (very annoying)

But I bit that bullet and changed to Groovy and it works. This was my resultant script.

Code: Select all
def dirOut = []
             
if (sourcePortTypeSet.contains( portEvaluating )) {
    dirOut += outObject
}       
if (targetPortTypeSet.contains( portEvaluating ))  {
    dirOut += inObject     
}

dirOut
mvinca-tsi
Forum Beginner
Forum Beginner
 
Posts: 26
Posts Rating:1
Joined: Wed Apr 23, 2014 7:03 am
Full name: Michael Vinca


Return to Diagramming

Who is online

Users browsing this forum: No registered users and 1 guest