Home » Modeling » Epsilon » Create Element and Link
Create Element and Link [message #693160] |
Tue, 05 July 2011 23:17 |
Elvis Messages: 15 Registered: May 2011 |
Junior Member |
|
|
Hi people,
I have the following metamodel:
@namespace(uri="example", prefix="example")
package example;
@gmf.diagram(foo="bar")
class Schema {
val Entity[*] entity_schema;
val Attribute[*] attribute_schema;
val LinkAttribute[*] linkAttribute_schema;
}
@gmf.node(label="name", label.icon="false", figure="rectangle", size="100,50")
class Entity {
id attr String identity;
attr String name;
}
@gmf.node(label="name", label.icon="false", figure="ellipse", size="100,50")
class Attribute {
id attr String identity;
attr String name;
}
@gmf.link(source="source", target="target")
class LinkAttribute {
ref Entity[1] source;
ref Attribute[1] target;
}
And I'm trying to implement it as follows: After creating an Entity, I want to select the Attribute on the objects palette, click on the Entity
created to create a new Attribute with a new LinkAttribute connected in the selected Entity.
Would anyone have any suggestions for how to do this?
Thanks for the help and sorry my English!
Best regards,
Elvis
|
|
|
Re: Create Element and Link [message #693309 is a reply to message #693160] |
Wed, 06 July 2011 08:46 |
|
Hi Elvis,
I think you will need to manually customise the code generated by GMF to do that. Eugenia is focused on helping create the GMF models, and does not customize the code generated by GMF beyond what is possible with those GMF models. I would recommend you ask this questions over the GMF forum: I'm sure they will be able to help you more there .
If you don't share Attributes between several Entities, another option would be storing the Attributes inside a compartment in Entity. Please check this example:
http://eclipse.org/gmt/epsilon/doc/eugenia/
Best regards,
Antonio
|
|
| |
Re: Create Element and Link [message #695298 is a reply to message #693453] |
Mon, 11 July 2011 13:10 |
|
Hi Elvis,
you have to manually modify your (generated) [XYZ]CreateCommand; you'll find them in your [xyz].diagram.edit.commands package. There you can replace the code of, say, AttributeCreateCommand with custom code operating at EMF level.
HTH, bye
Giovanni
|
|
| | |
Re: Create Element and Link [message #697841 is a reply to message #697500] |
Mon, 18 July 2011 07:45 |
|
Hi Elvis,
you have two ways to do this:
- you can intercept the current selection in your DiagramItemSemanticEditPolicy, or
- you can find the current selection directly in your Command (not recommended)
In both cases, the code is about the same:
IStructuredSelection sel = (IStructuredSelection) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
Then you have to check if sel.getFirstElement is an instance of EntityEditPart, and retrieve the (inner) semantic element: this is your source element.
Bye,
Giovanni
|
|
| | |
Re: Create Element and Link [message #698687 is a reply to message #693160] |
Wed, 20 July 2011 00:58 |
Silvia Messages: 12 Registered: March 2011 |
Junior Member |
|
|
Hi Elvis,
I'm not sure to understand your initial question. Nevertheless, the following variation of your emf script can be an alternative solution, which doesn't involve modifications to generated code.
@namespace(uri="example", prefix="example")
package example;
@gmf.diagram(foo="bar")
class Schema {
val Entity[*] entity_schema;
val Attribute[*] attribute_schema;
}
@gmf.node(label="name", label.icon="false", figure="rectangle", size="100,50")
class Entity {
id attr String identity;
attr String name;
@gmf.link(target.decoration="arrow")
ref Attribute [*] attribues;
}
@gmf.node(label="name", label.icon="false", figure="ellipse", size="100,50")
class Attribute {
id attr String identity;
attr String name;
}
|
|
|
Re: Create Element and Link [message #698784 is a reply to message #698668] |
Wed, 20 July 2011 08:20 |
|
Hi Elvis,
the "create node" commands are called by [Diagram]ItemSemanticEditPolicy; in your own code, I think this is the SchemaItemSemanticEditPolicy class. There you need to modify your getCreateCommand method, intercepting the element type from the CreateElementRequest...but I don't know how to react to single mouse click, not yet. I have the same requirement, when I solve the problem I post back the solution.
Bye,
Giovanni
|
|
| |
Goto Forum:
Current Time: Thu Sep 26 23:25:25 GMT 2024
Powered by FUDForum. Page generated in 0.04216 seconds
|