

IntroductionIn this tutorial we outline the basic operations required to generate and display a workflow (taskgraph) programmatically within Triana. The conclusion of this tutorial contains the code for a simple example workflow wizard which can be built upon to create more advanced workflow wizards. The basic operations for generating a workflow (taskgraph) in Triana are as follows:
Note that in Triana we refer to the data structure used to store a workflow as a taskgraph, the components within that workflow as tasks, and uninstantiated components as tools. |
Step 1 - Acquiring ToolsIn order to instantiate a component in a workflow you first need the tool that represents that component. There are multiple ways of acquiring the tool for a component, the following is an outline of the most useful:
|
|
| Step 2 - Creating a TaskGraph
The following method in TaskGraphManager is used to create an empty taskgraph TaskGraph taskgraph = TaskGraphManager.createTaskGraph(); |
|
| Step 3 - Populating a TaskGraph
Once tools for the components required within a taskgraph have been acquired, they can be instantiated within the taskgraph. This can be done using the following taskgraph method: TaskInterface task = taskgraph.createTask(tool); |
|
| Step 4 - Connecting Tasks
The next step is to connect the tasks within a taskgraph together to create a workflow. However, as tasks can have multiple input/output nodes, it must be identified which of these nodes are being connected. To do this there are getDataInputNode and getDataOutputNode methods in the task interface that allow you to select individual nodes. Note that the first input/output node on a task is at index 0. For example, to connect output node 0 on task1 to input node 3 on task2 is as follows:
NodeInterface outnode = task1.getDataOutputNode(0); |
|
| Step 4 - Displying a Taskgraph
Once a taskgraph has been created and poplutated, it can be displayed in the Triana workspace using the following method: GUIEnv.getApplicationFrame().addParentTaskGraphPanel(taskgraph); Note: The addParentTaskGraphPanel method creates and returns a new instance of the TaskGraph with a 'runnable' backend. If you wish to update the taskgraph after it has been displayed, alterations should be done to this 'runnable' taskgraph not the original taskgraph. |
|
| Putting it all Together
The following is an example wizard that creates and displays a workflow containing a StringGen task connected to a StringViewer task:
import triana.taskgraph.*; |
|
| Example Workflow Wizard (including GUI)
The code for an example workflow wizard is available at ExampleWizardAction.java. This example is implemented as a Java action, which allows it to be included as an option within the Triana menus (both static and pop-up). To add the example workflow wizard to the main Triana menus you need to amend the createMenus() method in the triana.gui.hci.TrianaMainMenu class. To add the example worklow wizard to the tools menu, add the following line: toolsMenu.add(new JMenuItem(new examples.ExampleWizardAction())); To use the example workflow wizard simply select the wizard from the tools menu. A dialog will be displayed asking for an input tool and an output tool. Enter the qualified name (package + name) of the input and output tools you required here, for example Common.String.StringGen as the input tool and Common.String.StringViewer as the output tool. |
|