1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 * Created on Apr 13, 2004
14 * TODO To change the template for this generated file go to Window -
15 * Preferences - Java - Code Generation - Code and Comments
17 package org.eclipse.jdt.internal.ui.search;
19 import java.util.HashSet;
20 import java.util.Iterator;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.core.runtime.IConfigurationElement;
25 import org.eclipse.core.runtime.IStatus;
26 import org.eclipse.core.runtime.Platform;
28 import org.eclipse.core.resources.IProject;
30 import org.eclipse.jdt.internal.ui.JavaPlugin;
32 public class SearchParticipantsExtensionPoint {
34 private Set<SearchParticipantDescriptor> fActiveParticipants= null;
35 private static SearchParticipantsExtensionPoint fgInstance;
37 public boolean hasAnyParticipants() {
38 return Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT).length > 0;
41 private synchronized Set<SearchParticipantDescriptor> getAllParticipants() {
42 if (fActiveParticipants != null)
43 return fActiveParticipants;
44 IConfigurationElement[] allParticipants= Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT);
45 fActiveParticipants= new HashSet<SearchParticipantDescriptor>(allParticipants.length);
46 for (int i= 0; i < allParticipants.length; i++) {
47 SearchParticipantDescriptor descriptor= new SearchParticipantDescriptor(allParticipants[i]);
48 IStatus status= descriptor.checkSyntax();
50 fActiveParticipants.add(descriptor);
52 JavaPlugin.log(status);
55 return fActiveParticipants;
58 private void collectParticipants(Set<SearchParticipantRecord> participants, IProject[] projects) {
59 Iterator<SearchParticipantDescriptor> activeParticipants= getAllParticipants().iterator();
60 Set<String> seenParticipants= new HashSet<String>();
61 while (activeParticipants.hasNext()) {
62 SearchParticipantDescriptor participant= activeParticipants.next();
63 String id= participant.getID();
64 if (participant.isEnabled() && !seenParticipants.contains(id)) {
65 for (int i= 0; i < projects.length; i++) {
67 if (projects[i].hasNature(participant.getNature())) {
68 participants.add(new SearchParticipantRecord(participant, participant.create()));
69 seenParticipants.add(id);
72 } catch (CoreException e) {
73 JavaPlugin.log(e.getStatus());
74 participant.disable();
83 public SearchParticipantRecord[] getSearchParticipants(IProject[] concernedProjects) {
84 Set<SearchParticipantRecord> participantSet= new HashSet<SearchParticipantRecord>();
85 collectParticipants(participantSet, concernedProjects);
86 SearchParticipantRecord[] participants= new SearchParticipantRecord[participantSet.size()];
87 return participantSet.toArray(participants);
90 public static SearchParticipantsExtensionPoint getInstance() {
91 if (fgInstance == null)
92 fgInstance= new SearchParticipantsExtensionPoint();
96 public static void debugSetInstance(SearchParticipantsExtensionPoint instance) {