1 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 27 public class SearchParticipantDescriptor { 28 private static final String CLASS= "class"; private static final String NATURE= "nature"; private static final String ID= "id"; 32 private IConfigurationElement fConfigurationElement; 33 private boolean fEnabled; 35 protected SearchParticipantDescriptor(IConfigurationElement configElement) { 36 fConfigurationElement= configElement; 37 fEnabled= true; 38 } 39 40 45 protected IStatus checkSyntax() { 46 if (fConfigurationElement.getAttribute(ID) == null) { 47 String format= SearchMessages.SearchParticipant_error_noID; 48 String message= Messages.format(format, new String [] { fConfigurationElement.getDeclaringExtension().getUniqueIdentifier() }); 49 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null); 50 } 51 if (fConfigurationElement.getAttribute(NATURE) == null) { 52 String format= SearchMessages.SearchParticipant_error_noNature; 53 String message= Messages.format(format, new String [] { fConfigurationElement.getAttribute(ID)}); 54 return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, message, null); 55 } 56 57 if (fConfigurationElement.getAttribute(CLASS) == null) { 58 String format= SearchMessages.SearchParticipant_error_noClass; 59 String message= Messages.format(format, new String [] { 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 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 e) { 81 throw new CoreException(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, SearchMessages.SearchParticipant_error_classCast, e)); 82 } 83 } 84 85 protected String getNature() { 86 return fConfigurationElement.getAttribute(NATURE); 87 } 88 89 90 } 91 | Popular Tags |