|
Re: Create connection that is not linked to a BO [message #912056 is a reply to message #912047] |
Wed, 12 September 2012 21:43 |
Hallvard Traetteberg 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 #912075 is a reply to message #912063] |
Wed, 12 September 2012 22:20 |
Hallvard Traetteberg 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
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03731 seconds