Example #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();
    }
  }
Example #2
0
  /**
   * @param e parameter
   * @see
   *     org.scilab.modules.graph.actions.base.DefaultAction#actionPerformed(java.awt.event.ActionEvent)
   */
  @Override
  public void actionPerformed(ActionEvent e) {
    final XcosDiagram graph = (XcosDiagram) getGraph(e);

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

    graph.info(XcosMessages.EXPORT_IN_PROGRESS);

    final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
    if (handler == null) {
      return;
    }
    (new SwingWorker<Void, Void>() {

          @Override
          protected Void doInBackground() {
            try {
              handler.writeDiagram(((XcosDiagram) getGraph(null)));
              ((XcosDiagram) getGraph(null)).setReadOnly(true);
            } catch (Exception e) {
              cancel(true);
            }
            return null;
          }

          @Override
          protected void done() {
            if (isCancelled()) {
              graph.info(XcosMessages.EMPTY_INFO);

              handler.release();
              return;
            }

            graph.info(XcosMessages.COMPILATION_IN_PROGRESS);
            String cmd = "cpr = xcos_compile(scs_m);";

            final ActionListener action =
                new ActionListener() {
                  @Override
                  public void actionPerformed(ActionEvent e) {
                    graph.setReadOnly(false);
                    graph.info(XcosMessages.EMPTY_INFO);

                    handler.release();
                  }
                };

            try {
              ScilabInterpreterManagement.asynchronousScilabExec(action, cmd);
            } catch (InterpreterException e) {
              Logger.getLogger(CompileAction.class.getName()).severe(e.toString());

              handler.release();
            }
          }
        })
        .execute();
  }