Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » replacing editparts..
replacing editparts.. [message #183886] Tue, 22 April 2008 10:25 Go to next message
Eclipse User
Originally posted by: nico.lammers.gmail.com

Hi all,

For my solution I'm using two different node mappings with two different
figures. This works well enough (I have to refresh using F5, still) but
I'd like to change the visuals by double clicking on the shape. I know I
need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
code-wise. I could use a pointer or two :)

~ Nico
Re: replacing editparts.. [message #183943 is a reply to message #183886] Wed, 23 April 2008 03:22 Go to previous messageGo to next message
Eclipse User
Originally posted by: nico.lammers.gmail.com

Anyone?

Nico Lammers wrote:
> Hi all,
>
> For my solution I'm using two different node mappings with two different
> figures. This works well enough (I have to refresh using F5, still) but
> I'd like to change the visuals by double clicking on the shape. I know I
> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
> code-wise. I could use a pointer or two :)
>
> ~ Nico
>
>
Re: replacing editparts.. [message #183948 is a reply to message #183943] Wed, 23 April 2008 03:40 Go to previous messageGo to next message
Richard Gronback is currently offline Richard Gronback
Messages: 605
Registered: July 2009
Senior Member
You could take a look at the default generated OpenEditPolicy that is used
for diagram partitioning (or, take a look at the one in the Ecore diagram
example). The important method is below, though you'll want to replace
OpenDiagramCommand with one that suits your needs.

What I don't think I follow is why you'd want to have a double-click change
an EditPart. Do you simply want to change the figure? If so, you should
probably take a look at the UML2 Tools approach to changing figures (e.g.
Displaying a circle or rectangle for an interface). They use a context menu
item. Note that they are able to maintain the position of the figure by
setting the original's in the request when creating the new view.

Best,
Rich

public class OpenDiagramEditPolicy extends OpenEditPolicy {

protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);
if (false == targetEditPart.getModel() instanceof View) {
return null;
}
View view = (View) targetEditPart.getModel();
Style link =
view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLink Style());
if (false == link instanceof HintedDiagramLinkStyle) {
return null;
}
return new ICommandProxy(new
OpenDiagramCommand((HintedDiagramLinkStyle) link));
}

private static class OpenDiagramCommand extends AbstractTransactionalCommand
{
....
}
}


On 4/23/08 9:22 AM, in article fumo4m$qiu$1@build.eclipse.org, "Nico
Lammers" <nico.lammers@gmail.com> wrote:

