Home » Eclipse Projects » GEF » How to place links at specific position on an object.
|
Re: How to place links at specific position on an object. [message #246186 is a reply to message #246185] |
Thu, 13 November 2008 08:42 |
Eclipse User |
|
|
|
Originally posted by: lifesting.gmail.com
Santosh Kumari wrote:
> Hi,
> Probelm Description:
>
> I need to show the relations between objects with a link and respective
> primary and secondary labels and Cardinalities
>
> If there is only one relation between objects then there is no problem,
> But, There can be more than one relation between two objects.I need to
> distribute my links over an object uniformly. For that I have to provide
> the anchors at specific locations.I am using a ChopBoxAnchor but all the
> links originate and culminate in the same point, giving it a spider web
> kind of appearance. I need to find specific anchors on the figure that
> so that I can place my links at specific positions.I have a
> ConnectionEditPart (GRMRelationLinkEditPart) and a figure
> GRMRelationLinkFigure which extends PolyLineConnection.I can access the
> figure in connectionEditPart.Now,I have following functions in
> connectionEditPart.
>
> refreshVisuals() :here we set the routingConstraint
>
> {
> getConnectionFigure().setRoutingConstraint( getLink().getBendPoints() );
>
> }
> two more functions are there.
>
> getSourceConnectionAnchor()
>
> getTargetConnectionAnchor()
>
> Please tell me where i need to make necessary changes,where to calculate
> those points on objects.Do i also need to look into edit policies for
> some code changes.
>
> Another problem is:
>
> How to find the height of an object before it is displayed in the UML
> Editor.The user may select just one objet ,right click select the object
> in the wizard and wants to show the relations. In that case, the second
> object is not present in UML editor physically. So how to calculate its
> height.
>
> I am not able to understand how to do that and how to handle the change
> in location/shape/dimension of the links according to the change in
> location or dimension of objects.
>
> can anyone throw some light on the issue.
>
>
1 There are two way to archive your goal that more than one relation
between two objects visually.
one is use custom anchor instead of ChopAnchor, which will get the same
result(point). Simply add a field to the class that be the model of
GRMRelationLinkEditPart, assume it's name is GRMRelation, code may like
below:
public class GRMRelation extends Element
{
public String touchDesc; // north#1, north#2, south#1, south#2...etc..
public void setTouchDesc(String desc) { ... }
public String getTouchDesc(){....}
}
further, add some properties/relations into the figure who own the
relation, for example:
public class ObjectFigure extends Shape
{
public static final Map<String, AnchorDescriptior> ANCHORS = new
HashMap(8) // 8 anchors on every figure
static{
ANCHORS.put("south#1",new
AnchorDescriptor(AnchorDescriptior.Direction.SOUTH,
AnchorDescriptior.Order.FIRST);
ANCHORS.put("south#2",AnchorDescriptor(AnchorDescription.Direction.SOUTH,
AnchorDescriptior.Order.SEC);
}
......
public ConnectionAnchor getAnchor(Request request)
{
...find the nearest anchor to link point.
String nearest_desc = findNearestAnchor(request);
return new FixAnchor(this,ANCHORS.get(nearest_desc);
}
}
public class AnchorDescriptor{
public static enum Direction{SOUTH,NORTH,EAST,WEST};
public static enum Order{FIRST,SEC}; // every side have two anchor point
.....
public Point getLocation(IFigure figure) //figure must be ObjectFigure
{
.....
}
}
class FixAnchor is simple:
public class FixedAnchor extends AbstractConnectionAnchor {
private IFigure figure;
private AnchorDescriptior desc;
public FixedAnchor(IFigure figure, AnchorDescriptior desc)
{
this.figure = figure;
this.desc = desc;
}
public Point getLocation(Point reference) {
return desc.getLocation(figure);
}
public IFigure getOwner() {
return figure;
}
public Point getReferencePoint() {
Point center = getOwner().getBounds().getCenter();
getOwner().translateToAbsolute(center);
return center;
}
}
the other method is making the relation bendable, M(model)-C(editpart)
all need be changed, details please refer Logic example, which perfectly
meet your requirements.
M: org.eclipse.gef.examples.logicdesigner.model.Wire, **BendPointCommand
V: org.eclipse.gef.examples.logicdesigner.edit.WireEditPart with crucial
method refreshBendpoints,
org.eclipse.gef.examples.logicdesigner.edit.WireEndpointEdit Policy
2 You can't calculate the height of an object when it's not in the GEF
context, because bounds is calculated by Figure with its layout. but why
do calculation? you need persist the object's visual bound before editor
is closed, so directly get the data such as height, width, location etc.
in the next time.
|
|
| |
Goto Forum:
Current Time: Sun Sep 22 06:03:34 GMT 2024
Powered by FUDForum. Page generated in 0.03487 seconds
|