Search in sources :

Example 1 with DataInput

use of org.vcell.workflow.DataInput in project vcell by virtualcell.

the class WorkflowJGraphProxy method addCells.

private void addCells(mxEventObject event) {
    try {
        // remove an existing connection
        Object[] cells = (Object[]) event.getProperty("cells");
        // add tasks first
        for (Object cellObject : cells) {
            if (cellObject instanceof WorkflowObjectCell) {
                WorkflowObjectCell cell = (WorkflowObjectCell) cellObject;
                if (!cell.isEdge()) {
                    // don't know how to add an object through an event yet ...
                    WorkflowObject addedTask = cell.workflowObject;
                    if (cell.workflowObject instanceof Task) {
                        Task task = (Task) cell.workflowObject;
                        task.setName(context.getWorkflow().getNextAvailableTaskName(task.getName()));
                        context.getWorkflow().addTask((Task) cell.workflowObject);
                        cell.setId(cell.workflowObject.getName());
                        cell.setGraph(graph);
                    } else {
                        // not a task, not an edge, and not already added ... can't handle this now
                        System.err.println("can't handle this now ... non-edge cell (id=" + cell.getId() + ") added to jGraphX but not already added to workflow");
                    }
                }
            }
        }
        // add edges next
        for (Object cellObject : cells) {
            if (cellObject instanceof mxCell) {
                mxCell cell = (mxCell) cellObject;
                if (cell.isEdge()) {
                    mxICell source = cell.getSource();
                    mxICell target = cell.getTarget();
                    if ((source instanceof WorkflowObjectCell) && (target instanceof WorkflowObjectCell)) {
                        String validationError = validateConnection(source, target);
                        if (validationError == null) {
                            WorkflowObject workflowSourceObject = ((WorkflowObjectCell) source).workflowObject;
                            WorkflowObject workflowTargetObject = ((WorkflowObjectCell) target).workflowObject;
                            if (workflowSourceObject instanceof DataOutput && workflowTargetObject instanceof DataInput) {
                                DataInput input = (DataInput) workflowTargetObject;
                                if (context.getWorkflow().getConnectorSource(input) != null) {
                                    System.out.println("don't add this connection, a connection already exists");
                                } else {
                                    DataOutput output = (DataOutput) workflowSourceObject;
                                    context.getWorkflow().connect2(output, input);
                                    System.out.println("added edge from " + workflowSourceObject.getPath() + " to " + workflowTargetObject.getPath());
                                }
                            }
                        } else {
                            System.out.println("didn't connect, " + validationError);
                        }
                    }
                }
            }
        }
    } finally {
        context.getWorkflow().refreshStatus();
    }
}
Also used : DataInput(org.vcell.workflow.DataInput) com.mxgraph.model.mxICell(com.mxgraph.model.mxICell) DataOutput(org.vcell.workflow.DataOutput) Task(org.vcell.workflow.Task) com.mxgraph.model.mxCell(com.mxgraph.model.mxCell) com.mxgraph.util.mxEventObject(com.mxgraph.util.mxEventObject) WorkflowObject(org.vcell.workflow.WorkflowObject) DataObject(org.vcell.workflow.DataObject) WorkflowObject(org.vcell.workflow.WorkflowObject)

Example 2 with DataInput

use of org.vcell.workflow.DataInput in project vcell by virtualcell.

the class WorkflowJGraphProxy method validateConnection.

