Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » EMF resource has been changed Error
EMF resource has been changed Error [message #1073620] Thu, 25 July 2013 07:32 Go to next message
serhat gezgin is currently offline serhat gezgin
Messages: 239
Registered: January 2013
Location: Izmir
Senior Member
Hi all,

I want to ask you a question about emf and gmf.

I have 2 metamodel

first is content.ecore
second is user.ecore

and content.ecore imports user.ecore (for referancing some elements from user model)

First i generate user as emf editor.
Secondly i generate content as gmf editor.

After that i need when i create web element on content metamodel i need to create SitePermission element on user model (automatically)

so i do this on gmf's create commands. when web created i trigger;

                    Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
		    Map<String, Object> m = reg.getExtensionToFactoryMap();
		    m.put("user", new XMIResourceFactoryImpl());

		    // Obtain a new resource set
		    ResourceSet resSet = new ResourceSetImpl();

		    // Create a resource
		    Resource resource = resSet.getResource(URI.createURI("platform:/resource/GMFEMF/user.user"), true);

                UserModel model = (UserModel) resource.getContents().get(0);
	        model.getSitePermissions().add(s);

                try {
			resource.save(Collections.EMPTY_MAP);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	        }




this code.

Now i must explain how this code work;

When i run Runtime Eclipse with this projects;

On first opening of Runtime Eclipse i can create web and than SitePermission created and referance done by code. There is no error.

But when i shut down Runtime Eclipse and than re open Runtime Eclipse and trigger Create Web command again, web and sitepermission elements created but on diagram i have confirm information as;

"The file has been changed on the filesystem. Do you want to load changes ?"

when i answer this confirmation as yes. My created elements deleted. But when i answer as no they are not deleted but same confirmation question asking to me. And Again when i answer as no my elements not deleted and same confirmation question not asking to me anymore

But this cinfirmation question is so bad. I dont want to show this confirmation question to user who work on this project.

Can u help me ?

Regards.

[Updated on: Thu, 25 July 2013 07:37]

Report message to a moderator

Re: EMF resource has been changed Error [message #1074138 is a reply to message #1073620] Fri, 26 July 2013 07:17 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26054
Registered: July 2009
Senior Member
Serhat,

Comments below.

On 25/07/2013 9:32 AM, serhat gezgin wrote:
> Hi all,
>
> I want to ask you a question about emf and gmf.
>
> I have 2 metamodel
> first is content.ecore
> second is user.ecore
>
> and content.ecore imports user.ecore (for referancing some elements
> from user model)
>
> First i generate user as emf editor.
> Secondly i generate content as gmf editor.
>
> After that i need when i create web element on content metamodel i
> need to create SitePermission element on user model (automatically)
>
> so i do this on gmf's create commands. when web created i trigger;
>
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("user", new XMIResourceFactoryImpl());
>
> // Obtain a new resource set
> ResourceSet resSet = new ResourceSetImpl();
>
> // Create a resource
> Resource resource =
> resSet.getResource(URI.createURI("platform:/resource/GMFEMF/user.user"),
> true);
So your code assumes this project with this resource exists in the
workspace?
>
> UserModel model = (UserModel) resource.getContents().get(0);
> model.getSitePermissions().add(s);
>
> try {
> resource.save(Collections.EMPTY_MAP);
You're modifying the workspace as part of a command execution. That
seems like a no-no. If this thing is more like a preference, it should
be stored as a preference not as a workspace resource.
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> this code.
>
> Now i must explain how this code work;
>
> When i run Runtime Eclipse with this projects;
>
> On first opening of Runtime Eclipse i can create web and than
> SitePermission created and referance done by code. There is no error.
>
> But when i shut down Runtime Eclipse and than re open Runtime Eclipse
> and trigger Create Web command again, web and sitepermission elements
> created but on diagram i have confirm information as;
>
> "The file has been changed on the filesystem. Do you want to load
> changes ?"
Because it's receiving a workspace delta it knows was caused by the
editor's own save operation.
>
> when i answer this confirmation as yes. My created elements deleted.
> But when i answer as no they are not deleted but same confirmation
> question asking to me. And Again when i answer as no my elements not
> deleted and same confirmation question not asking to me anymore
>
> But this cinfirmation question is so bad. I dont want to show this
> confirmation question to user who work on this project.
>
> Can u help me ?
Saving something to the workspace outside of your editor's save
operation is a bad idea. That goes counter to the user expectation that
until they save their editor, the edits they perform have no permanent
effect other than to change the editor's local state.
>
> Regards.
Previous Topic:[Texo] usage of other JSON/WS
Next Topic:EMF customizing element delete command
Goto Forum:
  


Current Time: Sun Sep 21 16:23:33 GMT 2014

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

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