Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Delayed coloring of shapes throws exception
Delayed coloring of shapes throws exception [message #917931] Thu, 20 September 2012 15:17 Go to next message
Jens B is currently offline Jens BFriend
Messages: 2
Registered: September 2012
Junior Member
Hello,

i am trying to color the shapes of my diagram with a delay of i.e. 1 sec programmaticly.

So what am i doing. First i start a new thread by clicking a menu button, then i iterate the outgoing connections of a container color them, wait a second, move to a target and start again iterating the connections and so on...

But sometimes i get a ConcurrentModificationException.

java.util.ConcurrentModificationException
	at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
	at java.util.HashMap$KeyIterator.next(Unknown Source)
	at org.eclipse.graphiti.ui.internal.editor.DiagramRefreshJob.runInUIThread(DiagramRefreshJob.java:101)
	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:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	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 org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	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(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	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)


The menu button:
public class MenuStartSim implements IWorkbenchWindowActionDelegate {
    public void run(IAction action) {
        new Simulation();
    }
}

public class Simulation implements Runnable{
    TransactionalEditingDomain editingDomain = null;
    IDiagramTypeProvider diagramTypeProvider = null;
    IFeatureProvider featureProvider = null;
    Diagram diagram = null;
    public Simulation {
        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
        IWorkbenchPage page = win.getActivePage();
        IEditorPart editor = page.getActiveEditor();
        if(editor instanceof org.eclipse.graphiti.platform.IDiagramEditor) {
            IDiagramEditor graphitiEditor = (IDiagramEditor) editor;
            editingDomain = graphitiEditor.getEditingDomain();
            diagramTypeProvider = graphitiEditor.getDiagramTypeProvider(); 
            featureProvider = diagramTypeProvider.getFeatureProvider();
            diagram = diagramTypeProvider.getDiagram(); 
        }
        new Thread(this).start();
    }
    public void run(){
        starting();
    }
    void nextStep(EList<Connection> incoming){
        try {
            colorTargets(incoming); //color the shapes
            TimeUnit.SECONDS.sleep( TaskmodelSimulationConfig.configSpeed );
            findTargets(incoming); //find new connections + call nextStep with new connections
        } catch ( InterruptedException e ) { 
			  
        }
    }
}


So what can i do? there has do be a problem with the given threads, but i dont know how to handle the exception.
I hope someone can help me.
Thanks in advance.
Re: Delayed coloring of shapes throws exception [message #918787 is a reply to message #917931] Fri, 21 September 2012 10:46 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1640
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Jens,

it seems that you modify a collection just while the editor loops over it
during the update. It's standard Java collection behavior to throw an
exception if that happens. Working on a copy of the collection might solve
this.

Michael
Previous Topic:GraphicsAlgorithm coordinates: relative to....?
Next Topic:DirectEditing field position
Goto Forum:
  


Current Time: Sat Dec 20 08:11:43 GMT 2014

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

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