Display second diagram with given resource [message #723365] |
Thu, 08 September 2011 08:22  |
Eclipse User |
|
|
|
Hi,
I am trying to open a new diagram window with given resource with following code:
ResourceSet resSet = new ResourceSetImpl();
Resource res = resSet.getResource(URI.createPlatformResourceURI(targetDiagram.getFullPath().toString(), false), true);
// get the current loaded editor
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IGraphicalEditPart ep = (IGraphicalEditPart) page.getActiveEditor();
DiagramEditPart diagramEP = ((DiagramEditDomain) ep.getDiagramEditDomain()).getDiagramEditorPart().getDiagramEditPart();
Object st = diagramEP.getChildren().get(0);
ShapeNodeEditPart store = (ShapeNodeEditPart) st;
SelectionRequest request = new SelectionRequest();
request.setLocation(store.getLocation());
request.setModifiers(0);
request.setType(RequestConstants.REQ_OPEN);
store.performRequest(request);
On the IGraphicalEditPart ep = (IGraphicalEditPart) page.getActiveEditor(); line it gives me error:
core.diagram.part.FnDiagramEditor cannot be cast to org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart
Any idea how to do it differently, or better... what am i doing wrong?
Thanks a lot
|
|
|
Re: Display second diagram with given resource [message #723383 is a reply to message #723365] |
Thu, 08 September 2011 08:46  |
Eclipse User |
|
|
|
Solved it:
public static void openLayeredDiagram(LayeredResource lRes) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("FN");
// get the target diagram file
IFile targetDiagram = project.getFile(resourceFolderLayers + lRes.getRelativePath());
// try loading it up with Eclipse
ResourceSet resSet = new ResourceSetImpl();
Resource res = resSet.getResource(URI.createPlatformResourceURI(targetDiagram.getFullPath().toString(), false), true);
IEditorInput editorInput = getEditorInput(res);
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try {
page.openEditor(editorInput, FnDiagramEditor.ID);
} catch (PartInitException e) {
FnDiagramEditorPlugin.getInstance().logError(
"Exception while openning diagram", e); //$NON-NLS-1$
}
}
private static IEditorInput getEditorInput(Resource diagramResource) {
URI uri = diagramResource.getURI();
String editorName = uri.lastSegment() + '#'
+ "Mine test segment";
IEditorInput editorInput = new URIEditorInput(uri, editorName);
return editorInput;
}
|
|
|
Powered by
FUDForum. Page generated in 0.04447 seconds