void CommandManager::SetHandlersByCommandId(const std::map<std::string, SmartPointer<IHandler> >& handlersByCommandId) {
    // Make that all the reference commands are created.
    for (std::map<std::string, SmartPointer<IHandler> >::const_iterator commandItr = handlersByCommandId.begin();
         commandItr != handlersByCommandId.end(); ++commandItr)
    {
      this->GetCommand(commandItr->first);
    }

    // Now, set-up the handlers on all of the existing commands.
    for (HandleObjectsByIdMap::Iterator commandItr = handleObjectsById.begin();
         commandItr != handleObjectsById.end(); ++commandItr)
    {
      const Command::Pointer command(commandItr->second.Cast<Command>());
      const std::string commandId(command->GetId());
      std::map<std::string, SmartPointer<IHandler> >::const_iterator handlerItr = handlersByCommandId.find(commandId);
      if (handlerItr != handlersByCommandId.end())
      {
        command->SetHandler(handlerItr->second);
      }
      else
      {
        command->SetHandler(IHandler::Pointer(0));
      }
    }
  }
  void CommandManager::CommandListener::CommandChanged(const SmartPointer<const CommandEvent> commandEvent) {
    if (commandEvent->IsDefinedChanged()) {
      const Command::Pointer command(commandEvent->GetCommand());
      const std::string commandId = command->GetId();
      const bool commandIdAdded = command->IsDefined();
      if (commandIdAdded) {
        commandManager->definedHandleObjects.insert(command);
      } else {
        commandManager->definedHandleObjects.erase(command);
      }
      CommandManagerEvent::Pointer event(new CommandManagerEvent(*commandManager,
            commandId, commandIdAdded, true, "", false, false));
        commandManager->FireCommandManagerChanged(event);

    }
  }