To prevent spam users, you can only post on this forum after registration, which is by invitation. If you want to post on the forum, please send me a mail (h DOT m DOT w DOT verbeek AT tue DOT nl) and I'll send you an invitation in return for an account.
How to return multiple objects while executing/running a plugin?
Hello,
I have followed this link on how to return multiple objects (https://svn.win.tue.nl/trac/prom/wiki/setup/SimplePlugIn/Outputs) while creating a plugin. For simpler types like strings and integers the plugin worked fine.
But in my case (new plugin), I would like to return a type of Graph(DFG namely) and also print some text (which will have some calculations) in the same output window (visualisation pane) with some customisation settings options as well. I have tried something as simple as the following and the result is always only DFG in the visualisation window. No exceptions or errors thrown anywhere.
The return labels and the return types are correctly entered.
I have followed this link on how to return multiple objects (https://svn.win.tue.nl/trac/prom/wiki/setup/SimplePlugIn/Outputs) while creating a plugin. For simpler types like strings and integers the plugin worked fine.
But in my case (new plugin), I would like to return a type of Graph(DFG namely) and also print some text (which will have some calculations) in the same output window (visualisation pane) with some customisation settings options as well. I have tried something as simple as the following and the result is always only DFG in the visualisation window. No exceptions or errors thrown anywhere.
public Object[] csvToDFG(UIPluginContext context, CSVFile csvFile) throws ConnectionCannotBeObtained {
XLog xlog = context.tryToFindOrConstructFirstNamedObject(XLog.class, "Convert CSV to XES", null, null, csvFile);
Dfg dfg = context.tryToFindOrConstructFirstNamedObject(Dfg.class, "Convert log to directly follows graph", null, null, xlog);
return new Object[] {dfg, "Hello world"};
}
The return labels and the return types are correctly entered.
returnLabels = { "DFG", "String" },
returnTypes = { Dfg.class, String.class }
I would like to know if it is possible to display text/other output along with a Graph(DFG) in the visualisation window? If so, then where am I going at wrong?
Thank you in advance.
Answers
-
Hi,Let me start with the basics. When a plugin has completed, the ProM framework will by default try to visualize the first result of that plugin. In your case, the first result is a Dfg, hence ProM will start looking for a visualizer that can take an object of this Dfg as its input. If it finds such a plugin (which it does in your case), it will run the visualizer and put the result (a JComponent) on the screen.There are two alternative solutions to your problem. The first solution is to combine the Dfg and the string into a single object of some new class, and to create a new visualizer for that new class. This new visualizer can then put the Dfg and the string on the screen.The second solution is by using connections. You could create a DfgStringConnection in ProM, that extends an AbstractConnection (provided by the ProM framework). Before returning your result (botht he Dfg and the string), you could then create a new DfgStringConnection for that Dfg and that String:
/*
* Create the string
*/
String s = new String("Hello world");
/*
* Create a provided object for the string.
* This adds the string to your workspace in ProM (use All tab).
*/
context.getProvidedObjectManager().createProvidedObject("Dfg text", s, context);
/*
* Create a connection between the dfg and the string.
*/
context.getConnectionManager().addConnection(new DfgStringConnection(dfg, s));The visualizer can then check for a given dfg whether a DfgStringConnection exists:/*
* Initialize the string to visualize.
*/
String s = "No string found";
/*
* Check connections.
*/
try {
/*
* Try to get the first DfgStringConnection that contains the dfg.
*/
DfgStringConnection connection = context.getConnectionManager().getFirstConnection(DfgStringConnection.class, context, dfg);
/*
* Found a connection. Get the string from the connection.
* Note that I assume the string uses the STRING role in the connection.
*/
s = connection.getObjectWithRole(DfgStringConnection.STRING)
} catch (ConnectionCannotBeObtained e) {
/*
* No connection found. Use default string.
*/
}After this, the visualizer has both the dfg and the string s, and can show both.Kind regards,Eric.
-
Hello, thank you for the quick response.
Should I be creating a new DfgStringConnection.java file by extending the AbstractConnection in my plugin section? And where does the second part of the code (try catch block) go in (which file)?
And also for my actual plugin, I want to display more than a simple string. A bunch of text with some dynamic values, which would be changing based on the settings provided in the left side of the visulisaton window. Does the procedure stay same for this case as well?
Thank you in advance. -
Hi @ge82gop ,Yes, you should create a new DfgStringConnection.java file by extending the AbstractConnection. The second part of the code goes into the implementation of the visualizer plugin. This plugin gets the dfg as input, and needs to find the string that is connected to that dfg.The procedure stays the same. Basically, using connections you can connect any number of objects of any classes.Kind regards, Eric.
-
Hello.
As per your suggestions, I implemented the "Connections" and it worked. Thank you for the suggestion. But I realised, this wouldn't be a feasible option for me as I will have many more components that should be displayed along with the DFG graph. Hence, I have decided to write my own JComponent visualizer and return it to the plugin as JComponent.
I have knowledge about how to write my own JComponent visualizer with the different components in it. But I am stuck at how to include DFG to my new visualizer.
May I know if there is any pre-existing code that visualize DFG? If yes, can you provide me with the file name? (I did search for one in the projects in the SVN, but I haven't found one).
Thank you in advance.
Kind Regards,
Manoj. -
Hello Manoj,You could use the Petri net visualizer as an example. See https://svn.win.tue.nl/trac/prom/browser/Packages/PetriNets/Trunk/src/org/processmining/plugins/petrinet/PetriNetVisualization.java for the sources. This visualizer visualizes a Petri net and adds information on all kinds of structural and behavioral properties of it if available. For the latter, it uses connections. The visualization of the Petri net is done on line 133, where a panel (JComponent)is constructed for the Petri net. This does require the Petri net to subclass some classes (like DirectedGraph for the graph and DirectedGraphNode for its nodes), you could do the same for your DFG.Note that a connection does not have to be binary. You can store any number of objects in a connection. If you need to visualize something else in your DFG visualizer, you can simply add that object to the connection as well.In general, having a regular plugin that returns a JComponent is a bad idea. Please create your own class that contains (1) your DFG and (2) all data that can be associated with it, and have your plugin return an object of that class. Then, you can create a visualizer plugin for that class that returns the JComponent. This way, you separate the creation of your object from its visualization.Kind regards,Eric.
Howdy, Stranger!
Categories
- 1.6K All Categories
- 45 Announcements / News
- 225 Process Mining
- 6 - BPI Challenge 2020
- 9 - BPI Challenge 2019
- 24 - BPI Challenge 2018
- 27 - BPI Challenge 2017
- 8 - BPI Challenge 2016
- 68 Research
- 1K ProM 6
- 393 - Usage
- 287 - Development
- 9 RapidProM
- 1 - Usage
- 7 - Development
- 54 ProM5
- 19 - Usage
- 187 Event Logs
- 32 - ProMimport
- 75 - XESame