public void buildTree() {
    for (int i = 0; i < oldExpressions.size(); i++) {
      final Expression oldExpression = oldExpressions.get(i);
      CompareScript left = new CompareScript(oldExpression.getName(), oldExpression);
      left.setElement(oldExpression);
      left.setImage(adapterFactoryLabelProvider.getImage(oldExpression));
      final Expression newExpression = newExpressions.get(i);

      final CompareScript right = new CompareScript(newExpression.getName(), newExpression);
      right.setElement(newExpression);
      right.addContentChangeListener(
          new IContentChangeListener() {

            @Override
            public void contentChanged(IContentChangeNotifier compareScript) {
              if (compareScript instanceof CompareScript) {
                setDirty(true);
                if (getViewer() == null || getViewer().getControl().isDisposed()) return;
                getViewer().refresh(true);
              }
            }
          });
      right.setImage(adapterFactoryLabelProvider.getImage(newExpression));
      DiffNode leaf = new DiffNode(null, Differencer.CHANGE, null, left, right);
      final DiffNode poolNode = buildPathNodes(oldExpression.eContainer(), leaf);
      if (((CompareScript) poolNode.getAncestor()).getElement() instanceof Pool
          && root.getChildren().length == 0) {
        root.add(poolNode);
      }
    }
  }
 private void getAllNodes(List<DiffNode> nodes, DiffNode root) {
   if (root.hasChildren()) {
     nodes.addAll((Collection<? extends DiffNode>) Arrays.asList(root.getChildren()));
     for (IDiffElement child : root.getChildren()) {
       getAllNodes(nodes, (DiffNode) child);
     }
   }
 }
 private boolean insertParentNode(DiffNode nodeToInsert) {
   List<DiffNode> nodes = new ArrayList<DiffNode>();
   getAllNodes(nodes, root);
   for (DiffNode node : nodes) {
     if (node.getAncestor() != null
         && ((CompareScript) node.getAncestor())
             .getElement()
             .equals(((CompareScript) nodeToInsert.getAncestor()).getElement())) {
       addChildrenToParent(node, nodeToInsert.getChildren());
       return true;
     }
   }
   return false;
 }
 private void flatDiffView(DiffNode rootNode, DiffNode currentNode) {
   if (currentNode != null) {
     IDiffElement[] dElems = currentNode.getChildren();
     if (dElems != null) {
       for (IDiffElement dElem : dElems) {
         DiffNode dNode = (DiffNode) dElem;
         if (dNode.getChildren() != null && dNode.getChildren().length > 0) {
           flatDiffView(rootNode, dNode);
         } else {
           rootNode.add(dNode);
         }
       }
     }
   }
 }
  private DiffNode addDirectoryFiles(ITypedElement elem, int diffType) {
    ITypedElement l = null;
    ITypedElement r = null;
    if (diffType == Differencer.DELETION) {
      r = elem;
    } else {
      l = elem;
    }

    if (elem.getType().equals(ITypedElement.FOLDER_TYPE)) {
      DiffNode diffNode = null;
      diffNode = new DiffNode(null, Differencer.CHANGE, null, l, r);
      ITypedElement[] children = (ITypedElement[]) ((IStructureComparator) elem).getChildren();
      for (ITypedElement child : children) {
        diffNode.add(addDirectoryFiles(child, diffType));
      }
      return diffNode;
    }
    return new DiffNode(diffType, null, l, r);
  }
  private DiffNode buildPathNodes(EObject container, DiffNode node) {
    DiffNode parentNode = new DiffNode(Differencer.NO_CHANGE);
    node.setParent(parentNode);
    parentNode.add(node);
    CompareScript ancestor = null;
    String name = adapterFactoryLabelProvider.getText(container);
    Expression expr = ExpressionHelper.createConstantExpression(name, String.class.getName());
    expr.setName(name);
    ancestor = new CompareScript(expr.getName(), expr);
    ancestor.setElement(container);
    ancestor.setImage(adapterFactoryLabelProvider.getImage(container));
    parentNode.setAncestor(ancestor);

    if (insertParentNode(parentNode)) {
      return parentNode;
    }
    if (container instanceof Pool) {
      return parentNode;
    }
    if (container instanceof ConnectorParameter) {
      return buildPathNodes(container.eContainer().eContainer(), parentNode);
    }
    return buildPathNodes(container.eContainer(), parentNode);
  }
 private void add(IDiffContainer result, String filePath, DiffNode diffNode) {
   IDiffContainer container = getFileParent(result, filePath);
   container.add(diffNode);
   diffNode.setParent(container);
 }
 private void addChildrenToParent(DiffNode parent, IDiffElement[] children) {
   for (IDiffElement child : children) {
     parent.add(child);
   }
 }
 private DiffNode compare(ITypedElement left, ITypedElement right) {
   if (left.getType().equals(ITypedElement.FOLDER_TYPE)) {
     // return new MyDiffContainer(null, left,right);
     DiffNode diffNode = new DiffNode(null, Differencer.CHANGE, null, left, right);
     ITypedElement[] lc = (ITypedElement[]) ((IStructureComparator) left).getChildren();
     ITypedElement[] rc = (ITypedElement[]) ((IStructureComparator) right).getChildren();
     int li = 0;
     int ri = 0;
     while (li < lc.length && ri < rc.length) {
       ITypedElement ln = lc[li];
       ITypedElement rn = rc[ri];
       int compareTo = ln.getName().compareTo(rn.getName());
       // TODO: Git ordering!
       if (compareTo == 0) {
         if (!ln.equals(rn)) diffNode.add(compare(ln, rn));
         ++li;
         ++ri;
       } else if (compareTo < 0) {
         DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, null, ln, null);
         diffNode.add(childDiffNode);
         if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
           ITypedElement[] children = (ITypedElement[]) ((IStructureComparator) ln).getChildren();
           if (children != null && children.length > 0) {
             for (ITypedElement child : children) {
               childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
             }
           }
         }
         ++li;
       } else {
         DiffNode childDiffNode = new DiffNode(Differencer.DELETION, null, null, rn);
         diffNode.add(childDiffNode);
         if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
           ITypedElement[] children = (ITypedElement[]) ((IStructureComparator) rn).getChildren();
           if (children != null && children.length > 0) {
             for (ITypedElement child : children) {
               childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
             }
           }
         }
         ++ri;
       }
     }
     while (li < lc.length) {
       ITypedElement ln = lc[li];
       DiffNode childDiffNode = new DiffNode(Differencer.ADDITION, null, ln, null);
       diffNode.add(childDiffNode);
       if (ln.getType().equals(ITypedElement.FOLDER_TYPE)) {
         ITypedElement[] children = (ITypedElement[]) ((IStructureComparator) ln).getChildren();
         if (children != null && children.length > 0) {
           for (ITypedElement child : children) {
             childDiffNode.add(addDirectoryFiles(child, Differencer.ADDITION));
           }
         }
       }
       ++li;
     }
     while (ri < rc.length) {
       ITypedElement rn = rc[ri];
       DiffNode childDiffNode = new DiffNode(Differencer.DELETION, null, null, rn);
       diffNode.add(childDiffNode);
       if (rn.getType().equals(ITypedElement.FOLDER_TYPE)) {
         ITypedElement[] children = (ITypedElement[]) ((IStructureComparator) rn).getChildren();
         if (children != null && children.length > 0) {
           for (ITypedElement child : children) {
             childDiffNode.add(addDirectoryFiles(child, Differencer.DELETION));
           }
         }
       }
       ++ri;
     }
     return diffNode;
   }
   return new DiffNode(left, right);
 }