Java Reference
In-Depth Information
For the implementation of the TopicSemanticEditPolicy class, we
need only override the getSemanticCommand() method and check for an
incoming CreateRelationshipRequest , returning a properly configured
SubtopicCreateCommand wrapped in an ICommandProxy . We compare the ele-
ment type of the request against our Subtopic element type, along with the val-
ues for source and target to return the proper command. Looking at our
SubtopicCreateCommand , we find the logic that determines whether the
returned command is executable.
public class SubtopicCreateCommand extends EditElementCommand {
private final EObject source;
private final EObject target;
public SubtopicCreateCommand(CreateRelationshipRequest request,
EObject source, EObject target) {
super (request.getLabel(), null , request);
this .source = source;
this .target = target;
}
public boolean canExecute() {
if (source == null && target == null ) {
return false;
}
if (source != null && !(source instanceof Topic)) {
return false;
}
if (target != null && !(target instanceof Topic)) {
return false;
}
if (target == source) {
return false;
}
return true;
}
protected CommandResult doExecuteWithResult(
IProgressMonitor monitor,
IAdaptable info) throws ExecutionException {
if (!canExecute()) {
throw new ExecutionException(
"Invalid arguments in create link command");
}
if (getSource() != null && getTarget() != null ) {
getSource().getSubtopics().add(getTarget());
}
return CommandResult.newOKCommandResult();
}
protected Topic getSource() {
Search WWH ::




Custom Search