From f3aa90026abc7a5340b76a0c36814d532c33b6aa Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Thu, 24 Apr 2008 20:38:13 +0000 Subject: [PATCH] [225911]Exception received after deleting a profile containing a connection https://bugs.eclipse.org/bugs/show_bug.cgi?id=225911 --- .../src/org/eclipse/rse/core/model/Host.java | 17 +-- .../rse/internal/ui/view/ElementComparer.java | 113 +++++++++--------- .../rse/internal/ui/view/SystemView.java | 49 ++++---- 3 files changed, 95 insertions(+), 84 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java index da48dbdacde..a979b8ed8dc 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/Host.java @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (c) 2006, 2007 IBM Corporation and others. All rights reserved. + * Copyright (c) 2006, 2008 IBM Corporation and others. 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 @@ -21,6 +21,7 @@ * Martin Oberhuber (Wind River) - [177523] Unify singleton getter methods * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() * Kevin Doyle (IBM) - [203365] Profile should not be saved as a result of file transfer + * David Dykstal (IBM) - [225911] Exception received after deleting a profile containing a connection ********************************************************************************/ package org.eclipse.rse.core.model; @@ -181,14 +182,16 @@ public class Host extends RSEModelObject implements IHost { * @see org.eclipse.rse.core.model.IHost#getSystemProfileName() */ public String getSystemProfileName() { - if (pool == null) - return null; - else { + String result = null; + if (_profile != null) { + result = _profile.getName(); + } else if (pool != null) { ISystemProfile profile = pool.getSystemProfile(); - if (profile != null) - return profile.getName(); - else return null; + if (profile != null) { + result = profile.getName(); + } } + return result; } /** diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/ElementComparer.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/ElementComparer.java index da331567589..5b6063febac 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/ElementComparer.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/ElementComparer.java @@ -1,70 +1,73 @@ /******************************************************************************** -* Copyright (c) 2007, 2008 IBM Corporation and others. 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 + * Copyright (c) 2007, 2008 IBM Corporation and others. 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 * Martin Oberhuber (Wind River) - [215820] Move SystemRegistry implementation to Core -********************************************************************************/ + * David Dykstal (IBM) - [225911] Exception received after deleting a profile containing a connection + ********************************************************************************/ package org.eclipse.rse.internal.ui.view; +import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.jface.viewers.IElementComparer; +import org.eclipse.osgi.util.NLS; import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.ISystemRegistry; import org.eclipse.rse.internal.core.model.SystemRegistry; import org.eclipse.rse.ui.view.ISystemViewElementAdapter; -public class ElementComparer implements IElementComparer -{ - - public boolean equals(Object a, Object b) - { +/** + * An implememtation of an element comparer for the system view. + */ +public class ElementComparer implements IElementComparer { + + public boolean equals(Object a, Object b) { + boolean result = false; ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry(); - if (registry instanceof SystemRegistry) - { - return ((SystemRegistry) registry).isSameObjectByAbsoluteName(a, null, b, null); + if (registry instanceof SystemRegistry) { + result = ((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; - } - } - + return result; + } + + public int hashCode(Object element) { + /* + * Hashcodes should be invariant across the lifetime of the object. + * 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 currently the hashCode of the object can change + * over time if properties are modified (this is probably a bug). + * Therefore, if there is no absolute name, play it safe and return the adapter's hashCode which won't ever change. + */ + int result = 0; + ISystemViewElementAdapter ident = null; + if (element instanceof IAdaptable) { + ident = (ISystemViewElementAdapter) ((IAdaptable) element).getAdapter(ISystemViewElementAdapter.class); + Assert.isNotNull(ident, NLS.bind("no adapter found for element {0}", element)); //$NON-NLS-1$ + String absName = ident.getAbsoluteName(element); + if (absName != null) { + result = absName.hashCode(); + } else { + result = ident.hashCode(); + } + } else if (element != null) { + result = element.hashCode(); + } + return result; + } + } - diff --git a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemView.java b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemView.java index 8955889967e..4747ff10d2b 100644 --- a/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemView.java +++ b/rse/plugins/org.eclipse.rse.ui/UI/org/eclipse/rse/internal/ui/view/SystemView.java @@ -51,6 +51,7 @@ * David Dykstal (IBM) - [222376] NPE if starting on a workspace with an old mark and a renamed default profile * David McKnight (IBM) - [224380] system view should only fire property sheet update event when in focus * David McKnight (IBM) - [224313] [api] Create RSE Events for MOVE and COPY holding both source and destination fields + * David Dykstal (IBM) - [225911] Exception received after deleting a profile containing a connection ********************************************************************************/ package org.eclipse.rse.internal.ui.view; @@ -1951,40 +1952,49 @@ public class SystemView extends SafeTreeViewer break; case ISystemResourceChangeEvents.EVENT_DELETE_MANY: - if (debug) logDebugMsg("SV event: EVENT_DELETE_MANY "); //$NON-NLS-1$ + if (debug) { + logDebugMsg("SV event: EVENT_DELETE_MANY "); //$NON-NLS-1$ + } multiSource = _event.getMultiSource(); // are we a secondary perspective, and our input or parent of our input was deleted? if (affectsInput(multiSource)) { close(); return Status.OK_STATUS; } - if (parent != null) + if (parent != null) { parentItem = findItem(parent); - else { + } else { // find first parentItem for source - if (multiSource != null && multiSource.length > 0){ + if (multiSource != null && multiSource.length > 0) { Widget sitem = findItem(multiSource[0]); - if (sitem instanceof TreeItem) - { + if (sitem instanceof TreeItem) { parentItem = ((TreeItem)sitem).getParentItem(); - if (parentItem == null) - { + if (parentItem == null) { parentItem = ((TreeItem)sitem).getParent(); } } } } - - if (parentItem == null) return Status.OK_STATUS; - if ((parentItem instanceof Item) && !getExpanded((Item) parentItem)) + if (parentItem == null) { + return Status.OK_STATUS; + } + if ((parentItem instanceof Item) && !getExpanded((Item) parentItem)) { refresh(parent); // flush memory - else if (parentItem instanceof Tree) { - if (_originatingViewer != null) _originatingViewer.remove(multiSource); + } else if (parentItem instanceof Tree) { + if (_originatingViewer != null) { + _originatingViewer.remove(multiSource); + } } else { wasSelected = isSelectedOrChildSelected(multiSource); - if (wasSelected) clearSelection(); - if (_originatingViewer != null) _originatingViewer.remove(multiSource); - if (wasSelected) setSelection(parent != null ? new StructuredSelection(parent) : null, true); + if (wasSelected) { + clearSelection(); + } + if (_originatingViewer != null) { + _originatingViewer.remove(multiSource); + } + if (wasSelected) { + setSelection(parent != null ? new StructuredSelection(parent) : null, true); + } } break; /* Now done below in systemRemoteResourceChanged @@ -5704,12 +5714,7 @@ public class SystemView extends SafeTreeViewer ISystemViewElementAdapter adapter = getViewAdapter(parentObject); ISystemViewElementAdapter targetAdapter = getViewAdapter(remoteObject); - - if (adapter == null) - { - System.out.println("adapter is null for "+parentObject); - return; - } + Assert.isNotNull(adapter, "adapter is null for " + parentObject); //$NON-NLS-1$ ISubSystem ss = adapter.getSubSystem(parentObject); String parentName = adapter.getAbsoluteName(parentObject); String remoteObjectName = targetAdapter.getAbsoluteName(remoteObject);