Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Display second diagram with given resource
Display second diagram with given resource [message #723365] Thu, 08 September 2011 12:22 Go to next message
janpojer is currently offline janpojerFriend
Messages: 40
Registered: July 2011
Member
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 12:46 Go to previous message
janpojer is currently offline janpojerFriend
Messages: 40
Registered: July 2011
Member
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;
	}
Previous Topic:Custom command to custom palette item
Next Topic:Saving a file from the editor
Goto Forum:
  


Current Time: Sat Apr 20 03:56:01 GMT 2024

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

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

Back to the top