//Do not delete null block references. Otherwise, get Block and RenderableBlock instances.
if (isNullBlockInstance(focusManager.getFocusBlockID())) {
throw new RuntimeException("TypeBlockManager: deleting a null block references.");
}
Block block = workspace.getEnv().getBlock(focusManager.getFocusBlockID());
RenderableBlock renderable = workspace.getEnv().getRenderableBlock(block.getBlockID());
//get workspace widget associated with current focus
WorkspaceWidget widget = renderable.getParentWidget();
//do not delete block instances in null widgets
if (widget == null) {
throw new RuntimeException("TypeBlockManager: do not delete blocks with no parent widget.");
//return;
}
//get parent container of this graphical representation
Container container = renderable.getParent();
//do not delete block instances in null parents
if (container == null) {
throw new RuntimeException("TypeBlockManager: do not delete blocks with no parent container.");
//return;
}
//get the Block's location on the canvas
Point location = SwingUtilities.convertPoint(
renderable, new Point(0, 0), this.blockCanvas.getCanvas());
//for every valid and active connection, disconnect it.
Long parentID = null;
if (validConnection(block.getPlug())) {
parentID = block.getPlugBlockID();
this.disconnectBlock(block, widget);
if (validConnection(block.getAfterConnector())) {
disconnectBlock(workspace.getEnv().getBlock(block.getAfterBlockID()), widget);
}
} else if (validConnection(block.getBeforeConnector())) {
parentID = block.getBeforeBlockID();
BlockConnector parentConnectorToBlock = workspace.getEnv().getBlock(parentID).getConnectorTo(block.getBlockID());
this.disconnectBlock(block, widget);
if (validConnection(block.getAfterConnector())) {
Long afterBlockID = block.getAfterBlockID();
disconnectBlock(workspace.getEnv().getBlock(afterBlockID), widget);
if (parentID != null) {
BlockLink link = BlockLinkChecker.canLink(
workspace,
workspace.getEnv().getBlock(parentID),
workspace.getEnv().getBlock(afterBlockID),
parentConnectorToBlock,
workspace.getEnv().getBlock(afterBlockID).getBeforeConnector());
if (link != null) {
link.connect();
workspace.notifyListeners(new WorkspaceEvent(
workspace,
workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).getParentWidget(),
link, WorkspaceEvent.BLOCKS_CONNECTED));
workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).repaintBlock();
workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).repaint();
workspace.getEnv().getRenderableBlock(link.getPlugBlockID()).moveConnectedBlocks();
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaintBlock();
workspace.getEnv().getRenderableBlock(link.getSocketBlockID()).repaint();
}
}
}
} else if (validConnection(block.getAfterConnector())) {
parentID = block.getAfterBlockID();
}
//remove form widget and container
this.removeChildrenBlock(renderable, widget, container);