View | Details | Raw Unified | Return to bug 195537
Collapse All | Expand All

(-)UI/org/eclipse/rse/internal/ui/view/scratchpad/SystemScratchpadView.java (-1 / +5 lines)
Lines 15-20 Link Here
15
 * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
15
 * Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry
16
 * Kevin Doyle (IBM) - [192278] Removed handleKeyPressed
16
 * Kevin Doyle (IBM) - [192278] Removed handleKeyPressed
17
 * Kevin Doyle (IBM) - [189150] _selectionFlagsUpdated reset after clear action performed
17
 * Kevin Doyle (IBM) - [189150] _selectionFlagsUpdated reset after clear action performed
18
 * Kevin Doyle (IBM) - [195537] Use Hashlookup and ElementComparer
18
 ********************************************************************************/
19
 ********************************************************************************/
19
20
20
package org.eclipse.rse.internal.ui.view.scratchpad;
21
package org.eclipse.rse.internal.ui.view.scratchpad;
Lines 65-70 Link Here
65
import org.eclipse.rse.internal.ui.actions.SystemOpenExplorerPerspectiveAction;
66
import org.eclipse.rse.internal.ui.actions.SystemOpenExplorerPerspectiveAction;
66
import org.eclipse.rse.internal.ui.actions.SystemShowInTableAction;
67
import org.eclipse.rse.internal.ui.actions.SystemShowInTableAction;
67
import org.eclipse.rse.internal.ui.actions.SystemSubMenuManager;
68
import org.eclipse.rse.internal.ui.actions.SystemSubMenuManager;
69
import org.eclipse.rse.internal.ui.view.ElementComparer;
68
import org.eclipse.rse.internal.ui.view.SystemView;
70
import org.eclipse.rse.internal.ui.view.SystemView;
69
import org.eclipse.rse.internal.ui.view.SystemViewDataDragAdapter;
71
import org.eclipse.rse.internal.ui.view.SystemViewDataDragAdapter;
70
import org.eclipse.rse.internal.ui.view.SystemViewDataDropAdapter;
72
import org.eclipse.rse.internal.ui.view.SystemViewDataDropAdapter;
Lines 185-191 Link Here
185
187
186
			_provider = new SystemScratchpadViewProvider(this);
188
			_provider = new SystemScratchpadViewProvider(this);
187
189
188
190
			setUseHashlookup(true);
191
			setComparer(new ElementComparer()); 
192
			
189
			setContentProvider(_provider);
193
			setContentProvider(_provider);
190
			
194
			
191
			IWorkbench wb = PlatformUI.getWorkbench();
195
			IWorkbench wb = PlatformUI.getWorkbench();
(-)UI/org/eclipse/rse/internal/ui/view/SystemView.java (-67 / +1 lines)
Lines 31-36 Link Here
31
 * Kevin Doyle (IBM) - [194602] handleDoubleClick does expand/collapse on treepath instead of element
31
 * Kevin Doyle (IBM) - [194602] handleDoubleClick does expand/collapse on treepath instead of element
32
 * David McKnight   (IBM)        - [194897] Should not remote refresh objects above subsystem.
32
 * David McKnight   (IBM)        - [194897] Should not remote refresh objects above subsystem.
33
 * Kevin Doyle - [193380] Deleting connection Refresh's Entire Remote Systems view
33
 * Kevin Doyle - [193380] Deleting connection Refresh's Entire Remote Systems view
34
 * Kevin Doyle - [195537] Move ElementComparer to Separate File
34
 ********************************************************************************/
35
 ********************************************************************************/
35
36
36
package org.eclipse.rse.internal.ui.view;
37
package org.eclipse.rse.internal.ui.view;
Lines 61-67 Link Here
61
import org.eclipse.jface.viewers.IBasicPropertyConstants;
62
import org.eclipse.jface.viewers.IBasicPropertyConstants;
62
import org.eclipse.jface.viewers.IContentProvider;
63
import org.eclipse.jface.viewers.IContentProvider;
63
import org.eclipse.jface.viewers.IDoubleClickListener;
64
import org.eclipse.jface.viewers.IDoubleClickListener;
64
import org.eclipse.jface.viewers.IElementComparer;
65
import org.eclipse.jface.viewers.ILabelDecorator;
65
import org.eclipse.jface.viewers.ILabelDecorator;
66
import org.eclipse.jface.viewers.IPostSelectionProvider;
66
import org.eclipse.jface.viewers.IPostSelectionProvider;
67
import org.eclipse.jface.viewers.ISelection;
67
import org.eclipse.jface.viewers.ISelection;
Lines 4599-4670 Link Here
4599
		}
4599
		}
4600
	}
4600
	}
4601
4601
4602
	protected class ElementComparer implements IElementComparer
