Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2010 itemis AG (http://www.itemis.eu) and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html /
 
 package org.eclipse.xtext.ui.editor.outline.impl;
 
import  org.eclipse.jface.resource.ImageDescriptor;
A fuzzy comparator used to restore the expansion of the outline tree after a change.

Author(s):
Jan Koehnlein - Initial contribution and API
public interface IOutlineNodeComparer {
	boolean equals(IOutlineNode node1IOutlineNode node2);
	class Default implements IOutlineNodeComparer {
		public boolean equals(IOutlineNode node1IOutlineNode node2) {
			if (node1 == null || node2 == null)
				return node1 == null && node2 == null;
			return node1.getClass() == node2.getClass() && equals(node1.getParent(), node2.getParent())
					&& equalsNullSafe(node1.getText().toString(), node2.getText().toString())
					&& equalsNullSafe(node1.getImage(), node2.getImage()) 
					&& isEquivalentIndex(node1node2);
		}
		protected boolean isEquivalentIndex(IOutlineNode node1IOutlineNode node2) {
			IOutlineNode parent1 = node1.getParent();
			IOutlineNode parent2 = node2.getParent();
			if (parent1 == null && parent2 == null)
				return true;
			if (parent1 != null && parent2 != null) {
				List<IOutlineNodesiblings1 = parent1.getChildren();
				List<IOutlineNodesiblings2 = parent2.getChildren();
				int index1 = siblings1.indexOf(node1);
				int index2 = siblings2.indexOf(node2);
				// same siblings =>  same index
				// sibling inserted after => same index
				// sibling inserted before => same # of following siblings
				if (index1 == index2 || siblings1.size() - index1 == siblings2.size() - index2)
					return true;
			}
			return false;
		}

Since:
2.4
		protected ImageDescriptor getImageDescriptor(IOutlineNode node) {
			return (node instanceof IOutlineNode.Extension
null;
		}
		protected boolean equalsNullSafe(Object o1Object o2) {
			return (o1 == null) ? o2 == null : o1.equals(o2);
		}
	}
New to GrepCode? Check out our FAQ X