in taverna-contextual-views-api/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/activity/ActivityConfigurationDialog.java [273:383]
private void configurePorts(Activity activity, List<Edit<?>> editList,
List<ProcessorBinding> processorBindings,
List<ActivityPortConfiguration> portDefinitions, PortType portType) {
Set<ActivityPort> ports = new HashSet<>();
for (ActivityPort activityPort : portType == PortType.INPUT ? activity
.getInputPorts() : activity.getOutputPorts())
ports.add(activityPort);
for (ActivityPortConfiguration portDefinition : portDefinitions) {
String portName = portDefinition.getName();
int portDepth = portDefinition.getDepth();
int granularPortDepth = portDefinition.getGranularDepth();
ActivityPort activityPort = portDefinition.getActivityPort();
if (activityPort == null) {
// no activity port so add a new one
if (portType == PortType.INPUT)
createInputPort(activity, editList, processorBindings, portDefinition);
else
createOutputPort(activity, editList, processorBindings, portDefinition);
} else {
ports.remove(activityPort);
// check if port has changed
for (ProcessorBinding processorBinding : processorBindings)
if (portType == PortType.INPUT)
for (ProcessorInputPortBinding portBinding : processorBinding
.getInputPortBindings()) {
if (!portBinding.getBoundActivityPort().equals(
activityPort))
continue;
InputProcessorPort processorPort = portBinding
.getBoundProcessorPort();
if (!activityPort.getName().equals(portName))
// port name changed
if (processorPort.getName().equals(activityPort.getName()))
// default mapping so change processor port
editList.add(new RenameEdit<>(processorPort, portName));
if (!processorPort.getDepth().equals(portDepth))
// port depth changed
editList.add(new ChangeDepthEdit<>(
processorPort, portDepth));
}
else
for (ProcessorOutputPortBinding portBinding : processorBinding
.getOutputPortBindings()) {
if (!portBinding.getBoundActivityPort().equals(
activityPort))
continue;
OutputProcessorPort processorPort = portBinding
.getBoundProcessorPort();
if (!activityPort.getName().equals(portName))
// port name changed
if (processorPort.getName().equals(
activityPort.getName()))
// default mapping so change processor port
editList.add(new RenameEdit<>(
processorPort, portName));
if (!processorPort.getDepth().equals(portDepth))
// port depth changed
editList.add(new ChangeDepthEdit<>(
processorPort, portDepth));
if (!processorPort.getGranularDepth().equals(
granularPortDepth))
// port granular depth changed
editList.add(new ChangeGranularDepthEdit<>(
processorPort, granularPortDepth));
}
if (!activityPort.getName().equals(portName))
// port name changed
editList.add(new RenameEdit<>(activityPort, portName));
if (!activityPort.getDepth().equals(portDepth))
// port depth changed
editList.add(new ChangeDepthEdit<>(activityPort, portDepth));
if (activityPort instanceof OutputActivityPort) {
OutputActivityPort outputActivityPort = (OutputActivityPort) activityPort;
Integer granularDepth = outputActivityPort
.getGranularDepth();
if (granularDepth == null
|| !granularDepth.equals(granularPortDepth))
// granular port depth changed
editList.add(new ChangeGranularDepthEdit<>(
outputActivityPort, granularPortDepth));
}
}
}
// remove any unconfigured ports
for (ActivityPort activityPort : ports) {
// remove processor ports and bindings
for (ProcessorBinding processorBinding : processorBindings)
if (portType.equals(PortType.INPUT))
for (ProcessorInputPortBinding portBinding : processorBinding
.getInputPortBindings()) {
if (portBinding.getBoundActivityPort().equals(activityPort)) {
editList.add(new RemoveProcessorInputPortEdit(processorBinding
.getBoundProcessor(), portBinding.getBoundProcessorPort()));
editList.add(new RemoveChildEdit<>(processorBinding,
portBinding));
}
}
else
for (ProcessorOutputPortBinding portBinding : processorBinding
.getOutputPortBindings())
if (portBinding.getBoundActivityPort().equals(activityPort)) {
editList.add(new RemoveProcessorOutputPortEdit(processorBinding
.getBoundProcessor(), portBinding.getBoundProcessorPort()));
editList.add(new RemoveChildEdit<>(processorBinding,
portBinding));
}
// remove activity port
editList.add(new RemoveChildEdit<Activity>(activity, activityPort));
}
}