KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > launching > CoverageLaunchShortcut


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: CoverageLaunchShortcut.java 167 2006-11-14 18:20:16Z mtnminds $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.ui.launching;
9
10 import org.eclipse.core.runtime.CoreException;
11 import org.eclipse.core.runtime.IConfigurationElement;
12 import org.eclipse.core.runtime.IExecutableExtension;
13 import org.eclipse.core.runtime.IExtensionPoint;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.debug.ui.IDebugUIConstants;
16 import org.eclipse.debug.ui.ILaunchShortcut;
17 import org.eclipse.jface.viewers.ISelection;
18 import org.eclipse.ui.IEditorPart;
19
20 import com.mountainminds.eclemma.core.CoverageTools;
21 import com.mountainminds.eclemma.internal.ui.EclEmmaUIPlugin;
22
23 /**
24  * Generic ILaunchShortcut implementation that delegates to another
25  * ILaunchShortcut with a given id. The id is specified via the executable
26  * extension attribute "class":
27  *
28  * <pre>
29  * class="com.mountainminds.eclemma.internal.ui.launching.CoverageLaunchShortcut:org.eclipse.jdt.debug.ui.localJavaShortcut"
30  * </pre>
31  *
32  * @author Marc R. Hoffmann
33  * @version $Revision: 167 $
34  */

35 public class CoverageLaunchShortcut implements ILaunchShortcut, IExecutableExtension {
36
37   private String JavaDoc delegateId;
38   private ILaunchShortcut delegate;
39   
40   private ILaunchShortcut getDelegate() {
41     if (delegate == null) {
42       IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(IDebugUIConstants.PLUGIN_ID, IDebugUIConstants.EXTENSION_POINT_LAUNCH_SHORTCUTS);
43       IConfigurationElement[] configs = extensionPoint.getConfigurationElements();
44       for (int i = 0; i < configs.length; i++) {
45         if (delegateId.equals(configs[i].getAttribute("id"))) { //$NON-NLS-1$
46
try {
47             delegate = (ILaunchShortcut) configs[i].createExecutableExtension("class"); //$NON-NLS-1$
48
} catch (CoreException e) {
49             EclEmmaUIPlugin.log(e);
50           }
51           break;
52         }
53       }
54       if (delegate == null) {
55         String JavaDoc msg = "ILaunchShortcut declaration not found: " + delegateId; //$NON-NLS-1$
56
EclEmmaUIPlugin.getInstance().getLog().log(EclEmmaUIPlugin.errorStatus(msg, null));
57       }
58     }
59     return delegate;
60   }
61   
62   // IExecutableExtension interface:
63

64   public void setInitializationData(IConfigurationElement config, String JavaDoc propertyName, Object JavaDoc data) throws CoreException {
65     delegateId = String.valueOf(data);
66   }
67
68   // ILaunchShortcut interface:
69

70   public void launch(ISelection selection, String JavaDoc mode) {
71     ILaunchShortcut delegate = getDelegate();
72     if (delegate != null) {
73       delegate.launch(selection, CoverageTools.LAUNCH_MODE);
74     }
75   }
76   
77   public void launch(IEditorPart editor, String JavaDoc mode) {
78     ILaunchShortcut delegate = getDelegate();
79     if (delegate != null) {
80       delegate.launch(editor, CoverageTools.LAUNCH_MODE);
81     }
82   }
83   
84 }
85
Popular Tags