public ViewerDescriptor[] findStructureViewerDescriptor(
      Viewer oldViewer, ICompareInput input, CompareConfiguration configuration) {
    if (input == null) return null;
    // we don't show the structure of additions or deletions
    if (input == null || input.getLeft() == null || input.getRight() == null) return null;

    Set result = new LinkedHashSet();

    // content type search
    IContentType ctype = getCommonType(input);
    if (ctype != null) {
      initializeRegistries();
      List list = fStructureMergeViewers.searchAll(ctype);
      if (list != null) result.addAll(list);
    }

    // old style search
    String[] types = getTypes(input);
    String type = null;
    if (isHomogenous(types)) {
      type = normalizeCase(types[0]);
      initializeRegistries();
      List list = fStructureMergeViewers.searchAll(type);
      if (list != null) result.addAll(list);
      String alias = getStructureViewerAlias(type);
      if (alias != null) {
        list = fStructureMergeViewers.searchAll(alias);
        if (list != null) result.addAll(list);
      }
    }

    return result.size() > 0 ? (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]) : null;
  }
  String findStructureTypeNameOrType(
      ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) {
    if (input == null) return null;
    // we don't show the structure of additions or deletions
    if (input == null || input.getLeft() == null || input.getRight() == null) return null;

    // content type search
    IContentType ctype = getCommonType(input);
    if (ctype != null) {
      initializeRegistries();
      List list = fStructureMergeViewers.searchAll(ctype);
      if (list != null) if (list.contains(vd)) return ctype.getName();
    }

    // old style search
    String[] types = getTypes(input);
    String type = null;
    if (isHomogenous(types)) {
      type = normalizeCase(types[0]);
      initializeRegistries();
      List list = fStructureMergeViewers.searchAll(type);
      if (list != null) if (list.contains(vd)) return type;
      String alias = getStructureViewerAlias(type);
      if (alias != null) {
        list = fStructureMergeViewers.searchAll(alias);
        if (list != null) if (list.contains(vd)) return alias;
      }
    }

    return null;
  }
  String findContentTypeNameOrType(
      ICompareInput input, ViewerDescriptor vd, CompareConfiguration cc) {
    IContentType ctype = getCommonType(input);
    if (ctype != null) {
      initializeRegistries();
      List list = fContentMergeViewers.searchAll(ctype);
      if (list != null) if (list.contains(vd)) return ctype.getName();
    }

    String[] types = getTypes(input);
    String type = null;
    if (isHomogenous(types)) type = types[0];

    if (ITypedElement.FOLDER_TYPE.equals(type)) return null;

    if (type == null) {
      int n = 0;
      for (int i = 0; i < types.length; i++)
        if (!ITypedElement.UNKNOWN_TYPE.equals(types[i])) {
          n++;
          if (type == null) type = types[i]; // remember the first known type
        }
      if (n > 1) // don't use the type if there were more than one
      type = null;
    }

    if (type != null) {
      initializeRegistries();
      List list = fContentMergeViewers.searchAll(type);
      if (list != null) if (list.contains(vd)) return type;
    }

    // fallback
    String leftType = guessType(input.getLeft());
    String rightType = guessType(input.getRight());

    if (leftType != null || rightType != null) {
      boolean right_text = rightType != null && ITypedElement.TEXT_TYPE.equals(rightType);
      boolean left_text = leftType != null && ITypedElement.TEXT_TYPE.equals(leftType);
      initializeRegistries();
      if ((rightType != null && !right_text) || (leftType != null && !left_text)) {
        List list = fContentMergeViewers.searchAll(BINARY_TYPE);
        if (list != null) if (list.contains(vd)) return type;
      }
      List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
      if (list != null) if (list.contains(vd)) return type;
    }
    return null;
  }
  /**
   * Returns a structure compare viewer based on an old viewer and an input object. If the old
   * viewer is suitable for showing the input, the old viewer is returned. Otherwise, the input's
   * type is used to find a viewer descriptor in the registry which in turn is used to create a
   * structure compare viewer under the given parent composite. If no viewer descriptor can be found
   * <code>null</code> is returned.
   *
   * @param oldViewer a new viewer is only created if this old viewer cannot show the given input
   * @param input the input object for which to find a structure viewer
   * @param parent the SWT parent composite under which the new viewer is created
   * @param configuration a configuration which is passed to a newly created viewer
   * @return the compare viewer which is suitable for the given input object or <code>null</code>
   */
  public Viewer findStructureViewer(
      Viewer oldViewer, ICompareInput input, Composite parent, CompareConfiguration configuration) {
    ViewerDescriptor[] descriptors = findStructureViewerDescriptor(oldViewer, input, configuration);
    if (descriptors == null || descriptors.length == 0) {
      // we didn't found any viewer so far.
      // now we try to find a structure creator for the generic StructureDiffViewer
      IContentType ctype = getCommonType(input);

      String[] types = getTypes(input);
      String type = null;
      if (isHomogenous(types)) {
        type = normalizeCase(types[0]);
      }

      StructureCreatorDescriptor scc = null;
      initializeRegistries();
      Object desc = fStructureCreators.search(ctype); // search for content type
      if (desc instanceof StructureCreatorDescriptor) scc = (StructureCreatorDescriptor) desc;
      if (scc == null && type != null)
        scc = getStructureCreator(type); // search for old-style type scheme
      if (scc != null) {
        IStructureCreator sc = scc.createStructureCreator();
        if (sc != null) {
          StructureDiffViewer sdv = new StructureDiffViewer(parent, configuration);
          sdv.setStructureCreator(sc);
          return sdv;
        }
      }
      return null;
    }
    return getViewer(descriptors[0], oldViewer, parent, configuration);
  }
  public ViewerDescriptor[] findContentViewerDescriptor(
      Viewer oldViewer, Object in, CompareConfiguration cc) {
    Set result = new LinkedHashSet();
    if (in instanceof IStreamContentAccessor) {
      String type = ITypedElement.TEXT_TYPE;

      if (in instanceof ITypedElement) {
        ITypedElement tin = (ITypedElement) in;

        IContentType ct = getContentType(tin);
        if (ct != null) {
          initializeRegistries();
          List list = fContentViewers.searchAll(ct);
          if (list != null) result.addAll(list);
        }

        String ty = tin.getType();
        if (ty != null) type = ty;
      }

      initializeRegistries();
      List list = fContentViewers.searchAll(type);
      if (list != null) result.addAll(list);
      // fallback
      result.add(
          fContentViewers.search(
              Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT)));
      return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
    }

    if (!(in instanceof ICompareInput)) return null;

    ICompareInput input = (ICompareInput) in;

    IContentType ctype = getCommonType(input);
    if (ctype != null) {
      initializeRegistries();
      List list = fContentMergeViewers.searchAll(ctype);
      if (list != null) result.addAll(list);
    }

    String[] types = getTypes(input);
    String type = null;
    if (isHomogenous(types)) type = types[0];

    if (ITypedElement.FOLDER_TYPE.equals(type)) return null;

    if (type == null) {
      int n = 0;
      for (int i = 0; i < types.length; i++)
        if (!ITypedElement.UNKNOWN_TYPE.equals(types[i])) {
          n++;
          if (type == null) type = types[i]; // remember the first known type
        }
      if (n > 1) // don't use the type if there were more than one
      type = null;
    }

    if (type != null) {
      initializeRegistries();
      List list = fContentMergeViewers.searchAll(type);
      if (list != null) result.addAll(list);
    }

    // fallback
    String leftType = guessType(input.getLeft());
    String rightType = guessType(input.getRight());

    if (leftType != null || rightType != null) {
      boolean right_text = rightType != null && ITypedElement.TEXT_TYPE.equals(rightType);
      boolean left_text = leftType != null && ITypedElement.TEXT_TYPE.equals(leftType);
      initializeRegistries();
      if ((rightType != null && !right_text) || (leftType != null && !left_text)) {
        List list = fContentMergeViewers.searchAll(BINARY_TYPE);
        if (list != null) result.addAll(list);
      }
      List list = fContentMergeViewers.searchAll(ITypedElement.TEXT_TYPE);
      if (list != null) result.addAll(list);

      return (ViewerDescriptor[]) result.toArray(new ViewerDescriptor[0]);
    }
    return null;
  }
 /**
  * Returns a stream merger for the given content type.
  *
  * @param type the type for which to find a stream merger
  * @return a stream merger for the given type, or <code>null</code> if no stream merger has been
  *     registered
  */
 public IStreamMerger createStreamMerger(IContentType type) {
   initializeRegistries();
   StreamMergerDescriptor descriptor = (StreamMergerDescriptor) fStreamMergers.search(type);
   if (descriptor != null) return descriptor.createStreamMerger();
   return null;
 }
 /**
  * Returns an structure creator descriptor for the given type.
  *
  * @param type the type for which to find a descriptor
  * @return a descriptor for the given type, or <code>null</code> if no descriptor has been
  *     registered
  */
 public StructureCreatorDescriptor getStructureCreator(String type) {
   initializeRegistries();
   return (StructureCreatorDescriptor) fStructureCreators.search(type);
 }