KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 package org.eclipse.jdt.internal.ui.search;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IConfigurationElement;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.core.runtime.Status;
18
19 import org.eclipse.jdt.internal.corext.util.Messages;
20
21 import org.eclipse.jdt.ui.search.IQueryParticipant;
22
23 import org.eclipse.jdt.internal.ui.JavaPlugin;
24
25 /**
26  */

27 public class SearchParticipantDescriptor {
28         private static final String JavaDoc CLASS= "class"; //$NON-NLS-1$
29
private static final String JavaDoc NATURE= "nature"; //$NON-NLS-1$
30
private static final String JavaDoc ID= "id"; //$NON-NLS-1$
31

32         private IConfigurationElement fConfigurationElement;
33         private boolean fEnabled; //
34

35         protected SearchParticipantDescriptor(IConfigurationElement configElement) {
36             fConfigurationElement= configElement;
37             fEnabled= true;
38         }
39
40     /**
41      * checks whether a participant has all the proper attributes.
42      *
43      * @return returns a status describing the result of the validation
44      */

45     protected IStatus checkSyntax() {
46         if (fConfigurationElement.getAttribute(ID) == null) {
47             String JavaDoc format= SearchMessages.SearchParticipant_error_noID;
48             String JavaDoc message= Messages.format(format, new String JavaDoc[] { fConfigurationElement.getDeclaringExtension().getUniqueIdentifier() });
49             return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
50         }
51         if (fConfigurationElement.getAttribute(NATURE) == null) {
52             String JavaDoc format= SearchMessages.SearchParticipant_error_noNature;
53             String JavaDoc message= Messages.format(format, new String JavaDoc[] { fConfigurationElement.getAttribute(ID)});
54             return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
55         }
56
57         if (fConfigurationElement.getAttribute(CLASS) == null) {
58             String JavaDoc format= SearchMessages.SearchParticipant_error_noClass;
59             String JavaDoc message= Messages.format(format, new String JavaDoc[] { fConfigurationElement.getAttribute(ID)});
60             return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null);
61         }
62         return Status.OK_STATUS;
63     }
64
65     public String JavaDoc getID() {
66         return fConfigurationElement.getAttribute(ID);
67     }
68     
69     public void disable() {
70         fEnabled= false;
71     }
72     
73     public boolean isEnabled() {
74         return fEnabled;
75     }
76     
77     protected IQueryParticipant create() throws CoreException {
78         try {
79             return (IQueryParticipant) fConfigurationElement.createExecutableExtension(CLASS);
80         } catch (ClassCastException JavaDoc e) {
81             throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, SearchMessages.SearchParticipant_error_classCast, e));
82         }
83     }
84
85     protected String JavaDoc getNature() {
86         return fConfigurationElement.getAttribute(NATURE);
87     }
88
89
90 }
91
Popular Tags