Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Modifying the underlying model of a diagram editor
Modifying the underlying model of a diagram editor [message #523814] Mon, 29 March 2010 13:31 Go to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hello NG,
first I tried to discuss this question in the emf newsgroup but didnt'
solve it. Here is my problem:
I select some elements in an gmf editor - I tried it with the
statemachine editor (*.umlstm). Then I want to do some modifications on
the EObject's to which the selected elements in the diagram editor are
corresponding. The underlying EObjects will be retrieved with

List<?> temp = ((StructuredSelection) selection).toList();
for (Object object : temp) {
if(object instanceof EditPart){
Object model = ((EditPart) object).getModel();
if(model instanceof View){
EditPartViewer viewer = ((EditPart) object).getViewer();
object = ((View) model).getElement();
System.out.println("found EObject " + object + " in diagram");
}
}
if(!(object instanceof EObject)){
return;
}
selectedElements.add((EObject) object);
}

After the modifications the diagram editor should present the modified
underlying model. The same modifications should be invoked from non gmf
editors (like the normal *.uml editor), too. That's why I used the
following code to invoke the modifications:

Resource resource = firstSelectedEObject.eResource();
ResourceSet rs = resource.getResourceSet();
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(rs);
if(domain == null){
domain =
TransactionalEditingDomain.Factory.INSTANCE.createEditingDom ain(rs);
}
CommandStack stack = domain.getCommandStack();
RecordingCommand command = new MyRecordingCommand(resource, domain);

doExecute() of MyRecordingCommand then invokes the modifications. The
problem with GMF editors is that after answering the question if I want
to reload the changes, the editor canvas gets empty and after closing
and reopening it the whole Eclipse instance freezes.

The question is now, how I can put the modifications into a command like
the RecordingCommand to not resulting in errors and freezes when the
modifications will be invoked on the underlying EObjects of an gmf editor.

best regards,
Gilbert
Re: Modifying the underlying model of a diagram editor [message #523821 is a reply to message #523814] Mon, 29 March 2010 13:53 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

perhaps you can try to use AbstractTransactionnalCommand which is a gmf command to modify EMF resource instead of using the RecordingCommand which is purely EMF.

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Modifying the underlying model of a diagram editor [message #523890 is a reply to message #523821] Mon, 29 March 2010 13:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

I tried this but this is not possible. AbstractTransactionalCommand is
not a command which I can pass as parameter :(
How do you modify the underlying models of a diagram?
I also tried to get the editing domain more in the GMF way:

DiagramCommandStack diagramStack =
diagramEditingDomain.getDiagramCommandStack();

diagramStack.execute(gmfCommand);

But I don't know which class I can extend for gmfCommand.
More suggestions?

Am 29.03.2010 15:53, schrieb Aurelien Pupier:
> Hi,
>
> perhaps you can try to use AbstractTransactionnalCommand which is a gmf
> command to modify EMF resource instead of using the RecordingCommand
> which is purely EMF.
>
> Regards,
Re: Modifying the underlying model of a diagram editor [message #523899 is a reply to message #523814] Mon, 29 March 2010 18:43 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

You can use:
OperationHistoryFactory.getOperationHistory().execute(...)


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Modifying the underlying model of a diagram editor [message #524054 is a reply to message #523899] Tue, 30 March 2010 13:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Hi Aurelien,
I think I'm a little bit further now.

> OperationHistoryFactory.getOperationHistory().execute(...)

I created a subclass of AbstractTransactionalCommand
(MyGMFTransactionalCommand) in which I implemented the method
doExecuteWithResult where all the modifications of the underlying model
take place. I execute the command as follows, where 'resource' is the
one of the underlying model and not of the diagram:

ResourceSet rs = resource.getResourceSet();
TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(rs);
AbstractTransactionalCommand gmfCommand = new
GMFTransactionalCommand(domain, activeEditor);
IStatus result =
OperationHistoryFactory.getOperationHistory().execute(gmfCom mand, null,
null);


Besides that, after the modifications, I want to save all other
resources that depend on the modifications made in the model. Therefore
I implemented IWorkspaceRunnable and invoked
ResourcesPlugin.getWorkspace().run(myRunnable, null) after the
modifications in MyGMFTransactionalCommand. The run method of my
IWorkspaceRunnable implementation looks like this:

public void run(IProgressMonitor monitor) throws CoreException {
EcoreUtil.resolveAll(resourceSet);
underlyingModel.save(null);
for (Resource resource : resourceSet.getResources()) {
if (!resource.equals(underlyingModel) && !resource.equals(gmfResource)) {
URI uri = resource.getURI();
if (uri.isPlatformResource()) {
resource.save(null);
}
}
}
}

As you can see I first save the underlying model because I must assure
that the other resources which will be saved will save the updated
references from the underlying model. That's the reason of the
!resource.equals(underlyingModel) check in the for loop. When I tried
now to invoke the modifications initiated by a selection of a gmf editor
the modifications took place and I then saw the right updated elements
in the canvas of the gmf editor. I just had to answer the questions if I
want to load the updates with yes. So I did but after answering the
canvas got empty again. But at this time I could close the gmf editor
and re-open it again and voilá Eclipse didn't freeze and the canvas
presented all elements as they should. So I thought that maybe the
described error behaviour won't appear if I don't save the resource
which represents the graphical file of the gmf editor itself because it
gets the updates by its own. That's the reason for the
!resource.equals(gmfResource) check in the for loop. But this hadn't any
positive effect. The same behaviour like before. Empty canvas but I can
close and re-open it. Besides that I get one entry in the error log
before clicking 'yes' in the dialog:

org.eclipse.swt.SWTException: Failed to execute runnable
(java.lang.NullPointerException)
....
Caused by: java.lang.NullPointerException
at
org.eclipse.emf.transaction.impl.TransactionImpl.start(Trans actionImpl.java:257)
....

Then, after clicking 'yes' for loading the updates, I get another one:

org.eclipse.swt.SWTException: Failed to execute runnable
(java.lang.NullPointerException)
....
Caused by: java.lang.NullPointerException
at
org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPar tService.createEditPart(EditPartService.java:226)
....

and this one:
java.lang.NullPointerException
at
org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor.persi stViewerSettings(DiagramEditor.java:1306)
....

But in the stacktrace there are only Eclipse code lines listed, not my
own ones. Can anybody help me with this exception messages and what to
do for not getting the empty canvas after clicking 'yes'?

best regards,
Gilbert
Re: Modifying the underlying model of a diagram editor [message #524238 is a reply to message #524054] Wed, 31 March 2010 09:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Any suggestions?
Re: Modifying the underlying model of a diagram editor [message #524359 is a reply to message #523814] Wed, 31 March 2010 16:05 Go to previous message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Today I had another try because a friend gave me a new hint to work
directly on the DiagramEditingDomain and wrap my command into an
ICommandProxy. So I did the following now:

IDiagramGraphicalViewer gmfViewer;
gmfViewer = (IDiagramGraphicalViewer) selectedEditPart.getViewer();
IDiagramEditDomain diagramEditingDomain = gmfViewer.getDiagramEditDomain();
ICommand myCommand = new MyCommand(someInput);
DiagramCommandStack diagramStack =
diagramEditingDomain.getDiagramCommandStack();
diagramStack.execute(new ICommandProxy(myCommand ));

MyCommand extends
org.eclipse.gmf.runtime.common.core.command.AbstractCommand in which
doRedoWithResult and doUndoWithResult are implemented just by calling
applyAndReverse() from a ChangeDescription. But when I run the
modifications now, no changes can be applied to the underlying model
because of several IllegalStateException: Cannot modify resource set
without a write transaction. Does this mean that AbstractCommand doesn't
hold such permissions? Which other class do I have to extend? I can't
imagine that nobody didn't try to change the underlying model of a GMF
editor programmatically.

best regards,
Gilbert
Re: Modifying the underlying model of a diagram editor [message #524381 is a reply to message #524359] Wed, 31 March 2010 12:54 Go to previous message
Eclipse UserFriend
Originally posted by: formatzeh.gmx.de

Wow...yet another try but without success. I found this articel:
http://wiki.eclipse.org/GMF_Tips#Create_New_Elements_Using_R ecordingCommand_and_CanonicalEditPolicies

And my hope grew. So I did the following:

CommandStack stack = diagramTransactionalEditingDomain.getCommandStack();
RecordingCommand gmfRecordingCommand = new
MyRecordingCommand(diagramTransactionalEditingDomain);
stack.execute(gmfRecordingCommand);
domain.dispose();

Well, I have almost the same behaviour as earlier. I answer the question
if I want to load the changes with yes and get the empty canvas and an
error log entry. When closing the editor I get another error log entry
but the changes will be presented when re-opening the editor. I tried
out so much options - what am I doing wrong?

best regards,
Gilbert
Previous Topic:How to handle the opening of a diagram to do a specific operation ?
Next Topic:Double-click on whitespace/canvas
Goto Forum:
  


Current Time: Tue Apr 23 13:34:38 GMT 2024

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

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

Back to the top