1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 19 import org.eclipse.core.resources.ResourcesPlugin; 20 21 import org.eclipse.ltk.core.refactoring.RefactoringCore; 22 23 import org.eclipse.jface.resource.ImageRegistry; 24 25 import org.eclipse.ui.IEditorPart; 26 import org.eclipse.ui.IEditorReference; 27 import org.eclipse.ui.IWorkbench; 28 import org.eclipse.ui.IWorkbenchPage; 29 import org.eclipse.ui.IWorkbenchWindow; 30 import org.eclipse.ui.plugin.AbstractUIPlugin; 31 32 import org.eclipse.ltk.ui.refactoring.IRefactoringUIStatusCodes; 33 import org.osgi.framework.BundleContext; 34 35 public class RefactoringUIPlugin extends AbstractUIPlugin { 36 37 private static RefactoringUIPlugin fgDefault; 38 39 public RefactoringUIPlugin() { 40 fgDefault= this; 41 } 42 43 public static RefactoringUIPlugin getDefault() { 44 return fgDefault; 45 } 46 47 public static String getPluginId() { 48 return "org.eclipse.ltk.ui.refactoring"; } 50 51 public void start(BundleContext context) throws Exception { 52 super.start(context); 53 RefactoringCore.internalSetQueryFactory(new UIQueryFactory(RefactoringCore.getQueryFactory())); 54 } 55 56 public void stop(BundleContext context) throws Exception { 57 RefactoringCore.internalSetQueryFactory(null); 58 super.stop(context); 59 } 60 61 public static void log(IStatus status) { 62 getDefault().getLog().log(status); 63 } 64 65 public static void log(Throwable t) { 66 IStatus status= new Status( 67 IStatus.ERROR, getPluginId(), 68 IRefactoringUIStatusCodes.INTERNAL_ERROR, 69 RefactoringUIMessages.RefactoringUIPlugin_internal_error, 70 t); 71 ResourcesPlugin.getPlugin().getLog().log(status); 72 } 73 74 public static void logErrorMessage(String message) { 75 log(new Status(IStatus.ERROR, getPluginId(), IRefactoringUIStatusCodes.INTERNAL_ERROR, message, null)); 76 } 77 78 public static void logRemovedListener(Throwable t) { 79 IStatus status= new Status( 80 IStatus.ERROR, getPluginId(), 81 IRefactoringUIStatusCodes.INTERNAL_ERROR, 82 RefactoringUIMessages.RefactoringUIPlugin_listener_removed, 83 t); 84 ResourcesPlugin.getPlugin().getLog().log(status); 85 } 86 87 public static IEditorPart[] getInstanciatedEditors() { 88 List result= new ArrayList (0); 89 IWorkbench workbench= getDefault().getWorkbench(); 90 IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); 91 for (int windowIndex= 0; windowIndex < windows.length; windowIndex++) { 92 IWorkbenchPage[] pages= windows[windowIndex].getPages(); 93 for (int pageIndex= 0; pageIndex < pages.length; pageIndex++) { 94 IEditorReference[] references= pages[pageIndex].getEditorReferences(); 95 for (int refIndex= 0; refIndex < references.length; refIndex++) { 96 IEditorPart editor= references[refIndex].getEditor(false); 97 if (editor != null) 98 result.add(editor); 99 } 100 } 101 } 102 return (IEditorPart[])result.toArray(new IEditorPart[result.size()]); 103 } 104 105 protected ImageRegistry createImageRegistry() { 106 return RefactoringPluginImages.getImageRegistry(); 107 } 108 } 109 | Popular Tags |