Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public void actionPerformed(ActionEvent e) {
    final XcosDiagram parentGraph = (XcosDiagram) getGraph(e);

    // action disabled when the cell is edited
    final ScilabComponent comp = ((ScilabComponent) parentGraph.getAsComponent());
    if (comp.isEditing()) {
      return;
    }

    parentGraph.info(XcosMessages.GENERATE_SUPERBLOCK);
    parentGraph.getModel().beginUpdate();
    try {

      final SuperBlock superBlock;
      final Collection<Broken> brokenLinks;
      final Set<Object> inSelectionCells;

      /*
       * Allocate superBlock
       */
      final Object[] selection = parentGraph.getSelectionCells();
      final Object[] blocks = XcosDiagram.filterByClass(selection, BasicBlock.class);
      inSelectionCells = new LinkedHashSet<Object>(Arrays.asList(blocks));

      superBlock = allocateSuperBlock(parentGraph, selection);

      /*
       * First perform all modification on the parent diagram to handle
       * well undo/redo operations.
       */
      brokenLinks = updateParent(parentGraph, superBlock, inSelectionCells);

      /*
       * Then move some cells to the child diagram
       */
      final SuperBlockDiagram childGraph =
          moveToChild(parentGraph, superBlock, brokenLinks, inSelectionCells);

      /*
       * Finish the install on the child and sync it.
       */
      childGraph.installListeners();
      childGraph.installSuperBlockListeners();
      superBlock.invalidateRpar();

      Xcos.getInstance().addDiagram(parentGraph.getSavedFile(), childGraph);
    } finally {
      parentGraph.getModel().endUpdate();
      parentGraph.info(XcosMessages.EMPTY_INFO);
    }
  }