Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Create connection that is not linked to a BO
Create connection that is not linked to a BO [message #912047] Wed, 12 September 2012 21:18 Go to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Hello all and sorry for this newbie question, here is my problem.

I have designed a meta-model in EMF (let's say BPMN like meta-model) and I am developing a Graphiti editor to model instances of this meta-model.

In my metamodel I have EClasses (ex.: A and B) with 1..* relationship. So, "A" holds an EList<B>.

In my Graphiti I could create so far instances of A and B (let's say a1 and b1). Now I want to link a1 and b1 (i.e. adding b1 to the EList<B> held by a1).

The natural way of doing this is by creating a connection between A1 and B1. However, I can't seem to figure out how to do this since a Connection must be linked to a BusinessObject. (Am I right about this?).

In the tutorial, an EReference is created for each Connection. In my case, all I want to do is:

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

        A a1 = getAClass(context.getSourceAnchor());
        B b1 = getBClass(context.getTargetAnchor());
 
        if (a1 != null && b1 != null) {
            // create new business object
            a1.getBList.add(b1);
            // add connection for business object
            AddConnectionContext addContext =
                new AddConnectionContext(context.getSourceAnchor(), context
                    .getTargetAnchor());
         
            newConnection =
                (Connection) getFeatureProvider().addIfPossible(addContext);
        }
       
        return newConnection;
}


Could someone please give me a hint how I could achieve this?

Thanks a lot!!
Re: Create connection that is not linked to a BO [message #912056 is a reply to message #912047] Wed, 12 September 2012 21:43 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
Anis,

I have the same issue. In general, I don't think a graphical object
needs to have a business object, so you can just create your connection
without it. You must however have enough information accessible to do
relevant things to it e.g. delete the corresponding reference if it is
deleted. If the anchors and their parent's business objects are enough
info. then you're ok, if not you can add properties, e.g. the name of
the Ecore EStructural feature to remove from.

Hope this helps.

Hallvard

On 12.09.12 14.18, Anis Boubaker wrote:
> Hello all and sorry for this newbie question, here is my problem.
> I have designed a meta-model in EMF (let's say BPMN like meta-model) and
> I am developing a Graphiti editor to model instances of this meta-model.
> In my metamodel I have EClasses (ex.: A and B) with 1..* relationship.
> So, "A" holds an EList<B>.
>
> In my Graphiti I could create so far instances of A and B (let's say a1
> and b1). Now I want to link a1 and b1 (i.e. adding b1 to the EList<B>
> held by a1).
> The natural way of doing this is by creating a connection between A1 and
> B1. However, I can't seem to figure out how to do this since a
> Connection must be linked to a BusinessObject. (Am I right about this?).
> In the tutorial, an EReference is created for each Connection. In my
> case, all I want to do is:
>
> public Connection create(ICreateConnectionContext context) {
> Connection newConnection = null;
>
> A a1 = getAClass(context.getSourceAnchor());
> B b1 = getBClass(context.getTargetAnchor());
>
> if (a1 != null && b1 != null) {
> // create new business object
> a1.getBList.add(b1);
> // add connection for business object
> AddConnectionContext addContext =
> new AddConnectionContext(context.getSourceAnchor(), context
> .getTargetAnchor());
> newConnection =
> (Connection)
> getFeatureProvider().addIfPossible(addContext);
> }
> return newConnection;
> }
>
>
> Could someone please give me a hint how I could achieve this?
>
> Thanks a lot!!
Re: Create connection that is not linked to a BO [message #912063 is a reply to message #912056] Wed, 12 September 2012 21:55 Go to previous messageGo to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Thanks Hallvard for your help!!

But then how do you manage to select the correct AddFeature class to call from the FeatureProvider?

Presently, I do basing on context.getNewObject(), like it's done in the tutorial. I can try testing if the IAddContext parameter is an instance of AddConnectionContext.

I'm also worried about the default deletion features. And yes the source and target anchors are enough information for me.

Let me try all this and let you know how it worked. Thanks again!

Anis
Re: Create connection that is not linked to a BO [message #912075 is a reply to message #912063] Wed, 12 September 2012 22:20 Go to previous messageGo to next message
Hallvard Traetteberg is currently offline Hallvard TraettebergFriend
Messages: 673
Registered: July 2009
Location: Trondheim, Norway
Senior Member
On 12.09.12 14.55, Anis Boubaker wrote:
> Thanks Hallvard for your help!!
> But then how do you manage to select the correct AddFeature class to
> call from the FeatureProvider?

I created a Link class as follows:

public class Link<S,T> {

public final S source;
public final T target;

public Link(S source, T target) {
this.source = source;
this.target = target;
}
}

and then in the create feature I did

AddConnectionContext addContext = new AddConnectionContext(...);
addContext.setNewObject(new Link<LinkSource, LinkTarget>(source, target));
Connection newConnection = (Connection)
getFeatureProvider().addIfPossible(addContext);

The addFeature checked and used this Link. Since it's generic it can be
used for all kinds of such connections. Note that you don't link to it,
just use it for selecting the add feature.

Hallvard

> Presently, I do basing on context.getNewObject(), like it's done in the
> tutorial. I can try testing if the IAddContext parameter is an instance
> of AddConnectionContext.
> I'm also worried about the default deletion features. And yes the source
> and target anchors are enough information for me.
> Let me try all this and let you know how it worked. Thanks again!
>
> Anis
Re: Create connection that is not linked to a BO [message #912257 is a reply to message #912075] Thu, 13 September 2012 07:58 Go to previous messageGo to next message
Aljoscha Hark is currently offline Aljoscha HarkFriend
Messages: 24
Registered: March 2012
Junior Member
Hi,

I do this by linking the connection to the adequate EReference from the EMF generated Literals interface. For your instance A --> B the would be such one in XPackage.Literals.A__TO_B. This "static" class can be tested against in your getAddFeature(IAddContext) method as well as in a RemoveFeature for the connection.

I think you don't have to create your own Link class.

Aljoscha
Re: Create connection that is not linked to a BO [message #922118 is a reply to message #912257] Mon, 24 September 2012 19:02 Go to previous messageGo to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Thanks guys for your help!

@Hallvard: I've managed to detect the type of connection i'm adding like this (without using an artificial link class)

public IAddFeature getAddFeature(IAddContext context){
	if(context instanceof AddConnectionContext){
			Object sourceObj = getBusinessObjectForPictogramElement(((AddConnectionContext) context).getSourceAnchor().getParent());
			Object targetObj = getBusinessObjectForPictogramElement(((AddConnectionContext) context).getTargetAnchor().getParent());
			if( //A <-> B connection
					(sourceObj instanceof A && targetObj instanceof B) ||
					(targetObj instanceof B && sourceObj instanceof A) ){ 
				return new Connection_AB_AddFeature(this);
			}
	} else {
			.... //Add shapes
	}
}


@Aljoscha: You're making a point. However I would've expected that since I'm linking the connection to the EReference object, the ERef instance would have been deleted once I delete the connection. However that does not seem to work so I didn't go into changing all my code. I agree though that your solution is more elegant.

I think however that this is a problem many Graphiti developer would encounter. It's not always the case where a connection is linked to a meta-model class. I think the artificial class would be a good idea if it was made part of the framework (rather than letting everyone implement his own solution).

interface IConnectionDefaultObject{
	
	void onDelete(IDeleteConext);
	void onAdd(IAddContext);
}


and then, when a connection is created, it's linked to an instance that implements IConnectionDefaultObject. The delete() method would test if the connection is linked to such an object. If that's the case, it calls the onDelete() method that handles the business matters.

What do you think?

Anis
Re: Create connection that is not linked to a BO [message #924268 is a reply to message #922118] Wed, 26 September 2012 17:20 Go to previous message
Aljoscha Hark is currently offline Aljoscha HarkFriend
Messages: 24
Registered: March 2012
Junior Member
Hi there,

I didn't really think about the DeleteFeature there, but instinctively it made sense to me that this case (the attempt to delete a constant 'instance') is catched by default EMF implementations.

I inspected EcoreUtil#delete(EObject, boolean) and it is really the case (nothing else makes sense, I think) it does not 'delete' the static EReference. So you could easily use the EReference as linked BO - this could be also helpful to decide in PropertySheetSections to whether and/or what to show.

In those cases the provided opportunity to link more than one BO to one PE could also be useful (but one has to be patient to update those links on any 'reconnection'!).

I don't see any need for such a 'phantom node' as seen in GMF. When you need a special BO deletion, you should create a custom DeleteFeature, I think. But as said, the static 'instances' (I really don't want to call them instances Wink ) will not be deleted anyhow. The deletion only happens when an EObject is contained in a 'real' resource.

Greets,
Aljoscha
Previous Topic:preDelete and postDelete not called for patterns
Next Topic:Using CDO Dawn with Graphiti
Goto Forum:
  


Current Time: Tue Mar 19 09:18:56 GMT 2024

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

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

Back to the top