Java Reference
In-Depth Information
return (Topic) source;
}
protected Topic getTarget() {
return (Topic) target;
}
}
From canExecute() , we see that if the request source and target do not
conform to the appropriate type ( Topic , in this case), false is returned. A
false is also returned if the target Topic is the same as the source Topic
because it doesn't make sense for a Topic to be a subtopic of itself. Other vali-
dation could take place here, such as ensuring that the target is not already found
in the source's subtopics reference.
The command extends the provided EditElementCommand , and we see
how the target is added to the subtopics reference in doExecuteWithResult() .
Now that we understand how the underlying semantic command is provided and
validated against the model, it's time to look at the View and EditPart aspects
of our Subtopic link.
Our MindmapViewProvider must be augmented to deal with edge views.
We can add another Map for diagram edges and initialize it with the provided
ConnectionViewFactory class, keyed to our Subtopic semantic hint, as
shown here:
public class MindmapViewProvider extends AbstractViewProvider {
private final Map<String, Class<?>> edgeMap = new HashMap<String,
Class<?>>();
{
edgeMap.put("Subtopic", ConnectionViewFactory. class );
}
// . . .
@Override
protected Class getEdgeViewClass(IAdaptable semanticAdapter,
View containerView, String semanticHint) {
Class clazz = null ;
if (semanticHint != null && semanticHint.length() > 0) {
clazz = edgeMap.get(semanticHint);
}
return clazz;
}
}
Search WWH ::




Custom Search