KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > RefactoringUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ltk.internal.ui.refactoring;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 JavaDoc getPluginId() {
48         return "org.eclipse.ltk.ui.refactoring"; //$NON-NLS-1$
49
}
50     
51     public void start(BundleContext context) throws Exception JavaDoc {
52         super.start(context);
53         RefactoringCore.internalSetQueryFactory(new UIQueryFactory(RefactoringCore.getQueryFactory()));
54     }
55     
56     public void stop(BundleContext context) throws Exception JavaDoc {
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 JavaDoc 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 JavaDoc message) {
75         log(new Status(IStatus.ERROR, getPluginId(), IRefactoringUIStatusCodes.INTERNAL_ERROR, message, null));
76     }
77     
78     public static void logRemovedListener(Throwable JavaDoc 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 JavaDoc result= new ArrayList JavaDoc(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