/**
   * Removes the resource changed listener to the managed method library resource and method
   * plug-ins.
   */
  protected void removeResourceChangedListeners() {
    if (library == null || library.eResource() == null) {
      return;
    }

    library.eResource().eAdapters().remove(resourceChangedListener);

    for (Iterator iter = library.getMethodPlugins().iterator(); iter.hasNext(); ) {
      MethodPlugin plugin = (MethodPlugin) iter.next();
      plugin.eResource().eAdapters().remove(resourceChangedListener);
    }

    for (Iterator it = library.getPredefinedConfigurations().iterator(); it.hasNext(); ) {
      MethodConfiguration config = (MethodConfiguration) it.next();
      config.eResource().eAdapters().remove(resourceChangedListener);
    }
  }
  /** Adds a resource changed listener to the managed method library resources. */
  protected void addResourceChangedListeners() {
    if (library == null || library.eResource() == null) {
      return;
    }

    if (!library.eResource().eAdapters().contains(resourceChangedListener)) {
      library.eResource().eAdapters().add(resourceChangedListener);
    }

    for (Iterator it = library.getMethodPlugins().iterator(); it.hasNext(); ) {
      MethodPlugin plugin = (MethodPlugin) it.next();
      if (!plugin.eResource().eAdapters().contains(resourceChangedListener)) {
        plugin.eResource().eAdapters().add(resourceChangedListener);
      }
    }

    for (Iterator it = library.getPredefinedConfigurations().iterator(); it.hasNext(); ) {
      MethodConfiguration config = (MethodConfiguration) it.next();
      if (!config.eResource().eAdapters().contains(resourceChangedListener)) {
        config.eResource().eAdapters().add(resourceChangedListener);
      }
    }
  }
  /** Fixes the imported library's system package guids with those base's. */
  public static void fixImportLibrarySystemPackageGUIDs(
      MethodLibrary baseLibrary, MethodLibrary importLibraty) {
    HashMap pluginsMap = new HashMap();
    List plugins = baseLibrary.getMethodPlugins();
    for (int i = 0; i < plugins.size(); i++) {
      MethodPlugin plugin = (MethodPlugin) plugins.get(i);
      pluginsMap.put(plugin.getGuid(), plugin);
    }
    if (pluginsMap.isEmpty()) {
      return;
    }

    List importPluginsToFix = new ArrayList();
    List importPlugins = importLibraty.getMethodPlugins();
    for (int i = 0; i < importPlugins.size(); i++) {
      MethodPlugin plugin = (MethodPlugin) importPlugins.get(i);
      if (pluginsMap.containsKey(plugin.getGuid())) {
        importPluginsToFix.add(plugin);
      }
    }

    for (int i = 0; i < importPluginsToFix.size(); i++) {
      MethodPlugin importPlugin = (MethodPlugin) importPluginsToFix.get(i);
      MethodPlugin basePlugin = (MethodPlugin) pluginsMap.get(importPlugin.getGuid());
      if (basePlugin == null) {
        continue;
      }
      List importPackages = TngUtil.getAllSystemPackages(importPlugin);
      HashMap importPackageMap = new HashMap();
      for (int j = 0; j < importPackages.size(); j++) {
        MethodElement importPackage = (MethodElement) importPackages.get(j);
        importPackageMap.put(importPackage.getName(), importPackage);
      }

      List basePackages = TngUtil.getAllSystemPackages(basePlugin);
      for (int j = 0; j < basePackages.size(); j++) {
        MethodElement basePackage = (MethodElement) basePackages.get(j);
        MethodElement importPackage = (MethodElement) importPackageMap.get(basePackage.getName());
        if (importPackage == null) {
          continue;
        }
        String guid = basePackage.getGuid();
        if (!importPackage.getGuid().equals(guid)) {
          importPackage.setGuid(guid);
        }
      }
    }
  }