@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);
}});
}}));
//Select the PE
//final SWTBotGefEditor editor = mBot.gefEditor("test");
//editor.getEditPart("DemoEcho\nEcho").click();
//editor.
//Pause, then hit delete
//mBot.sleep(1000);
/*
final Event down = new Event();
down.type = SWT.KeyDown;
down.keyCode = SWT.DEL;
down.character = SWT.DEL;
final Event up = new Event();
up.type = SWT.KeyUp;
up.keyCode = SWT.DEL;
up.character = SWT.DEL;
editor.getWidget().notifyListeners(eventType, event)
editor.getWidget().getDisplay().syncExec(new Runnable() {
public void run() {
assertTrue(editor.getWidget().getDisplay().post(down));
assertTrue(editor.getWidget().getDisplay().post(up));
}
});
*/
//char del = 0x7F;
//Keyboard k = KeyboardFactory.getMockKeyboard(editor.getWidget(), null);
//mBot.waitUntil(Conditions.shellIsActive("Confirm Delete"));
//Close confirmation
SWTBotShell shell = mBot.shell("Confirm Delete");
shell.activate();
mBot.button("Yes").click();
mBot.sleep(1000);
mBot.menu("File").menu("Save").click();
mBot.sleep(1000);
//Make sure deleted from diagram and model
assertFalse(d.getChildren().contains(peShape));
assertNull(linked.eContainer());
//Incoming connections should be dead too
for (Connection c : cons) {
assertNull(c.getParent());
}