4603
	{
4604
	      public boolean equals(Object a, Object b) 
4605
	      {
4606
	          if(a==b) return true;
4607
	          if(a==null || b==null) return false;
4608
	          //TODO not sure if this equals() check is a good idea.
4609
	          //It may be expensive and unnecessary. It might be better
4610
	          //to do this as a fallback instead, in case the adapter 
4611
	          //is not found. 
4612
	          if(a.equals(b)) return true;
4613
	 
4614
	          if( (a instanceof IAdaptable) && (b instanceof IAdaptable) ) {
4615
	        	  ISystemViewElementAdapter identa =
4616
	        		  (ISystemViewElementAdapter)
4617
	        		  ((IAdaptable)a).getAdapter(ISystemViewElementAdapter.class);
4618
	        	  ISystemViewElementAdapter identb = 
4619
	        		  (ISystemViewElementAdapter)
4620
	        		  ((IAdaptable)b).getAdapter(ISystemViewElementAdapter.class);
4621
	        	  if(identa != null && identb != null) {
4622
	        		  // first need to check subsystems
4623
	        		  ISubSystem ssa = identa.getSubSystem(a);
4624
	        		  ISubSystem ssb = identb.getSubSystem(b);
4625
	        		  if (ssa == ssb) {
4626
	        			  // if the subsystems are the same OR if both are null
4627
	        			  // (the absolute name will distinguish them)
4628
	        			  String ana = identa.getAbsoluteName(a);
4629
	        			  if (ana!=null) {
4630
	        				  return ana.equals(identb.getAbsoluteName(b));
4631
	        			  }
4632
		              }
4633
		          }
4634
	          }
4635
	          return false;
4636
	      }
4637
	      
4638
	      public int hashCode(Object element) 
4639
	      {
4640
	          ISystemViewElementAdapter ident=null;
4641
	          if(element instanceof IAdaptable) {
4642
	              ident = (ISystemViewElementAdapter)
4643
	                  ((IAdaptable)element).getAdapter(ISystemViewElementAdapter.class);
4644
	              if(ident!=null) {
4645
	                  String absName = ident.getAbsoluteName(element);
4646
	                  if(absName!=null) return absName.hashCode();
4647
	                  //Since one adapter is typically used for many elements in RSE,
4648
	                  //performance would be better if the original Element's hashCode
4649
	                  //were used rather than the adapter's hashCode. The problem with
4650
	                  //this is, that if the remote object changes, it cannot be 
4651
	                  //identified any more.
4652
	                  //Note that even if the SAME object is modified during refresh
4653
	                  //(so object a==b), the hashCode of the object can change 
4654
	                  //over time if properties are modified. Therefore, play it
4655
	                  //safe and return the adapter's hashCode which won't ever change.
4656
	                  return ident.hashCode();
4657
	              }
4658
	          }		          
4659
	          if (element != null) { // adding check because I hit a null exception here once at startup
4660
	        	  return element.hashCode();
4661
	          } else {
4662
	        	  //System.out.println("null element");
4663
	        	  return 0;
4664
	          }
4665
	      }
4666
	    }
4667
4668
	/**
4602
	/**
4669
	 * --------------------------------------------------------------------------------
4603
	 * --------------------------------------------------------------------------------
4670
	 * For many actions we have to walk the selection list and examine each selected
4604
	 * For many actions we have to walk the selection list and examine each selected
(-)UI/org/eclipse/rse/internal/ui/view/ElementComparer.java (+69 lines)
Added Link Here
1
/********************************************************************************
2
* Copyright (c) 2007 IBM Corporation. All rights reserved.
3
* This program and the accompanying materials are made available under the terms
4
* of the Eclipse Public License v1.0 which accompanies this distribution, and is 
5
* available at http://www.eclipse.org/legal/epl-v10.html 
6
* 
7
* Initial Contributors:
8
* The following IBM employees contributed to the Remote System Explorer
9
* component that contains this file: David McKnight, Kushal Munir, 
10
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, 
11
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
12
* 
13
* Contributors:
14
* Kevin Doyle (IBM) - [195537] Move ElementComparer From SystemView to Separate File
15
********************************************************************************/
16
17
package org.eclipse.rse.internal.ui.view;
18
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.jface.viewers.IElementComparer;
21
import org.eclipse.rse.core.RSECorePlugin;
22
import org.eclipse.rse.core.model.ISystemRegistry;
23
import org.eclipse.rse.ui.internal.model.SystemRegistry;
24
import org.eclipse.rse.ui.view.ISystemViewElementAdapter;
25
26
public class ElementComparer implements IElementComparer 
27
{
28
29
	public boolean equals(Object a, Object b) 
30
    {
31
		ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
32
		if (registry instanceof SystemRegistry)
33
		{
34
			return ((SystemRegistry) registry).isSameObjectByAbsoluteName(a, null, b, null);
35
		}
36
		return false;
37
    }
38
    
39
    public int hashCode(Object element) 
40
    {
41
        ISystemViewElementAdapter ident=null;
42
        if(element instanceof IAdaptable) {
43
            ident = (ISystemViewElementAdapter)
44
                ((IAdaptable)element).getAdapter(ISystemViewElementAdapter.class);
45
            if(ident!=null) {
46
                String absName = ident.getAbsoluteName(element);
47
                if(absName!=null) return absName.hashCode();
48
                //Since one adapter is typically used for many elements in RSE,
49
                //performance would be better if the original Element's hashCode
50
                //were used rather than the adapter's hashCode. The problem with
51
                //this is, that if the remote object changes, it cannot be 
52
                //identified any more.
53
                //Note that even if the SAME object is modified during refresh
54
                //(so object a==b), the hashCode of the object can change 
55
                //over time if properties are modified. Therefore, play it
56
                //safe and return the adapter's hashCode which won't ever change.
57
                return ident.hashCode();
58
            }
59
        }		          
60
        if (element != null) { // adding check because I hit a null exception here once at startup
61
      	  return element.hashCode();
62
        } else {
63
      	  //System.out.println("null element");
64
      	  return 0;
65
        }
66
    }
67
    
68
}
69
 

Return to bug 195537