Skip to content

Package: Activator

Activator

nameinstructionbranchcomplexitylinemethod
Activator()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
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(URL)
M: 39 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
log(Throwable)
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
start(BundleContext)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
stop(BundleContext)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

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: package org.eclipse.emf.ecp.view.internal.categorization.swt;
15:
16: import java.net.URL;
17: import java.util.LinkedHashMap;
18: import java.util.Map;
19:
20: import org.eclipse.core.runtime.IStatus;
21: import org.eclipse.core.runtime.Plugin;
22: import org.eclipse.core.runtime.Status;
23: import org.eclipse.jface.resource.ImageDescriptor;
24: import org.eclipse.swt.graphics.Image;
25: import org.osgi.framework.BundleContext;
26:
27: /**
28: * The activator class controls the plug-in life cycle.
29: */
30: public class Activator extends Plugin {
31:
32:         /** The plug-in ID. */
33:         public static final String PLUGIN_ID = "org.eclipse.emf.ecp.view.categorization.swt"; //$NON-NLS-1$
34:
35:         /** The shared instance. */
36:         private static Activator plugin;
37:
38:         @SuppressWarnings("restriction")
39:         private final Map<String, org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage> imageRegistry = new LinkedHashMap<String, org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage>(
40:                 20, .8F, true) {
41:                 private static final long serialVersionUID = 1L;
42:
43:                 // This method is called just after a new entry has been added
44:                 @Override
45:                 public boolean removeEldestEntry(
46:                         Map.Entry<String, org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage> eldest) {
47:                         return size() > 20;
48:                 }
49:
50:                 @Override
51:                 public org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage remove(Object arg0) {
52:                         final org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage image = super.remove(arg0);
53:                         image.getImage().dispose();
54:                         return image;
55:                 }
56:
57:         };
58:
59:         /**
60:          * The constructor.
61:          */
62:         public Activator() {
63:         }
64:
65:         /*
66:          * (non-Javadoc)
67:          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
68:          */
69:         @Override
70:         public void start(BundleContext context) throws Exception {
71:                 super.start(context);
72:                 plugin = this;
73:         }
74:
75:         /*
76:          * (non-Javadoc)
77:          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
78:          */
79:         @Override
80:         public void stop(BundleContext context) throws Exception {
81:                 plugin = null;
82:                 super.stop(context);
83:         }
84:
85:         /**
86:          * Returns the shared instance.
87:          *
88:          * @return the shared instance
89:          */
90:         public static Activator getDefault() {
91:                 return plugin;
92:         }
93:
94:         /**
95:          * Log an Exception.
96:          *
97:          * @param throwable the {@link Throwable} to log
98:          */
99:         public static void log(Throwable throwable) {
100:                 plugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, throwable.getMessage(), throwable));
101:         }
102:
103:         /**
104:          * Loads an image based on the provided {@link URL} form this bundle. The url may be null, then an empty image is
105:          * returned.
106:          *
107:          * @param url the {@link URL} to load the {@link Image} from
108:          * @return the {@link Image}
109:          */
110:         @SuppressWarnings("restriction")
111:         public static Image getImage(URL url) {
112:•                if (!getDefault().imageRegistry.containsKey(url == null ? "NULL" : url.toExternalForm())) { //$NON-NLS-1$
113:
114:                         final ImageDescriptor createFromURL = ImageDescriptor.createFromURL(url);
115:•                        getDefault().imageRegistry.put(url == null ? "NULL" : url.toExternalForm(), //$NON-NLS-1$
116:                                 new org.eclipse.emf.ecp.edit.internal.swt.ImageDescriptorToImage(createFromURL));
117:                 }
118:•                return getDefault().imageRegistry.get(url == null ? "NULL" : url.toExternalForm()).getImage(); //$NON-NLS-1$
119:
120:         }
121:
122: }