mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-05 08:05:24 +02:00
[195537] Kevin's patch for Move ElementComparer From SystemView to Separate File
This commit is contained in:
parent
fa54878306
commit
ad2e9287a6
3 changed files with 75 additions and 68 deletions
|
@ -0,0 +1,69 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2007 IBM Corporation. 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
|
||||
*
|
||||
* Initial Contributors:
|
||||
* The following IBM employees contributed to the Remote System Explorer
|
||||
* component that contains this file: David McKnight, Kushal Munir,
|
||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* Kevin Doyle (IBM) - [195537] Move ElementComparer From SystemView to Separate File
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.ui.view;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jface.viewers.IElementComparer;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.core.model.ISystemRegistry;
|
||||
import org.eclipse.rse.ui.internal.model.SystemRegistry;
|
||||
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
|
||||
|
||||
public class ElementComparer implements IElementComparer
|
||||
{
|
||||
|
||||
public boolean equals(Object a, Object b)
|
||||
{
|
||||
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
|
||||
if (registry instanceof SystemRegistry)
|
||||
{
|
||||
return ((SystemRegistry) registry).isSameObjectByAbsoluteName(a, null, b, null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode(Object element)
|
||||
{
|
||||
ISystemViewElementAdapter ident=null;
|
||||
if(element instanceof IAdaptable) {
|
||||
ident = (ISystemViewElementAdapter)
|
||||
((IAdaptable)element).getAdapter(ISystemViewElementAdapter.class);
|
||||
if(ident!=null) {
|
||||
String absName = ident.getAbsoluteName(element);
|
||||
if(absName!=null) return absName.hashCode();
|
||||
//Since one adapter is typically used for many elements in RSE,
|
||||
//performance would be better if the original Element's hashCode
|
||||
//were used rather than the adapter's hashCode. The problem with
|
||||
//this is, that if the remote object changes, it cannot be
|
||||
//identified any more.
|
||||
//Note that even if the SAME object is modified during refresh
|
||||
//(so object a==b), the hashCode of the object can change
|
||||
//over time if properties are modified. Therefore, play it
|
||||
//safe and return the adapter's hashCode which won't ever change.
|
||||
return ident.hashCode();
|
||||
}
|
||||
}
|
||||
if (element != null) { // adding check because I hit a null exception here once at startup
|
||||
return element.hashCode();
|
||||
} else {
|
||||
//System.out.println("null element");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@
|
|||
* Kevin Doyle (IBM) - [194602] handleDoubleClick does expand/collapse on treepath instead of element
|
||||
* David McKnight (IBM) - [194897] Should not remote refresh objects above subsystem.
|
||||
* Kevin Doyle - [193380] Deleting connection Refresh's Entire Remote Systems view
|
||||
* Kevin Doyle - [195537] Move ElementComparer to Separate File
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.ui.view;
|
||||
|
@ -61,7 +62,6 @@ import org.eclipse.jface.viewers.DoubleClickEvent;
|
|||
import org.eclipse.jface.viewers.IBasicPropertyConstants;
|
||||
import org.eclipse.jface.viewers.IContentProvider;
|
||||
import org.eclipse.jface.viewers.IDoubleClickListener;
|
||||
import org.eclipse.jface.viewers.IElementComparer;
|
||||
import org.eclipse.jface.viewers.ILabelDecorator;
|
||||
import org.eclipse.jface.viewers.IPostSelectionProvider;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
|
@ -4599,72 +4599,6 @@ public class SystemView extends SafeTreeViewer
|
|||
}
|
||||
}
|
||||
|
||||
protected class ElementComparer implements IElementComparer
|
||||
{
|
||||
public boolean equals(Object a, Object b)
|
||||
{
|
||||
if(a==b) return true;
|
||||
if(a==null || b==null) return false;
|
||||
//TODO not sure if this equals() check is a good idea.
|
||||
//It may be expensive and unnecessary. It might be better
|
||||
//to do this as a fallback instead, in case the adapter
|
||||
//is not found.
|
||||
if(a.equals(b)) return true;
|
||||
|
||||
if( (a instanceof IAdaptable) && (b instanceof IAdaptable) ) {
|
||||
ISystemViewElementAdapter identa =
|
||||
(ISystemViewElementAdapter)
|
||||
((IAdaptable)a).getAdapter(ISystemViewElementAdapter.class);
|
||||
ISystemViewElementAdapter identb =
|
||||
(ISystemViewElementAdapter)
|
||||
((IAdaptable)b).getAdapter(ISystemViewElementAdapter.class);
|
||||
if(identa != null && identb != null) {
|
||||
// first need to check subsystems
|
||||
ISubSystem ssa = identa.getSubSystem(a);
|
||||
ISubSystem ssb = identb.getSubSystem(b);
|
||||
if (ssa == ssb) {
|
||||
// if the subsystems are the same OR if both are null
|
||||
// (the absolute name will distinguish them)
|
||||
String ana = identa.getAbsoluteName(a);
|
||||
if (ana!=null) {
|
||||
return ana.equals(identb.getAbsoluteName(b));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int hashCode(Object element)
|
||||
{
|
||||
ISystemViewElementAdapter ident=null;
|
||||
if(element instanceof IAdaptable) {
|
||||
ident = (ISystemViewElementAdapter)
|
||||
((IAdaptable)element).getAdapter(ISystemViewElementAdapter.class);
|
||||
if(ident!=null) {
|
||||
String absName = ident.getAbsoluteName(element);
|
||||
if(absName!=null) return absName.hashCode();
|
||||
//Since one adapter is typically used for many elements in RSE,
|
||||
//performance would be better if the original Element's hashCode
|
||||
//were used rather than the adapter's hashCode. The problem with
|
||||
//this is, that if the remote object changes, it cannot be
|
||||
//identified any more.
|
||||
//Note that even if the SAME object is modified during refresh
|
||||
//(so object a==b), the hashCode of the object can change
|
||||
//over time if properties are modified. Therefore, play it
|
||||
//safe and return the adapter's hashCode which won't ever change.
|
||||
return ident.hashCode();
|
||||
}
|
||||
}
|
||||
if (element != null) { // adding check because I hit a null exception here once at startup
|
||||
return element.hashCode();
|
||||
} else {
|
||||
//System.out.println("null element");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------------
|
||||
* For many actions we have to walk the selection list and examine each selected
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
|
||||
* Kevin Doyle (IBM) - [192278] Removed handleKeyPressed
|
||||
* Kevin Doyle (IBM) - [189150] _selectionFlagsUpdated reset after clear action performed
|
||||
* Kevin Doyle (IBM) - [195537] Use Hashlookup and ElementComparer
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.ui.view.scratchpad;
|
||||
|
@ -65,6 +66,7 @@ import org.eclipse.rse.internal.ui.actions.SystemCommonSelectAllAction;
|
|||
import org.eclipse.rse.internal.ui.actions.SystemOpenExplorerPerspectiveAction;
|
||||
import org.eclipse.rse.internal.ui.actions.SystemShowInTableAction;
|
||||
import org.eclipse.rse.internal.ui.actions.SystemSubMenuManager;
|
||||
import org.eclipse.rse.internal.ui.view.ElementComparer;
|
||||
import org.eclipse.rse.internal.ui.view.SystemView;
|
||||
import org.eclipse.rse.internal.ui.view.SystemViewDataDragAdapter;
|
||||
import org.eclipse.rse.internal.ui.view.SystemViewDataDropAdapter;
|
||||
|
@ -185,7 +187,9 @@ public class SystemScratchpadView
|
|||
|
||||
_provider = new SystemScratchpadViewProvider(this);
|
||||
|
||||
|
||||
setUseHashlookup(true);
|
||||
setComparer(new ElementComparer());
|
||||
|
||||
setContentProvider(_provider);
|
||||
|
||||
IWorkbench wb = PlatformUI.getWorkbench();
|
||||
|
|
Loading…
Add table
Reference in a new issue