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
protected abstract Item[] getChildren(Widget widget);
	
	/**
	 * Get the child for the widget at index. Note that the default
	 * implementation is not very effecient and should be overridden
	 * if this class is implemented.
	 * @param widget the widget to check
	 * @param index the index of the widget
	 * @return Item or <code>null</code> if widget is not a type
	 * that can contain items.
     *
	 * @throws ArrayIndexOutOfBoundsException if the index is not valid.
     * @since 3.1
	 */
    protected Item getChild (Widget widget, int index) {
		return getChildren(widget)[index];
    }
    /**
     * Returns whether the given SWT item is expanded or collapsed.
     * 
     * @param item
     *           the item
     * @return <code>true</code> if the item is considered expanded and
     *         <code>false</code> if collapsed
     */
    protected abstract boolean getExpanded(Item item);
    /**
     * Returns a list of elements corresponding to expanded nodes in this
     * viewer's tree, including currently hidden ones that are marked as
     * expanded but are under a collapsed ancestor.