From b0d5cfee9dbbd164a7c3bdf933453b4b949c2f76 Mon Sep 17 00:00:00 2001 From: Craig Otis Date: Fri, 20 May 2016 15:25:17 -0400 Subject: [PATCH] Implements the equals() and hashCode() methods of WizardCollectionElement, comparing/including the id, pluginId, and name properties of the instances. This alleviates a bug (439299) in which WCE instances were being refreshed in a TreeViewer, and due to the lack of these implementations, were not maintaining their collapsed/expanded status. Signed-off-by: Craig Otis --- .../internal/dialogs/WizardCollectionElement.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java index 3a94318..266e1a4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/WizardCollectionElement.java @@ -8,12 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation * Jan-Hendrik Diederich, Bredex GmbH - bug 201052 + * Craig Otis - bug 439299 *******************************************************************************/ package org.eclipse.ui.internal.dialogs; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IPath; @@ -311,6 +313,40 @@ public class WizardCollectionElement extends AdaptableList implements IPluginCon return size() == 0 && wizards.size() == 0; } + /** + * A shallow equals based only on stored string properties. Child wizards or + * children inherited from AdaptableList are not compared. + * + * See: Bug 439299 + * + * @author Craig Otis + */ + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof WizardCollectionElement)) { + return false; + } + WizardCollectionElement other = (WizardCollectionElement) obj; + return Objects.equals(this.getId(), other.getId()) && Objects.equals(this.name, other.name) + && Objects.equals(this.getPluginId(), other.getPluginId()); + } + + /** + * A shallow hashCode based only on stored string properties. Child wizards + * or children inherited from AdaptableList are not included. + * + * See: Bug 439299 + * + * @author Craig Otis + */ + @Override + public int hashCode() { + return Objects.hash(getId(), this.name, getPluginId()); + } + /** * For debugging purposes. */ -- 2.7.2.windows.1