void listCommands() {
    if (ServiceManager.Current != null) {
      Scriptable scope = ServiceManager.Current.getScope();

      Object[] objs = scope.getIds();

      for (int i = 0; i < objs.length; i++) {
        Object obj = objs[i];

        try {
          int pos = commanddoc.getLength();

          commanddoc.insertString(pos, obj.toString() + "\n", responseStyle);
        } catch (BadLocationException ex) {
          Exceptions.printStackTrace(ex);
        }
      }
    }
  }
  void sendCommand() {
    {
      String command = editCommand.getText();

      if (command != null && !command.isEmpty()) {
        // attempt to execute the command
        if (m_context == null) {
          m_context = Context.enter();
          // m_scope = m_context.initStandardObjects();

          // load up all services
          if (ServiceManager.Current != null) ServiceManager.Current.applyServices(m_context);
        }

        if (command.equals("?")) {
          listCommands();
          editCommand.setText("");
          return;
        }

        try {
          int pos = commanddoc.getLength();

          commanddoc.insertString(pos, command + "\n", commandStyle);

          Object ret =
              m_context.evaluateString(
                  ServiceManager.Current.getScope(), command, "Script", 1, null);

          // commands that succeed will be placed in the command list
          m_commandHistory.add(command);
          m_commandIndex = m_commandHistory.size();

          if (ret != null) {
            pos = commanddoc.getLength();

            commanddoc.insertString(pos, ret.toString() + "\n", responseStyle);
          }
        } catch (EcmaError ee) {
          try {
            int pos = commanddoc.getLength();

            commanddoc.insertString(pos, ee.details() + "\n", errorStyle);
          } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
          }

          ee.details();
        } catch (Exception ex) {
          int pos = commanddoc.getLength();

          try {
            commanddoc.insertString(pos, ex.getMessage() + "\n", errorStyle);
          } catch (BadLocationException ex1) {
            Exceptions.printStackTrace(ex1);
          }
        }

        editCommand.setText("");
      }
    }
  }