I have been facing a problem when trying to repaint the cytoscape network. In response to some interaction, I need to update some
The problem starts when I try to repaint the graph in response of some events. If the repainting is so exhaustive, then I get the network as shown in the screenshot below:
2017-05-02 11:14:47,191 [pool-3-thread-1] ERROR org.cytoscape.event.internal.CyListenerAdapter - Unexpected exception while handling listener: org.cytoscape.model.events.RowsSetListener
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.ding.impl.DGraphView.updateView(DGraphView.java:1098)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:884)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.event.internal.CyEventHelperImpl$1.run(CyEventHelperImpl.java:70)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ConcurrentModificationException
at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(IdentityHashMap.java:734)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:842)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:836)
at org.cytoscape.ding.impl.AbstractDViewModel.clearVisualProperties(AbstractDViewModel.java:236)
at org.cytoscape.view.vizmap.internal.ApplyToNetworkHandler.apply(ApplyToNetworkHandler.java:80)
at org.cytoscape.view.vizmap.internal.VisualStyleImpl.apply(VisualStyleImpl.java:172)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:883)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
... 21 more
2017-05-02 11:14:47,220 [pool-3-thread-1] ERROR org.cytoscape.event.internal.CyListenerAdapter - Unexpected exception while handling listener: org.cytoscape.model.events.RowsSetListener
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.event.internal.CyEventHelperImpl$1.run(CyEventHelperImpl.java:70)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ConcurrentModificationException
at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(IdentityHashMap.java:734)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:842)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:836)
at org.cytoscape.ding.impl.AbstractDViewModel.clearVisualProperties(AbstractDViewModel.java:236)
at org.cytoscape.view.vizmap.internal.ApplyToNetworkHandler.apply(ApplyToNetworkHandler.java:80)
at org.cytoscape.view.vizmap.internal.VisualStyleImpl.apply(VisualStyleImpl.java:172)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:883)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
... 13 more
CyRow row = network.getRow(node);
row.set(CyNetwork.NAME, nodeName);
row.set(NODE_SIZE_, size);
row.set(NODE_SHAPE_, shape);
row.set(NODE_FILL_COLOR_, color);
row.set(NODE_VISIBLE, visible);
row.set(NODE_TRANSPARENCY, transparency);
row.set(NODE_LABEL, nodeLabel);
row.set(NODE_TYPE, type);
row.set(NODE_BORDER_COLOR_, borderColor);
row.set(NODE_BORDER_LINE_TYPE_, borderLineType);
row.set(NODE_BORDER_WIDTH_, borderWidth);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_SHAPE,shape);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR,nodeColor);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_TRANSPARENCY,transparency);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_PAINT,borderColor);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_LINE_TYPE,lineType);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_WIDTH, borderWidth);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_SIZE,size);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_HEIGHT,size);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_WIDTH,size);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_LABEL_TRANSPARENCY, transparency);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_LABEL_FONT_SIZE,labelFontSize);
To fix this problem, I have to force the repaint either with the option [Select] -> [Show all nodes and edges] on Cytoscape v3.2.1, or programatically for Cytoscape v3.4.0 with the following code:
The repainting process is ugly, due to it repaints so many times. My question is if is this ConcurrentModificationException a bug? or is there a way to do this repainting process smoothly and correct?, Am I following the correct approach?