Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Capture linestyle of a connection and change it (Capture linestyle of a connection and change it )
Capture linestyle of a connection and change it [message #514750] Tue, 16 February 2010 14:34 Go to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Hallo,

I create my nodes and links from db and based on some relationships between objects, set the width of thier connection. How can I capture the linestyle and change it?

Best regards,
Alireza
Re: Capture linestyle of a connection and change it [message #515412 is a reply to message #514750] Thu, 18 February 2010 17:26 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Anybody any idea? When I create a gmf relationship, it does not have any method to set the width of its line. I have seen some samples but they change the line width of all objects of the model.

Best,
Alireza
Re: Capture linestyle of a connection and change it [message #515438 is a reply to message #515412] Thu, 18 February 2010 18:52 Go to previous messageGo to next message
Milan Milanovich is currently offline Milan MilanovichFriend
Messages: 201
Registered: July 2009
Senior Member
Your ConnectionEditPart usually have a PolylineConnectionEx figure. In the constructor of this figure, setLineStyle and setLineWidth methods are used to set line style (Graphics.LINE_DASH, etc.) and width, respectively. From your ConnectionEditPart, you can allways call getPrimaryShape() to get this figure.

--
Regards, Milan
Re: Capture linestyle of a connection and change it [message #515520 is a reply to message #515438] Fri, 19 February 2010 08:24 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Milan,

Thank you for your answer.
I create the gmf diagram inside an Eclipse view. Inside this view how could I access the EditPart of a connection? Should I create an instance? If yes, what should be the input parameter of the construtor (of type View)?


Best regards,
Alireza
Re: Capture linestyle of a connection and change it [message #515545 is a reply to message #515520] Fri, 19 February 2010 10:42 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

isn't there a refresh method at each EditPart (a ConnectionEditPart in
your case) that is called on any model change of the underlaying eObject
by the canonical edit policy? This might be the starting point for your
investigation.

Sven
Re: Capture linestyle of a connection and change it [message #515574 is a reply to message #515545] Fri, 19 February 2010 12:41 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


I do not know how to use this ConnectionEditPart. Could you give me more explanation about its usage? What is a ConnectionEditPart? The object related to the link that I want to set its width?

Best,
Alireza
Re: Capture linestyle of a connection and change it [message #515781 is a reply to message #515574] Sat, 20 February 2010 17:43 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Alireza,

the edit part is the controller between the view (gef IFigure) and the model (EObject). There are three generell kinds of edit parts: DiagramEditPart, ShapeEditPart and ConnectionEditPart. As the name says belongs these different edit parts to different kind of figures. Each edit part has a releation to its model element (getNotationView().getElement()). The refresh method is called indirectly on each model element change. So you have the freedom changing the line style, width, color or what ever you want as result of a model change.

Sven

[Updated on: Sun, 21 February 2010 16:19]

Report message to a moderator

Re: Capture linestyle of a connection and change it [message #515900 is a reply to message #515781] Mon, 22 February 2010 07:52 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

Thank you for your explanation. Since I want to change the line'swidth of a connection I tried to use it as follows:

AppSwtEditPart ep = new AppSwtEditPart(null);
ep.setModel(appSwitch);
ep.getPrimaryShape().setLineWidth(20);
ep.getPrimaryShape().refreshLine();

but it does not work. AppSwt is the name of the connection. How should access the edit part related to a specific connection?

Best,
Alireza

Re: Capture linestyle of a connection and change it [message #516786 is a reply to message #515900] Thu, 25 February 2010 07:54 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Alireza,

why do you need to create a new editpart? The edit part is a piece of
the diagram edit part tree. It is created in the context of your editor
for each of your models AppSwt connection instance.

It should be suffient overwrting the refresh() method of your
AppSwtEditPart a la:

class AppSwtEditPart ... {

....
/**
* ...
* @generated not
*/
void refresh() {
AppSwt model = (AppSwt) getNotationView().getElement();
if( ...) {
getPrimaryShape().setLineWidth(20);
}
super.refresh();
}
....
}

Sven

Am 22.02.2010 08:52, schrieb Alireza:
>
>
> Dear Sven,
> Thank you for your explanation. Since I want to change the line'swidth
> of a connection I tried to use it as follows:
> AppSwtEditPart ep = new AppSwtEditPart(null);
> ep.setModel(appSwitch);
> ep.getPrimaryShape().setLineWidth(20);
> ep.getPrimaryShape().refreshLine();
>
> but it does not work. AppSwt is the name of the connection. How should
> access the edit part related to a specific connection?
> Best,
> Alireza
>
Re: Capture linestyle of a connection and change it [message #516791 is a reply to message #516786] Thu, 25 February 2010 08:20 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

I think I need to explain a little more about my problem: I read data from DB and then generate a gmf diagram elements based of the db data. This is done in a Eclipse view class. So, whenever I create a connection, I want to be able to set its line width. Based on what you said, I need to overwrite refresh method, this works if want same line width for all connection of the same type. So, it does not work for me. The reason that I said I need an instance of EditPart is because of this, i.e., when create a connection, I could be able to call its getPrimaryShape and change the linestyle (linewidth). What do you think?

Best,
Alireza
Re: Capture linestyle of a connection and change it [message #516813 is a reply to message #516791] Thu, 25 February 2010 09:21 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

it is not suffifient creating a new edit part at a dedicated point. The
edit part needs to be integrated into the diagram (represented as the
diagram edit part). The edit part creation is usually in the
responsibility fo the canonical edit part. In your concrete case: the
connection element container has an edit part (lets say SourceElement -
there will be an SourceElemenentCanonicalEditPolicy - dependent of the
graph model named figure descriptor). This edit part will ensure that
the AppSwtEditPart is created and registered at the
SourceElemenentEditParts children. So there is no need to create the
edit part by yourself - independent of the diagrams presentation -
editor or view.

At the other hand: if you are maintaing the edit part tree by yourself,
then you need of course to play the CanonicalEditPolicys role: creating
the edit part, but also adding is to its parent edit parts children list.

Sven
Re: Capture linestyle of a connection and change it [message #516832 is a reply to message #516813] Thu, 25 February 2010 10:07 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

Well, I was too complicate for me ! Could give a more concrete example of how to use this CanonicalEditPolicy to create EditPart and manage. In the list of CanonicalEditPolicy methods there is no method for EditPart creation.

Best,
Alireza
Re: Capture linestyle of a connection and change it [message #516841 is a reply to message #516832] Thu, 25 February 2010 10:37 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Ok. The extract is: you do not create the edit part by your own. This is
in the responsibility of one of the various edit policies. The only one
you need to do is to customize the refresh method of your specific
connection edit part. Only and only: if you don't have due to whatever
reasons no canonical edit policy - you have to create an edit part view
new XYZEditPart().

Just override the refresh method, set a breakpoint and look when its
called within the debugger.

Sven

Am 25.02.2010 11:07, schrieb Alireza:
>
>
> Dear Sven,
>
> Well, I was too complicate for me ! Could give a more concrete example
> of how to use this CanonicalEditPolicy to create EditPart and manage. In
> the list of CanonicalEditPolicy methods there is no method for EditPart
> creation.
> Best,
> Alireza
Re: Capture linestyle of a connection and change it [message #517090 is a reply to message #516841] Fri, 26 February 2010 08:43 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Sven,

There is no refresh method in the entire GMF project.

Ali
Re: Capture linestyle of a connection and change it [message #517152 is a reply to message #517090] Fri, 26 February 2010 11:53 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

what is the AppSwtEditParts class hierarchy? Isn't there a
org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeE ditPart?
This has a refresh method you can override? If not, where did you get
your AppSwtEditPart class from?

Sven
Re: Capture linestyle of a connection and change it [message #518518 is a reply to message #517152] Thu, 04 March 2010 11:17 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

Let me give a more concrete example of what I intend to do:

Suppose we have one entity A with a self relationship (source and target of the relationship are of the same type) and we also want to have label for this relationship. So, we create another entity name RelEntity that contains one string as label and two references both of type A as source and target. Now, given this EMF model and its corresponding GMF diagram, we have a db containing self-relationships between instances of A and strength of each relationship. Suppose there are a1 and a2 with relationship strength of w in db , so I call the factory of gmf to build instances of A namely a1 and a2 and set their attributes and add them to my diagram. Then I create the RelEntity to connect a1 and a2 and add it to the diagram. The final step is to set the width of the link between a1 and a2 based on w (strength of the relationship). How could I do this?

Best,
Alireza
Re: Capture linestyle of a connection and change it [message #518546 is a reply to message #518518] Thu, 04 March 2010 12:47 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

comments below.
>
>
> Dear Sven,
>
> Let me give a more concrete example of what I intend to do:
>
> Suppose we have one entity A with a self relationship (source and target
> of the relationship are of the same type) and we also want to have label
> for this relationship. So, we create another entity name RelEntity that
> contains one string as label and two references both of type A as source
> and target.
Thats the way as gmf deals with connections.
> Now, given this EMF model and its corresponding GMF diagram,
> we have a db containing self-relationships between instances of A and
> strength of each relationship. Suppose there are a1 and a2 with
> relationship strength of w in db , so I call the factory of gmf to build
> instances of A namely a1 and a2 and set their attributes and add them to
> my diagram. Then I create the RelEntity to connect a1 and a2 and add it
> to the diagram.
How is this RelEntity referenced from your entity A? There should be a A
<<contains>> RelEntity relation (e.g. "connections"). Addionally should
the relation RelEntity.source defined as opposite to this contaiment
relation. And how is the mapping for the connection made in the
graphmapping? The link mapping has 4 domain attributes:
Element == RelEntity
Source Feature == RelEntity.source: A
Target Feature == RelEntity.target: A
ContainerFeaturen = A.connections.

> The final step is to set the width of the link between
> a1 and a2 based on w (strength of the relationship). How could I do this?
Back to the former discussion: this task should be part of the
element/view creation process. You would like to set a graphical style
dependent on an model attribute value however this value is calculated.
Here joins the edit part the game. His job is to mediate between model
and view. The edit part knows its view (getFigure()) and the model
(getNotationView().getElement()). So the challange is to locate the
proper place when to reflect the model state to the view and this is
afik the edit parts refresh() method. Remark that your view should be
updated, when someone else (might be a command triggered by any kind of
adapter attached to your model) manipulates your relation between a1 and a2.
> Best,
> Alireza

Sven
Re: Capture linestyle of a connection and change it [message #518548 is a reply to message #518518] Thu, 04 March 2010 12:54 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

comments below.
>
>
> Dear Sven,
>
> Let me give a more concrete example of what I intend to do:
>
> Suppose we have one entity A with a self relationship (source and target
> of the relationship are of the same type) and we also want to have label
> for this relationship. So, we create another entity name RelEntity that
> contains one string as label and two references both of type A as source
> and target.
Thats the way as gmf deals with connections.
> Now, given this EMF model and its corresponding GMF diagram,
> we have a db containing self-relationships between instances of A and
> strength of each relationship. Suppose there are a1 and a2 with
> relationship strength of w in db , so I call the factory of gmf to build
> instances of A namely a1 and a2 and set their attributes and add them to
> my diagram. Then I create the RelEntity to connect a1 and a2 and add it
> to the diagram.
How is this RelEntity referenced from your entity A? There should be a A
<<contains>> RelEntity relation (e.g. "connections"). Addionally should
the relation RelEntity.source defined as opposite to this contaiment
relation. And how is the mapping for the connection made in the
graphmapping? The link mapping has 4 domain attributes:
Element == RelEntity
Source Feature == RelEntity.source: A
Target Feature == RelEntity.target: A
ContainerFeaturen = A.connections.

> The final step is to set the width of the link between
> a1 and a2 based on w (strength of the relationship). How could I do this?
Back to the former discussion: this task should be NOT part of the
element/view creation process. You would like to set a graphical style
dependent on an model attribute value however this value is calculated.
Here joins the edit part the game. His job is to mediate between model
and view. The edit part knows its view (getFigure()) and the model
(getNotationView().getElement()). So the challange is to locate the
proper place when to reflect the model state to the view and this is
afik the edit parts refresh() method. Remark that your view should be
updated, when someone else (might be a command triggered by any kind of
adapter attached to your model) manipulates your relation between a1 and a2.
> Best,
> Alireza

Sven
Re: Capture linestyle of a connection and change it [message #520242 is a reply to message #518548] Thu, 11 March 2010 16:44 Go to previous messageGo to next message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

I tried hard to figure out the solution, but I could not.
Suppose I create an Eclipse view (ViewPart) and inside the class of this view I read data from DB and I build the GMF diagram accordingly. How can I do the line width setting part? How I access edit part? Could you please give some sample code sample?


Regards,
Alireza
Re: Capture linestyle of a connection and change it [message #521012 is a reply to message #520242] Tue, 16 March 2010 08:23 Go to previous messageGo to next message
Sven Krause is currently offline Sven KrauseFriend
Messages: 119
Registered: July 2009
Senior Member
Hi Alireza,

sorry for the delay...

The thread become an endless nature right now. Would send me your skype
or icq contact to my email account, so that we might speed up the
communication?

Sven
Re: Capture linestyle of a connection and change it [message #521339 is a reply to message #521012] Wed, 17 March 2010 10:44 Go to previous message
Alireza Missing name is currently offline Alireza Missing nameFriend
Messages: 105
Registered: July 2009
Senior Member


Dear Sven,

My skype name is alireza.rezaei.mahdiraji.


Regards,
Ali
Previous Topic:Java Heap Space error during code generation
Next Topic:Element copy paste
Goto Forum:
  


Current Time: Fri Sep 25 11:21:16 GMT 2020

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

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

Back to the top