Bug 138608 [Viewers] JFace AbstractTreeViewer: itemExists doesn't handle equal tree entries
I use a TreeViewer with - setUseHashLookup(true) - without any sorter or filter - with a comparer When I try to add an object that is equal to an existing entry in the tree, it will not be added. This is because the method private boolean itemExists(Item[] items, Object element) { if(usingElementMap()) { return findItem(element) != null; } for (int i = 0; i < items.length; i++) { if(items[i].getData().equals(element)) { return true; } } return false; } takes a shortcut if there is an element map, but the shortcut doesn't handle the 'multiple equal elements' case. There is a workaround, however: Setting a dummy sorter will avoid the call to itemExists and multiple equal elements can be added to the tree.
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractTreeViewer.java
* Return the tree path that should be used as the parent path for the
     * given widget and sorter. A <code>null</code> is returned if either
     * the sorter is not a {@link TreePathViewerSorter} or if the parent
     * widget is not an {@link Item} (i.e. is the root of the tree).
     * 
     * @param parent the parent widget
     * @param sorter the sorter
     * @return the tree path that should be used as the parent path for the
     * given widget and sorter
     */
	private TreePath internalGetSorterParentPath(Widget parent, ViewerComparator comparator) {
		TreePath path;
		if (comparator instanceof TreePathViewerSorter && parent instanceof Item) {
			Item item = (Item) parent;
			path = getTreePathFromItem(item);
		} else {
			path = null;
		}
		return path;
	}
	/**
	 * Compare the two elements using the given sorter. If the
	 * sorter is a {@link TreePathViewerSorter}, the provided
	 * tree path will be used. If the tree path is null and the
	 * sorter is a tree path sorter, then the elements are root elements
	 * @param sorter the sorter
	 * @param parentPath the path of the elements' parent
	 * @param e1 the first element
	 * @param e2 the seocnd element
	 * @return the result of comparing the two elements