Ejemplo n.º 1
0
  public void workspaceEventOccurred(WorkspaceEvent event) {
    // THIS ENTIRE METHOD IS A HACK!
    // PLEASE CHANGE WITH CAUTION
    // IT DOES SOME PREETY STRANGE THINGS
    if (event.getEventType() == WorkspaceEvent.BLOCK_ADDED) {
      if (event.getSourceWidget() instanceof Page) {
        Page page = (Page) event.getSourceWidget();
        Block block = Block.getBlock(event.getSourceBlockID());
        // block may not be null if this is a block added event
        if (block.hasStubs()) {
          for (BlockStub stub : block.getFreshStubs()) {
            this.addDynamicBlock(
                new FactoryRenderableBlock(this, stub.getBlockID()), page.getPageDrawer());
          }
        }
      }
    } else if (event.getEventType() == WorkspaceEvent.BLOCK_REMOVED) {
      // may not be removing a null stanc eof block, so DO NOT check for it
      Block block = Block.getBlock(event.getSourceBlockID());
      if (block.hasStubs()) {
        for (Long stub : BlockStub.getStubsOfParent(block.getBlockID())) {
          RenderableBlock rb = RenderableBlock.getRenderableBlock(stub);
          if (rb != null
              && !rb.getBlockID().equals(Block.NULL)
              && rb.getParentWidget() != null
              && rb.getParentWidget().equals(this)) {
            // rb.getParent() should not be null
            rb.getParent().remove(rb);
            rb.setParentWidget(null);
          }
        }
      }
      this.relayoutBlocks();
    } else if (event.getEventType() == WorkspaceEvent.BLOCK_MOVED) {
      Block block = Block.getBlock(event.getSourceBlockID());
      if (block != null && block.hasStubs()) {
        for (Long stub : BlockStub.getStubsOfParent(block.getBlockID())) {
          RenderableBlock rb = RenderableBlock.getRenderableBlock(stub);
          if (rb != null
              && !rb.getBlockID().equals(Block.NULL)
              && rb.getParentWidget() != null
              && rb.getParentWidget().equals(this)) {
            // rb.getParent() should not be null
            rb.getParent().remove(rb);
            rb.setParentWidget(null);
          }
        }
        this.relayoutBlocks();
      }

    } else if (event.getEventType() == WorkspaceEvent.PAGE_RENAMED) {
      // this.relayoutBlocks();
    }
  }
Ejemplo n.º 2
0
  public void blockDropped(RenderableBlock block) {
    // remove block
    WorkspaceWidget oldParent = block.getParentWidget();
    if (oldParent != null) oldParent.removeBlock(block);

    Container parent = block.getParent();
    if (parent != null) {
      parent.remove(block);
      parent.validate();
      parent.repaint();
      block.setParentWidget(null);
    }

    // fire to workspace that block was removed
    // DO FIRE AN EVENT IF BLOCK IS REMOVED BY USER!!!!
    // NOTE however that we do not throw na event for adding internally
    Workspace.getInstance()
        .notifyListeners(
            new WorkspaceEvent(this, block.getBlockID(), WorkspaceEvent.BLOCK_REMOVED));
  }