Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Connections / References issue(How to get connections / references to work, when not using EClasses like shown in the tutorial)
Connections / References issue [message #683966] Tue, 14 June 2011 19:01 Go to next message
Bjoern Ickx is currently offline Bjoern IckxFriend
Messages: 17
Registered: June 2011
Junior Member
Hello together,

I created the Graphiti Editor within a RCP. Adding Objects (in my case States and Processes) works fine.

Now I am having problems to get the connections to work. In the whole Tutorial "EClasses" where used as Objects. In my case I created my own simple EMF Model.

http://popcornclub.de/pub/model.png

States and Processes need to be connected to each other.
But I am not quite sure how to adapt the following methods in that way. I couldn't find a way to access the references I defined in the above mentioned model.

private EReference createEReference(EClass source, EClass target) {
        EReference eReference = EcoreFactory.eINSTANCE.createEReference();
        eReference.setName("new EReference");
        eReference.setEType(target);
        eReference.setLowerBound(0);
        eReference.setUpperBound(1);
        source.getEStructuralFeatures().add(eReference);
        return eReference;
   }


public Connection create(ICreateConnectionContext context) {
        Connection newConnection = null;
 
        // get EClasses which should be connected
        EClass source = getEClass(context.getSourceAnchor());
        EClass target = getEClass(context.getTargetAnchor());
 
        if (source != null && target != null) {
            // create new business object
            EReference eReference = createEReference(source, target);
            // add connection for business object
            AddConnectionContext addContext =
                new AddConnectionContext(context.getSourceAnchor(), context
                    .getTargetAnchor());
            addContext.setNewObject(eReference);
            newConnection =
                (Connection) getFeatureProvider().addIfPossible(addContext);
        }
       
        return newConnection;
    }


To make it simple in the beginning I tried to use just the 'Process' object not the 'State':

private EReference createEReference(Process source, Process target) {
        EReference eReference = EcoreFactory.eINSTANCE.createEReference();
        eReference.setName("new EReference");
        eReference.setEType((EClass) target);
        eReference.setLowerBound(0);
        eReference.setUpperBound(1);       
        ((EClass) source).getEStructuralFeatures().add(eReference);
        return eReference;
   }


But setEType and getEStructuralFeatures don't seem to be general methods, and to cast them throwd an exception.

So I alternatively created another EClass in the Model called Flow which I tried to use instead of the type EReference. This try looks like this:

private Flow createReference(EObject source, EObject target) {
	    	Flow flow = ModelFactory.eINSTANCE.createFlow();	    
	        flow.setTarget(target);
	        flow.setSource(source);	        
	        return flow;
	   }


public Connection create(ICreateConnectionContext context) {
	Connection newConnection = null;	
        EObject source = getElement(context.getSourceAnchor());
        EObject target = getElement(context.getTargetAnchor());
  
        if (source != null && target != null) {
        	Flow flow = createReference(source, target);
              AddConnectionContext addContext =
                new AddConnectionContext(context.getSourceAnchor(), context
                    .getTargetAnchor());
            addContext.setNewObject(flow);
            newConnection =
                (Connection) getFeatureProvider().addIfPossible(addContext);
        }      
        return newConnection;
	}


But this seems to be another wrong way. I think the "addIfPossible(addContext)" method is not happy with an AddConnectionContext where the Flow object is used with setNewObject() instead of an eReference.

When I try to drag the line it simply does not appear.

Can you give me a clue, how to solve this puzzle?

Thanks for your help

Bjoern

[Updated on: Tue, 14 June 2011 19:06]

Report message to a moderator

Re: Connections / References issue [message #684185 is a reply to message #683966] Wed, 15 June 2011 07:43 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1923
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, this appears to me to be more a problem how to do the linking on EMF
side...

Usually with Graphiti connections you visualize any kind of links existing
in your model. So you would need to model that in your EMF model. Basically
there's 2 possibilities: the first one would be to introduce a new reference
(choose new EReference in the EMF editor on your EObject) and set the target
to the desired one; the second one would be using an explicit object for
linking, you would most probably want to add that object to a container
(that might be a specific object in your model or might also be your source
EObject for the connection).

Maybe you should read through the EMF reference documentation (search for
EMF reference, e.g. here
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/org.eclipse.emf.doc/references/overview/EMF.html).
Once you have done that you can use Graphiti's connections to visualize the
links between your EObjects.

HTH,
Michael

"Bjoern" schrieb im Newsbeitrag news:it8ak9$avu$1@news.eclipse.org...

Hello together,

I created the Graphiti Editor within a RCP. Adding Objects (in my case
States and Processes) works fine.

Now I am having problems to get the connections to work. In the whole
Tutorial "EClasses" where used as Objects. In my case I created my own
simple EMF Model.

Model: popcornclub.de/pub/model.png
(don't have enough posts to embed the linked image, sorry)

States and Processes need to be connected to each other.
But I am not quite sure how to adapt the following methods in that way. I
couldn't find a way to access the references I defined in the above
mentioned model.

private EReference createEReference(EClass source, EClass target) {
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("new EReference");
eReference.setEType(target);
eReference.setLowerBound(0);
eReference.setUpperBound(1);
source.getEStructuralFeatures().add(eReference);
return eReference;
}

public Connection create(ICreateConnectionContext context) {
Connection newConnection = null;

// get EClasses which should be connected
EClass source = getEClass(context.getSourceAnchor());
EClass target = getEClass(context.getTargetAnchor());

if (source != null && target != null) {
// create new business object
EReference eReference = createEReference(source, target);
// add connection for business object
AddConnectionContext addContext =
new AddConnectionContext(context.getSourceAnchor(), context
.getTargetAnchor());
addContext.setNewObject(eReference);
newConnection =
(Connection) getFeatureProvider().addIfPossible(addContext);
}

return newConnection;
}


To make it simple in the beginning I tried to use just the 'Process' object
not the 'State':

private EReference createEReference(Process source, Process target) {
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setName("new EReference");
eReference.setEType((EClass) target);
eReference.setLowerBound(0);
eReference.setUpperBound(1);
((EClass) source).getEStructuralFeatures().add(eReference);
return eReference;
}

But setEType and getEStructuralFeatures don't seem to be general methods,
and to cast them throwd an exception.

So I alternatively created another EClass in the Model called Flow which I
tried to use instead of the type EReference. This try looks like this:


private Flow createReference(EObject source, EObject target) {
Flow flow = ModelFactory.eINSTANCE.createFlow();
flow.setTarget(target);
flow.setSource(source);
return flow;
}



public Connection create(ICreateConnectionContext context) {
Connection newConnection = null;
EObject source = getElement(context.getSourceAnchor());
EObject target = getElement(context.getTargetAnchor());

if (source != null && target != null) {
Flow flow = createReference(source, target);
AddConnectionContext addContext =
new AddConnectionContext(context.getSourceAnchor(), context
.getTargetAnchor());
addContext.setNewObject(flow);
newConnection =
(Connection) getFeatureProvider().addIfPossible(addContext);
}
return newConnection;
}


But this seems to be another wrong way. I think the
"addIfPossible(addContext)" method is not happy with an AddConnectionContext
where the Flow object is used with setNewObject() instead of an eReference.

When I try to drag the line it simply does not appear.

Can you give me a clue, how to solve this puzzle?

Thanks for your help

Bjoern
Re: Connections / References issue [message #684323 is a reply to message #684185] Wed, 15 June 2011 12:07 Go to previous messageGo to next message
Bjoern Ickx is currently offline Bjoern IckxFriend
Messages: 17
Registered: June 2011
Junior Member
Hello Michael,

thank you for your answer but I already read all the tutorials, references, help files and ebooks I could find regarding EMF, and it didn't help me a lot, otherwise I wouldn't have posted in this forum.

Do you have an example or a code snippet how to crate a connection with your own model elements, not the already existing eClasses? As you can see in my EMF model, there are references and I also tried it with an explicit object, but I must have made something wrong within the implementation. So a simple example / code snippet would for sure solve my problems.

Does anyone has a simple example? The Book / Library Example sadly don't uses connections. With this kind of example I could solve my problems within 5 minutes I guess.

Thanks in advance

Bjoern

[Updated on: Wed, 15 June 2011 12:08]

Report message to a moderator

Re: Connections / References issue [message #684368 is a reply to message #684323] Wed, 15 June 2011 13:49 Go to previous messageGo to next message
Bjoern Ickx is currently offline Bjoern IckxFriend
Messages: 17
Registered: June 2011
Junior Member
Ok, finally I was able to solve the problem by using an explicit object. In my case "Flow". (see before mentioned Diagram)
I simply forgot to change an If statement of the FeatureProvider from EReference to Flow. Rolling Eyes

Now I am interested in the way of creating connections by using the already modeled References. References are implemented via getters and setters, in my case getNextProcess(), getPreviousProcess().

I have now some understanding issues with Graphitis link() method, as it has only very poor JavaDoc:

void org.eclipse.graphiti.features.impl.AbstractFeature.link(PictogramElement pe, Object businessObject)
Link.
Parameters:
pe the pe
businessObject the business object


What kind of Object does this method expect? Only an explicit object that represents the relation? Or is it also possible to hand over the source or maybe the target object? Because when the modeled reference is implemented as getters and setters there isn't really an explicit object for this reference. The next object is simply an attribute of the recent object and vice versa.

So what should I hand over to the link method in this case?

Thanks in advance for your help

Bjoern

[Updated on: Wed, 15 June 2011 13:53]

Report message to a moderator

Re: Connections / References issue [message #684822 is a reply to message #684368] Thu, 16 June 2011 09:53 Go to previous message
Christian Brand is currently offline Christian BrandFriend
Messages: 36
Registered: July 2009
Location: Walldorf/Germany
Member
You can link any objects to the connection. In some cases there are no objects at all linked to a PE.
Usually Graphiti users link elements they need when diagram editor interaction causes domain model changes.


Christian Brand
SAP AG - Walldorf - Germany
Previous Topic:Selection Listener in Graphiti Diagram
Next Topic:BoxRelativeAnchor vs FixPointAnchor
Goto Forum:
  


Current Time: Thu Nov 26 10:38:15 GMT 2020

Powered by FUDForum. Page generated in 0.01843 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top