Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Problem with EReference
Problem with EReference [message #1385071] Wed, 04 June 2014 08:20 Go to next message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
Hello,
I have a problem when adding an ERefernce to my editor. In fact, when opening the editor, the Ereference is already added to palette,then, when i try to draw a connection from StartEvent to EndEvent, the arrow cannot be visualized in the editor (see image )
Here is the code:
The CreateConnection.java :
package eclipse.emf.editeurgraphique.risque.features;

import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateConnectionContext;
import org.eclipse.graphiti.features.context.impl.AddConnectionContext;
import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature;
import org.eclipse.graphiti.mm.pictograms.Anchor;
import org.eclipse.graphiti.mm.pictograms.Connection;

import eclipse.emf.editeurgraphique.model.editeurgraphique.Activity;
import eclipse.emf.editeurgraphique.model.editeurgraphique.ComplexGateway;
import eclipse.emf.editeurgraphique.model.editeurgraphique.EditeurgraphiqueFactory;
import eclipse.emf.editeurgraphique.model.editeurgraphique.EndEvent;
import eclipse.emf.editeurgraphique.model.editeurgraphique.ExclusiveGateway;
import eclipse.emf.editeurgraphique.model.editeurgraphique.InclusiveGateway;
import eclipse.emf.editeurgraphique.model.editeurgraphique.ParallelGateway;
import eclipse.emf.editeurgraphique.model.editeurgraphique.SequenceFlow;
import eclipse.emf.editeurgraphique.model.editeurgraphique.StartEvent;
import org.eclipse.emf.ecore.ETypedElement;

import org.eclipse.emf.ecore.EStructuralFeature;
public class CreateConnection extends AbstractCreateConnectionFeature {

private Anchor sourceAnchor = null;
private Anchor targetAnchor = null;

public CreateConnection(IFeatureProvider fp) {
 super(fp, "EReference", "Create EReference");
}

@Override
public boolean canStartConnection(ICreateConnectionContext context) {
if ((getStartEvent(context.getSourceAnchor()) != null)
|| (getEndEvent(context.getSourceAnchor()) != null))
//(getActivity(context.getSourceAnchor()) != null)
//(getInclusiveGateway(context.getSourceAnchor()) != null)||
//(getExclusiveGateway(context.getSourceAnchor()) != null)||
//(getParallelGateway(context.getSourceAnchor()) != null)
//|| (getComplexGateway(context.getSourceAnchor()) != null)) 
{
return true;
}

return false;
}

@Override
public boolean canCreate(ICreateConnectionContext context) {
// get anchors
sourceAnchor = context.getSourceAnchor();
targetAnchor = context.getTargetAnchor();

StartEvent sourceStartEvent = getStartEvent(context.getSourceAnchor());
StartEvent targetStartEvent = getStartEvent(context.getTargetAnchor());

EndEvent sourceEndEvent = getEndEvent(context.getSourceAnchor());
EndEvent targetEndEvent = getEndEvent(context.getTargetAnchor());
Activity sourceActivity  = getActivity(context.getSourceAnchor());
Activity  targetActivity = getActivity (context.getTargetAnchor());
InclusiveGateway sourceInclusiveGateway  = getInclusiveGateway (context.getSourceAnchor());
InclusiveGateway  targetInclusiveGateway  = getInclusiveGateway (context.getTargetAnchor());
ExclusiveGateway  sourceExclusiveGateway = getExclusiveGateway(context.getSourceAnchor());
ExclusiveGateway targetExclusiveGateway = getExclusiveGateway(context.getTargetAnchor());
ParallelGateway sourceParallelGateway = getParallelGateway(context.getSourceAnchor());
ParallelGateway targetParallelGateway = getParallelGateway(context.getTargetAnchor());
ComplexGateway sourceComplexGateway = getComplexGateway(context.getSourceAnchor());
ComplexGateway targetComplexGateway = getComplexGateway(context.getTargetAnchor());
if ((sourceStartEvent != null && targetStartEvent != null && sourceStartEvent !=targetStartEvent)
|| (sourceEndEvent != null && targetEndEvent != null && sourceEndEvent!= targetEndEvent)||
(sourceExclusiveGateway != null && targetExclusiveGateway != null && sourceExclusiveGateway!=targetExclusiveGateway)||
(sourceParallelGateway != null && targetParallelGateway != null && sourceParallelGateway !=targetParallelGateway)||
(sourceActivity != null && targetActivity != null && sourceActivity!= targetActivity )
||(sourceComplexGateway != null && targetComplexGateway != null && sourceComplexGateway != targetComplexGateway)||
(sourceInclusiveGateway != null && targetInclusiveGateway != null && sourceInclusiveGateway != targetInclusiveGateway ))
{
return true;
}

return false;
}

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

StartEvent sourceStartEvent = getStartEvent(sourceAnchor);
StartEvent targetStartEvent = getStartEvent(targetAnchor);
EndEvent targetEndEvent = getEndEvent(targetAnchor);
EndEvent sourceEndEvent = getEndEvent(sourceAnchor);
Activity targetActivity = getActivity(targetAnchor);
Activity sourceActivity = getActivity(sourceAnchor);
InclusiveGateway targetInclusiveGateway = getInclusiveGateway(targetAnchor);
InclusiveGateway sourceInclusiveGateway = getInclusiveGateway(sourceAnchor);
ExclusiveGateway targetExclusiveGateway = getExclusiveGateway(targetAnchor);
ExclusiveGateway sourceExclusiveGateway = getExclusiveGateway(sourceAnchor);
ParallelGateway targetParallelGateway = getParallelGateway(targetAnchor);
ParallelGateway sourceParallelGateway = getParallelGateway(sourceAnchor);
ComplexGateway targetComplexGateway = getComplexGateway(targetAnchor);
ComplexGateway sourceComplexGateway= getComplexGateway(sourceAnchor);
if ((targetStartEvent != null && sourceEndEvent!= null)
|| (sourceStartEvent != null && targetEndEvent != null)) {
//SequenceFlow flow = EditeurgraphiqueFactory.eINSTANCE
// .createSequenceFlow();
 EReference eReference = createEReference(sourceEndEvent,targetStartEvent);
AddConnectionContext addContext = new AddConnectionContext(
sourceAnchor, targetAnchor);
addContext.setNewObject(eReference);
newConnection = (Connection) getFeatureProvider().addIfPossible(
addContext);
//System.out.println("New Connection: " + newConnection.toString());
}
else if ((targetInclusiveGateway != null && sourceExclusiveGateway!= null)
|| (sourceInclusiveGateway != null && targetExclusiveGateway != null)) {
 EReference eReference = createEReference(sourceExclusiveGateway,targetInclusiveGateway);
AddConnectionContext addContext = new AddConnectionContext(
sourceAnchor, targetAnchor);
addContext.setNewObject(eReference);
newConnection = (Connection) getFeatureProvider().addIfPossible(
addContext);
//System.out.println("New Connection: " + newConnection.toString());
}
else if   ((targetParallelGateway != null && sourceComplexGateway!= null)
|| (sourceParallelGateway != null && targetComplexGateway != null)) {
 EReference eReference = createEReference(sourceParallelGateway,targetComplexGateway);
AddConnectionContext addContext = new AddConnectionContext(
sourceAnchor, targetAnchor);
addContext.setNewObject(eReference);
newConnection = (Connection) getFeatureProvider().addIfPossible(
addContext);
//System.out.println("New Connection: " + newConnection.toString());
}
return newConnection;
}

private StartEvent getStartEvent(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof StartEvent) {
return (StartEvent) object;
}
}
return null;
}

