| Home » Eclipse Projects » GEF » How to place links at specific position on an object.
 Goto Forum:| 
| How to place links at specific position on an object. [message #246185] | Thu, 13 November 2008 02:21  |  | 
| Eclipse User  |  |  |  |  | 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.
 |  |  |  |  | 
| Re: How to place links at specific position on an object. [message #246186 is a reply to message #246185] | Thu, 13 November 2008 03: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.
 |  |  |  |  | 
| Re: How to place links at specific position on an object. [message #246195 is a reply to message #246186] | Thu, 13 November 2008 23:40  |  | 
| Eclipse User  |  |  |  |  | David, 
 Thanks for the detailed solution.But I need to calculate the height of the
 object before it is displayed in the UML Editor.Here is how it is done.
 
 User has one object in the editor.He right clicks chooses "show relations"
 from the menu.A dialog box opens and he chooses the secondary object and
 relation in the dialog box.
 
 According to his selection the object and relations are displayed in the
 editor as soon as he clicks on "Finish".Now when the user is choosing the
 object in the dialog box the object is not there in the UML Editor.When he
 clicks on "finish" all the processing(creation of anchors on
 objects,placing the links etc) has to be done.But since the second object
 is not physically present,how can i calculate the height of the object to
 create anchors on it uniformly.
 
 I need to uniformly distribute the links.For eg. if the first object's
 height is 80 and second object's 60,and they have three relations between
 them. The links should be at 20,40,60 for first object and in the same
 ratio on second.
 
 Is it possible?if yes,please giude me on this.
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 00:02:08 EDT 2025 
 Powered by FUDForum . Page generated in 0.03657 seconds |