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
* <p>
     * This method should be called (by the content provider) when elements
     * have been added to the model, in order to cause the viewer to accurately
     * reflect the model. This method only affects the viewer, not the model.
     * </p>
     * 
     * @param parentElementOrTreePath
     *           the parent element
     * @param childElements
     *           the child elements to add
     */
    public void add(Object parentElementOrTreePath, Object[] childElements) {
        Assert.isNotNull(parentElementOrTreePath);
        assertElementsNotNull(childElements);
        Widget[] widgets = internalFindItems(parentElementOrTreePath);
        
        if (widgets.length == 0) {
			return;
		}
		for (int i = 0; i < widgets.length; i++) {
			internalAdd(widgets[i], parentElementOrTreePath, childElements);
		}        
    }
    /**
     * Find the items for the given element of tree path
     * @param parentElementOrTreePath the element or tree path
     * @return the items for that element
     */
	private Widget[] internalFindItems(Object parentElementOrTreePath) {
		Widget[] widgets = findItems(parentElementOrTreePath);