Java Reference
In-Depth Information
private final
Map<String, Class<?>> nodeMap =
new
HashMap<String,
Class<?>>();
{
nodeMap.put("Topic", TopicViewFactory.
class
);
}
@Override
protected
Class getDiagramViewClass(IAdaptable semanticAdapter,
String diagramKind) {
return
diagramMap.get(diagramKind);
}
@Override
protected
Class getNodeViewClass(IAdaptable semanticAdapter,
View containerView, String semanticHint) {
Class clazz =
null
;
if
(semanticHint !=
null
&& semanticHint.length() > 0) {
clazz = nodeMap.get(semanticHint);
}
return
clazz;
}
}
Note that as an alternative to using the
semanticHint
obtained from the
elementType
contribution in our plug-in manifest, we could use the
getSemanticEClass(semanticAdapter)
method to resolve the semantic ele-
ment. Of course, we'd then have to modify our
Map
storage to use the
EClass
as the key, as shown here:
private final
Map<EClass, Class<?>> nodeMap =
new
HashMap<EClass,
Class<?>>();
{
nodeMap.put(MindmapPackage.eINSTANCE.getTopic(),
TopicViewFactory.
class
);
}
@Override
protected
Class getNodeViewClass(IAdaptable semanticAdapter,
View containerView, String semanticHint) {
return
nodeMap.get(getSemanticEClass(semanticAdapter));
}
The
TopicViewFactory
extends the provided
AbstractShapeView
Factory
but provides no additional capabilities. The provided
DiagramView
Factory
suffices for our mindmap's diagram view class.
At this point, we have registered
IElementType
s that correspond to our
domain model elements and are referenced by our creation tools in our palette.
When creating a
Topic
on the diagram, the creation tool invokes a compound
Search WWH ::
Custom Search