Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Drag and dropping ports into tasks
Drag and dropping ports into tasks [message #728390] Fri, 23 September 2011 07:37 Go to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
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 08:37]

Report message to a moderator

Re: Drag and dropping ports into tasks [message #728457 is a reply to message #728390] Fri, 23 September 2011 09:59 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

In your ecore, do you have ports contained in tasks?
In your gmfmap, do you have a NodeMapping ChildReference on your Task node?
--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: Drag and dropping ports into tasks [message #728485 is a reply to message #728457] Fri, 23 September 2011 10:50 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hi!
"In your ecore, do you have ports contained in tasks?" Yes.
"In your gmfmap, do you have a NodeMapping ChildReference on your Task node?" No, I don´t know how to do it. I have two doubts:

1. I define a childreference, but how should I configure the parameters?:
- Child: Node Mapping <In:InputPort/InputPort>
- Child Feature: task.in:InputPort
- Compartment: CompartmentMapping<>
- Containment Feature: ??? (What should I write here?)
- Referenced Child: Node Mapping <In:InputPort/InputPort>

2. I also define a compartmentMapping:
- Children: ChildReference <|In:InputPort/InputPort>
- Compartment: ??? (I have nothing to choose here!)

[Updated on: Fri, 23 September 2011 10:50]

Report message to a moderator

Re: Drag and dropping ports into tasks [message #728501 is a reply to message #728485] Fri, 23 September 2011 11:14 Go to previous messageGo to next message
Mickael Istria is currently offline Mickael IstriaFriend
Messages: 865
Registered: July 2009
Location: Grenoble, France
Senior Member

On 23/09/2011 12:50, Iban wrote:
> Hi!
> "In your ecore, do you have ports contained in tasks?" Yes.
> "In your gmfmap, do you have a NodeMapping ChildReference on your Task
> node?" No, I don´t know how to do it. I have two doubts:
>
> 1. I define a childreference, but how should I configure the parameters:
> - Child: Node Mapping <In:InputPort/InputPort>
> - Child Feature: task.in:InputPort
> - Compartment: CompartmentMapping<>
> - Containment Feature: ??? (What should I write here?)
> - Referenced Child: Node Mapping <In:InputPort/InputPort>
Let's ignore compartment for the first iteration.
According to your Ecore, you should set the containment feature to task.in.


> 2. I also define a compartmentMapping:
> - Children: ChildReference <|In:InputPort/InputPort>
> - Compartment: ??? (I have nothing to choose here!)
You don't have to use a compartment in a first time. You can add it once
the containment works.

HTH


--
http://mickaelistria.wordpress.com
http://twitter.com/#!/mickaelistria
http://www.petalslink.com
Re: Drag and dropping ports into tasks [message #728504 is a reply to message #728501] Fri, 23 September 2011 11:36 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Thank you very much, that way it generates the gmfgen.

But I think I made another mistake, because now I can't draw anything!What a disaster! Laughing
Re: Drag and dropping ports into tasks [message #731957 is a reply to message #728504] Mon, 03 October 2011 14:53 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
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 21:05 Go to previous messageGo to next message
Svyatoslav Kovalsky is currently offline Svyatoslav KovalskyFriend
Messages: 12
Registered: October 2011
Junior Member
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 21:57]

Report message to a moderator

Re: Drag and dropping ports into tasks [message #734020 is a reply to message #733481] Thu, 06 October 2011 11:57 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Hello Svyatoslav,

I have a doubt with the code you adviced. The program tells me that "The method customFindRootElementFor(Module) is undefined for the type TaskCreateCommand", so I think I should define it by myself. Should I? How can I do that?

Thanks in advance

[Updated on: Thu, 06 October 2011 12:38]

Report message to a moderator

Re: Drag and dropping ports into tasks [message #734889 is a reply to message #733481] Mon, 10 October 2011 09:59 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Does anybody know how to define the "customFindRootElementFor(Module)" Svyatoslav suggested?
Re: Drag and dropping ports into tasks [message #735090 is a reply to message #734889] Mon, 10 October 2011 22:13 Go to previous messageGo to next message
Svyatoslav Kovalsky is currently offline Svyatoslav KovalskyFriend
Messages: 12
Registered: October 2011
Junior Member
Hello!

I can't write an exact implementation of the 'customFindRootElementFor' method for you, since it's specifics of your semantic model.

The only role of the method is to find a container (MainProgram) for the newly created child (Task).
Since model is a tree, there should be a way from Module reference element (childHolder) to the MainProgram container element,
and this has nothing to do with the diagram - its only about pure EMF and your requirements.

Regards,
Svyatoslav Kovalsky
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zurich, Switzerland
Re: Drag and dropping ports into tasks [message #735988 is a reply to message #735090] Thu, 13 October 2011 10:00 Go to previous messageGo to next message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
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 10:11]

Report message to a moderator

Re: Drag and dropping ports into tasks [message #739169 is a reply to message #735988] Mon, 17 October 2011 06:57 Go to previous message
Iban Ayestaran is currently offline Iban AyestaranFriend
Messages: 58
Registered: September 2011
Member
Anybody knows the answer for this??
Previous Topic:Drag and Drop a view onto another
Next Topic:Problems with layout
Goto Forum:
  


Current Time: Thu Mar 28 19:12:04 GMT 2024

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

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

Back to the top