KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > EclEmmaUIPlugin


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: EclEmmaUIPlugin.java 396 2007-08-30 06:07:12Z mtnminds $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.ui;
9
10 import java.net.URL JavaDoc;
11
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.jface.resource.ImageRegistry;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.IViewPart;
20 import org.eclipse.ui.IWorkbenchPage;
21 import org.eclipse.ui.IWorkbenchWindow;
22 import org.eclipse.ui.PartInitException;
23 import org.eclipse.ui.plugin.AbstractUIPlugin;
24 import org.osgi.framework.BundleContext;
25
26 import com.mountainminds.eclemma.core.CoverageTools;
27 import com.mountainminds.eclemma.core.ICoverageSession;
28 import com.mountainminds.eclemma.core.ISessionListener;
29 import com.mountainminds.eclemma.internal.ui.annotation.EditorTracker;
30 import com.mountainminds.eclemma.internal.ui.coverageview.CoverageView;
31
32 /**
33  *
34  * @author Marc R. Hoffmann
35  * @version $Revision: 396 $
36  */

37 public class EclEmmaUIPlugin extends AbstractUIPlugin {
38   
39   public static final String JavaDoc ID = "com.mountainminds.eclemma.ui"; //$NON-NLS-1$
40

41   /** Identifier for the 'coverage' launch group. */
42   public static final String JavaDoc ID_COVERAGE_LAUNCH_GROUP = ID + ".launchGroup.coverage"; //$NON-NLS-1$
43

44   
45   // Icons used by the Plugin
46

47   public static final String JavaDoc ELCL_REFRESH = "icons/full/elcl16/refresh.gif"; //$NON-NLS-1$
48
public static final String JavaDoc DLCL_REFRESH = "icons/full/dlcl16/refresh.gif"; //$NON-NLS-1$
49
public static final String JavaDoc ELCL_IMPORT = "icons/full/elcl16/import.gif"; //$NON-NLS-1$
50
public static final String JavaDoc DLCL_IMPORT = "icons/full/dlcl16/import.gif"; //$NON-NLS-1$
51
public static final String JavaDoc ELCL_EXPORT = "icons/full/elcl16/export.gif"; //$NON-NLS-1$
52
public static final String JavaDoc DLCL_EXPORT = "icons/full/dlcl16/export.gif"; //$NON-NLS-1$
53
public static final String JavaDoc ELCL_REMOVE = "icons/full/elcl16/remove.gif"; //$NON-NLS-1$
54
public static final String JavaDoc DLCL_REMOVE = "icons/full/dlcl16/remove.gif"; //$NON-NLS-1$
55
public static final String JavaDoc ELCL_REMOVEALL = "icons/full/elcl16/removeall.gif"; //$NON-NLS-1$
56
public static final String JavaDoc DLCL_REMOVEALL = "icons/full/dlcl16/removeall.gif"; //$NON-NLS-1$
57
public static final String JavaDoc ELCL_MERGESESSIONS = "icons/full/elcl16/mergesessions.gif"; //$NON-NLS-1$
58
public static final String JavaDoc DLCL_MERGESESSIONS = "icons/full/dlcl16/mergesessions.gif"; //$NON-NLS-1$
59
public static final String JavaDoc ELCL_RELAUNCH = "icons/full/elcl16/relaunch.gif"; //$NON-NLS-1$
60
public static final String JavaDoc DLCL_RELAUNCH = "icons/full/dlcl16/relaunch.gif"; //$NON-NLS-1$
61
public static final String JavaDoc ELCL_SESSION = "icons/full/elcl16/session.gif"; //$NON-NLS-1$
62
public static final String JavaDoc DLCL_SESSION = "icons/full/dlcl16/session.gif"; //$NON-NLS-1$
63
public static final String JavaDoc ELCL_SHOWPROJECTS = "icons/full/elcl16/showprojects.gif"; //$NON-NLS-1$
64
public static final String JavaDoc ELCL_SHOWPACKAGEROOTS = "icons/full/elcl16/showpackageroots.gif"; //$NON-NLS-1$
65
public static final String JavaDoc ELCL_SHOWPACKAGES = "icons/full/elcl16/showpackages.gif"; //$NON-NLS-1$
66
public static final String JavaDoc ELCL_SHOWTYPES = "icons/full/elcl16/showtypes.gif"; //$NON-NLS-1$
67
public static final String JavaDoc ELCL_COLLAPSEALL = "icons/full/elcl16/collapseall.gif"; //$NON-NLS-1$
68
public static final String JavaDoc ELCL_LINKED = "icons/full/elcl16/linked.gif"; //$NON-NLS-1$
69

70   public static final String JavaDoc EVIEW_COVERAGE = "icons/full/eview16/coverage.gif"; //$NON-NLS-1$
71

72   public static final String JavaDoc OBJ_SESSION = "icons/full/obj16/session.gif"; //$NON-NLS-1$
73

74   private static final String JavaDoc[] OBJ_COVERAGE = new String JavaDoc[] {
75     "icons/full/obj16/coverage00.gif", //$NON-NLS-1$
76
"icons/full/obj16/coverage01.gif", //$NON-NLS-1$
77
"icons/full/obj16/coverage02.gif", //$NON-NLS-1$
78
"icons/full/obj16/coverage03.gif", //$NON-NLS-1$
79
"icons/full/obj16/coverage04.gif", //$NON-NLS-1$
80
"icons/full/obj16/coverage05.gif", //$NON-NLS-1$
81
"icons/full/obj16/coverage06.gif", //$NON-NLS-1$
82
"icons/full/obj16/coverage07.gif", //$NON-NLS-1$
83
"icons/full/obj16/coverage08.gif", //$NON-NLS-1$
84
"icons/full/obj16/coverage09.gif", //$NON-NLS-1$
85
"icons/full/obj16/coverage10.gif", //$NON-NLS-1$
86
"icons/full/obj16/coverage11.gif", //$NON-NLS-1$
87
"icons/full/obj16/coverage12.gif" //$NON-NLS-1$
88
};
89   
90   private static final String JavaDoc[] OBJ_COVERAGE_OVERLAY = new String JavaDoc[] {
91     "icons/full/ovr16/coverage00.gif", //$NON-NLS-1$
92
"icons/full/ovr16/coverage01.gif", //$NON-NLS-1$
93
"icons/full/ovr16/coverage02.gif", //$NON-NLS-1$
94
"icons/full/ovr16/coverage03.gif", //$NON-NLS-1$
95
"icons/full/ovr16/coverage04.gif", //$NON-NLS-1$
96
"icons/full/ovr16/coverage05.gif", //$NON-NLS-1$
97
"icons/full/ovr16/coverage06.gif", //$NON-NLS-1$
98
"icons/full/ovr16/coverage07.gif" //$NON-NLS-1$
99
};
100
101   public static final String JavaDoc WIZBAN_EXPORT_SESSION = "icons/full/wizban/export_session.gif"; //$NON-NLS-1$
102
public static final String JavaDoc WIZBAN_IMPORT_SESSION = "icons/full/wizban/import_session.gif"; //$NON-NLS-1$
103

104   
105   private static EclEmmaUIPlugin instance;
106
107   private EditorTracker editorTracker;
108   
109   private ISessionListener sessionListener = new ISessionListener() {
110     public void sessionAdded(ICoverageSession addedSession) {
111       if (getPreferenceStore().getBoolean(UIPreferences.PREF_SHOW_COVERAGE_VIEW)) {
112         getWorkbench().getDisplay().asyncExec(new Runnable JavaDoc() {
113           public void run() {
114             showCoverageView();
115           }
116         });
117       }
118     }
119     public void sessionRemoved(ICoverageSession removedSession) {
120     }
121     public void sessionActivated(ICoverageSession session) {
122     }
123   };
124   
125   public void start(BundleContext context) throws Exception JavaDoc {
126     super.start(context);
127     CoverageTools.setPreferences(UIPreferences.CORE_PREFERENCES);
128     CoverageTools.getSessionManager().addSessionListener(sessionListener);
129     editorTracker = new EditorTracker(getWorkbench());
130     instance = this;
131   }
132
133   public void stop(BundleContext context) throws Exception JavaDoc {
134     instance = null;
135     editorTracker.dispose();
136     CoverageTools.getSessionManager().removeSessionListener(sessionListener);
137     super.stop(context);
138   }
139   
140   public static EclEmmaUIPlugin getInstance() {
141     return instance;
142   }
143   
144   private void showCoverageView() {
145     IWorkbenchWindow window = getWorkbench().getActiveWorkbenchWindow();
146     if (window == null) return;
147     IWorkbenchPage page = window.getActivePage();
148     if (page != null) {
149       try {
150         IViewPart view = page.showView(CoverageView.ID, null, IWorkbenchPage.VIEW_CREATE);
151         page.bringToTop(view);
152       } catch (PartInitException e) {
153         log(e);
154       }
155     }
156   }
157   
158   public Shell getShell() {
159     return getWorkbench().getActiveWorkbenchWindow().getShell();
160   }
161   
162   public static IStatus errorStatus(String JavaDoc message, Throwable JavaDoc t) {
163     return new Status(IStatus.ERROR, ID, IStatus.ERROR, message, t);
164   }
165
166   public static void log(Throwable JavaDoc t) {
167     String JavaDoc message = t.getMessage();
168     if (message == null) {
169       message = "Internal Error"; //$NON-NLS-1$
170
}
171     instance.getLog().log(errorStatus(message, t));
172   }
173
174   public static void log(CoreException t) {
175     instance.getLog().log(t.getStatus());
176   }
177   
178   public static ImageDescriptor getImageDescriptor(String JavaDoc key) {
179     return loadImage(key).getDescriptor(key);
180   }
181
182   public static Image getImage(String JavaDoc key) {
183     return loadImage(key).get(key);
184   }
185   
186   public static Image getCoverageImage(double ratio) {
187     int idx = (int) Math.round(ratio * OBJ_COVERAGE.length);
188     if (idx < 0) idx = 0;
189     if (idx >= OBJ_COVERAGE.length) idx = OBJ_COVERAGE.length - 1;
190     return getImage(OBJ_COVERAGE[idx]);
191   }
192   
193   public static ImageDescriptor getCoverageOverlay(double ratio) {
194       int idx = (int) Math.round(ratio * OBJ_COVERAGE_OVERLAY.length);
195       if (idx < 0) idx = 0;
196       if (idx >= OBJ_COVERAGE_OVERLAY.length) idx = OBJ_COVERAGE_OVERLAY.length - 1;
197       return getImageDescriptor(OBJ_COVERAGE_OVERLAY[idx]);
198   }
199   
200   private static ImageRegistry loadImage(String JavaDoc path) {
201     ImageRegistry reg = getInstance().getImageRegistry();
202     if (reg.getDescriptor(path) == null) {
203       URL JavaDoc url = instance.getBundle().getEntry(path);
204       reg.put(path, ImageDescriptor.createFromURL(url));
205     }
206     return reg;
207   }
208    
209 }
210
Popular Tags