KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > SearchParticipantsExtensionPoint


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 /*
12  * Created on Apr 13, 2004
13  *
14  * TODO To change the template for this generated file go to Window -
15  * Preferences - Java - Code Generation - Code and Comments
16  */

17 package org.eclipse.jdt.internal.ui.search;
18
19 import java.util.HashSet JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
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 JavaDoc 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 JavaDoc getAllParticipants() {
40         if (fActiveParticipants != null)
41             return fActiveParticipants;
42         IConfigurationElement[] allParticipants= Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT);
43         fActiveParticipants= new HashSet JavaDoc(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 JavaDoc participants, IProject[] projects) {
57         Iterator JavaDoc activeParticipants= getAllParticipants().iterator();
58         Set JavaDoc seenParticipants= new HashSet JavaDoc();
59         while (activeParticipants.hasNext()) {
60             SearchParticipantDescriptor participant= (SearchParticipantDescriptor) activeParticipants.next();
61             if (participant.isEnabled()) {
62                 String JavaDoc 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 JavaDoc participantSet= new HashSet JavaDoc();
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