Multiple nodes of the same domain element type [message #165235] |
Wed, 12 December 2007 23:46 |
Ted Bashor Messages: 6 Registered: July 2009 |
Junior Member |
|
|
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 08:58 |
Stefan Kuhn Messages: 355 Registered: July 2009 |
Senior Member |
|
|
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
>
>
>
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.03434 seconds