private String validateConnection(mxICell source, mxICell target) {
    try {
        if (!(source instanceof WorkflowObjectCell) || !(target instanceof WorkflowObjectCell)) {
            return "source or target is null";
        }
        WorkflowObject workflowSourceObject = ((WorkflowObjectCell) source).workflowObject;
        WorkflowObject workflowTargetObject = ((WorkflowObjectCell) target).workflowObject;
        if (workflowSourceObject instanceof DataOutput && workflowTargetObject instanceof DataInput) {
            DataInput input = (DataInput) workflowTargetObject;
            Type inputClass = input.getType();
            if (context.getWorkflow().getConnectorSource(input) != null) {
                return "don't add this connection, a connection already exists";
            } else {
                DataOutput output = (DataOutput) workflowSourceObject;
                Type outputClass = output.getType();
                if (outputClass.getClass().isAssignableFrom(inputClass.getClass())) {
                    return null;
                } else {
                    return "can't connect " + workflowSourceObject.getPath() + " of type " + outputClass + "\n to " + workflowTargetObject.getPath() + " of type " + inputClass;
                }
            }
        } else {
            return "unknown source or desintation type";
        }
    } catch (Exception e) {
        e.printStackTrace();
        return "error validating edge: exception: " + e.getMessage();
    } finally {
        context.getWorkflow().refreshStatus();
    }
}
Also used : DataInput(org.vcell.workflow.DataInput) DataOutput(org.vcell.workflow.DataOutput) Type(java.lang.reflect.Type) WorkflowObject(org.vcell.workflow.WorkflowObject)

Example 3 with DataInput

use of org.vcell.workflow.DataInput in project vcell by virtualcell.

the class WorkflowObjectsPanel method hasDisplayData.

private boolean hasDisplayData(TaskContext taskContext, WorkflowObject workflowObject) {
    if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
        String title = parametersFunctionsTableModel.getName(workflowObject);
        WindowListener listener = new WindowAdapter() {
        };
        Object data = null;
        if (workflowObject instanceof WorkflowDataSource) {
            WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
            data = taskContext.getRepository().getData(dataHolder);
        } else if (workflowObject instanceof DataInput) {
            DataInput dataInput = (DataInput) workflowObject;
            data = taskContext.getData(dataInput);
        }
        if (data instanceof RowColumnResultSet || data instanceof ROI || data instanceof ProfileData[] || data instanceof Image || data instanceof ImageTimeSeries) {
            return true;
        }
    }
    return false;
}
Also used : DataOutput(org.vcell.workflow.DataOutput) WindowListener(java.awt.event.WindowListener) WindowAdapter(java.awt.event.WindowAdapter) ProfileData(org.vcell.optimization.ProfileData) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) DataInput(org.vcell.workflow.DataInput) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 4 with DataInput

use of org.vcell.workflow.DataInput in project vcell by virtualcell.

the class WorkflowObjectsPanel method displayData.

private void displayData(TaskContext taskContext, WorkflowObject workflowObject) {
    if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
        String title = parametersFunctionsTableModel.getName(workflowObject);
        WindowListener listener = new WindowAdapter() {
        };
        Object data = null;
        if (workflowObject instanceof WorkflowDataSource) {
            WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
            data = taskContext.getRepository().getData(dataHolder);
        } else if (workflowObject instanceof DataInput) {
            DataInput dataInput = (DataInput) workflowObject;
            data = taskContext.getData(dataInput);
        }
        if (data instanceof RowColumnResultSet) {
            RowColumnResultSet rc = (RowColumnResultSet) data;
            try {
                new DisplayPlotOp().displayPlot(rc, title, listener);
            } catch (ExpressionException e) {
                e.printStackTrace();
            }
        } else if (data instanceof ROI) {
            ROI roi = (ROI) data;
            Image image = roi.getRoiImages()[0];
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ProfileData[]) {
            ProfileData[] profileData = (ProfileData[]) data;
            new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, title, listener);
        } else if (data instanceof Image) {
            Image image = (Image) data;
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ImageTimeSeries) {
            ImageTimeSeries imageTimeSeries = (ImageTimeSeries) data;
            try {
                DisplayTimeSeries.displayImageTimeSeries(imageTimeSeries, title, listener);
            } catch (ImageException | IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : DataOutput(org.vcell.workflow.DataOutput) DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) WindowListener(java.awt.event.WindowListener) ImageException(cbit.image.ImageException) WindowAdapter(java.awt.event.WindowAdapter) ProfileData(org.vcell.optimization.ProfileData) IOException(java.io.IOException) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) ExpressionException(cbit.vcell.parser.ExpressionException) DataInput(org.vcell.workflow.DataInput) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 5 with DataInput

