]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/search/SearchParticipantsExtensionPoint.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / search / SearchParticipantsExtensionPoint.java
CommitLineData
1b2798f6
EK
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
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 */
17package org.eclipse.jdt.internal.ui.search;
18
19import java.util.HashSet;
20import java.util.Iterator;
21import java.util.Set;
22
23import org.eclipse.core.runtime.CoreException;
24import org.eclipse.core.runtime.IConfigurationElement;
25import org.eclipse.core.runtime.IStatus;
26import org.eclipse.core.runtime.Platform;
27
28import org.eclipse.core.resources.IProject;
29
30import org.eclipse.jdt.internal.ui.JavaPlugin;
31
32public class SearchParticipantsExtensionPoint {
33
34 private Set<SearchParticipantDescriptor> fActiveParticipants= null;
35 private static SearchParticipantsExtensionPoint fgInstance;
36
37 public boolean hasAnyParticipants() {
38 return Platform.getExtensionRegistry().getConfigurationElementsFor(JavaSearchPage.PARTICIPANT_EXTENSION_POINT).length > 0;
39 }
40
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();
49 if (status.isOK()) {
50 fActiveParticipants.add(descriptor);
51 } else {
52 JavaPlugin.log(status);
53 }
54 }
55 return fActiveParticipants;
56 }
57
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++) {
66 try {
67 if (projects[i].hasNature(participant.getNature())) {
68 participants.add(new SearchParticipantRecord(participant, participant.create()));
69 seenParticipants.add(id);
70 break;
71 }
72 } catch (CoreException e) {
73 JavaPlugin.log(e.getStatus());
74 participant.disable();
75 }
76 }
77 }
78 }
79 }
80
81
82
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);
88 }
89
90 public static SearchParticipantsExtensionPoint getInstance() {
91 if (fgInstance == null)
92 fgInstance= new SearchParticipantsExtensionPoint();
93 return fgInstance;
94 }
95
96 public static void debugSetInstance(SearchParticipantsExtensionPoint instance) {
97 fgInstance= instance;
98 }
99}