Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Undo/Redo Menu Items Not Updating Automatically with Databinding
EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1718362] Tue, 22 December 2015 23:03 Go to next message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
Hi,

I am having an issue that some out there knows the answer to intuitively but I am not yet at that level of expertise Embarrassed

I am basically creating a forms based property editor for ecore models. I want to use all of the built-in functionality of ecore, but simply create a custom property editing interface for my users. I have copied the stock EcoreEditor class into my project and replaced the table property editor with a forms-based tabbed editor. I am using EMF databinding to bind the UI with the Ecore model. Everything is working great, the editing domain is being used, the command stack contains my updates, etc. The problem is, when I change a property value in one of my SWT text fields and fire the binding update event, the model is updated but the menu Edit->Undo command does not change to Edit->Undo Set until I click on the tree viewer. It looks like the undo/redo menu items then refresh and I am able to take advantage of undo/redo. The question is, what do I need to do to force the menu update and why does it work fine with the stock ecore properties editor?

I have been struggling with this issue for hours and have finally decided to throw in the towel. Any advice is welcome. Thanks!

--Jim
Re: EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1718371 is a reply to message #1718362] Wed, 23 December 2015 06:09 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jim,

A generated editor has a command stack listener:

commandStack.addCommandStackListener
(new CommandStackListener()
{
public void commandStackChanged(final EventObject event)
{
getContainer().getDisplay().asyncExec
(new Runnable()
{
public void run()
{
firePropertyChange(IEditorPart.PROP_DIRTY);

// Try to select the affected objects.
//
Command mostRecentCommand =
((CommandStack)event.getSource()).getMostRecentCommand();
if (mostRecentCommand != null)
{
setSelectionToViewer(mostRecentCommand.getAffectedObjects());
}
for (Iterator<PropertySheetPage> i =
propertySheetPages.iterator(); i.hasNext(); )
{
PropertySheetPage propertySheetPage = i.next();
if (propertySheetPage.getControl().isDisposed())
{
i.remove();
}
else
{
propertySheetPage.refresh();
}
}
}
});
}
});

So when a command is executed, the dirty state of the editor is checked
and the selection is updated (which updates all the actions). I'm not
sure what's going on with this logic in your specific case, but that's
the place to look... It's
org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.update() that
updates the undo action and
org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor.propertyChanged(Object,
int) would normally trigger this. Likely there is some issue with the
editor not being considered active when your property editor is active...

On 23/12/2015 12:03 AM, Jim Boone wrote:
> Hi,
>
> I am having an issue that some out there knows the answer to
> intuitively but I am not yet at that level of expertise :blush:
> I am basically creating a forms based property editor for ecore
> models. I want to use all of the built-in functionality of ecore, but
> simply create a custom property editing interface for my users. I have
> copied the stock EcoreEditor class into my project and replaced the
> table property editor with a forms-based tabbed editor. I am using EMF
> databinding to bind the UI with the Ecore model. Everything is
> working great, the editing domain is being used, the command stack
> contains my updates, etc. The problem is, when I change a property
> value in one of my SWT text fields and fire the binding update event,
> the model is updated but the menu Edit->Undo command does not change
> to Edit->Undo Set until I click on the tree viewer. It looks like the
> undo/redo menu items then refresh and I am able to take advantage of
> undo/redo. The question is, what do I need to do to force the menu
> update and why does it work fine with the stock ecore properties editor?
> I have been struggling with this issue for hours and have finally
> decided to throw in the towel. Any advice is welcome. Thanks!
>
> --Jim


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1718420 is a reply to message #1718371] Wed, 23 December 2015 13:56 Go to previous messageGo to next message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
Ed,

Thank you for the prompt reply!

I can see that that the firePropertyChange(IEditorPart.PROP_DIRTY) method is firing and the update() command (below) is running. The
 undoAction.update();
 redoAction.update();

methods are also executing and the actions are being updated. Unfortunately, the Edit menu does not reflect the above updates until I select the tree view (or click elsewhere?). I know I am on the right track. It looks like maybe a timing issue or refresh issue. I plan to keep looking.

EditingDomainActionBarContributor.update()
  public void update()
  {
    ISelectionProvider selectionProvider = 
      activeEditor instanceof ISelectionProvider ?
        (ISelectionProvider)activeEditor :
        activeEditor.getEditorSite().getSelectionProvider();

    if (selectionProvider != null)
    {
      ISelection selection = selectionProvider.getSelection();
      IStructuredSelection structuredSelection =
        selection instanceof IStructuredSelection ?  (IStructuredSelection)selection : StructuredSelection.EMPTY;

      deleteAction.updateSelection(structuredSelection);
      cutAction.updateSelection(structuredSelection);
      copyAction.updateSelection(structuredSelection);
      pasteAction.updateSelection(structuredSelection);

      if (validateAction != null)
      {
        validateAction.updateSelection(structuredSelection);
      }

      if (controlAction != null)
      {
        controlAction.updateSelection(structuredSelection);
      }
    }

    undoAction.update();
    redoAction.update();

    if (loadResourceAction != null)
    {
      loadResourceAction.update();
    }

    if (liveValidationAction != null)
    {
      liveValidationAction.update();
    }
  }