use of org.vcell.workflow.DataInput in project vcell by virtualcell.

the class WorkflowObjectsTableModel method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    super.propertyChange(evt);
    if (evt.getSource() instanceof WorkflowObject) {
        int changeRow = getRowIndex((WorkflowObject) evt.getSource());
        if (changeRow >= 0) {
            fireTableRowsUpdated(changeRow, changeRow);
        }
    } else {
        String propertyName = evt.getPropertyName();
        if (evt.getSource() == taskContext.getWorkflow()) {
            if (propertyName.equals(Workflow.PROPERTY_NAME_PARAMETERS)) {
                WorkflowParameter[] oldValue = (WorkflowParameter[]) evt.getOldValue();
                if (oldValue != null) {
                    for (WorkflowParameter parameter : oldValue) {
                        parameter.removePropertyChangeListener(this);
                    }
                }
                WorkflowParameter[] newValue = (WorkflowParameter[]) evt.getNewValue();
                if (newValue != null) {
                    for (WorkflowParameter parameter : newValue) {
                        parameter.addPropertyChangeListener(this);
                    }
                }
                refreshData();
            } else if (propertyName.equals(Workflow.PROPERTY_NAME_TASKS)) {
                Task[] oldValue = (Task[]) evt.getOldValue();
                if (oldValue != null) {
                    for (Task task : oldValue) {
                        task.removePropertyChangeListener(this);
                        for (DataInput dataInput : task.getInputs()) {
                            dataInput.removePropertyChangeListener(this);
                        }
                        for (DataOutput dataOutput : task.getOutputs()) {
                            dataOutput.removePropertyChangeListener(this);
                        }
                    }
                }
                Task[] newValue = (Task[]) evt.getNewValue();
                if (newValue != null) {
                    for (Task task : newValue) {
                        task.addPropertyChangeListener(this);
                        for (DataInput dataInput : task.getInputs()) {
                            dataInput.addPropertyChangeListener(this);
                        }
                        for (DataOutput dataOutput : task.getOutputs()) {
                            dataOutput.addPropertyChangeListener(this);
                        }
                    }
                }
                refreshData();
            }
        }
    }
}
Also used : DataInput(org.vcell.workflow.DataInput) DataOutput(org.vcell.workflow.DataOutput) Task(org.vcell.workflow.Task) WorkflowParameter(org.vcell.workflow.WorkflowParameter) WorkflowObject(org.vcell.workflow.WorkflowObject)

Aggregations

DataInput (org.vcell.workflow.DataInput)8 DataOutput (org.vcell.workflow.DataOutput)7 WorkflowObject (org.vcell.workflow.WorkflowObject)7 Task (org.vcell.workflow.Task)5 Image (cbit.vcell.VirtualMicroscopy.Image)3 ROI (cbit.vcell.VirtualMicroscopy.ROI)3 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)3 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)3 DataObject (org.vcell.workflow.DataObject)3 WorkflowDataSource (org.vcell.workflow.WorkflowDataSource)3 com.mxgraph.model.mxCell (com.mxgraph.model.mxCell)2 com.mxgraph.model.mxICell (com.mxgraph.model.mxICell)2 com.mxgraph.util.mxEventObject (com.mxgraph.util.mxEventObject)2 WindowAdapter (java.awt.event.WindowAdapter)2 WindowListener (java.awt.event.WindowListener)2 ProfileData (org.vcell.optimization.ProfileData)2 ImageException (cbit.image.ImageException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 File (java.io.File)1 IOException (java.io.IOException)1