private EndEvent getEndEvent(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof EndEvent) {
return (EndEvent) object;
}
}
return null;
}
private Activity getActivity(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof Activity) {
return (Activity) object;
}
}
return null;
}
private InclusiveGateway getInclusiveGateway(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof InclusiveGateway) {
return (InclusiveGateway) object;
}
}
return null;
}
private ExclusiveGateway getExclusiveGateway(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof ExclusiveGateway) {
return (ExclusiveGateway) object;
}
}
return null;
}
private ParallelGateway getParallelGateway(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof ParallelGateway) {
return (ParallelGateway) object;
}
}
return null;
}
private ComplexGateway getComplexGateway(Anchor anchor) {
if (anchor != null) {
Object object = getBusinessObjectForPictogramElement(anchor
.getParent());
if (object instanceof ComplexGateway) {
return (ComplexGateway) object;
}
}
return null;
}
private EReference createEReference(EndEvent source, StartEvent 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;
  }
private EReference createEReference(ExclusiveGateway source, InclusiveGateway 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;
  }
private EReference createEReference(  ParallelGateway source, ComplexGateway 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;
  }

}

The AddConnection.java :
import org.eclipse.emf.ecore.EReference;
import org.eclipse.graphiti.datatypes.IDimension;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddConnectionContext;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.pictograms.Connection;
import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator;
import org.eclipse.graphiti.mm.pictograms.FreeFormConnection;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.services.IPeService;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;

