How to access BPMN Resource [message #1248491] |
Mon, 17 February 2014 10:16 |
Cédric Casenove Messages: 22 Registered: December 2013 |
Junior Member |
|
|
Hi Bob, Hi everybody,
I am quite new in Eclipse programming, so perhaps my question will sound a bit odd, but here is my problem:
I currently store the expressions (the code of a script task for example) of my BPMN process in separate files in a project, and not directly in the bpmn file (in the case of a script task, I only have a reference to the real code).
From a builder, when a script file is updated, I would like to retrieve some information from the associated bpmn process and also modify it. I know I can create an EMF resource from the workspace file, but I would like to access the EMF resource currently edited in a BPMN2 editor if one is opened. Is there a way to share the Resource/ResourceSet used by the BPMN2 editor ?
Thanks
|
|
|
Re: How to access BPMN Resource [message #1248759 is a reply to message #1248491] |
Mon, 17 February 2014 16:30 |
|
Hi Cédric,
You can adapt the BPMN2 editor to a graphiti Diagram and from that get the Resource that corresponds to a given namespace URI, like this:
Resource getResource (String nsURI) {
IWorkbenchPage[] pages = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getPages();
for (IWorkbenchPage page : pages) {
IEditorReference[] otherEditors = page.findEditors(
null,
"org.eclipse.bpmn2.modeler.ui.bpmn2editor",
IWorkbenchPage.MATCH_ID);
for (IEditorReference ref : otherEditors) {
IEditorPart part = ref.getEditor(true);
Diagram diagram = (Diagram) part.getAdapter(Diagram.class);
if (diagram!=null && diagram.eResource()!=null) {
ResourceSet rs = diagram.eResource().getResourceSet();
for (Resource r : rs.getResources()) {
if (r.getURI().equals(nsURI))
return r;
}
}
}
}
return null;
}
HTH,
Bob
|
|
|
Powered by
FUDForum. Page generated in 0.02759 seconds