Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Drawing a connection is not possible(cursor always indicates it is not possible starting a connection)
Drawing a connection is not possible [message #1707760] Wed, 09 September 2015 08:37 Go to next message
Marianne Stecklina is currently offline Marianne StecklinaFriend
Messages: 5
Registered: September 2015
Junior Member
I created a Graphiti editor based on an Ecore model, which contains a root EClass Diagram, an abstract EClass Element (and several derived classes) and an EClass Wire. In the editor two elements should be connected by a wire.

It is possible to drag elements on the editor screen. I can't draw a connection (wire) between them as the cursor always indicates it is not allowed to start a connection. Methods from WireCreateFeature and WireAddFeature (e.g. canStartConnection) are not even called.

Could anyone point out to me which method outside my one classes is responsible for this? Or is it caused by the way I modeled the classes and references in my ecore model?
Re: Drawing a connection is not possible [message #1707896 is a reply to message #1707760] Thu, 10 September 2015 08:57 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Marianne,

this sounds as if your feature classes are not returned by your feature provider. Please check if your implementation of getCreateConnectionFeatures() returns your create connection feature and getAddFeature() returns the corresponding add feature.

This is also explained in the tutorial: http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.graphiti.doc%2Fresources%2Fdocu%2Fgfw%2Fadd-connection-feature.htm&cp=27_1_3_8

HTH,
Michael
Re: Drawing a connection is not possible [message #1707913 is a reply to message #1707896] Thu, 10 September 2015 13:33 Go to previous messageGo to next message
Marianne Stecklina is currently offline Marianne StecklinaFriend
Messages: 5
Registered: September 2015
Junior Member
Michael,
thanks for the quick reply. For me it looks like I implemented everything as mentioned in the tutorial.
I checked, that getCreateConnectionFeatures() returns my WireCreatefeature. getAddFeature() works fine for the elements (e.g. busbar), but is not called when selecting Wire in the editor instead of an Element.

Just to be sure, here is my FeatureProvider code:

public class SLDFeatureProvider extends DefaultFeatureProvider {
	
	private IAddFeature wireAddFeature    = new WireAddFeature(this);
	private IAddFeature busbarAddFeature  = new BusbarAddFeature(this);
	
	public SLDFeatureProvider(IDiagramTypeProvider dtp) {
		super(dtp);
	}

	@Override
	public ICreateFeature[] getCreateFeatures() {
		return new ICreateFeature[] { new BusbarCreateFeature(this) };
	}

	@Override
	public ICreateConnectionFeature[] getCreateConnectionFeatures() {
	    return new ICreateConnectionFeature[] { new WireCreateFeature(this) };
	}
	
	@Override
	public IAddFeature getAddFeature(IAddContext context) {
		if (context.getNewObject() instanceof Wire) {
			return wireAddFeature;
		}
		else if (context.getNewObject() instanceof Busbar) {
			return busbarAddFeature;
		}
		return super.getAddFeature(context);
	}
}
Re: Drawing a connection is not possible [message #1707923 is a reply to message #1707913] Thu, 10 September 2015 14:30 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Marianne,

from a first glance this looks ok. The next thing that comes to my mind would be to check if your create connection feature triggers the add feature, something like

// add connection for business object
AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
addContext.setNewObject(eReference);
newConnection = (Connection) getFeatureProvider().addIfPossible(addContext);

in your create method. Especially the call to setNewObject is required as that is checked by the else if in your getAddFeature method.

Michael

Re: Drawing a connection is not possible [message #1707929 is a reply to message #1707923] Thu, 10 September 2015 15:07 Go to previous messageGo to next message
Marianne Stecklina is currently offline Marianne StecklinaFriend
Messages: 5
Registered: September 2015
Junior Member
Yes, I implemented it like this. Anyway the create method (or any other method from WireCreateFeature except the constructor) is never called. That's what gets me so confused.
Re: Drawing a connection is not possible [message #1707979 is a reply to message #1707929] Fri, 11 September 2015 07:45 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Have you set a breakpoint in the canCreate and canStartConnection methods of the create connection feature and checked if they return true? Can you share your coding of the create connection feature?

Michael
Re: Drawing a connection is not possible [message #1709455 is a reply to message #1707979] Mon, 28 September 2015 14:02 Go to previous messageGo to next message
Marianne Stecklina is currently offline Marianne StecklinaFriend
Messages: 5
Registered: September 2015
Junior Member
Back from holydays... I have set breakpoints in both methods but they are never reached. That's why I think it is not a matter of the implementation at all, but I can share it anyway:

public class WireCreateFeature extends AbstractCreateConnectionFeature {

    public WireCreateFeature(IFeatureProvider fp) {
        super(fp, "Wire", "Create a Wire");
    }
    
    private Element getElement(Anchor anchor) {
        if (anchor != null) {
            Object object = getBusinessObjectForPictogramElement(anchor.getParent());
            if (object instanceof Element) {
                return (Element) object;
            }
        }
        return null;
    }
 
    @Override
    public boolean canStartConnection(ICreateConnectionContext context) {
        return getElement(context.getSourceAnchor()) != null;
    }

    @Override
    public boolean canCreate(ICreateConnectionContext context) {
    	PictogramElement sourcePictogramElement = context.getSourcePictogramElement();
		PictogramElement targetPictogramElement = context.getTargetPictogramElement();

		if (sourcePictogramElement == null || targetPictogramElement == null) {
			return false;
		}

		Object sourceDomainObject = getBusinessObjectForPictogramElement(sourcePictogramElement);
		Object targetDomainObject = getBusinessObjectForPictogramElement(targetPictogramElement);

		return sourceDomainObject instanceof Element
				&& targetDomainObject instanceof Element;
    }
 
    @Override
    public Connection create(ICreateConnectionContext context) {
        Element source = getElement(context.getSourceAnchor());
        Element target = getElement(context.getTargetAnchor());
        if (source == null || target == null) {
            throw new IllegalStateException("Cannot retrieve the source or target.");
        }
 
        Wire wire = SLDFactory.eINSTANCE.createWire();
        wire.setStartPoint(source);
        wire.setEndPoint(target);
        
        AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(),
                context.getTargetAnchor());
        addContext.setNewObject(wire);
        return (Connection) getFeatureProvider().addIfPossible(addContext);
    }
}
Re: Drawing a connection is not possible [message #1709512 is a reply to message #1709455] Tue, 29 September 2015 06:30 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Marianne,

hm, I'm stuck on this. Can you share the complete project so I can debug?

Michael
Previous Topic:Saving only the domain model
Next Topic:Splitting the domain model and diagram file
Goto Forum:
  


Current Time: Tue Mar 19 04:37:50 GMT 2024

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

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

Back to the top