Home » Modeling » GMF (Graphical Modeling Framework) » Drag and dropping ports into tasks
Drag and dropping ports into tasks [message #728390] |
Fri, 23 September 2011 03:37  |
Eclipse User |
|
|
|
Hello,
I have designed a meta-model in Ecore, and now I am designing a graphical modeling tool with the GMF.
In the meta-model I have declared somethig called task, and something called port. In the diagram, I can now draw ports and tasks separately, but I want to force the user to draw the ports only inside the tasks, by drag-and-dropping the ports inside tasks.
Tasks have an atribute called InPorts, where all the ports of the task have to be declared. I would also like the ports to be declared automatically when they are drag-and-dropped inside the tasks.
How can I do this?
Thanks in advance.
[Updated on: Fri, 23 September 2011 04:37] by Moderator
|
|
| | | | |
Re: Drag and dropping ports into tasks [message #731957 is a reply to message #728504] |
Mon, 03 October 2011 10:53   |
Eclipse User |
|
|
|
Hello again,
related to this topic, I have another question now. I want to make something similar to what I did with ports and tasks (that is, to draw ports only inside tasks), but I need something different.
The thing is that I have some blocks called modules, and I want to force the designer to draw first the modules, then the tasks inside modules, and then the ports inside tasks. But in my ecore modules do not contain tasks, they only have a reference to tasks and tasks are contained by the "MainProgram" block. The reason for this is that I want a single tasks to be able to be called from different modules.
So my question is: is it possible to force the designer to draw tasks only inside modules, if tasks are not contained in modules?
|
|
|
Re: Drag and dropping ports into tasks [message #733481 is a reply to message #731957] |
Tue, 04 October 2011 17:05   |
Eclipse User |
|
|
|
Hello,
This is straightforward, except the one step at the end.
So you should proceed exactly like the tasks are contained in modules:
- create Top Reference and node mapping for Module, set up everything for it as always
- inside it create child reference for Task, set the children feature to (non-containment) Module#tasks, set containment feature to your actual containment for Tasks - say, to your RootElement#tasksContainment
- inside it create the same structure for Ports as before
- run Create Generator Model as always
You will have the validation error for map model - 'Containment feature must be owned by class or superclass...', just ignore it, by checking Ignore Validation Error's check box for the Mapping Model Validation Result page of Create Generator model wizard.
- generate the code
- go to the generated TaskCreateCommand, you will see the code like this:
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Task newElement = XXXFactory.eINSTANCE.createTask();
RootElement owner = (RootElement) getElementToEdit(); //<HERE IS ERROR>
owner.getTasksContainment().add(newElement);
Module childHolder = (Module) getElementToEdit();
childHolder.getTasks().add(newElement);
//... the rest omitted
The line marked with <HERE IS ERROR> is, well, an error - getElementToEdit will actually be the Module, not the RootElement, so you will get ClassCast here. (should not be a surprise - you had been told that there may be a problems with code, when you were presented with a Warning earlier).
So you have to replace the error line with @generated NOT version that correctly navigates from Module childHolder to your actual container and correctly adds the new created Task to correct containment;
So you will have something like
/*
* @generated NOT
*/
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Task newElement = XXXFactory.eINSTANCE.createTask();
Module childHolder = (Module) getElementToEdit();
childHolder.getTasks().add(newElement);
//custom code:
RootElement owner = customFindRootElementFor(chldHolder);
owner.getTasksContainment().add(newElement);
//... the rest omitted
Regards,
Svyatoslav Kovalsky
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zürich, Switzerland
[Updated on: Tue, 04 October 2011 17:57] by Moderator
|
|
| | | |
Re: Drag and dropping ports into tasks [message #735988 is a reply to message #735090] |
Thu, 13 October 2011 06:00   |
Eclipse User |
|
|
|
Hello!
I tried what you said, by typing this:
Module childHolder = (Module) getElementToEdit();
childHolder.getTasks().add(newElement);
RootElement owner = (RootElement) childHolder.eContainer();
owner.getTasks().add(newElement);
Now, in the diagram I can draw tasks inside ports as I wanted, but in the model the tasks appears defined twice, one in the RootElement (as I want) and another inside the Module (and I don't want that, I just want to make a reference to the task contained by the RootElement).
Now, from the model file (not the diagram file, I mean), I can drag and drop a task to other modules, but if I delete a task, all the tasks are deleted, including the one in the RootElement. I mean, it seems that what I define in the Module is not really a reference to the task, but the task itself, that it is repeated in all the modules an in the RootElement.
I think the problem is in the "childHolder.getTasks().add(newElement);" statement. How can I specify not to be a contained element, but just a reference to the task contained by the RootElement? I was thinking of typing "childHolder.setTasks();", but that gives an error....
Thanks for all your answers!!
[Updated on: Thu, 13 October 2011 06:11] by Moderator
|
|
| |
Goto Forum:
Current Time: Wed Jul 23 15:24:38 EDT 2025
Powered by FUDForum. Page generated in 0.04829 seconds
|