1 11 package org.eclipse.ui.internal.cheatsheets.registry; 12 13 import java.lang.reflect.Constructor ; 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.ui.cheatsheets.AbstractItemExtensionElement; 17 import org.eclipse.ui.internal.cheatsheets.*; 18 import org.eclipse.ui.model.*; 19 import org.osgi.framework.Bundle; 20 21 24 public class CheatSheetItemExtensionElement extends WorkbenchAdapter implements IAdaptable { 25 private String className; 26 private String itemAttribute; 27 private IConfigurationElement configurationElement; 28 private final Class [] stringArray = { String .class }; 29 30 34 public CheatSheetItemExtensionElement() { 35 } 36 37 42 public Object getAdapter(Class adapter) { 43 if (adapter == IWorkbenchAdapter.class) { 44 return this; 45 } 46 return Platform.getAdapterManager().getAdapter(this, adapter); 47 } 48 49 53 public IConfigurationElement getConfigurationElement() { 54 return configurationElement; 55 } 56 57 62 public String getClassName() { 63 return className; 64 } 65 66 71 public String getItemAttribute() { 72 return itemAttribute; 73 } 74 75 79 public void setConfigurationElement(IConfigurationElement newConfigurationElement) { 80 configurationElement = newConfigurationElement; 81 } 82 83 88 public void setClassName(String value) { 89 className = value; 90 } 91 92 97 public void setItemAttribute(String value) { 98 itemAttribute = value; 99 } 100 101 public AbstractItemExtensionElement createInstance() { 102 Class extClass = null; 103 AbstractItemExtensionElement extElement = null; 104 String pluginId = configurationElement.getContributor().getName(); 105 106 try { 107 Bundle bundle = Platform.getBundle(pluginId); 108 extClass = bundle.loadClass(className); 109 } catch (Exception e) { 110 String message = NLS.bind(Messages.ERROR_LOADING_CLASS, (new Object [] {className})); 111 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); 112 CheatSheetPlugin.getPlugin().getLog().log(status); 113 } 114 try { 115 if (extClass != null) { 116 Constructor c = extClass.getConstructor(stringArray); 117 Object [] parameters = { itemAttribute }; 118 extElement = (AbstractItemExtensionElement) c.newInstance(parameters); 119 } 120 } catch (Exception e) { 121 String message = NLS.bind(Messages.ERROR_CREATING_CLASS, (new Object [] {className})); 122 IStatus status = new Status(IStatus.ERROR, ICheatSheetResource.CHEAT_SHEET_PLUGIN_ID, IStatus.OK, message, e); 123 CheatSheetPlugin.getPlugin().getLog().log(status); 124 } 125 126 if (extElement != null){ 127 return extElement; 128 } 129 130 return null; 131 } 132 } 133 | Popular Tags |