Accessing EMF resource from another file [message #1172490] |
Tue, 05 November 2013 23:56 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Hi,
I've a special use case. We've so far a combined EMF/GMF Editor where users can create models. Now we want to have another editor for further processing. For this case, I've an org.eclipse.ui.menus extension point, so that a user can right click on the EMF File and a new file will be created (see image)
The file extension (.plc) of the created file is associated with a MultiPageEditor, where one page should display the emf tree as a checkboxtreeviewer and the other page should display the selected elements as a tree.
Now to my questions:
1. What would be a good way to access the emf resource? Is it better to access the resource when I create the new file (in my defaulthandler) or later in my MultipageEditor? When I get access to the EMF resource, I'll be able to build up the checkBoxTreeView, based on the EMF model structure.
2. I've to save the user selection in the new created file, but I'm unsure how do this. I reckon I've to use a XMI structure like in EMF. Can someone give me a hint how to make this. I already had a look at the EMF editor, but I don't realy understand it.
3. Are there other things where I've to pay attention too so far?
Cheers,
Phil
-
Attachment: menu.png
(Size: 38.07KB, Downloaded 490 times)
|
|
|
Re: Accessing EMF resource from another file [message #1173219 is a reply to message #1172490] |
Wed, 06 November 2013 11:15 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Phil,
Comments below.
On 06/11/2013 12:56 AM, Phil H wrote:
> Hi,
>
> I've a special use case. We've so far a combined EMF/GMF Editor where users can create models. Now we want to have another editor for further processing. For this case, I've an org.eclipse.ui.menus extension point, so that a user can right click on the EMF File and a new file will be created (see image)
>
>
>
> The file extension (.plc) of the created file is associated with a MultiPageEditor, where one page should display the emf tree as a checkboxtreeviewer and the other page should display the selected elements as a tree.
>
> Now to my questions:
>
> 1. What would be a good way to access the emf resource? Is it better to access the resource when I create the new file (in my defaulthandler) or later in my MultipageEditor?
Either. When creating the resource I assume you'll use
ResourceSet.createResource, populate it, and save it. Then you open the
editor with the appropriate editor input and it will load the resource
you saved.
> When I get access to the EMF resource, I'll be able to build up the checkBoxTreeView, based on the EMF model structure.
>
> 2. I've to save the user selection in the new created file, but I'm unsure how do this.
Resource.save.
> I reckon I've to use a XMI structure like in EMF. Can someone give me a hint how to make this.
Look in things like your generated wizard for creating a new instance or
in the generated editor's save methods.
> I already had a look at the EMF editor, but I don't realy understand it.
>
> 3. Are there other things where I've to pay attention too so far?
No, it sounds pretty straight forward, much like what the generated
wizard does.
>
> Cheers,
> Phil
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Accessing EMF resource from another file [message #1175642 is a reply to message #1173219] |
Thu, 07 November 2013 22:23 |
Phil H Messages: 267 Registered: November 2012 |
Senior Member |
|
|
Thx Ed for your answers. I tried now for hours to uderstand this, but I don't really get it how to assign an existing resource to a new file. At the moment I've in my org.eclipse.ui.menus DefaultHandler the follwoing:
if (element instanceof IResource) {
IResource pldFile = (IResource) element;
String path = pldFile.getLocation().toString();
URI uri = URI.createFileURI(path);
// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();
// Get the existing resource
Resource emfResource = resSet.getResource(uri, true);
IProject project = pldFile.getProject();
String fileName = pldFile.getName().replace(pldFile.getFileExtension(), "plc");
IFile plcFile = project.getFile(new Path(fileName));
byte[] bytes = "".getBytes();
try {
InputStream source = new ByteArrayInputStream(bytes);
if (plcFile.exists()) {
int i = 1;
String tmp = "";
do {
tmp = fileName;
int index = tmp.indexOf(".plc");
tmp = tmp.substring(0, index) + i + tmp.substring(index, tmp.length());
plcFile = project.getFile(new Path(tmp));
i++;
} while (plcFile.exists());
plcFile.create(source, IResource.NONE, null);
} else {
plcFile.create(source, IResource.NONE, null);
}
PlcEditorInput input = new PlcEditorInput(emfResource);
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
IWorkbenchPage page = window.getActivePage();
IDE.openEditor(page, plcFile);
} catch (CoreException e) {
e.printStackTrace();
}
I don't really know hot use createResource for my case. Would it be similiar to this one: http://www.vogella.com/articles/EclipseEMFPersistence/article.html ?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03612 seconds