1 11 package org.eclipse.help.ui.internal.views; 12 13 import java.util.Dictionary ; 14 import java.util.Hashtable ; 15 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.help.search.*; 18 import org.eclipse.help.ui.*; 19 import org.eclipse.help.ui.internal.IHelpUIConstants; 20 import org.eclipse.jface.preference.IPreferenceStore; 21 import org.eclipse.jface.resource.ImageDescriptor; 22 import org.eclipse.swt.graphics.Image; 23 24 27 public class EngineDescriptor implements IEngineDescriptor { 28 public static final String P_MASTER = "__enabled__"; 30 private ISearchEngine engine; 31 32 private IConfigurationElement config; 33 34 private EngineDescriptorManager manager; 35 36 private EngineTypeDescriptor etdesc; 37 38 private Hashtable parameters; 39 40 42 44 private String id; 45 46 private String label; 47 48 private String desc; 49 50 private boolean userDefined; 51 52 55 public EngineDescriptor(IConfigurationElement config) { 56 this.config = config; 57 } 58 59 public EngineDescriptor(EngineDescriptorManager manager) { 60 this.manager = manager; 61 } 62 63 public void setEngineType(EngineTypeDescriptor etdesc) { 64 this.etdesc = etdesc; 65 } 66 67 public void setEngineDescriptorManager(EngineDescriptorManager manager) { 68 this.manager = manager; 69 } 70 71 public IConfigurationElement getConfig() { 72 return config; 73 } 74 75 public String getLabel() { 76 if (label != null) 77 return label; 78 String clabel = null; 79 if (config != null) 80 clabel = config.getAttribute(IHelpUIConstants.ATT_LABEL); 81 if (clabel == null) 82 clabel = etdesc.getLabel(); 83 return clabel; 84 } 85 86 public String getId() { 87 if (id != null) 88 return id; 89 return config.getAttribute(IHelpUIConstants.ATT_ID); 90 } 91 92 public String getEngineTypeId() { 93 if (etdesc != null) 94 return etdesc.getId(); 95 return config.getAttribute(IHelpUIConstants.ATT_ENGINE_TYPE_ID); 96 } 97 98 public boolean isEnabled() { 99 if (userDefined) 100 return true; 101 String aenabled = config.getAttribute(IHelpUIConstants.ATT_ENABLED); 102 if (aenabled != null) 103 return aenabled.equals("true"); return false; 105 } 106 107 public Image getIconImage() { 108 return etdesc.getIconImage(); 109 } 110 111 public String getDescription() { 112 if (desc != null) 113 return desc; 114 String cdesc = null; 115 if (config != null) { 116 IConfigurationElement[] children = config 117 .getChildren(IHelpUIConstants.TAG_DESC); 118 if (children.length == 1) 119 cdesc = children[0].getValue(); 120 } 121 if (cdesc == null) 122 return etdesc.getDescription(); 123 return cdesc; 124 } 125 126 public IConfigurationElement[] getPages() { 127 return etdesc.getPages(); 128 } 129 130 public ImageDescriptor getImageDescriptor() { 131 return etdesc.getImageDescriptor(); 132 } 133 134 public RootScopePage createRootPage(String scopeSetName) { 135 RootScopePage page = etdesc.createRootPage(scopeSetName); 136 if (page != null) { 137 page.init(this, scopeSetName); 139 } 140 return page; 141 } 142 143 public Dictionary getParameters() { 144 if (parameters != null) 145 return parameters; 146 parameters = new Hashtable (); 147 parameters.put(P_MASTER, isEnabled() ? Boolean.TRUE : Boolean.FALSE); 148 if (config != null) { 149 IConfigurationElement[] params = config.getChildren("param"); for (int i = 0; i < params.length; i++) { 151 IConfigurationElement param = params[i]; 152 String name = param.getAttribute(IHelpUIConstants.ATT_NAME); 153 String value = param.getAttribute(IHelpUIConstants.ATT_VALUE); 154 if (name != null && value != null) 155 parameters.put(name, value); 156 } 157 } 158 return parameters; 159 } 160 161 public ISearchEngine getEngine() { 162 if (engine == null) { 163 engine = etdesc.createEngine(); 164 } 165 return engine; 166 } 167 168 public ISearchScope createSearchScope(IPreferenceStore store) { 169 return etdesc.createSearchScope(store, getId(), getParameters()); 170 } 171 172 void setId(String id) { 173 this.id = id; 174 } 175 176 public void setLabel(String label) { 177 if (isUserDefined()) { 178 this.label = label; 179 if (manager!=null) 180 manager.notifyPropertyChange(this); 181 } 182 } 183 184 public void setDescription(String desc) { 185 if (isUserDefined()) { 186 this.desc = desc; 187 if (manager!=null) 188 manager.notifyPropertyChange(this); 189 } 190 } 191 192 public boolean isUserDefined() { 193 return userDefined; 194 } 195 196 public void setUserDefined(boolean userDefined) { 197 this.userDefined = userDefined; 198 } 199 } 200 | Popular Tags |