1 11 package org.eclipse.ui.texteditor.quickdiff; 12 13 import org.osgi.framework.Bundle; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.Platform; 19 20 21 22 23 30 public class ReferenceProviderDescriptor { 31 32 33 private static final String LABEL_ATTRIBUTE= "label"; 35 private static final String CLASS_ATTRIBUTE= "class"; 37 private static final String ID_ATTRIBUTE= "id"; 39 private static final String DEFAULT_ATTRIBUTE= "default"; 41 42 private IConfigurationElement fConfiguration; 43 44 private String fLabel; 45 46 private String fId; 47 48 private Boolean fDefault; 49 50 private Bundle fBundle; 51 52 60 public ReferenceProviderDescriptor(IConfigurationElement element) { 61 Assert.isLegal(element != null); 62 fConfiguration= element; 63 } 64 65 70 public String getLabel() { 71 if (fLabel == null) { 72 fLabel= fConfiguration.getAttribute(LABEL_ATTRIBUTE); 73 Assert.isNotNull(fLabel); 74 } 75 return fLabel; 76 } 77 78 83 public String getId() { 84 if (fId == null) { 85 fId= fConfiguration.getAttribute(ID_ATTRIBUTE); 86 Assert.isNotNull(fId); 87 } 88 return fId; 89 } 90 91 95 public IQuickDiffReferenceProvider createProvider() { 96 try { 97 IQuickDiffReferenceProvider impl= (IQuickDiffReferenceProvider)fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE); 98 impl.setId(getId()); 99 return impl; 100 } catch (CoreException e) { 101 return null; 102 } 103 } 104 105 110 public boolean isPluginLoaded() { 111 if (fBundle == null) 112 fBundle= Platform.getBundle(fConfiguration.getContributor().getName()); 113 return (fBundle != null && fBundle.getState() == Bundle.ACTIVE); 114 } 115 116 122 public boolean getDefault() { 123 if (fDefault == null) { 124 String def= fConfiguration.getAttribute(DEFAULT_ATTRIBUTE); 125 if ("true".equalsIgnoreCase(def)) fDefault= Boolean.TRUE; 127 else 128 fDefault= Boolean.FALSE; 129 } 130 return fDefault.booleanValue(); 131 } 132 133 } 134 | Popular Tags |