}
@Test
public void testDeletePE() {
final DiagramEditor de = TestUtil.loadFile("test.dispel");
Diagram d = de.getDiagramTypeProvider().getDiagram();
ILinkService ls = Graphiti.getLinkService();
Shape peShape = null;
EObject linked = null;
//Find a PE
for (Shape s : d.getChildren()) {
linked = ls.getBusinessObjectForLinkedPictogramElement(s);
if (linked instanceof LocalVariableStatement) {
if (((LocalVariableStatement) linked).getVariable().getName(
).equals("DemoEcho")) {
peShape = s;
break;
}
}
}
assertNotNull(peShape);
assertNotNull(linked.eContainer());
//Take a note of any incoming connections
List<Connection> cons = new ArrayList<Connection>();
for (Anchor a :peShape.getAnchors()) {
cons.addAll(a.getIncomingConnections());
}
//Just make sure they're linked
for (Connection c : cons) {
assertNotNull(c.getParent());
}
final Shape deleteShape = peShape;
//Have to async call delete within transaction, then use swtbot to
//confirm
asyncExec((new VoidResult() {
@Override
public void run() {
de.getEditingDomain().getCommandStack().execute(
new RecordingCommand(de.getEditingDomain()) {
@Override
protected void doExecute() {
IDiagramTypeProvider dtp =
de.getDiagramTypeProvider();
IFeatureProvider fp = dtp.getFeatureProvider();
final DeleteContext dc = new DeleteContext(
deleteShape);
final IDeleteFeature df =
de.getDiagramTypeProvider(
).getFeatureProvider().getDeleteFeature(
dc);
assert(df.canDelete(dc));
df.delete(dc);