1 19 20 package org.netbeans.modules.palette; 21 22 import org.openide.ErrorManager; 23 import org.openide.text.ActiveEditorDrop; 24 import org.openide.util.Lookup; 25 import org.openide.util.lookup.InstanceContent; 26 27 31 class ActiveEditorDropProvider implements InstanceContent.Convertor<String ,ActiveEditorDrop> { 32 33 private static ActiveEditorDropProvider instance = new ActiveEditorDropProvider(); 34 35 36 private ActiveEditorDropProvider() { 37 } 38 39 static ActiveEditorDropProvider getInstance() { 40 return instance; 41 } 42 43 public Class <? extends ActiveEditorDrop> type(String obj) { 44 return ActiveEditorDrop.class; 46 } 47 48 public String id(String obj) { 49 return obj; 50 } 51 52 public String displayName(String obj) { 53 return obj; 54 } 55 56 public ActiveEditorDrop convert(String obj) { 57 return getActiveEditorDrop(obj); 58 } 59 60 private ActiveEditorDrop getActiveEditorDrop(String instanceName) { 61 62 ActiveEditorDrop drop = null; 63 64 if (instanceName != null && instanceName.trim().length() > 0) { try { 66 ClassLoader loader = (ClassLoader )Lookup.getDefault().lookup(ClassLoader .class); 67 if (loader == null) 68 loader = getClass ().getClassLoader (); 69 Class instanceClass = loader.loadClass (instanceName); 70 drop = (ActiveEditorDrop)instanceClass.newInstance(); 71 } 72 catch (Exception ex) { 73 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 74 } 75 } 76 77 return drop; 78 } 79 80 } 81 | Popular Tags |