1 11 package org.eclipse.ui.internal.cheatsheets.registry; 12 13 import org.eclipse.core.runtime.*; 14 import org.eclipse.osgi.util.NLS; 15 import org.eclipse.ui.IPluginContribution; 16 import org.eclipse.ui.cheatsheets.CheatSheetListener; 17 import org.eclipse.ui.internal.cheatsheets.*; 18 import org.eclipse.ui.model.WorkbenchAdapter; 19 import org.eclipse.ui.model.IWorkbenchAdapter; 20 import org.osgi.framework.Bundle; 21 22 25 public class CheatSheetElement extends WorkbenchAdapter implements IAdaptable, IPluginContribution { 26 private String contentFile; 27 private String id; 28 private String name; 29 private String description; 30 private IConfigurationElement configurationElement; 31 private String listenerClass; 32 private boolean composite; 33 private boolean registered = false; 34 private String contentXml; 35 private String href; 36 37 42 public CheatSheetElement(String name) { 43 this.name = name; 44 } 45 46 51 public Object getAdapter(Class adapter) { 52 if (adapter == IWorkbenchAdapter.class) { 53 return this; 54 } 55 return Platform.getAdapterManager().getAdapter(this, adapter); 56 } 57 58 62 public IConfigurationElement getConfigurationElement() { 63 return configurationElement; 64 } 65 66 71 public String getContentFile() { 72 return contentFile; 73 } 74 75 80 public String getDescription() { 81 return description; 82 } 83 84 89 public String getID() { 90 return id; 91 } 92 93 96 public String getLabel(Object element) { 97 return name; 98 } 99 100 103 public String getListenerClass() { 104 return listenerClass; 105 } 106 107 111 public void setConfigurationElement(IConfigurationElement newConfigurationElement) { 112 configurationElement = newConfigurationElement; 113 } 114 115 120 public void setContentFile(String value) { 121 contentFile = value; 122 } 123 124 129 public void setDescription(String value) { 130 description = value; 131 } 132 133 138 public void setID(String value) { 139 id = value; 140 } 141 142 145 public void setListenerClass(String value) { 146 listenerClass = value; 147 } 148 149 public CheatSheetListener createListenerInstance() { 150 if(listenerClass == null || configurationElement == null) { 151 return null; 152 } 153 154 Class extClass = null; 155 CheatSheetListener listener = null; 156 String pluginId = configurationElement.getContributor().getName(); 157 158 try { 159 Bundle bundle = Platform.getBundle(pluginId); 160 extClass = bundle.loadClass(listenerClass); 161 } catch (Exception e) { 162 String message = NLS.bind(Messages.ERROR_LOADING_CLASS, (new Object [] {listenerClass})); 163 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); 164 CheatSheetPlugin.getPlugin().getLog().log(status); 165 } 166 try { 167 if (extClass != null) { 168 listener = (CheatSheetListener) extClass.newInstance(); 169 } 170 } catch (Exception e) { 171 String message = NLS.bind(Messages.ERROR_CREATING_CLASS, (new Object [] {listenerClass})); 172 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); 173 CheatSheetPlugin.getPlugin().getLog().log(status); 174 } 175 176 if (listener != null){ 177 return listener; 178 } 179 180 return null; 181 } 182 183 public String getLocalId() { 184 return id; 185 } 186 187 public String getPluginId() { 188 return configurationElement.getContributor().getName(); 189 } 190 191 public void setComposite(boolean composite) { 192 this.composite = composite; 193 } 194 195 public boolean isComposite() { 196 return composite; 197 } 198 199 205 public String getRestorePath() { 206 if (!registered) { 207 return contentFile; 208 } 209 return null; 210 } 211 212 public void setRegistered(boolean registered) { 213 this.registered = registered; 214 } 215 216 public boolean isRegistered() { 217 return registered; 218 } 219 220 public void setContentXml(String xml) { 221 this.contentXml = xml; 222 } 223 224 public String getContentXml() { 225 return contentXml; 226 } 227 228 public void setHref(String contentPath) { 229 this.href = contentPath; 230 } 231 232 public String getHref() { 233 return href; 234 } 235 236 } 237 | Popular Tags |