import eclipse.emf.editeurgraphique.model.editeurgraphique.SequenceFlow;

public class AddConnection extends AbstractAddFeature {
IPeService peService = Graphiti.getPeService();
     static IGaService gaService = Graphiti.getGaService();
private static final IColorConstant E_REFERENCE_FOREGROUND = new ColorConstant(98, 131, 167);
 
    public  AddConnection (IFeatureProvider fp) {
        super(fp);
    }
    private Polyline createArrow(GraphicsAlgorithmContainer gaContainer) {
        IGaService gaService = Graphiti.getGaService();
        Polyline polyline =
            gaService.createPolyline(gaContainer, new int[] { -15, 10, 0, 0, -15,
                    -10 });
        polyline.setForeground(manageColor(E_REFERENCE_FOREGROUND));
        polyline.setLineWidth(2);
        return polyline;
    }
 
    public PictogramElement add(IAddContext context) {
        IAddConnectionContext addConContext = (IAddConnectionContext) context;
        EReference addedEReference = (EReference) context.getNewObject();
        IPeCreateService peCreateService = Graphiti.getPeCreateService();
        
        // CONNECTION WITH POLYLINE
        Connection connection = peCreateService
            .createFreeFormConnection(getDiagram());
        connection.setStart(addConContext.getSourceAnchor());
        connection.setEnd(addConContext.getTargetAnchor());
     
        Polyline polyline = gaService.createPolyline(connection);
        //polyline.setLineWidth(2);
        polyline.setForeground(manageColor(E_REFERENCE_FOREGROUND));
        peService.createChopboxAnchor(connection);
        //addFixedPointAnchors(connection,polyline);
        // create link and wire it
        link(connection, addedEReference);
     // add dynamic text decorator for the association name 
        ConnectionDecorator textDecorator =
            peCreateService.createConnectionDecorator(connection, true,
            0.5, true);
        Text text = gaService.createDefaultText(getDiagram(),textDecorator);
        text.setForeground(manageColor(IColorConstant.BLACK));
        gaService.setLocation(text, 10, 0);
        // set reference name in the text decorator
        EReference eReference = (EReference) context.getNewObject();
        text.setValue(eReference.getName());
    
        // add static graphical decorator (composition and navigable)
        ConnectionDecorator cd;
        cd = peCreateService
              .createConnectionDecorator(connection, false, 1.0, true);
        createArrow(cd);
        return connection;
    }
     
   
public boolean canAdd(IAddContext context) {
        // return true if given business object is an EReference
        // note, that the context must be an instance of IAddConnectionContext
        if (context instanceof IAddConnectionContext)
           // && context.getNewObject() instanceof EReference)
        {
            return true;
        }
        return false;
    }
}



