Skip to main content



      Home
Home » Eclipse Projects » GEF » Connections
Connections [message #181106] Thu, 12 May 2005 09:39 Go to next message
Eclipse UserFriend
Originally posted by: eduardo.valdes.gmail.com

Hello everybody,
I've a problem with GEF and Connections.
I've two model's objects and I want to link them. My actual version shows
a PolylineConnection, but the end of it doesn't reach the target.
Can you explain what steps I have to do to have connections in my editor??

Please help me!!

Thanks a lot.
Re: Connections [message #181540 is a reply to message #181106] Tue, 17 May 2005 05:25 Go to previous message
Eclipse UserFriend
Originally posted by: a.morgan.pilz.ie

Here's some notes I made while working on my first GEF app.
They're probably a bit too basic for what you need but no harm having a list
to read through to make sure you didn't miss anything.

There are a number of things that need to be added to existing classes and
also some new classes.
The changes are as follows:

Model of object to connect
We need to hold a list of source and target connection here and add the
following methods:

protected void addSourceConnection(ConnectionModel connection)
protected void addTargetConnection(ConnectionModel connection)
protected void removeSourceConnection(ConnectionModel
connection)
protected void removeTargetConnection(ConnectionModel
connection)
public List getSourceConnections()
public List getTargetConnections()


Add Connection Model object
Add a Model object for the Connection.
The methods you would typically need are as follows:

public String getSourceTerminal()
public void setSourceTerminal(String sourceTerminal)
public String getTargetTerminal()
public void setTargetTerminal(String targetTerminal)
public void setSource(DiagramElementModel newSource)
public void setTarget(DiagramElementModel newTarget)
public DiagramElementModel getSource()
public DiagramElementModel getTarget()

Add Connection EditPart object
Needs to extend AbstractConnectionEditPart.
The createFigure method would typically return a PolylineConnection

Add to EditPartFactory
Add code here to return the Connection EditPart when the Connection Model is
passed in.

EditPart that you want to connect
Must implement NodeEditPart which requires following methods to be
implemented:

ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection);
ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection);
ConnectionAnchor getSourceConnectionAnchor(Request request);
ConnectionAnchor getTargetConnectionAnchor(Request request);

In simple cases an object will just have a single source and target anchor.
We must add the anchor to the figure. This may be done in the createFigure()
method.
An example of the usage of a basic anchor type is as follows:

ChopboxAnchor sourceAnchor = new ChopboxAnchor(figure);
ChopboxAnchor targetAnchor = new ChopboxAnchor(figure);

If you wish the anchor to be placed in a specific location then you can
extend AbstractConnectionAnchor

You need to add the following methods:
public List getModelSourceConnections()
public List getModelTargetConnections()

which should make a call to the Model to get the connections stored there.

A policy for the NODE_ROLE will need to be installed here as:

installEditPolicy(EditPolicy.NODE_ROLE, new MiscNodeEditPolicyImpl());


We need to listen to the Model and when the connections have been updated
we need to call:
refreshSourceConnections() or
refreshTargetConnections()

Add GraphicalNodeEditPolicy
We need to create a subclass of GraphicalNodeEditPolicy to handle the
creation of the Connections. The following methods are the important ones:

protected Command getConnectionCompleteCommand(CreateConnectionRequest
request)
protected Command
getConnectionCreateCommand(CreateConnectionRequest request)

These methods will invoke a Create Connection Command.

Add Command to create connection
Create a command that will do something similar to the following:

connection = new ConnectionModel();
if (source != null){

connection.setSourceTerminal(sourceTerminal);
connection.setSource(source);
}
if (target != null) {

connection.setTargetTerminal(targetTerminal);
connection.setTarget(target);
}
if (source == null && target == null){
connection.setTarget(null);
connection.setSource(null);
}




Hope this helps



"Eduardo Vald
Previous Topic:Nested layout managers
Next Topic:Enabling CopyTemplateAction with copying of edit parts, etc.
Goto Forum:
  


Current Time: Sun Jun 08 06:35:36 EDT 2025

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

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

Back to the top