Open diagram programmatically with custom input (no file) [message #1741004] |
Mon, 22 August 2016 06:39  |
Eclipse User |
|
|
|
Hello,
I have a question to open a diagram with custom input (not file). I have class MyEditorInput that implements the interface IEditorInput. MyEditorInput contains a variable InputStream that contains a graphic representation (content file representation.aird). This file, but there is no local disk. The thing that file representation.aird is stored in the database, read its contents and the need to open the diagram without saving the file to disk.
Can this be done? And if so, how?
Currently I have to open a diagram class that implements the interface IEditorLauncher and is defined as the launcher in org.eclipse.ui.editors. This class opens a diagram of an external editor using DialectUIManager.INSTANCE.openEditor (*).
Thanks for any advice. Any example, any code.
Martin
|
|
|
|
|
|
Re: Open diagram programmatically with custom input (no file) [message #1741742 is a reply to message #1741610] |
Mon, 29 August 2016 04:59  |
Eclipse User |
|
|
|
Hi Maxime,
thanks for reply.
I understand this and it works. Thanks.
But ... somehow I do not understand how to create a session and representation for the resource in memory.
I have the code (alternatively, I can send my entire code):
final IPath filePath = ((ComponentEditorInput) input).getResource().getLocation();
final URI modelURI = URI.createGenericURI(URIQuery.INMEMORY_URI_SCHEME, "file.process", null);
final URI representationURI = URI.createGenericURI(URIQuery.INMEMORY_URI_SCHEME, "temp.aird", null);
// create session
final SessionCreationOperation creationOperation = new DefaultLocalSessionCreationOperation(representationURI, monitor);
try {
creationOperation.execute();
} catch (CoreException e) {
e.printStackTrace();
}
session = creationOperation.getCreatedSession();
findAndSetViepoint(monitor);
InputStream inputStream = ((ComponentEditorInput) input).getInputStream();
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createFileURI("temp.viewpoint"));
try {
resource.load(inputStream, Collections.EMPTY_MAP);
} catch (IOException e) {
e.printStackTrace();
}
// create representation
final DRepresentation representation = createRepresentation(modelURI, monitor);
return createNewEditorInput(representation, filePath);
but it still shows that the file was not found "temp.viewpoint". Perhaps I do not understand how the editor referring to the resource in memory and not from the file.
Thanks a lot.
Martin
|
|
|
Powered by
FUDForum. Page generated in 0.03034 seconds