Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to create edit part for specialized model object
How to create edit part for specialized model object [message #148912] Tue, 04 September 2007 15:37 Go to next message
Eclipse UserFriend
Originally posted by: mike.aol.com

I have a problem generating a diagram from a model with the correct edit
part. In my model, I have two different classes, X and Y, and a
different edit part for each, EPX and EPY. However, class Y is a
subclass of X. When I compose a diagram using the palette, the correct
edit part, EPY, is created for Y. However, if I generate a diagram from
the model, EPX is created instead of EPY for instances of Y.

Any suggestions?

Thanks,
Mike
Re: How to create edit part for specialized model object [message #148932 is a reply to message #148912] Tue, 04 September 2007 22:09 Go to previous messageGo to next message
Eclipse UserFriend
Mike,

Are you sure that the mapping between node and tool for Y is correct?
In fact, I can't reproduce your situation.

Koji


Mike Gering wrote:

> I have a problem generating a diagram from a model with the correct edit
> part. In my model, I have two different classes, X and Y, and a
> different edit part for each, EPX and EPY. However, class Y is a
> subclass of X. When I compose a diagram using the palette, the correct
> edit part, EPY, is created for Y. However, if I generate a diagram from
> the model, EPX is created instead of EPY for instances of Y.

> Any suggestions?

> Thanks,
> Mike
Re: How to create edit part for specialized model object [message #149037 is a reply to message #148912] Wed, 05 September 2007 08:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jan.herriger.gmx.de

Sounds like an issue with VisualIDRegistry#getNodeVisualID
(xxx.part.XxxVisualIDRegistry).

In getNodeVisualID(...) you'll probably see something like:

....
case XxxModelEditPart.VISUAL_ID:
if (XxxPackage.eINSTANCE.getX().isSuperTypeOf(
domainElement.eClass())) {
return EPX.VISUAL_ID;
}
if (XxxPackage.eINSTANCE.getY().isSuperTypeOf(
domainElement.eClass())) {
return EPY.VISUAL_ID;
}
....

In this case, changing the order would help. (the second statement is
never reached, because X is super type of Y.

Mike Gering schrieb:
> I have a problem generating a diagram from a model with the correct edit
> part. In my model, I have two different classes, X and Y, and a
> different edit part for each, EPX and EPY. However, class Y is a
> subclass of X. When I compose a diagram using the palette, the correct
> edit part, EPY, is created for Y. However, if I generate a diagram from
> the model, EPX is created instead of EPY for instances of Y.
>
> Any suggestions?
>
> Thanks,
> Mike
Re: How to create edit part for specialized model object [message #149098 is a reply to message #148932] Wed, 05 September 2007 10:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mike.aol.com

Koji Hashimoto wrote:
> Are you sure that the mapping between node and tool for Y is correct?
> In fact, I can't reproduce your situation.
>

Yes, the tool mapping works. I can create a node for Y from the tool
palette. The problem is when I create a new diagram from an emf model
using the new diagram file wizard.

I here is more detail about how I've defined my gmf models. The diagram
root object is class P and has a containment relationship to X, xrel.
Since Y is a subclass of X, the xrel relationship also accommodates
instances of Y in my model.

I have top node references in my map for both X and Y. Each top node
reference uses the same containment feature, xrel.

I've been trying to understand what's happening by debugging. What I've
seen so far is that the generated VisualIDRegistry.getNodeVisualID()
method includes this code fragment:
if ((semanticHint == null || XEditPart.VISUAL_ID == nodeVisualID)
&& ProviderPackage.eINSTANCE.getX()
..isSuperTypeOf(domainElementMetaclass)
&& (domainElement == null || isNodeX_1001((X) domainElement))) {
return XEditPart.VISUAL_ID;
}

It evaluates to true and returns the X edit part.

I changed the implementation of the generated code in this class to
check for instances of Y:

private static boolean isNodeX_1001(X element) {
if(element instanceof Y) {
return false;
}
return true;
}

This seems to work and solve the problem. Is it the best way to do it?

Thanks,
Mike
Re: How to create edit part for specialized model object [message #149106 is a reply to message #149037] Wed, 05 September 2007 11:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mike.aol.com

Jan Herriger wrote:
> ...
>
> In this case, changing the order would help. (the second statement is
> never reached, because X is super type of Y.
>

That is also what I discovered. However, changing the order means that I
have to hand edit changes in the future for any modifications I make to
my model. I discovered that I can get the same effect by editing another
generated method as follows:

private static boolean isNodeX_1001(X element) {
if(element instanceof Y) {
return false;
}
return true;
}

This at least provides better insulation against future model changes,
but I'd welcome other opinions.

Thanks,
Mike
Re: How to create edit part for specialized model object [message #149152 is a reply to message #149037] Wed, 05 September 2007 21:14 Go to previous messageGo to next message
Eclipse UserFriend
Jan,

That's why I could not reproduce the problem.
Thanks.

Anyway, we have to be careful if we create a diagram editor in which both
a class and its subclass can be instantiated.

Koji


Jan Herriger wrote:

> Sounds like an issue with VisualIDRegistry#getNodeVisualID
> (xxx.part.XxxVisualIDRegistry).

> In getNodeVisualID(...) you'll probably see something like:

> ....
> case XxxModelEditPart.VISUAL_ID:
> if (XxxPackage.eINSTANCE.getX().isSuperTypeOf(
> domainElement.eClass())) {
> return EPX.VISUAL_ID;
> }
> if (XxxPackage.eINSTANCE.getY().isSuperTypeOf(
> domainElement.eClass())) {
> return EPY.VISUAL_ID;
> }
> ....

> In this case, changing the order would help. (the second statement is
> never reached, because X is super type of Y.

> Mike Gering schrieb:
>> I have a problem generating a diagram from a model with the correct edit
>> part. In my model, I have two different classes, X and Y, and a
>> different edit part for each, EPX and EPY. However, class Y is a
>> subclass of X. When I compose a diagram using the palette, the correct
>> edit part, EPY, is created for Y. However, if I generate a diagram from
>> the model, EPX is created instead of EPY for instances of Y.
>>
>> Any suggestions?
>>
>> Thanks,
>> Mike
Re: How to create edit part for specialized model object [message #149400 is a reply to message #149098] Thu, 06 September 2007 07:09 Go to previous messageGo to next message
Eclipse UserFriend
Hi Mike,

The best way to deal with such situations is to declare a
DomainSpecialization constraint for the NodeMappings in the mapping
model. (The resulting code will be effectively the same, but your intent
to show Y's as EPY, not EPX will be more readily available from the model).

Best regards,
Boris



Mike Gering wrote:
> Koji Hashimoto wrote:
>> Are you sure that the mapping between node and tool for Y is correct?
>> In fact, I can't reproduce your situation.
>>
>
> Yes, the tool mapping works. I can create a node for Y from the tool
> palette. The problem is when I create a new diagram from an emf model
> using the new diagram file wizard.
>
> I here is more detail about how I've defined my gmf models. The diagram
> root object is class P and has a containment relationship to X, xrel.
> Since Y is a subclass of X, the xrel relationship also accommodates
> instances of Y in my model.
>
> I have top node references in my map for both X and Y. Each top node
> reference uses the same containment feature, xrel.
>
> I've been trying to understand what's happening by debugging. What I've
> seen so far is that the generated VisualIDRegistry.getNodeVisualID()
> method includes this code fragment:
> if ((semanticHint == null || XEditPart.VISUAL_ID == nodeVisualID)
> && ProviderPackage.eINSTANCE.getX()
> ..isSuperTypeOf(domainElementMetaclass)
> && (domainElement == null || isNodeX_1001((X) domainElement))) {
> return XEditPart.VISUAL_ID;
> }
>
> It evaluates to true and returns the X edit part.
>
> I changed the implementation of the generated code in this class to
> check for instances of Y:
>
> private static boolean isNodeX_1001(X element) {
> if(element instanceof Y) {
> return false;
> }
> return true;
> }
>
> This seems to work and solve the problem. Is it the best way to do it?
>
> Thanks,
> Mike
Re: How to create edit part for specialized model object [message #149443 is a reply to message #149400] Thu, 06 September 2007 12:09 Go to previous message
Eclipse UserFriend
Originally posted by: mike.aol.com

Boris,

Thanks! I took your suggestion and it works great.

Mike

Boris Blajer wrote:
> The best way to deal with such situations is to declare a
> DomainSpecialization constraint for the NodeMappings in the mapping
> model. (The resulting code will be effectively the same, but your intent
> to show Y's as EPY, not EPX will be more readily available from the model).
Previous Topic:How can I use my AutomaticRouter?
Next Topic:Missing properties in Property View using GMF diagram
Goto Forum:
  


Current Time: Sun Jun 01 13:46:23 EDT 2025

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

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

Back to the top