1 11 17 package org.eclipse.jdt.internal.ui.search; 18 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 import org.eclipse.core.resources.IProject; 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IConfigurationElement; 26 import org.eclipse.core.runtime.IStatus; 27 import org.eclipse.core.runtime.Platform; 28 import org.eclipse.jdt.internal.ui.JavaPlugin; 29 30 public class SearchParticipantsExtensionPoint { 31 32 private Set fActiveParticipants= null; 33 private static SearchParticipantsExtensionPoint fgInstance; 34 35 public boolean hasAnyParticipants() { 36 return Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT).length > 0; 37 } 38 39 private synchronized Set getAllParticipants() { 40 if (fActiveParticipants != null) 41 return fActiveParticipants; 42 IConfigurationElement[] allParticipants= Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT); 43 fActiveParticipants= new HashSet (allParticipants.length); 44 for (int i= 0; i < allParticipants.length; i++) { 45 SearchParticipantDescriptor descriptor= new SearchParticipantDescriptor(allParticipants[i]); 46 IStatus status= descriptor.checkSyntax(); 47 if (status.isOK()) { 48 fActiveParticipants.add(descriptor); 49 } else { 50 JavaPlugin.log(status); 51 } 52 } 53 return fActiveParticipants; 54 } 55 56 private void collectParticipants(Set participants, IProject[] projects) { 57 Iterator activeParticipants= getAllParticipants().iterator(); 58 Set seenParticipants= new HashSet (); 59 while (activeParticipants.hasNext()) { 60 SearchParticipantDescriptor participant= (SearchParticipantDescriptor) activeParticipants.next(); 61 if (participant.isEnabled()) { 62 String id= participant.getID(); 63 for (int i= 0; i < projects.length; i++) { 64 if (seenParticipants.contains(id)) 65 continue; 66 try { 67 if (projects[i].hasNature(participant.getNature())) { 68 participants.add(new SearchParticipantRecord(participant, participant.create())); 69 seenParticipants.add(id); 70 } 71 } catch (CoreException e) { 72 JavaPlugin.log(e.getStatus()); 73 participant.disable(); 74 } 75 } 76 } 77 } 78 } 79 80 81 82 public SearchParticipantRecord[] getSearchParticipants(IProject[] concernedProjects) throws CoreException { 83 Set participantSet= new HashSet (); 84 collectParticipants(participantSet, concernedProjects); 85 SearchParticipantRecord[] participants= new SearchParticipantRecord[participantSet.size()]; 86 return (SearchParticipantRecord[]) participantSet.toArray(participants); 87 } 88 89 public static SearchParticipantsExtensionPoint getInstance() { 90 if (fgInstance == null) 91 fgInstance= new SearchParticipantsExtensionPoint(); 92 return fgInstance; 93 } 94 95 public static void debugSetInstance(SearchParticipantsExtensionPoint instance) { 96 fgInstance= instance; 97 } 98 } 99 | Popular Tags |