LONI.tree.module.Output runWorkflow = new LONI.tree.module.Output();
runWorkflow.setEnabled(true);
runWorkflow.setFormat(new Format());
runWorkflow.getFormat().setCardinality(1);
runWorkflow.getFormat().setType("File");
FileType runFileType = new FileType();
runFileType.setName(GENERIC_DICT_TYPE);
runFileType.setDescription("");
runFileType.setExtension("");
runWorkflow.getFormat().getFileTypes().addFileType(runFileType);
runWorkflow.setOrder(0);
runWorkflow.setPrefix("-workflow");
runWorkflow.setPrefixSpaced(true);
runWorkflow.setName("Workflow Data");
runModule.getOutputs().add(runWorkflow);
//Add the setup and run modules to the setup and run contexts respectively.
setupContext.getPathContext().addContext("Setup");
runContext.getPathContext().addContext("Run");
/*
*VISIT THE STEPS IN THE WORKFLOW
*/
//used to place run, setup modules
int totalY=0; // running sum of y values.
int leftX = -1; //furthest left x position
int rightX = 0; //furthest right y position
int spacing = 200; //spacing between modules.
// TODO Auto-generated method stub
for(Step s : workflow.getSteps()){
//visit each step in the workflow
Pair<GraphObject,LoniEnvironment> step = stepVisitor.visit(s, new LoniContext());
//add the returned environment to the pipeline environment.
le.addEnvironment(step.getElem2());
//add the returned graphobject to the pipeline modulegroup
moduleGroup.getModules().add(step.getElem1());
//add the step's y value to the running sum of y values.
totalY += s.getPosition().getFromTop();
//update furthest left position
if(leftX < 0 || leftX > s.getPosition().getFromLeft())
leftX =s.getPosition().getFromLeft();
//update furthest right position
if(rightX < s.getPosition().getFromLeft())
rightX=s.getPosition().getFromLeft();
}
//calculate the average y value from the total.
int avgY = totalY;
if(workflow.getSteps().size() > 0)
avgY = totalY / workflow.getSteps().size();
//place the setup module futhest to the left, at the
//average y value.
setupModule.setPosX(leftX);
setupModule.setPosY(avgY + spacing);
//Place the run module furthest to the right, at the
//average y value.
runModule.setPosX(rightX+ spacing);
runModule.setPosY(avgY);
//add the run, setupmodule
moduleGroup.getModules().add(setupModule);
moduleGroup.getModules().add(runModule);
/*
* Connect module outputs that are not connected to anything to the
* run module.
*/
int conncount=1;
/*
* For each module output
*/
for(String id : le.getOutputAliases().keySet()){
boolean isConnected = false;
//check if any connections link the output of that module
//to the input of some other module.
for(Connection c : le.getConnections()){
if(c.getSource().equals(id))
isConnected = true;
}
//If the output is not connected to any other modules.
if(isConnected == false){
Connection runConn; //connection to the run module
//Create a new parameter for the runmodule that is connected
//to the connectionless output.
LONI.tree.module.Parameter runInput = new LONI.tree.module.Parameter();
runInput.setId(runContext.getPathContext().getAbsoluteContext("conn"+conncount));
runInput.setFileFormat(new Format());
runInput.getFormat().setCardinality(1);
runInput.getFormat().setType("File");
runFileType = new FileType();
runFileType.setName(GENERIC_DICT_TYPE);
runFileType.setDescription("");
runFileType.setExtension("");
runInput.getFormat().getFileTypes().addFileType(runFileType);
runInput.setOrder(conncount);
runInput.setPrefix("-input");
runInput.setPrefixSpaced(true);
runInput.setEnabled(true);