file Creating an Interaction Message

2 years 8 months ago - 2 years 8 months ago #4288 by ua138
Hi I would like to know how to create an interaction message. Apparently, creating a Message requires to have a reference to a MessageEnd, but it cannot be instantiated from the session.getModule.createMessageEnd(). I was not able to find any documentation related to the creation of this kind of messages.

I have created this particular code, but it is not working:
public void actionPerformed(IDiagramHandle representation, IDiagramGraphic origin, IDiagramGraphic target,
	    IDiagramLink.LinkRouterKind kind, ILinkPath path) {
	IModelingSession session = DCaseModule.getInstance().getModuleContext().getModelingSession();
	ITransaction transaction = session
		.createTransaction(I18nMessageService.getString("Info.Session.Create", new String[] { "" }));

	try {
	    ModelElement originElement = (ModelElement) origin.getElement();
	    ModelElement targetElement = (ModelElement) target.getElement();

            Message createdElement = session.getModel().createMessage("Name",MessageSort.ASYNCCALL);

	    List<IDiagramGraphic> graphics = representation.unmask(message, 0, 0);

	    for (IDiagramGraphic graphic : graphics) {
		createLink(kind, path, graphic);
	    }

	    representation.save();
	    representation.close();
	    transaction.commit();
	    transaction.close();
	} finally {
	    transaction.close();
	}
}

Can anyone help me finishing this code? Thank you very much in advance.

Attached an image of the type of message that I would like to have (asynchronous message)
Attachments:

Please Log in or Create an account to join the conversation.

2 years 8 months ago #4293 by pan
Hi ua138,

The Modelio API does not provide an easy way to do it :(

Maybe you can take a look on the Modelio source code to see how it is working. You can consult the CreateMessageHelper class how it works in Modelio.

Let us know if it helps or if you need more information about it.

Please Log in or Create an account to join the conversation.

2 years 8 months ago #4298 by ua138
Hi pan,

I have managed to finally create one message by replicating the code used in the CreateMessageHelper class. The code looks like this:
public Message createMessage(IModelingSession session, Lifeline source, Lifeline target, String stereotypeName) {
	//////////

	// MESSAGE START
	Interaction sourceInteraction = source.getOwner();
	ExecutionOccurenceSpecification messageStart = session.getModel().createExecutionOccurenceSpecification();
	messageStart.getCovered().add(source);
	messageStart.setLineNumber(20);
	messageStart.setEnclosingInteraction(sourceInteraction);

	// TARGET EXECUTION START
	Interaction targetInteraction = target.getOwner();
	ExecutionOccurenceSpecification targetExecutionStart = session.getModel()
		.createExecutionOccurenceSpecification();
	targetExecutionStart.getCovered().add(target);
	targetExecutionStart.setEnclosingInteraction(targetInteraction);

	// MESSAGE
	Message theMessage = session.getModel().createMessage();
	theMessage.setSendEvent(messageStart);
	targetExecutionStart.setReceivedMessage(theMessage);
	theMessage.setSortOfMessage(MessageSort.ASYNCCALL);

	try {
	    theMessage.addStereotype(DCasePeerModule.MODULE_NAME, stereotypeName);
	} catch (ExtensionNotFoundException e) {
	    logger.log(Level.SEVERE, e.getMessage(), e);
	}

	DiagramUtils.getInstance().setFreeName(theMessage, I18nMessageService.getString("Ui.Message.Name"));
	targetExecutionStart.setLineNumber(20);

	// TARGET EXECUTION END

	ExecutionOccurenceSpecification targetExecutionEnd = session.getModel().createExecutionOccurenceSpecification();
	targetExecutionEnd.getCovered().add(target);
	targetExecutionEnd.setEnclosingInteraction(targetInteraction);
	targetExecutionEnd.setLineNumber(40);

	theMessage.setReceiveEvent(targetExecutionEnd);

	return theMessage;
    }

But i am a bit lost with the "lineNumbers". I have set some provisional values of 20 and 40, which makes me have the message on a default location each time is created. But how can I take the current values that the user is clicking? What is the class used? Is it "Point" from the actionPerformed method in the "DefaultAttachedBoxTool"?

Please Log in or Create an account to join the conversation.

2 years 8 months ago #4308 by pan
Hi ua138,

From the Modelio API, you can access the LineNumber on an InteractionFragment element (See the InteractionFragment API ).
This is the metamodel documentation for InteractionFragment so you can see which elements inherits from InteractionFragment.

Hope this helps

Please Log in or Create an account to join the conversation.

Moderators: tmachmaab
Time to create page: 0.039 seconds
^ Back to Top