1 11 package org.eclipse.ui.internal; 12 13 import java.lang.reflect.Constructor ; 14 import java.lang.reflect.InvocationTargetException ; 15 import java.lang.reflect.Method ; 16 17 import org.eclipse.core.resources.IFile; 18 import org.eclipse.core.resources.IMarker; 19 import org.eclipse.core.runtime.IPluginDescriptor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.ui.IEditorInput; 24 import org.eclipse.ui.IEditorPart; 25 import org.eclipse.ui.IEditorRegistry; 26 import org.eclipse.ui.IWorkbenchPage; 27 import org.eclipse.ui.PartInitException; 28 29 42 public class CompatibleWorkbenchPage implements ICompatibleWorkbenchPage { 43 44 48 public IEditorPart openEditor(IFile input) throws PartInitException { 49 return openEditor(new Class [] { IWorkbenchPage.class, IFile.class, 52 boolean.class }, 53 new Object [] { this, input, new Boolean (true) }); 54 } 55 56 60 public IEditorPart openEditor(IFile input, String editorID) 61 throws PartInitException { 62 return openEditor(input, editorID, true); 63 } 64 65 69 public IEditorPart openEditor(IFile input, String editorID, boolean activate) 70 throws PartInitException { 71 return ((IWorkbenchPage) this).openEditor(getFileEditorInput(input), 72 editorID); 73 } 74 75 79 public IEditorPart openEditor(IMarker marker) throws PartInitException { 80 return openEditor(marker, true); 81 } 82 83 87 public IEditorPart openEditor(IMarker marker, boolean activate) 88 throws PartInitException { 89 return openEditor(new Class [] { IWorkbenchPage.class, IMarker.class, 92 boolean.class }, new Object [] { this, marker, 93 new Boolean (activate) }); 94 } 95 96 100 public void openSystemEditor(IFile file) throws PartInitException { 101 ((IWorkbenchPage) this).openEditor(getFileEditorInput(file), 102 IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID); 103 104 } 105 106 111 private IEditorInput getFileEditorInput(IFile file) 112 throws PartInitException { 113 IPluginDescriptor desc = Platform.getPluginRegistry() 114 .getPluginDescriptor("org.eclipse.ui.ide"); Exception problem; 116 try { 117 Class clazz = desc.getPluginClassLoader().loadClass( 118 "org.eclipse.ui.part.FileEditorInput"); Constructor constructor = clazz 120 .getConstructor(new Class [] { IFile.class }); 121 return (IEditorInput) constructor 122 .newInstance(new Object [] { file }); 123 } catch (NullPointerException e) { 124 problem = e; 125 } catch (ClassNotFoundException e) { 126 problem = e; 127 } catch (NoSuchMethodException e) { 128 problem = e; 129 } catch (IllegalArgumentException e) { 130 problem = e; 131 } catch (IllegalAccessException e) { 132 problem = e; 133 } catch (InvocationTargetException e) { 134 problem = e; 135 } catch (InstantiationException e) { 136 problem = e; 137 } 138 IStatus status = new Status( 139 IStatus.ERROR, 140 WorkbenchPlugin.PI_WORKBENCH, 141 0, 142 "openEditor() compatibility support failed - new FileEditorInput(file)", problem); WorkbenchPlugin.log(status.getMessage(), status); 144 throw new PartInitException(status); 145 } 146 147 152 private IEditorPart openEditor(Class [] argTypes, Object [] args) 153 throws PartInitException { 154 IPluginDescriptor desc = Platform.getPluginRegistry() 155 .getPluginDescriptor("org.eclipse.ui.ide"); Throwable problem; 157 try { 158 Class clazz = desc.getPluginClassLoader().loadClass( 159 "org.eclipse.ui.ide.IDE"); Method method = clazz.getMethod("openEditor", argTypes); return (IEditorPart) method.invoke(null, args); 162 } catch (NullPointerException e) { 163 problem = e; 164 } catch (ClassNotFoundException e) { 165 problem = e; 166 } catch (NoSuchMethodException e) { 167 problem = e; 168 } catch (IllegalArgumentException e) { 169 problem = e; 170 } catch (IllegalAccessException e) { 171 problem = e; 172 } catch (InvocationTargetException e) { 173 problem = e; 174 } 175 IStatus status = new Status( 176 IStatus.ERROR, 177 WorkbenchPlugin.PI_WORKBENCH, 178 0, 179 "openEditor() compatibility support failed - IDE.openEditor()", problem); WorkbenchPlugin.log(status.getMessage(), status); 181 throw new PartInitException(status); 182 } 183 } 184 | Popular Tags |