1 11 package org.eclipse.ui.internal.editorsupport; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.lang.reflect.Method ; 15 16 import org.eclipse.core.runtime.Platform; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.ui.IEditorPart; 19 import org.eclipse.ui.internal.util.BundleUtility; 20 import org.osgi.framework.Bundle; 21 22 26 public final class ComponentSupport { 27 28 32 public static boolean inPlaceEditorSupported() { 33 return SWT.getPlatform().equals("win32"); } 36 37 41 public static IEditorPart getSystemInPlaceEditor() { 42 if (inPlaceEditorSupported()) { 43 return getOleEditor(); 44 } 45 return null; 46 } 47 48 54 public static boolean inPlaceEditorAvailable(String filename) { 55 if (inPlaceEditorSupported()) { 56 return testForOleEditor(filename); 57 } else { 58 return false; 59 } 60 } 61 62 66 private static IEditorPart getOleEditor() { 67 Bundle bundle = Platform.getBundle("org.eclipse.ui.ide"); 74 if (!BundleUtility.isActivated(bundle)) { 76 return null; 77 } 78 79 try { 80 Class c = bundle 81 .loadClass("org.eclipse.ui.internal.editorsupport.win32.OleEditor"); return (IEditorPart) c.newInstance(); 83 } catch (ClassNotFoundException exception) { 84 return null; 85 } catch (IllegalAccessException exception) { 86 return null; 87 } catch (InstantiationException exception) { 88 return null; 89 } 90 } 91 92 public static boolean testForOleEditor(String filename) { 93 int nDot = filename.lastIndexOf('.'); 94 if (nDot >= 0) { 95 try { 96 String strName = filename.substring(nDot); 97 Class oleClass = Class.forName("org.eclipse.swt.ole.win32.OLE"); Method findMethod = oleClass.getDeclaredMethod( 99 "findProgramID", new Class [] { String .class }); strName = (String ) findMethod.invoke(null, 101 new Object [] { strName }); 102 if (strName.length() > 0) { 103 return true; 104 } 105 } catch (ClassNotFoundException exception) { 106 return false; 108 } catch (NoSuchMethodException exception) { 109 return false; 111 } catch (IllegalAccessException exception) { 112 return false; 113 } catch (InvocationTargetException exception) { 114 return false; 115 } 116 117 } 118 return false; 119 } 120 } 121 | Popular Tags |