Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » get access to Diagram from DiagramEditor
get access to Diagram from DiagramEditor [message #875502] Tue, 22 May 2012 21:33 Go to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Hello everyone,

I am trying to create a simulation view from Graphiti. No change is necessary or allowed during the simulation. Therefore, I decide to create a simple dedicated editor to handle simulation, which will never be dirty and I want all changes stay in the diagram object in memory (without persist to model).

In eclipse launcher delegate class, launch() uses something like PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor() to get the diagram editor object, from Graphiti doc I can see a getDiagram() defined for DiagramEditorInput class, which seems perfect, because I can get access to diagram object by DiagramEditor.getEditorInput().getDiagram().

However, I don't find getDiagram() method in DiagramEditorInput source code. Is it removed? I am using version 0.9

Without this approach, how do I get access to Diagram object from DiagramEditor (without using resource)?

Thanks,
Johnny
Re: get access to Diagram from DiagramEditor [message #875706 is a reply to message #875502] Wed, 23 May 2012 07:55 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Yes, the getDiagram() method has been removed from the input in the cause of
the editor API reworks (see Bugzilla
https://bugs.eclipse.org/bugs/show_bug.cgi?id=336488). The input needs to be
a very lighweight object and must not hold the diagram instance; before it
needed to have some "wild" logic to be able to retrieve the diagram in case
it had been cleared.

Now the editor input only holds a URI to the diagram, you could use this URI
and your own editing domain to retrieve the diagram yourself or you can try
to find the opened diagram editor (it appears you have one?) and call
getDiagram on that.

Does that help?

Michael
Re: get access to Diagram from DiagramEditor [message #876047 is a reply to message #875706] Wed, 23 May 2012 20:05 Go to previous messageGo to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Thanks a lot, Michael. getDiagram method on diagram editor gave me the Diagram object.

In simulation, what I need is to change color of different shapes programmatically. Therefore, I dig into the Diagram object, find the shapes that I want to change, change it in diagram editor's editing domain.
TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
                            editingDomain.getCommandStack().execute(new RecordingCommand(editingDomain) {

                                @Override
                                protected void doExecute() {
                                    text.setForeground(highlightColor);
                                }
                            });


When I run it, changes are reflected visually. However, I get the following error popup in Eclipse because of java.util.ConcurrentModificationException

(I cannot use link until have posted more than 25 messages, so here's the link of error screenshot, please put http by yourself:)
//dl.dropbox.com/u/6621367/Screen%20Shot%202012-05-23%20at%203.44.36%20PM.png)

Maybe I am not supposed to do this?

Initially I tried to load pictogram model from resource file, updated color in the model, then use unload method to update editor. This way, when it runs, editor keeps reminding dirty status, which destroys the simulation because user is not supposed to hit save button after every graphical change during simulation.

Any idea or recommendations are highly appreciated!

Thanks,
Johnny

[Updated on: Wed, 23 May 2012 20:08]

Report message to a moderator

Re: get access to Diagram from DiagramEditor [message #876304 is a reply to message #876047] Thu, 24 May 2012 10:46 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
That should basically be correct. Maybe there's something else. Can you post
the stacktrace of the ConcurrentModificationException?

Another option you have to execute a feature on the editor's command stack
ist the method executeFeature(feature, context) on the DiagramEditor. You
would only need to wrap your functionality into a (Custom-) feature.

Michael

"Johnny Qin" schrieb im Newsbeitrag news:jpjfuk$i4a$1@xxxxxxxxe.org...

Thanks a lot, Michael. getDiagram method on diagram editor gave me the
Diagram object.

In simulation, what I need is to change color of different shapes
programmatically. Therefore, I dig into the Diagram object, find the shapes
that I want to change, change it in diagram editor's editing domain.

TransactionalEditingDomain editingDomain = diagramEditor.getEditingDomain();
editingDomain.getCommandStack().execute(new
RecordingCommand(editingDomain) {

@Override
protected void doExecute() {
text.setForeground(highlightColor);
}
});


When I run it, changes are reflected visually. However, I get the following
error popup in Eclipse because of java.util.ConcurrentModificationException



Maybe I am not supposed to do this?

Initially I tried to load pictogram model from resource file, updated color
in the model, then use unload method to update editor. This way, when it
runs, editor keeps reminding dirty status, which destroys the simulation
because user is not supposed to hit save button after every graphical change
during simulation.

Any idea or recommendations are highly appreciated!

Thanks,
Johnny
Re: get access to Diagram from DiagramEditor [message #878538 is a reply to message #876304] Tue, 29 May 2012 13:49 Go to previous messageGo to next message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Hello Michael,

Here's the stacktrace of ConcurrentModificationException.

!ENTRY org.eclipse.ui 4 4 2012-05-29 09:45:23.861
!MESSAGE An internal error has occurred.
!STACK 0
java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
	at java.util.HashMap$KeyIterator.next(HashMap.java:828)
	at org.eclipse.graphiti.ui.internal.editor.DiagramRefreshJob.runInUIThread(DiagramRefreshJob.java:104)
	at org.eclipse.ui.progress.UIJob$1.run(UIJob.java:95)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3938)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3615)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at com.company.designer.application.DesignerApplication.start(DesignerApplication.java:38)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)


Re: get access to Diagram from DiagramEditor [message #879023 is a reply to message #878538] Wed, 30 May 2012 11:30 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, this looks a bit like the parallel feature execution on the command
stack, that we have fixed just recently:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=371717

This fix is part of Graphiti 0.9.0 RC1 (RC1 of our Juno contribution). Could
you try with this version?

Michael
Re: get access to Diagram from DiagramEditor [message #879066 is a reply to message #879023] Wed, 30 May 2012 13:08 Go to previous message
Johnny Qin is currently offline Johnny QinFriend
Messages: 40
Registered: April 2012
Member
Sure, I will try. Thanks as always.

Later I abandoned the approach of modifying the diagram in simulator(editor) because of this exception. Instead, I modified resource and refreshed simulator. At the same time, isDirty of simulator is override to always return false. It met my need.

Regards,
Johnny
Previous Topic:trying to create a simulator using Graphiti
Next Topic:Spray: containment of different objects
Goto Forum:
  


Current Time: Thu Apr 25 23:21:05 GMT 2024

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

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

Back to the top