ArrayList toDelete = null;
// Update existing ones and remove deleted ones
for (Iterator itVar = oldVars.iterator(); itVar.hasNext();)
{
ProcessVariable oldVar = (ProcessVariable) itVar.next();
ProcessVariable newVar = findVariable(newVars, oldVar);
if (newVar != null)
{
// DEBUG System.out.println ("Updating " + oldVar.getName () + " to " + newVar.getName ());
try
{
// Existing one
oldVar.copyFrom(newVar, Copyable.COPY_FIRST_LEVEL);
}
catch (CloneNotSupportedException e)
{
e.printStackTrace();
}
}
else
{
// This variable has been deleted
// DEBUG System.out.println ("Deleting " + oldVar.getName ());
List dataLinks = null;
try
{
// Make a copy of the data link list, it might get modified during the iteration
dataLinks = (List) CopyUtil.copyCollection(currentProcess.getDataLinkList(), CopyUtil.CLONE_NONE);
// Delete each data link from/to it by releasing the associated figure
for (Iterator itLinks = dataLinks.iterator(); itLinks.hasNext();)
{
DataLink link = (DataLink) itLinks.next();
if (link.getSourceParam() == oldVar || link.getTargetParam() == oldVar)
{
// DEBUG System.out.println ("Removing data link " + link.getName () + " from " + link.getSourceParam ().getPath () + " to " + link.getTargetParam ().getPath ());
ProcessVariableConnection con = (ProcessVariableConnection) link.getRepresentation();
con.release();
// Remove the link itself
currentProcess.removeDataLink(link);
}
}
}
catch (CloneNotSupportedException e)
{
// Doesn't happen
e.printStackTrace();
}
// Save the variable to delete in order to prevent ConcurrentModificationException
if (toDelete == null)
toDelete = new ArrayList();
toDelete.add(oldVar);
}
}
if (toDelete != null)
{
for (Iterator it = toDelete.iterator(); it.hasNext();)
{
ProcessVariable oldVar = (ProcessVariable) it.next();
// Remove the process variable itself
currentProcess.removeProcessVariable(oldVar);
}
}
}
// Add new ones
if (newVars != null)
{
for (Iterator itVar = newVars.iterator(); itVar.hasNext();)
{
ProcessVariable newVar = (ProcessVariable) itVar.next();
ProcessVariable oldVar = findVariable(oldVars, newVar);
if (oldVar == null)
{
// DEBUG System.out.println ("Adding " + newVar.getName ());
// Add new one
try
{
ProcessVariable toAdd = (ProcessVariable) newVar.clone();
// Create a temporary reference id in order to prevent match by CommonUtil.equalsNull, see below
toAdd.setTmpReference("!");
currentProcess.addProcessVariable(toAdd);
}
catch (CloneNotSupportedException e)
{