* @return true if successful
*/
public static boolean initGraphicalEditor(IFile diagramFile,
URI domainModelURI) {
TransactionalEditingDomain editingDomain =
DiagramEditorFactory.createResourceSetAndEditingDomain();
ResourceSet resourceSet = editingDomain.getResourceSet();
LinkedList<IFile> affectedFiles = new LinkedList<IFile>();
affectedFiles.add(diagramFile);
URI diagramModelURI = URI.createPlatformResourceURI(diagramFile
.getFullPath().toString(), true);
final Resource diagramResource = resourceSet
.createResource(diagramModelURI);
final String localName = diagramFile.getName().substring(
0, diagramFile.getName().indexOf('.'));
//Have to put commands in a transaction if we want to change things
final Runnable runnable = new Runnable() {
public void run() {
Diagram diagram = Graphiti.getPeCreateService().createDiagram(
"DISPEL", localName, false);
diagramResource.getContents().add(diagram);
}
};
editingDomain.getCommandStack().execute(
new RecordingCommand(editingDomain, "create diagram") {
protected void doExecute() {
runnable.run();
}
});