Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Multiple nodes of the same domain element type
Multiple nodes of the same domain element type [message #165235] Wed, 12 December 2007 18:46 Go to next message
Eclipse UserFriend
Hi,

In a model derived from XSD, I have a couple of elements that are of the
same type: DefaultComponentType. Let's call them AComponent and
BComponent.

I created one FigureDescriptor, Node, and Diagram Label for a common
"DefaultComponent" visualization. Created a palette tool for AComponent
and BComponent. Then added Child References for each to the Node Mapping
for the parent element. And set up a compartment that can hold one or the
other depending on which is dragged into it.

When I generate my gmfgen model, I get a
Gen Child Node DefaultComponentTypeEditPart
Metamodel Type DefaultComponentType
Gen Child Node DefaultComponentType2EditPart
Specialization Type DefaultComponentType

I generate diagram code, fix up the DefaultComponentTypeCreateCommand and
DefaultComponentType2CreateCommand to add the appropriate element via
DocumentRoot.

When I drag-n-drop A Component, it works fine. When I drag-n-drop B
Component I get
Caused by: org.eclipse.jface.util.Assert$AssertionFailedException: null
argument;failed to create a view
at org.eclipse.jface.util.Assert.isNotNull(Assert.java:153)
at
org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand.do ExecuteWithResult(CreateCommand.java:99)

I traced through in the debugger and found that the problem is that

XYZViewProvider.getNodeViewClass()
visualID = CoreVisualIDRegistry.getVisualID(semanticHint);
...
if (domainElement != null
&& visualID != XYZVisualIDRegistry.getNodeVisualID(
containerView, domainElement)) {
return null; // visual id for node EClass should match visual id
from element type
}

is returning null, because in getNodeVisualID(containerView,
domainElement) there's the following generated code

case ParentTypeCOMPONENTEditPart.VISUAL_ID:
...
if (XYZPackage.eINSTANCE.getDefaultComponentType().isSuperTypeO f(
domainElement.eClass())) {
return DefaultComponentTypeEditPart.VISUAL_ID;
}
if (CorePackage.eINSTANCE.getDefaultComponentType().isSuperType Of(
domainElement.eClass())) {
return DefaultComponentType2EditPart.VISUAL_ID;
}
break;

Since the domain element type of both A and B are the same, the above code
always returns the VISUAL_ID from DefaultComponentTypeEditPart (A
Component). So the calling code returns null because the visual id
derived from the semantic hint (correct) isn't matching the one derived
from the domain element (incorrect).

If I simply comment out this check in my ViewProvider, the UI works
perfectly.

Is a specialization type the right way to handle items of the same domain
element type? Is there some configuration I'm missing that will fix the
generated code above?

Thanks! ~Ted
Re: Multiple nodes of the same domain element type [message #165345 is a reply to message #165235] Fri, 14 December 2007 03:58 Go to previous messageGo to next message
Eclipse UserFriend
hi ted,

are you using constraints to distinguish elements of the same Metaclass?

-stefan

Ted Bashor wrote:
> Hi,
>
> In a model derived from XSD, I have a couple of elements that are of the
> same type: DefaultComponentType. Let's call them AComponent and
> BComponent.
>
> I created one FigureDescriptor, Node, and Diagram Label for a common
> "DefaultComponent" visualization. Created a palette tool for AComponent
> and BComponent. Then added Child References for each to the Node
> Mapping for the parent element. And set up a compartment that can hold
> one or the other depending on which is dragged into it.
>
> When I generate my gmfgen model, I get a Gen Child Node
> DefaultComponentTypeEditPart
> Metamodel Type DefaultComponentType
> Gen Child Node DefaultComponentType2EditPart
> Specialization Type DefaultComponentType
>
> I generate diagram code, fix up the DefaultComponentTypeCreateCommand
> and DefaultComponentType2CreateCommand to add the appropriate element
> via DocumentRoot.
>
> When I drag-n-drop A Component, it works fine. When I drag-n-drop B
> Component I get
> Caused by: org.eclipse.jface.util.Assert$AssertionFailedException: null
> argument;failed to create a view
> at org.eclipse.jface.util.Assert.isNotNull(Assert.java:153)
> at
> org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand.do ExecuteWithResult(CreateCommand.java:99)
>
>
> I traced through in the debugger and found that the problem is that
>
> XYZViewProvider.getNodeViewClass()
> visualID = CoreVisualIDRegistry.getVisualID(semanticHint);
> ...
> if (domainElement != null
> && visualID != XYZVisualIDRegistry.getNodeVisualID(
> containerView, domainElement)) {
> return null; // visual id for node EClass should match visual id
> from element type
> }
>
> is returning null, because in getNodeVisualID(containerView,
> domainElement) there's the following generated code
>
> case ParentTypeCOMPONENTEditPart.VISUAL_ID:
> ...
> if (XYZPackage.eINSTANCE.getDefaultComponentType().isSuperTypeO f(
> domainElement.eClass())) {
> return DefaultComponentTypeEditPart.VISUAL_ID;
> }
> if (CorePackage.eINSTANCE.getDefaultComponentType().isSuperType Of(
> domainElement.eClass())) {
> return DefaultComponentType2EditPart.VISUAL_ID;
> }
> break;
>
> Since the domain element type of both A and B are the same, the above
> code always returns the VISUAL_ID from DefaultComponentTypeEditPart (A
> Component). So the calling code returns null because the visual id
> derived from the semantic hint (correct) isn't matching the one derived
> from the domain element (incorrect).
>
> If I simply comment out this check in my ViewProvider, the UI works
> perfectly.
>
> Is a specialization type the right way to handle items of the same
> domain element type? Is there some configuration I'm missing that will
> fix the generated code above?
>
> Thanks! ~Ted
>
>
>
>
Re: Multiple nodes of the same domain element type [message #165514 is a reply to message #165345] Fri, 14 December 2007 15:39 Go to previous message
Eclipse UserFriend
That's exactly what I needed. Thanks for the pointer Stefan!

For other newbies like me...

In gmfmap, create a Constraint on your Node Mapping. I used "java" as the
language and "aComponentConstraint" as the method name that is generated
and called in XYZVisualIDRegistry.

Since I'm working with substitution group elements, my code looks
something like

private static java.lang.Boolean aComponentConstraint(
DefaultComponentType self) {
XYZType container = (XYZType) self.eContainer();
FeatureMap map = ((XYZType) container).getAbstractComponentGroup();
// Since I know there can only be zero or one component in the
container...
DefaultComponentType component = (DefaultComponentType)
map.get(XYZPackage.eINSTANCE.getDocumentRoot_AComponent(), false);
return self.equals(component);
}

Perhaps there's a way to do this in OCL, but I'm too green for that :-)
Previous Topic:2 editors probblem
Next Topic:How to get IPathmapManager reference?
Goto Forum:
  


Current Time: Thu May 29 03:53:14 EDT 2025

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

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

Back to the top