Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Accessing EMF resource from another file
Accessing EMF resource from another file [message #1172490] Tue, 05 November 2013 23:56 Go to next message
Phil H is currently offline Phil HFriend
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)

index.php/fa/16665/0/

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 333 times)
Re: Accessing EMF resource from another file [message #1173219 is a reply to message #1172490] Wed, 06 November 2013 11:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30372
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
Re: Accessing EMF resource from another file [message #1175642 is a reply to message #1173219] Thu, 07 November 2013 22:23 Go to previous messageGo to next message
Phil H is currently offline Phil HFriend
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 ?
Re: Accessing EMF resource from another file [message #1176211 is a reply to message #1173219] Fri, 08 November 2013 07:33 Go to previous messageGo to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 295
Registered: March 2012
Senior Member
On 06/11/2013 12:15, Ed Merks wrote:

>> 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.

Not sure If I understand correctly:

Both the graphical editor and the tree editor would make modifications
to the same model? But why would you need a different file then..

If they affect the same model, should changes in one editor should
affect the other or do you assume a more simplistic "exclusive" editing
mode?
Re: Accessing EMF resource from another file [message #1176284 is a reply to message #1176211] Fri, 08 November 2013 08:34 Go to previous message
Phil H is currently offline Phil HFriend
Messages: 267
Registered: November 2012
Senior Member
Ignore this, I just need a new file with an existing emf resource for further processing with my own editor.
Previous Topic:Ecore design and derived EReference
Next Topic:Extending EMF Compare
Goto Forum:
  


Current Time: Mon Aug 26 07:51:20 GMT 2019

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

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

Back to the top