Few days back we received a requirement from client to generate an image out of our existing work flow
definition. We started development using
JgraphX to generate image for existing work
flow. We wrote complete API tested this locally on Linux box, every thing is working properly. Once we deployed
this in cloud (Amazon instance in our case) it started throwing HeadlessException because cloud
instance is a Headless Environment.
Exception Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.awt.HeadlessException | |
at java.awt.dnd.DragSource.<init>(DragSource.java:258) [:1.6.0_20] | |
at com.mxgraph.swing.handler.mxGraphHandler.installDragGestureHandler(Unknown Source) [jgraphx-13.0.0.jar:] | |
at com.mxgraph.swing.handler.mxGraphHandler.<init>(Unknown Source) [jgraphx-13.0.0.jar:] | |
at com.mxgraph.swing.mxGraphComponent.createGraphHandler(Unknown Source) [jgraphx-13.0.0.jar:] | |
at com.mxgraph.swing.mxGraphComponent.createHandlers(Unknown Source) [jgraphx-13.0.0.jar:] | |
at com.mxgraph.swing.mxGraphComponent.<init>(Unknown Source) [jgraphx-13.0.0.jar:] |
Root Cause
We tried to search solution for this problem from Google and JGraph form as well, during the search we came across a thread in JGraphX form. Finally I went ahead and debugged the JGraphX code to figure out actual problem, so we can solve this issue. During debugging I came across a code in JGraphX library that it is trying to create Drag and Drop functionality, but I don't need this for my requirement. Same time I also came across a flag in Graph component to check isDragEnabled to validate that Drag and Drop service is required or not. This lib creates DragSource object irrespective of this flag is set or not.After digging into the JGraphX code, I solved this problem by overriding
installDragGestureHandler
method of mxGraphHandler
and createHandlers
method mxGraphComponent
class.
Disable Drag & Drop
OverrideinstallDragGestureHandler
implementation to blank because my application does not
require any Drag and Drop feature.
Install Drag Gesture Handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void installDragGestureHandler() { | |
DragGestureListener dragGestureListener = new DragGestureListener() { | |
public void dragGestureRecognized(DragGestureEvent e) { | |
if (graphComponent.isDragEnabled() && first != null) { | |
//Removed some code as we don't need for this blog post | |
// ... | |
// ... | |
} | |
} | |
}; | |
DragSource dragSource = new DragSource(); | |
dragSource.createDefaultDragGestureRecognizer(graphComponent.getGraphControl(), DnDConstants.ACTION_COPY_OR_MOVE, dragGestureListener); | |
} |
MymxGraphHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MymxGraphHandler extends mxGraphHandler { | |
public MymxGraphHandler(mxGraphComponent graphComponent) { | |
super(graphComponent); | |
} | |
protected void installDragGestureHandler() { | |
//My Blank implementation for the installDragGestureHandler | |
} | |
} |
MymxGraphComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MymxGraphComponent extends mxGraphComponent { | |
public MymxGraphComponent(mxGraph graph) { | |
super(graph); | |
} | |
protected mxGraphHandler createGraphHandler() { | |
return new MymxGraphHandler(this); | |
} | |
} |
3 Comments
Hi could you please help me, how to create workflow image using jGraph?
ReplyDeleteRajesh,
DeleteWhat exactly you want.. would you like to create a workflow image using jgraph library.... or you have any other question...
Thank you, I got the same problem and this page helped me.
ReplyDeleteIt is a shame this bug is not solved yet with the last version of mxGraph.
Post a Comment