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.

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

  • hverbeekhverbeek Posts: 864
    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.





  • ge82gopge82gop Posts: 5
    edited January 4
    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.
    Post edited by ge82gop on
  • hverbeekhverbeek Posts: 864
    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.
Sign In or Register to comment.