1 11 12 package org.eclipse.ui.internal.navigator.dnd; 13 14 import java.lang.ref.WeakReference ; 15 import java.util.HashSet ; 16 import java.util.Iterator ; 17 import java.util.Set ; 18 19 import org.eclipse.ui.navigator.INavigatorContentService; 20 21 28 public class NavigatorContentServiceTransfer { 29 30 private static final NavigatorContentServiceTransfer instance = new NavigatorContentServiceTransfer(); 31 32 36 public static NavigatorContentServiceTransfer getInstance() { 37 return instance; 38 } 39 40 private final Set registeredContentServices = new HashSet (); 41 42 46 public synchronized void registerContentService(INavigatorContentService aContentService) { 47 if(findService(aContentService.getViewerId()) == null) { 48 registeredContentServices.add(new WeakReference (aContentService)); 49 } 50 } 51 52 56 public synchronized void unregisterContentService(INavigatorContentService aContentService) { 57 58 for (Iterator iter = registeredContentServices.iterator(); iter.hasNext();) { 59 WeakReference ref = (WeakReference ) iter.next(); 60 if(ref.get() == null) { 61 iter.remove(); 62 } else { 63 if(ref.get() == aContentService) { 64 iter.remove(); 65 return; 66 } 67 } 68 } 69 } 70 71 76 public synchronized INavigatorContentService findService(String aViewerId) { 77 if(aViewerId == null || aViewerId.length() == 0) { 78 return null; 79 } 80 INavigatorContentService contentService; 81 for (Iterator iter = registeredContentServices.iterator(); iter.hasNext();) { 82 WeakReference ref = (WeakReference ) iter.next(); 83 if(ref.get() == null) { 84 iter.remove(); 85 } else { 86 contentService = (INavigatorContentService)ref.get(); 87 if(aViewerId.equals(contentService.getViewerId())) { 88 return contentService; 89 } 90 } 91 } 92 return null; 93 } 94 95 96 } 97 | Popular Tags |