|
|
Re: Create new element and prefill it [message #1232305 is a reply to message #1232213] |
Thu, 16 January 2014 16:41 |
Ralph Bergmann Messages: 10 Registered: July 2009 Location: Berlin / Germany |
Junior Member |
|
|
Hi Michael,
Michael Wenz wrote on Thu, 16 January 2014 07:51not sure, but aren't you mixing up concepts here? In the create feature for the dataobject you should also create the field (both on domain model level), in the add feature of the data object you should delegate via the addGraphicalRepresentation call to the add feature of the field.
I hope that I did it the right way
It works for me, here my code:
public class DataobjectPattern extends AbstractPattern implements IPattern {
@Override
public Object[] create(final ICreateContext context) {
final Dataobject newDataObject = ModelFactory.eINSTANCE.createDataobject();
newDataObject.setName(newDataObjectName);
final Field newField = ModelFactory.eINSTANCE.createField();
// ... settters
newDataObject.addField(newField);
final ContainerShape target = context.getTargetContainer();
if (target instanceof Diagram) {
getDiagram().eResource().getContents().add(newDataObject);
} else {
final PictogramLink link = target.getLink();
final EList<EObject> businessObjects = link.getBusinessObjects();
for (final EObject bo : businessObjects) {
if (bo instanceof Database) {
final Database db = (Database) bo;
final EList<Version> versions = db.getVersions();
final Version version = versions.get(versions.size() - 1);
version.addTable(newDataObject);
}
}
}
addGraphicalRepresentation(context, newDataObject);
return new Object[] { newDataObject, newField };
}
@Override
public PictogramElement add(final IAddContext context) {
final Dataobject newDataObject = (Dataobject) context.getNewObject();
final IPeCreateService peCreateService = Graphiti.getPeCreateService();
final IGaService gaService = Graphiti.getGaService();
final ContainerShape target = context.getTargetContainer();
final ContainerShape containerShape = peCreateService.createContainerShape(target, true);
link(containerShape, newDataObject);
// ... graphics
// peCreateService.createChopboxAnchor(containerShape);
layoutPictogramElement(containerShape);
// add ID field to diagram
final EList<Field> fields = newDataObject.getFields();
if (fields.size() > 0) {
final CreateContext createCtx = new CreateContext();
createCtx.setTargetContainer(containerShape);
addGraphicalRepresentation(createCtx, fields.get(0));
}
return containerShape;
}
}
|
|
|
Re: Create new element and prefill it [message #1232589 is a reply to message #1232305] |
Fri, 17 January 2014 09:34 |
Martin Hanysz Messages: 30 Registered: November 2013 |
Member |
|
|
Dear Ralph,
It seems you are indeed mixing up the responsibilities of the add and create methods.
In the create method you should only deal with business objects (your domain model). So code like
final Dataobject newDataObject = ModelFactory.eINSTANCE.createDataobject();
is supposed to be in this method, code that deals with pictogram elements is not. That is what the add method is for. By calling
addGraphicalRepresentation(context, newDataObject);
you get from the create to the add method in order to create the graphical representation for the business objects you created in the create method.
I suggest you try the following:
- in the create method: create your two business objects (DataObject and Field)
- in the create method: call addGraphicalRepresentation for each business object you created
- in the add method: create the pictogram elements you need to visualize your business objects in the diagram
Best regards,
Martin
[Updated on: Fri, 17 January 2014 09:35] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03269 seconds