Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » How to access BPMN Resource
How to access BPMN Resource [message #1248491] Mon, 17 February 2014 10:16 Go to next message
Cédric Casenove is currently offline Cédric Casenove
Messages: 15
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 Go to previous message
Robert Brodt is currently offline Robert Brodt
Messages: 611
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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
Previous Topic:Use BPMN2-Modeler to make M2T Transformation
Next Topic:Opening BPMN2 in Eclipse view instead of editor
Goto Forum:
  


Current Time: Mon Oct 20 23:10:01 GMT 2014

Powered by FUDForum. Page generated in 0.07004 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software