|
Re: Restricting the allowed ends when creating a relationship element type? [message #1745913 is a reply to message #1745887] |
Wed, 19 October 2016 09:53 |
|
yes you can
Associate an edithelper and overload the method protected ICommand getCreateRelationshipCommand(CreateRelationshipRequest request) {
you can write something like that
EObject source = request.getSource();
EObject target = request.getTarget();
boolean noSourceOrTarget = (source == null || target == null);
boolean noSourceAndTarget = (source == null && target == null);
if (!noSourceAndTarget && !canCreate(source, target)) {
// Abort creation.
return UnexecutableCommand.INSTANCE;
}
Here I Test null but I can test the type of my elements source and target and return UnexecutableCommand.INSTANCE; if I do not want that.
|
|
|
Re: Restricting the allowed ends when creating a relationship element type? [message #1745914 is a reply to message #1745887] |
Wed, 19 October 2016 09:53 |
|
yes you can
Associate an edithelper and overload the method protected ICommand getCreateRelationshipCommand(CreateRelationshipRequest request) {
you can write something like that
EObject source = request.getSource();
EObject target = request.getTarget();
boolean noSourceOrTarget = (source == null || target == null);
boolean noSourceAndTarget = (source == null && target == null);
if (!noSourceAndTarget && !canCreate(source, target)) {
// Abort creation.
return UnexecutableCommand.INSTANCE;
}
Here I Test null but I can test the type of my elements source and target and return UnexecutableCommand.INSTANCE; if I do not want that.
|
|
|
|
|
Re: Restricting the allowed ends when creating a relationship element type? [message #1747393 is a reply to message #1747278] |
Mon, 14 November 2016 09:46 |
|
no you cannot do that by an advice.
why ?
In the engine of elementtype, when advice returns a command that cannot be executed (canExecute()==false), the command is not added in the chain command. So you cannot restrict it. Only the helper send a command that can fail all the chained command.
Maybe there is means with the approved request. But we need to dig.
Patrick
see code from org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper
private ICommand getEditCommand(IEditCommandRequest req, IEditHelperAdvice[] advice) {
ICompositeCommand command = createCommand(req);
// Get 'before' commands from matching element type
// specializations
if (advice != null) {
for (int i = 0; i < advice.length; i++) {
IEditHelperAdvice nextAdvice = advice[i];
// Before commands
ICommand beforeAdvice = nextAdvice.getBeforeEditCommand(req);
if (beforeAdvice != null) {
if (beforeAdvice.canExecute()) {
command.compose(beforeAdvice);
} else {
return beforeAdvice;
}
}
}
}
// Check if the parameter has been set to ignore the default edit command.
Object replaceParam = req
.getParameter(IEditCommandRequest.REPLACE_DEFAULT_COMMAND);
if (replaceParam != Boolean.TRUE) {
// Get 'instead' command from this edit helper
ICommand insteadCommand = getInsteadCommand(req);
if (insteadCommand != null) {
if (insteadCommand.canExecute()) {
command.compose(insteadCommand);
} else {
return insteadCommand;
}
}
}
// Get 'after' commands from matching element type
// specializations
if (advice != null) {
for (int i = 0; i < advice.length; i++) {
IEditHelperAdvice nextAdvice = advice[i];
// After commands
ICommand afterAdvice = nextAdvice.getAfterEditCommand(req);
if (afterAdvice != null) {
if (afterAdvice.canExecute()) {
command.compose(afterAdvice);
} else {
return afterAdvice;
}
}
}
}
return command.isEmpty() ? null
: command;
}
|
|
|
Powered by
FUDForum. Page generated in 0.03850 seconds