Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » isModified() returns true on undo though reverting to saved state(isModified() returns true on undo though reverting to saved state)
isModified() returns true on undo though reverting to saved state [message #941207] Fri, 12 October 2012 09:46 Go to next message
Anit Nair is currently offline Anit NairFriend
Messages: 6
Registered: October 2012
Junior Member
My application contains a Multipage graphical editor. I using emf 0.8 with graphiti 0.9.0.

Editor uses the resource.isModified() call to check for dirty state. I have set
setTrackingModification() true option for the resource as well. The call works as expected for any resource change. However, it behaves strangely for undo commands.

Following the use case:
1) I open an existing resource in the editor. resource is in saved state. Editor is in saved state. (OK)
2) I make some changes to the resource. The resource.ismodified() return false. Editor is in dirty state. (OK)
3) I undo the change made. The resource.ismodified() still returns true. Editor is in dirty state yet. (Not Ok).

I am not sure why the resource.isModified() would return true on undo().

Regards,
Anit
Re: isModified() returns true on undo though reverting to saved state [message #941554 is a reply to message #941207] Fri, 12 October 2012 16:34 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Anit,

Comments below.

On 12/10/2012 11:46 AM, Anit Nair wrote:
> My application contains a Multipage graphical editor. I using emf 0.8
> with graphiti 0.9.0.
>
> Editor uses the resource.isModified() call to check for dirty state. I
> have set setTrackingModification() true option for the resource as
> well. The call works as expected for any resource change. However, it
> behaves strangely for undo commands.
It has no idea about undo and redo so all changes make it dirty. That's
why the generated editor relies on the command stack's state for
determining dirtiness.

>
> Following the use case:
> 1) I open an existing resource in the editor. resource is in saved
> state. Editor is in saved state. (OK)
> 2) I make some changes to the resource. The resource.ismodified()
> return false. Editor is in dirty state. (OK)
> 3) I undo the change made. The resource.ismodified() still returns
> true. Editor is in dirty state yet. (Not Ok).
Yes, I would expect that.
>
> I am not sure why the resource.isModified() would return true on undo().
Because it knows nothing about undo and we don't generally use this for
dirtiness tracking. Not just for this reason but also because even if a
resource isn't change, it may reference objects in other resources and
changes to those other resources can affect the URI and hence the
serialization. So we use the command stack and rely on "save only if
change" option to write out only resources that produce different bytes
when saved.
>
> Regards,
> Anit
>
Re: isModified() returns true on undo though reverting to saved state [message #941587 is a reply to message #941554] Fri, 12 October 2012 17:21 Go to previous messageGo to next message
Anit Nair is currently offline Anit NairFriend
Messages: 6
Registered: October 2012
Junior Member
Thanks for replying.

I tried using the command stack as well for determining dirtiness, however it still does not seem to be working for me.

Following is the snippet

editingDomain.getCommandStack().addCommandStackListener(new CommandStackListener() {
			@Override
			public void commandStackChanged(EventObject event) {
				Object source = event.getSource();
				if(source instanceof IWorkspaceCommandStack){
					IWorkspaceCommandStack commandstackImpl = (IWorkspaceCommandStack) source;
					IOperationHistory operationHistory = commandstackImpl.getOperationHistory();
					if(operationHistory != null){
						IUndoableOperation nextUndoableOperation = operationHistory.getUndoOperation(commandstackImpl.getDefaultUndoContext());
						if(nextUndoableOperation != null){
							setSaveNeeded(hasUnSavedContext(nextUndoableOperation));
						}
						else
							setSaveNeeded(false);
					}
				}
			}
		});


	protected boolean hasUnSavedContext(IUndoableOperation nextUndoableOperation) {
		IUndoContext[] contexts = nextUndoableOperation.getContexts();
		if(contexts.length ==1){
			return false;
		}
		
		for(IUndoContext context:contexts){

			if(context instanceof ResourceUndoContext){
				ResourceUndoContext resUndoContext =  (ResourceUndoContext) iUndoContext;
				Resource resource = resUndoContext.getResource();
				if(resource instanceof Bpmn2ModelerResourceImpl){
					return true;
				}
			}
		}
		return false
	}


I am not too sure if this the right way to do it. Also can i use isSaveNeeded on commandstack instance to check for save, as i tried that too but it seems to return true every time.

Regars,
Anit
Re: isModified() returns true on undo though reverting to saved state [message #942093 is a reply to message #941587] Sat, 13 October 2012 05:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Anit,

Comments below.

On 12/10/2012 7:21 PM, Anit Nair wrote:
> Thanks for replying.
>
> I tried using the command stack as well for determining dirtiness,
> however it still does not seem to be working for me.
It works in the generated editor...
>
> Following is the snippet
>
>
> editingDomain.getCommandStack().addCommandStackListener(new
> CommandStackListener() {
> @Override
> public void commandStackChanged(EventObject event) {
> Object source = event.getSource();
> if(source instanceof IWorkspaceCommandStack){
Does it ever get in here? I don't think so...
> IWorkspaceCommandStack commandstackImpl = (IWorkspaceCommandStack)
> source;
> IOperationHistory operationHistory =
> commandstackImpl.getOperationHistory();
> if(operationHistory != null){
> IUndoableOperation nextUndoableOperation =
> operationHistory.getUndoOperation(commandstackImpl.getDefaultUndoContext());
>
> if(nextUndoableOperation != null){
> setSaveNeeded(hasUnSavedContext(nextUndoableOperation));
> }
> else
> setSaveNeeded(false);
> }
> }
> }
> });
>
>
> protected boolean hasUnSavedContext(IUndoableOperation
> nextUndoableOperation) {
> IUndoContext[] contexts = nextUndoableOperation.getContexts();
> if(contexts.length ==1){
> return false;
> }
>
> for(IUndoContext context:contexts){
>
> if(context instanceof ResourceUndoContext){
> ResourceUndoContext resUndoContext =
> (ResourceUndoContext) iUndoContext;
> Resource resource = resUndoContext.getResource();
> if(resource instanceof Bpmn2ModelerResourceImpl){
> return true;
> }
> }
> }
> return false
> }
>
>
> I am not too sure if this the right way to do it.
No, look in a generated EMF editor...
> Also can i use isSaveNeeded on commandstack instance to check for
> save, as i tried that too but it seems to return true every time.
>
> Regars,
> Anit
Re: isModified() returns true on undo though reverting to saved state [message #943422 is a reply to message #942093] Sun, 14 October 2012 13:33 Go to previous messageGo to next message
Anit Nair is currently offline Anit NairFriend
Messages: 6
Registered: October 2012
Junior Member
Hi,

Thanks for the comments. I modified the implementation as per the generated editor and it seems to work ok. However, there is still some behavior which seems little different from what i expected.

Here is the use case.

- Open the editor (Save point 1)
- Make some changes (gets dirty)
- Undo the changes (goes back to save point 1)
- Redo the changes and save (save point 2)
- Again make some changes ( gets dirty)
- Undo the changes (goes to save point 2)
- Undo again (makes editor dirty as save point 2 is undone)
- Undo again, i would expect it to go to save point 1, but it still remains dirty.

Is this expected behavior, if yes why so.
Regards,
Anit

Re: isModified() returns true on undo though reverting to saved state [message #943586 is a reply to message #943422] Sun, 14 October 2012 16:52 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26281
Registered: July 2009
Senior Member
Anit,

Comments below.

On 14/10/2012 3:33 PM, Anit Nair wrote:
> Hi,
>
> Thanks for the comments. I modified the implementation as per the
> generated editor and it seems to work ok. However, there is still some
> behavior which seems little different from what i expected.
>
> Here is the use case.
>
> - Open the editor (Save point 1)
> - Make some changes (gets dirty)
> - Undo the changes (goes back to save point 1)
I'd expect it to be clean.
> - Redo the changes and save (save point 2)
I'd expect it to be dirty again and then be clean when you save.
> - Again make some changes ( gets dirty)
Yes, I'd expect it to get dirty.
> - Undo the changes (goes to save point 2)
It should be clean again.
> - Undo again (makes editor dirty as save point 2 is undone)
Yes, it should be dirty again.
> - Undo again, i would expect it to go to save point 1, but it still
> remains dirty.
You saved for save point 2, that's the only command stack state where
it's clean. This reflects the command stack being in the same known
state as the file system. Any other state of the command stack is
dirty. There's only one save point.
>
> Is this expected behavior, if yes why so.
The command stack is dirty any time the model's state doesn't match the
file system.
> Regards,
> Anit
>
>
Re: isModified() returns true on undo though reverting to saved state [message #949871 is a reply to message #943586] Fri, 19 October 2012 11:39 Go to previous message
Anit Nair is currently offline Anit NairFriend
Messages: 6
Registered: October 2012
Junior Member
Hi,

Thanks for your help. I could finally figure out the right way to handle the dirty state.

Regards,
Anit
Previous Topic:[Xcore] Bug? import ecore.EcorePackage; is generate is *PackageImpl
Next Topic:Create ItemPropertyDescriptor for editing Map
Goto Forum:
  


Current Time: Fri Dec 19 01:38:08 GMT 2014

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

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