> Anyone?
>
> Nico Lammers wrote:
>> Hi all,
>>
>> For my solution I'm using two different node mappings with two different
>> figures. This works well enough (I have to refresh using F5, still) but
>> I'd like to change the visuals by double clicking on the shape. I know I
>> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
>> code-wise. I could use a pointer or two :)
>>
>> ~ Nico
>>
>>
Re: replacing editparts.. [message #183963 is a reply to message #183948] Wed, 23 April 2008 04:08 Go to previous messageGo to next message
Eclipse User
Originally posted by: nico.lammers.gmail.com

What I want to do is basically 'expand' and 'collapse' the EditPart. Not
just change the figure, but also change the way features are displayed,
and which features are displayed. So basically I want to keep my
original view, or at least have an exact copy.

Basically, with the different top node reference I get what I want. Only
think is I want to do this programmatically, instead of changing the
property in the sheet and refreshing the diagram manually..

Let's see if I can find OpenDiagramEditPolicy first.. I don't think it's
generated in my particular project though..

~ Nico


Richard Gronback wrote:
> You could take a look at the default generated OpenEditPolicy that is used
> for diagram partitioning (or, take a look at the one in the Ecore diagram
> example). The important method is below, though you'll want to replace
> OpenDiagramCommand with one that suits your needs.
>
> What I don't think I follow is why you'd want to have a double-click change
> an EditPart. Do you simply want to change the figure? If so, you should
> probably take a look at the UML2 Tools approach to changing figures (e.g.
> Displaying a circle or rectangle for an interface). They use a context menu
> item. Note that they are able to maintain the position of the figure by
> setting the original's in the request when creating the new view.
>
> Best,
> Rich
>
> public class OpenDiagramEditPolicy extends OpenEditPolicy {
>
> protected Command getOpenCommand(Request request) {
> EditPart targetEditPart = getTargetEditPart(request);
> if (false == targetEditPart.getModel() instanceof View) {
> return null;
> }
> View view = (View) targetEditPart.getModel();
> Style link =
> view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLink Style());
> if (false == link instanceof HintedDiagramLinkStyle) {
> return null;
> }
> return new ICommandProxy(new
> OpenDiagramCommand((HintedDiagramLinkStyle) link));
> }
>
> private static class OpenDiagramCommand extends AbstractTransactionalCommand
> {
> ...
> }
> }
>
>
> On 4/23/08 9:22 AM, in article fumo4m$qiu$1@build.eclipse.org, "Nico
> Lammers" <nico.lammers@gmail.com> wrote:
>
>> Anyone?
>>
>> Nico Lammers wrote:
>>> Hi all,
>>>
>>> For my solution I'm using two different node mappings with two different
>>> figures. This works well enough (I have to refresh using F5, still) but
>>> I'd like to change the visuals by double clicking on the shape. I know I
>>> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
>>> code-wise. I could use a pointer or two :)
>>>
>>> ~ Nico
>>>
>>>
>
Re: replacing editparts.. [message #183980 is a reply to message #183963] Wed, 23 April 2008 04:20 Go to previous messageGo to next message
Richard Gronback is currently offline Richard Gronback
Messages: 605
Registered: July 2009
Senior Member
Well, it won't be generated if you've not set the Related Diagrams property
on a node mapping.

I suppose a compartment didn't suit your needs for expand/collapse?

- Rich


On 4/23/08 10:08 AM, in article fumqqk$ks0$1@build.eclipse.org, "Nico
Lammers" <nico.lammers@gmail.com> wrote:

> What I want to do is basically 'expand' and 'collapse' the EditPart. Not
> just change the figure, but also change the way features are displayed,
> and which features are displayed. So basically I want to keep my
> original view, or at least have an exact copy.
>
> Basically, with the different top node reference I get what I want. Only
> think is I want to do this programmatically, instead of changing the
> property in the sheet and refreshing the diagram manually..
>
> Let's see if I can find OpenDiagramEditPolicy first.. I don't think it's
> generated in my particular project though..
>
> ~ Nico
>
>
> Richard Gronback wrote:
>> You could take a look at the default generated OpenEditPolicy that is used
>> for diagram partitioning (or, take a look at the one in the Ecore diagram
>> example). The important method is below, though you'll want to replace
>> OpenDiagramCommand with one that suits your needs.
>>
>> What I don't think I follow is why you'd want to have a double-click change
>> an EditPart. Do you simply want to change the figure? If so, you should
>> probably take a look at the UML2 Tools approach to changing figures (e.g.
>> Displaying a circle or rectangle for an interface). They use a context menu
>> item. Note that they are able to maintain the position of the figure by
>> setting the original's in the request when creating the new view.
>>
>> Best,
>> Rich
>>
>> public class OpenDiagramEditPolicy extends OpenEditPolicy {
>>
>> protected Command getOpenCommand(Request request) {
>> EditPart targetEditPart = getTargetEditPart(request);
>> if (false == targetEditPart.getModel() instanceof View) {
>> return null;
>> }
>> View view = (View) targetEditPart.getModel();
>> Style link =
>> view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLink Style());
>> if (false == link instanceof HintedDiagramLinkStyle) {
>> return null;
>> }
>> return new ICommandProxy(new
>> OpenDiagramCommand((HintedDiagramLinkStyle) link));
>> }
>>
>> private static class OpenDiagramCommand extends AbstractTransactionalCommand
>> {
>> ...
>> }
>> }
>>
>>
>> On 4/23/08 9:22 AM, in article fumo4m$qiu$1@build.eclipse.org, "Nico
>> Lammers" <nico.lammers@gmail.com> wrote:
>>
>>> Anyone?
>>>
>>> Nico Lammers wrote:
>>>> Hi all,
>>>>
>>>> For my solution I'm using two different node mappings with two different
>>>> figures. This works well enough (I have to refresh using F5, still) but
>>>> I'd like to change the visuals by double clicking on the shape. I know I
>>>> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
>>>> code-wise. I could use a pointer or two :)
>>>>
>>>> ~ Nico
>>>>
>>>>
>>
Re: replacing editparts.. [message #183992 is a reply to message #183980] Wed, 23 April 2008 05:15 Go to previous messageGo to next message
Eclipse User
Originally posted by: nico.lammers.gmail.com

Okay.. well diagram partitioning wasn't really on my to-do list but I
can experiment a bit ofcourse..

I've considered using a compartment, but then.. the figure should still
resize and/or change.

~ Nico

Richard Gronback wrote:
> Well, it won't be generated if you've not set the Related Diagrams property
> on a node mapping.
>
> I suppose a compartment didn't suit your needs for expand/collapse?
>
> - Rich
>
>
> On 4/23/08 10:08 AM, in article fumqqk$ks0$1@build.eclipse.org, "Nico
> Lammers" <nico.lammers@gmail.com> wrote:
>
>> What I want to do is basically 'expand' and 'collapse' the EditPart. Not
>> just change the figure, but also change the way features are displayed,
>> and which features are displayed. So basically I want to keep my
>> original view, or at least have an exact copy.
>>
>> Basically, with the different top node reference I get what I want. Only
>> think is I want to do this programmatically, instead of changing the
>> property in the sheet and refreshing the diagram manually..
>>
>> Let's see if I can find OpenDiagramEditPolicy first.. I don't think it's
>> generated in my particular project though..
>>
>> ~ Nico
>>
>>
>> Richard Gronback wrote:
>>> You could take a look at the default generated OpenEditPolicy that is used
>>> for diagram partitioning (or, take a look at the one in the Ecore diagram
>>> example). The important method is below, though you'll want to replace
>>> OpenDiagramCommand with one that suits your needs.
>>>
>>> What I don't think I follow is why you'd want to have a double-click change
>>> an EditPart. Do you simply want to change the figure? If so, you should
>>> probably take a look at the UML2 Tools approach to changing figures (e.g.
>>> Displaying a circle or rectangle for an interface). They use a context menu
>>> item. Note that they are able to maintain the position of the figure by
>>> setting the original's in the request when creating the new view.
>>>
>>> Best,
>>> Rich
>>>
>>> public class OpenDiagramEditPolicy extends OpenEditPolicy {
>>>
>>> protected Command getOpenCommand(Request request) {
>>> EditPart targetEditPart = getTargetEditPart(request);
>>> if (false == targetEditPart.getModel() instanceof View) {
>>> return null;
>>> }
>>> View view = (View) targetEditPart.getModel();
>>> Style link =
>>> view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLink Style());
>>> if (false == link instanceof HintedDiagramLinkStyle) {
>>> return null;
>>> }
>>> return new ICommandProxy(new
>>> OpenDiagramCommand((HintedDiagramLinkStyle) link));
>>> }
>>>
>>> private static class OpenDiagramCommand extends AbstractTransactionalCommand
>>> {
>>> ...
>>> }
>>> }
>>>
>>>
>>> On 4/23/08 9:22 AM, in article fumo4m$qiu$1@build.eclipse.org, "Nico
>>> Lammers" <nico.lammers@gmail.com> wrote:
>>>
>>>> Anyone?
>>>>
>>>> Nico Lammers wrote:
>>>>> Hi all,
>>>>>
>>>>> For my solution I'm using two different node mappings with two different
>>>>> figures. This works well enough (I have to refresh using F5, still) but
>>>>> I'd like to change the visuals by double clicking on the shape. I know I
>>>>> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
>>>>> code-wise. I could use a pointer or two :)
>>>>>
>>>>> ~ Nico
>>>>>
>>>>>
>
Re: replacing editparts.. [message #184040 is a reply to message #183886] Wed, 23 April 2008 08:19 Go to previous messageGo to next message
Eclipse User
Originally posted by: news.wartmal.de

Hi Nico,

Nico Lammers schrieb:
> Hi all,
>
> For my solution I'm using two different node mappings with two different
> figures. This works well enough (I have to refresh using F5, still) but
> I'd like to change the visuals by double clicking on the shape. I know I
> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
> code-wise. I could use a pointer or two :)