could anyone explain me what is the matter ?
Thanks in advance.
Re: Problem with EReference [message #1385105 is a reply to message #1385071] Wed, 04 June 2014 11:24 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
First of all, no one is willing to read such an amount of code. Clean it up, make a small example if needed and dont open three threads about it.
Re: Problem with EReference [message #1385145 is a reply to message #1385105] Wed, 04 June 2014 15:07 Go to previous messageGo to next message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
I'm sorry but I put all the code to understand the code and see the error.
In fact, when opening the editor, the Ereference is already added to palette,then, when i try to draw a connection from StartEvent to EndEvent, the arrow cannot be visualized in the editor .
this is the method Connection
@Override
public Connection create(ICreateConnectionContext context) {
Connection newConnection = null;

StartEvent sourceStartEvent = getStartEvent(sourceAnchor);
StartEvent targetStartEvent = getStartEvent(targetAnchor);
EndEvent targetEndEvent = getEndEvent(targetAnchor);
EndEvent sourceEndEvent = getEndEvent(sourceAnchor);

if ((targetStartEvent != null && sourceEndEvent!= null)
|| (sourceStartEvent != null && targetEndEvent != null)) {

 EReference eReference = createEReference(sourceEndEvent,targetStartEvent);
AddConnectionContext addContext = new AddConnectionContext(
sourceAnchor, targetAnchor);
addContext.setNewObject(eReference);
newConnection = (Connection) getFeatureProvider().addIfPossible(
addContext);

}

return newConnection;
}

private EReference createEReference(EndEvent source, StartEvent 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;
  }

Re: Problem with EReference [message #1385156 is a reply to message #1385145] Wed, 04 June 2014 16:07 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
First of all I would check if the connection is created, just ask the start anchor after the creation for its outgoing connections.
I don't know if its necessary, but you don't set an eResource for your connection.

Edit: Maybe a stupid question, but do you have an AddFeature? You could step through your FeatureProvider as well and check if its created.

[Updated on: Wed, 04 June 2014 16:57]

Report message to a moderator

Re: Problem with EReference [message #1385169 is a reply to message #1385156] Wed, 04 June 2014 17:52 Go to previous messageGo to next message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
yes I have a class addCoonection and I add this method in Freature provider
public ICreateConnectionFeature[] getCreateConnectionFeatures() {
		return new ICreateConnectionFeature[] { new CreateConnection(this) };
	}

but the arrow cannot be visualized in the editor.
Re: Problem with EReference [message #1385228 is a reply to message #1385169] Thu, 05 June 2014 05:25 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
No, thats the CreateFeature, not the AddFeature.
Re: Problem with EReference [message #1385233 is a reply to message #1385228] Thu, 05 June 2014 06:03 Go to previous messageGo to next message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
Yes ,I add the AddConnection function in feature provider but the arrow cannot be visualized in the editor .
this is the method in feature Provider:
public IAddFeature getAddFeature(IAddContext context) {
		if (context.getNewObject() instanceof StartEvent) {
			return new AddStartEvent(this);
		} else if (context.getNewObject() instanceof EndEvent) {
			return new AddEndEvent(this);
		} else if (context.getNewObject() instanceof EReference) {
			return new AddConnection(this);
		}
		else if (context.getNewObject() instanceof Activity) {
			return new AddActivity(this);
		}
		else if (context.getNewObject() instanceof InclusiveGateway) {
			return new AddInclusiveGateway(this);
		}
		else if (context.getNewObject() instanceof ExclusiveGateway) {
			return new AddExclusiveGateway(this);
		}
		else if (context.getNewObject() instanceof ParallelGateway) {
			return new AddParallelGateway(this);
		}
		else if (context.getNewObject() instanceof ComplexGateway) {
			return new AddComplexGateway(this);
		}
		
		
		
		return super.getAddFeature(context);
	}

Re: Problem with EReference [message #1385240 is a reply to message #1385233] Thu, 05 June 2014 06:46 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
I think you've never debugged this.
You add an eReference, but you never ask for an eReference, instead you ask for one of your objects.
Re: Problem with EReference [message #1385244 is a reply to message #1385240] Thu, 05 June 2014 07:20 Go to previous messageGo to next message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
So how should I do so that the arrow can be Visualized in the editor.
Re: Problem with EReference [message #1385305 is a reply to message #1385244] Thu, 05 June 2014 13:41 Go to previous message
hafidhi imen is currently offline hafidhi imenFriend
Messages: 8
Registered: April 2014
Junior Member
In the code that I do, I got a connection between Activity and StartEvent and connection arrow is discontinuous how I should implemente createConnection for the connection between the various elements presented in the pallete (StartEvent, EndEvent, InclusiveGateway, ExclusiveGateway, ComplexGteways, Activity).
Previous Topic:Race condition on save
Next Topic:Auto update not fully working ?
Goto Forum:
  


Current Time: Fri Apr 26 20:35:35 GMT 2024

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

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

Back to the top