// Put cells not in a blocking region to back
HashSet<Object> putBack = new HashSet<Object>();
for (Object cell2 : cells) {
if (cell2 instanceof JmtCell && ((JmtCell) cell2).parentChanged()) {
// This cell was moved in, out or between blocking regions
JmtCell cell = (JmtCell) cell2;
Object key = ((CellComponent) cell.getUserObject()).getKey();
Object oldRegionKey, newRegionKey;
if (!(cell.getParent() instanceof BlockingRegion)) {
// Object removed from blocking region
putBack.add(cell2);
oldRegionKey = ((BlockingRegion) cell.getPrevParent()).getKey();
model.removeRegionStation(oldRegionKey, key);
// If region is empty, removes region too
if (model.getBlockingRegionStations(oldRegionKey).size() == 0) {
model.deleteBlockingRegion(oldRegionKey);
}
// Allow adding of removed objects to a new blocking region
enableAddBlockingRegion(true);
} else if (cell.getPrevParent() instanceof BlockingRegion) {
// Object changed blocking region
oldRegionKey = ((BlockingRegion) cell.getPrevParent()).getKey();
model.removeRegionStation(oldRegionKey, key);
// If region is empty, removes region too
if (model.getBlockingRegionStations(oldRegionKey).size() == 0) {
model.deleteBlockingRegion(oldRegionKey);
}
newRegionKey = ((BlockingRegion) cell.getParent()).getKey();
model.addRegionStation(newRegionKey, key);
} else {
// Object added to a blocking region
newRegionKey = ((BlockingRegion) cell.getParent()).getKey();
if (!model.addRegionStation(newRegionKey, key)) {
// object cannot be added to blocking region (for
// example it's a source)
cell.removeFromParent();
graph.getModel().insert(new Object[] { cell }, null, null, null, null);
putBack.add(cell);
}
// Doesn't allow adding of selected objects to a new
// blocking region
enableAddBlockingRegion(false);
}
// Resets parent for this cell
cell.resetParent();
}
// Avoid insertion of a blocking region in an other
else if (cell2 instanceof BlockingRegion) {
BlockingRegion region = (BlockingRegion) cell2;
if (region.getParent() != null) {