Exemple #1
0
  @Override
  public void actionPerformed(ActionEvent e) {
    final XcosDiagram graph = (XcosDiagram) getGraph(e);
    final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
    if (handler == null) {
      return;
    }

    final BasicBlock block;
    final ActionListener callback;
    try {
      /*
       * Export the whole diagram, to update all the sub-diagrams on demand.
       */
      handler.writeDiagram(graph.getRootDiagram());

      /*
       * Then export the selected block
       */
      Object cell = graph.getSelectionCell();
      if (cell instanceof BasicBlock) {
        block = (BasicBlock) cell;
        handler.writeBlock(block);
      } else {
        block = null;
      }

      /*
       * Import the updated block
       */
      if (block != null) {
        callback =
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                try {

                  final BasicBlock modifiedBlock = handler.readBlock();
                  block.updateBlockSettings(modifiedBlock);

                  graph.fireEvent(
                      new mxEventObject(
                          XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, block));
                } catch (ScicosFormatException e1) {
                  LOG.severe(e1.getMessage());
                } finally {
                  handler.release();
                }
              }
            };
      } else {
        callback =
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                handler.release();
              }
            };
      }

      ScilabInterpreterManagement.asynchronousScilabExec(callback, localCommand);
    } catch (InterpreterException e2) {
      LOG.warning(e2.toString());

      handler.release();
    }
  }