I had a very similar problem and asked here before two days in the
thread "Refresh when constraint value has changed". The only difference
in my problem was, that I wanted to refresh the figure, when a property
of the domain model changes instead of double click. However, the main
trick to solve it was to call refresh() on the ???CanonicalEditPoliy.

Actually the answer from Boris Blajer in
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg12307.html
helped me to solve it.

I implemented a custom IEditPolicyProvider to extend the extension point
org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders. That policy
provider registered a custom ???CanonicalEditPolicy for the diagram
editPart and the role EditPolicyRoles.CANONICAL_ROLE. That's my custom
edit policy, you can see, that it just calls refresh of the generated
CanonicalEditPolicy, that's all:


public class CustomWorkflowCanonicalEditPolicy extends
WorkflowCanonicalEditPolicy {

private ResourceSetListenerImpl changeListener;

@Override
public void activate() {
super.activate();
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
getHost()).getEditingDomain();
changeListener = new ResourceSetListenerImpl() {
@Override
public void resourceSetChanged(ResourceSetChangeEvent event) {
super.resourceSetChanged(event);
refresh();
}

};
editingDomain.addResourceSetListener(changeListener);
}

@Override
public void deactivate() {
TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
getHost()).getEditingDomain();
editingDomain.removeResourceSetListener(changeListener);
super.deactivate();
}
}




