Find Parent Diagram of an IReference object


#1

Hi guys,
consider this situation :

We have two Projects (A and B)

In project A, we have a usecase diagram that has a usecase with name UC1

in Project B, we have a Business Process diagram that has a Task with name T1 that has a Reference (with name IR1) to UC1.

Now i have access to IR1 object (an IReference object) and i want to find name of Project that has a model element that IR1 is referencing to it !!!

Actually the input is IR1 (i retrieve IR1 with: T1.toReferenceArray() ) and what i need is “ProjectB” (name of project that UC1 is inside it )

Some method like IR1.getparent() or IR1.getMasterView(0 or IR1.getMirrorSource() returns null value and can’t help me.

Do you have any idea about this ?


#2

Keep in mind that I’m solely basing myself on the API documentation here.

Anyway, I think you need more than toReferenceArray(). See, that gets you IReference[] but if you then look at the IReference API you’ll notice a few methods: getUrlAsModel() and getUrlAsShape().

That makes me believe that you’re going to need those before you can actually access the referenced model, and once you have the actual IModelElement then you should also be able to check its parent.


#3

Hey,

So if I’m following correctly, you want to know the actual project name of which the referenced diagram belongs to?

So once you have an array of diagrams from your referenced model, you can call the .getProject() against a IDiagramUIModel.

So with that, you could do something like;

IReference[] modelRefs = baseModel.toReferenceArray();
for(int i = 0; i < modelRefs.length; i++) {
   if(modelRefs[i].getType() == 2){
      IProject project = modelRefs[i].getUrlAsDiagram().getProject();
   }
}

I hope this helps.