|
|
Re: Create new element and prefill it [message #1232305 is a reply to message #1232213] |
Thu, 16 January 2014 11:41   |
Eclipse User |
|
|
|
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;
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04678 seconds