예제 #1
0
  /**
   * @param childBlock
   * @param widget
   * @requires widget != null
   * @modifies
   * @effects Does nothing if: childBlock is invalid (null) Otherwise, remove childBlock from it's
   *     parent block if the childBlock has a parent. If it does not have a parent, do nothing.
   */
  private void disconnectBlock(Block childBlock, WorkspaceWidget widget) {
    if (childBlock == null || invalidBlockID(childBlock.getBlockID())) {
      return;
    }
    BlockConnector childPlug = BlockLinkChecker.getPlugEquivalent(childBlock);
    if (childPlug == null || !childPlug.hasBlock() || isNullBlockInstance(childPlug.getBlockID())) {
      return;
    }
    Block parentBlock = workspace.getEnv().getBlock(childPlug.getBlockID());
    BlockConnector parentSocket = parentBlock.getConnectorTo(childBlock.getBlockID());
    if (parentSocket == null) {
      return;
    }
    // disconector if child connector exists and has a block connected to it
    BlockLink link =
        BlockLink.getBlockLink(workspace, childBlock, parentBlock, childPlug, parentSocket);
    if (link == null) {
      return;
    }

    link.disconnect();

    RenderableBlock parentRenderable =
        workspace.getEnv().getRenderableBlock(parentBlock.getBlockID());
    if (parentRenderable == null) {
      throw new RuntimeException(
          "INCONSISTANCY VIOLATION: "
              + "parent block was valid, non-null, and existed.\n\tBut yet, when we get it's renderable"
              + "representation, we recieve a null instance.\n\tIf the Block instance of an ID is non-null"
              + "then its graphical RenderableBlock should be non-null as well");
    }
    parentRenderable.blockDisconnected(parentSocket);
    workspace.notifyListeners(
        new WorkspaceEvent(workspace, widget, link, WorkspaceEvent.BLOCKS_DISCONNECTED));
  }
예제 #2
0
 /**
  * @param renderable
  * @param widget
  * @param container
  * @requires renderable != null && renderable.blockID != null && renderable.blockID != Block.NULL
  *     && widget != null && container != null
  * @modifies renderable && children blocks connected to renderable
  * @effects removes renderable from container and widget and re-renders renderable block, widget,
  *     and container appropriately. Repeats for all of renderable's children.
  */
 private void removeBlock(
     RenderableBlock renderable, WorkspaceWidget widget, Container container) {
   widget.removeBlock(renderable);
   container.remove(renderable);
   container.validate();
   container.repaint();
   renderable.setParentWidget(null);
   // Workspace.getInstance().notifyListeners(new WorkspaceEvent(widget, renderable.getBlockID(),
   // WorkspaceEvent.BLOCK_REMOVED));
   for (BlockConnector child :
       BlockLinkChecker.getSocketEquivalents(
           workspace.getEnv().getBlock(renderable.getBlockID()))) {
     if (child == null || child.getBlockID().equals(Block.NULL)) {
       continue;
     }
     RenderableBlock childRenderable = workspace.getEnv().getRenderableBlock(child.getBlockID());
     if (childRenderable == null) {
       continue;
     }
     removeBlock(childRenderable, widget, container);
   }
   if (renderable.hasComment()) {
     renderable.removeComment();
   }
   workspace.notifyListeners(
       new WorkspaceEvent(
           workspace, widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
 }
예제 #3
0
 /**
  * Checks if a connection is a valid and ACTIVE connection.
  *
  * @param connection - BlockConnector in question
  * @requires none
  * @return true if and only if connection != null && connection.hasBlock() == true
  */
 private boolean validConnection(BlockConnector connection) {
   if (connection != null) {
     Long blockID = connection.getBlockID();
     if (!isNullBlockInstance(blockID)) {
       if (connection.hasBlock()) {
         return true;
       }
     }
   }
   return false;
 }
예제 #4
0
 private void removeChildrenBlock(
     RenderableBlock renderable, WorkspaceWidget widget, Container container) {
   widget.removeBlock(renderable);
   container.remove(renderable);
   container.validate();
   container.repaint();
   renderable.setParentWidget(null);
   // Workspace.getInstance().notifyListeners(new WorkspaceEvent(widget, renderable.getBlockID(),
   // WorkspaceEvent.BLOCK_REMOVED));
   for (BlockConnector child : workspace.getEnv().getBlock(renderable.getBlockID()).getSockets()) {
     if (child == null || child.getBlockID().equals(Block.NULL)) {
       continue;
     }
     RenderableBlock childRenderable = workspace.getEnv().getRenderableBlock(child.getBlockID());
     if (childRenderable == null) {
       continue;
     }
     removeBlock(childRenderable, widget, container);
   }
   // If it is a procedure block, we want to delete the entire stack
   if (workspace.getEnv().getBlock(renderable.getBlockID()).isProcedureDeclBlock()) {
     if (workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID() != Block.NULL) {
       removeAfterBlock(
           workspace
               .getEnv()
               .getRenderableBlock(
                   workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID()),
           widget,
           container);
       this.disconnectBlock(
           workspace
               .getEnv()
               .getBlock(workspace.getEnv().getBlock(renderable.getBlockID()).getAfterBlockID()),
           widget);
     }
   }
   if (renderable.hasComment()) {
     renderable.removeComment();
   }
   workspace.notifyListeners(
       new WorkspaceEvent(
           workspace, widget, renderable.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
 }
예제 #5
0
 public static BlockNode makeNodeWithChildren(Long blockID) {
   if (isNullBlockInstance(blockID)) {
     return null;
   }
   Block block = Block.getBlock(blockID);
   String genus = block.getGenusName();
   String parentGenus = block instanceof BlockStub ? ((BlockStub) block).getParentGenus() : null;
   String label;
   if (!block.labelMustBeUnique() || block instanceof BlockStub) {
     label = block.getBlockLabel();
   } else {
     label = null;
   }
   BlockNode node = new BlockNode(genus, parentGenus, label);
   for (BlockConnector socket : block.getSockets()) {
     if (socket.hasBlock()) {
       node.addChild(makeNodeWithStack(socket.getBlockID()));
     }
   }
   return node;
 }