Regards,
tobi
Re: replacing editparts.. [message #184051 is a reply to message #184040] Wed, 23 April 2008 09:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: nico.lammers.gmail.com

This won't solve my problem exactly, but all help is welcome :)
I think I can use at least some of this... thanks!

~ Nico

Tobias Vogele wrote:
> Hi Nico,
>
> Nico Lammers schrieb:
>> Hi all,
>>
>> For my solution I'm using two different node mappings with two
>> different figures. This works well enough (I have to refresh using F5,
>> still) but I'd like to change the visuals by double clicking on the
>> shape. I know I need to use an OpenEditPolicy, but I'm unsure how to
>> accomplish this, code-wise. I could use a pointer or two :)
>
> I had a very similar problem and asked here before two days in the
> thread "Refresh when constraint value has changed". The only difference
> in my problem was, that I wanted to refresh the figure, when a property
> of the domain model changes instead of double click. However, the main
> trick to solve it was to call refresh() on the ???CanonicalEditPoliy.
>
> Actually the answer from Boris Blajer in
> http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg12307.html
> helped me to solve it.
>
> I implemented a custom IEditPolicyProvider to extend the extension point
> org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders. That policy
> provider registered a custom ???CanonicalEditPolicy for the diagram
> editPart and the role EditPolicyRoles.CANONICAL_ROLE. That's my custom
> edit policy, you can see, that it just calls refresh of the generated
> CanonicalEditPolicy, that's all:
>
>
> public class CustomWorkflowCanonicalEditPolicy extends
> WorkflowCanonicalEditPolicy {
>
> private ResourceSetListenerImpl changeListener;
>
> @Override
> public void activate() {
> super.activate();
> TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
> getHost()).getEditingDomain();
> changeListener = new ResourceSetListenerImpl() {
> @Override
> public void resourceSetChanged(ResourceSetChangeEvent event) {
> super.resourceSetChanged(event);
> refresh();
> }
>
> };
> editingDomain.addResourceSetListener(changeListener);
> }
>
> @Override
> public void deactivate() {
> TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)
> getHost()).getEditingDomain();
> editingDomain.removeResourceSetListener(changeListener);
> super.deactivate();
> }
> }
>
>
>
>
> Regards,
> tobi
Re: replacing editparts.. [message #184063 is a reply to message #183886] Wed, 23 April 2008 09:28 Go to previous message
Eclipse User
Originally posted by: nico.lammers.gmail.com

I think I should be able to solve it like this:

- Set the property that the top node reference constraint acts on
- refresh the diagram

These things should be done from an overridden OpenEditPolicy, since
I want to do them on double clicking on the element.

Any light anyone could shed on this would be appreciated..


~ Nico



Nico Lammers wrote:
> Hi all,
>
> For my solution I'm using two different node mappings with two different
> figures. This works well enough (I have to refresh using F5, still) but
> I'd like to change the visuals by double clicking on the shape. I know I
> need to use an OpenEditPolicy, but I'm unsure how to accomplish this,
> code-wise. I could use a pointer or two :)
>
> ~ Nico
>
>
Previous Topic:Change connection color (Constraint?)
Next Topic:Root nodes not contained in Canvas object
Goto Forum:
  


Current Time: Tue Oct 08 08:12:53 EDT 2013

Powered by FUDForum. Page generated in 0.11977 seconds