package $packageName$.features;
import org.eclipse.graphiti.features.IAddFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.mm.algorithms.RoundedRectangle;
import org.eclipse.graphiti.mm.algorithms.Text;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
%if useShapeDomainObject
import $shapeDomainObjectClassName$;
%endif
public class Add$shapeDomainObjectClassNameShort$Feature extends AbstractAddFeature implements
IAddFeature {
public Add$shapeDomainObjectClassNameShort$Feature(IFeatureProvider fp) {
super(fp);
}
@Override
public boolean canAdd(IAddContext context) {
// TODO: check for right domain object instance below
return /* context.getNewObject() instanceof $shapeDomainObjectClassNameShort$ && */ context.getTargetContainer() instanceof Diagram;
}
@Override
public PictogramElement add(IAddContext context) {
Diagram targetDiagram = (Diagram) context.getTargetContainer();
IPeCreateService peCreateService = Graphiti.getPeCreateService();
IGaService gaService = Graphiti.getGaService();
ContainerShape containerShape = peCreateService.createContainerShape(targetDiagram, true);
RoundedRectangle roundedRectangle = gaService.createRoundedRectangle(containerShape, 5, 5);
gaService.setLocationAndSize(roundedRectangle, context.getX(), context.getY(), context.getWidth(), context.getHeight());
roundedRectangle.setFilled(false);
Shape shape = peCreateService.createShape(containerShape, false);
Text text = gaService.createText(shape, "$shapeDomainObjectClassNameShort$");
text.setHorizontalAlignment(Orientation.ALIGNMENT_CENTER);
text.setVerticalAlignment(Orientation.ALIGNMENT_CENTER);
gaService.setLocationAndSize(text, 0, 0, context.getWidth(), context.getHeight());
peCreateService.createChopboxAnchor(containerShape);
// TODO: enable the link to the domain object
// Object addedDomainObject = context.getNewObject();
// link(containerShape, addedDomainObject);
return containerShape;
}
}