Re: EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1718427 is a reply to message #1718420] Wed, 23 December 2015 14:53 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Jim,

Comments below.

On 23/12/2015 2:56 PM, Jim Boone wrote:
> Ed,
>
> Thank you for the prompt reply!
> I can see that that the firePropertyChange(IEditorPart.PROP_DIRTY)
> method is firing and the update() command (below) is running. The
> undoAction.update();
> redoAction.update();
>
> methods are also executing and the actions are being updated.
> Unfortunately, the Edit menu does not reflect the above updates until
> I select the tree view (or click elsewhere?).
This likely has something to do with whether the editor's action bar
contribute is active or not. Note in the generated editor has a
listener like this, so if the property sheet page of the editor is
activated, the action bar is informed that the editor itself should be
considered active.

protected IPartListener partListener =
new IPartListener()
{
public void partActivated(IWorkbenchPart p)
{
if (p instanceof ContentOutline)
{
if (((ContentOutline)p).getCurrentPage() == contentOutlinePage)
{
getActionBarContributor().setActiveEditor(EcoreEditor.this);

setCurrentViewer(contentOutlineViewer);
}
}
else if (p instanceof PropertySheet)
{
if
(propertySheetPages.contains(((PropertySheet)p).getCurrentPage()))
{
getActionBarContributor().setActiveEditor(EcoreEditor.this);
handleActivate();
}
}
else if (p == EcoreEditor.this)
{
handleActivate();
}
}

If you've implemented some other type of new satellite View, it will
need this type of handling so that the action bar contributor for the
editor itself will remains active when that view is given focus.
> I know I am on the right track. It looks like maybe a timing issue or
> refresh issue. I plan to keep looking.
> EditingDomainActionBarContributor.update()
>
> public void update()
> {
> ISelectionProvider selectionProvider = activeEditor instanceof
> ISelectionProvider ?
> (ISelectionProvider)activeEditor :
> activeEditor.getEditorSite().getSelectionProvider();
>
> if (selectionProvider != null)
> {
> ISelection selection = selectionProvider.getSelection();
> IStructuredSelection structuredSelection =
> selection instanceof IStructuredSelection ?
> (IStructuredSelection)selection : StructuredSelection.EMPTY;
>
> deleteAction.updateSelection(structuredSelection);
> cutAction.updateSelection(structuredSelection);
> copyAction.updateSelection(structuredSelection);
> pasteAction.updateSelection(structuredSelection);
>
> if (validateAction != null)
> {
> validateAction.updateSelection(structuredSelection);
> }
>
> if (controlAction != null)
> {
> controlAction.updateSelection(structuredSelection);
> }
> }
>
> undoAction.update();
> redoAction.update();
>
> if (loadResourceAction != null)
> {
> loadResourceAction.update();
> }
>
> if (liveValidationAction != null)
> {
> liveValidationAction.update();
> }
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1718442 is a reply to message #1718427] Wed, 23 December 2015 17:37 Go to previous messageGo to next message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
Thanks again for the reply Ed!

Quote:

This likely has something to do with whether the editor's action bar
contribute is active or not. Note in the generated editor has a
listener like this, so if the property sheet page of the editor is
activated, the action bar is informed that the editor itself should be
considered active.


This sounds like the problem. It looks like I need to tell eclipse that the editor's action bar is active when the form-based properties are being edited. Hopefully it will be obvious how the generated editor code does it and I will play monkey see, monkey do Rolling Eyes I will post the final resolution when I find it.
Re: EMF Undo/Redo Menu Items Not Updating Automatically with Databinding [message #1719561 is a reply to message #1718442] Fri, 08 January 2016 20:52 Go to previous message
Jim Boone is currently offline Jim BooneFriend
Messages: 15
Registered: August 2015
Location: North Carolina
Junior Member
I finally figured it out. I had to override the setActionBars() method on the PropertySheetPage just like the generated editor does for the ExtendedPropertySheetPage. Duh!

					@Override
					public void setActionBars(IActionBars actionBars) {
						getActionBarContributor().shareGlobalActions(this, actionBars);
					}
Previous Topic:[CDO] Master - Clone Server Example
Next Topic:CDO server with Microsoft sql server
Goto Forum:
  


Current Time: Fri Apr 26 15:52:02 GMT 2024

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

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

Back to the top