Skip to content

Package: Activator

Activator

nameinstructionbranchcomplexitylinemethod
Activator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getDefault()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getImage(String)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getImageDescriptor(String)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getStatus(Throwable)
M: 29 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
loadImage(String)
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
loadImageDescriptor(String)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
log(IStatus)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
log(String)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
log(String, Throwable)
M: 23 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
log(Throwable)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
start(BundleContext)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
stop(BundleContext)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2013 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.ui.platform;
16:
17: import java.net.URL;
18:
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.core.runtime.FileLocator;
21: import org.eclipse.core.runtime.IStatus;
22: import org.eclipse.core.runtime.Path;
23: import org.eclipse.core.runtime.Platform;
24: import org.eclipse.core.runtime.Status;
25: import org.eclipse.jface.resource.ImageDescriptor;
26: import org.eclipse.swt.graphics.Image;
27: import org.eclipse.ui.plugin.AbstractUIPlugin;
28: import org.osgi.framework.BundleContext;
29:
30: /**
31: * The activator class controls the plug-in life cycle.
32: */
33: public class Activator extends AbstractUIPlugin {
34:
35:         /** The plug-in ID. */
36:         public static final String PLUGIN_ID = "org.eclipse.emf.ecp.ui.e3"; //$NON-NLS-1$
37:
38:         // The shared instance
39:         private static Activator instance;
40:
41:         /**
42:          * The constructor.
43:          */
44:         public Activator() {
45:         }
46:
47:         // BEGIN SUPRESS CATCH EXCEPTION
48:         @Override
49:         public void start(BundleContext context) throws Exception {
50:                 super.start(context);
51:                 instance = this;
52:
53:         }
54:
55:         @Override
56:         public void stop(BundleContext context) throws Exception {
57:                 instance = null;
58:                 super.stop(context);
59:         }
60:
61:         // END SUPRESS CATCH EXCEPTION
62:         /**
63:          * Returns the shared instance.
64:          *
65:          * @return the shared instance
66:          */
67:         public static Activator getDefault() {
68:                 return instance;
69:         }
70:
71:         /**
72:          * Logs messages.
73:          *
74:          * @param message the message
75:          */
76:         public static void log(String message) {
77:                 instance.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message));
78:         }
79:
80:         /**
81:          * Logs messages and {@link Throwable}.
82:          *
83:          * @param message the message
84:          * @param t the throwable
85:          */
86:         public static void log(String message, Throwable t) {
87:•                if (t instanceof CoreException) {
88:                         final CoreException coreException = (CoreException) t;
89:                         instance.getLog().log(coreException.getStatus());
90:                 } else {
91:                         instance.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, t));
92:                 }
93:         }
94:
95:         /**
96:          * Logs {@link IStatus}.
97:          *
98:          * @param status the {@link IStatus}
99:          */
100:         public static void log(IStatus status) {
101:                 instance.getLog().log(status);
102:         }
103:
104:         /**
105:          * Logs {@link Throwable}.
106:          *
107:          * @param t the {@link Throwable}
108:          * @return the message of the created status
109:          */
110:         public static String log(Throwable t) {
111:                 final IStatus status = getStatus(t);
112:                 log(status);
113:                 return status.getMessage();
114:         }
115:
116:         /**
117:          * Gets a {@link IStatus} for a throwable.
118:          *
119:          * @param t the {@link Throwable}
120:          * @return the created {@link IStatus}
121:          */
122:         public static IStatus getStatus(Throwable t) {
123:•                if (t instanceof CoreException) {
124:                         final CoreException coreException = (CoreException) t;
125:                         return coreException.getStatus();
126:                 }
127:
128:                 String msg = t.getLocalizedMessage();
129:•                if (msg == null || msg.length() == 0) {
130:                         msg = t.getClass().getName();
131:                 }
132:
133:                 return new Status(IStatus.ERROR, PLUGIN_ID, msg, t);
134:         }
135:
136:         /**
137:          * Returns an {@link ImageDescriptor} for a path.
138:          *
139:          * @param path the path to an image
140:          * @return the {@link ImageDescriptor}
141:          */
142:         public static ImageDescriptor getImageDescriptor(String path) {
143:                 // return ResourceManager.getPluginImageDescriptor(PLUGIN_ID, path);
144:                 ImageDescriptor id = getDefault().getImageRegistry().getDescriptor(path);
145:•                if (id == null) {
146:                         id = loadImageDescriptor(path);
147:                 }
148:                 return id;
149:         }
150:
151:         /**
152:          * Gets an {@link Image} for a path.
153:          *
154:          * @param path the path to an image
155:          * @return the image
156:          */
157:         public static Image getImage(String path) {
158:                 Image image = getDefault().getImageRegistry().get(path);
159:•                if (image == null) {
160:                         image = loadImage(path);
161:                 }
162:                 return image;
163:         }
164:
165:         private static Image loadImage(String path) {
166:                 final ImageDescriptor id = loadImageDescriptor(path);
167:•                if (id == null) {
168:                         return null;
169:                 }
170:                 getDefault().getImageRegistry().put(path, id);
171:                 return getDefault().getImageRegistry().get(path);
172:         }
173:
174:         private static ImageDescriptor loadImageDescriptor(String path) {
175:                 final URL url = FileLocator.find(Platform.getBundle(PLUGIN_ID), new Path(path), null);
176:•                if (url == null) {
177:                         return null;
178:                 }
179:                 final ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
180:                 getDefault().getImageRegistry().put(path, imageDescriptor);
181:                 return imageDescriptor;
182:         }
183: }