Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Restricting the allowed ends when creating a relationship element type?
Restricting the allowed ends when creating a relationship element type? [message #1745887] Tue, 18 October 2016 21:23 Go to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 169
Registered: January 2013
Location: Sweden
Senior Member
When I create a new element type specializing a relationship I'd like to restrict the allowed types of the ends. How can I do that?

/Patrik
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 Go to previous messageGo to next message
Patrick Tessier is currently offline Patrick TessierFriend
Messages: 238
Registered: July 2009
Location: Paris Saclay, France
Senior Member
yes you can Very Happy
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 Go to previous messageGo to next message
Patrick Tessier is currently offline Patrick TessierFriend
Messages: 238
Registered: July 2009
Location: Paris Saclay, France
Senior Member
yes you can Very Happy
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 #1745974 is a reply to message #1745914] Thu, 20 October 2016 05:25 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 169
Registered: January 2013
Location: Sweden
Senior Member
Thanks Patrick, I'll give it a try.
Re: Restricting the allowed ends when creating a relationship element type? [message #1747278 is a reply to message #1745974] Fri, 11 November 2016 15:00 Go to previous messageGo to next message
Patrik Nandorf is currently offline Patrik NandorfFriend
Messages: 169
Registered: January 2013
Location: Sweden
Senior Member
I didn't manage to get it working properly. I'll give it a second try.

But as I understand it, it is not possible to to this purely using and advice? E.g by returning UnexecutableCommand.INSTANCE from getBeforeConfigureCommand()?

I also tried to return false in canExecute() of my custom ConfigureElementCommand() but the relationship get created anyway.

Patrik Nandorf wrote on Thu, 20 October 2016 07:25
Thanks Patrick, I'll give it a try.

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 Go to previous message
Patrick Tessier is currently offline Patrick TessierFriend
Messages: 238
Registered: July 2009
Location: Paris Saclay, France
Senior Member
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;
    }
Previous Topic:Re-hash Reverse Engineering
Next Topic:Selecting deployed viewpoint configuration
Goto Forum:
  


Current Time: Tue Jan 21 22:43:10 GMT 2020

Powered by FUDForum. Page generated in 0.01803 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top