Confusion about usage of generated model [message #1395130] |
Sun, 06 July 2014 12:11 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Hi,
I'm on my first Graphiti project and I'm a little confused about how to use my generated model classes.
The project is using the Pattern approach.
The creation of a node, when I drag and drop a node onto my diagram, is done via the following code:
public Object[] create(ICreateContext context) {
// ask user for node name
String newName = ExampleUtil.askString(TITLE, USER_QUESTION, "");
if (newName == null || newName.trim().length() == 0) {
// TODO: default name with incrementing number?
return EMPTY;
}
// get target from context
EObject targetModel = (EObject) getBusinessObjectForPictogramElement(context
.getTargetContainer());
// create new model object
Node newObject = NodeModelFactory.eINSTANCE.createNode();
newObject.setName(newName);
// add created model object to resource of targetModel
targetModel.eResource().getContents().add(newObject);
// add graphical representation to canvas
addGraphicalRepresentation(context, newObject);
// return newly created model object(s)
return new Object[] { newObject };
}
Now, for simplicity's sake, let's say the model is built so that a Node can have Nodes as children and I've a diagram with a Node that has several Nodes inside it:
When I call
Node node = (Node) context.getNewObject();
List<Node> nodeList = node.getNodes();
nodeList remains null.
What am I missing?
--
Homer
[Updated on: Sun, 27 July 2014 14:32] Report message to a moderator
|
|
|
|
|
|
Re: Confusion about usage of my model [message #1403792 is a reply to message #1396840] |
Sun, 27 July 2014 14:32 |
Homer S Messages: 13 Registered: June 2014 |
Junior Member |
|
|
Ok, i've been stupid. Finally understood how to use the generated ecore model. One simply does have to use it.
Here's a simple sketch for the node example:
public Object[] create(ICreateContext context) {
...
// get target from context
Node targetModel = (Node) getBusinessObjectForPictogramElement(context
.getTargetContainer());
// create new model object
Node newObject = NodeModelFactory.eINSTANCE.createNode();
newObject.setName(newName);
// add created model object to resource of targetModel
targetModel.getNodes().add(newObject);
...
}
The model will be actually useable via it's getter and setter methods, which will make it easier to fetch/search for certain business objects. At the same time the diagram file will be populated with the model objects according to it's model specification in the ecore file.
I can't believe I haven't come up with this myself earlier.
[Updated on: Sun, 27 July 2014 14:32] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02178 seconds