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%
getImageDescriptor(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValidationService(ECPProject)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValidationServiceProvider()
M: 18 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
start(BundleContext)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
stop(BundleContext)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008-2012 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: ******************************************************************************/
13: package org.eclipse.emf.ecp.validation.connector;
14:
15: import java.util.Collection;
16: import java.util.HashSet;
17: import java.util.Set;
18:
19: import org.eclipse.core.runtime.Plugin;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecp.core.ECPProject;
22: import org.eclipse.emf.ecp.core.util.ECPUtil;
23: import org.eclipse.emf.ecp.core.util.observer.ECPProjectContentChangedObserver;
24: import org.eclipse.emf.ecp.core.util.observer.ECPProjectsChangedObserver;
25: import org.eclipse.emf.ecp.validation.api.IValidationService;
26: import org.eclipse.emf.ecp.validation.api.IValidationServiceProvider;
27: import org.eclipse.jface.resource.ImageDescriptor;
28: import org.osgi.framework.BundleContext;
29: import org.osgi.framework.ServiceReference;
30:
31: /**
32: * The activator class controls the plug-in life cycle.
33: *
34: * @author emueller
35: */
36: public class Activator extends Plugin {
37:
38:         /**
39:          * The plug-in ID.
40:          */
41:         public static final String PLUGIN_ID = "org.eclipse.emf.ecp.validation.connector"; //$NON-NLS-1$
42:
43:         /**
44:          * The shared instance.
45:          */
46:         private static Activator plugin;
47:
48:         private IValidationServiceProvider validationServiceProvider;
49:
50:         private ValidationObserver validationObserver;
51:
52:         private BundleContext context;
53:
54:         /**
55:          * The constructor.
56:          */
57:         public Activator() {
58:         }
59:
60:         /**
61:          * {@inheritDoc}
62:          */
63:         @Override
64:         public void start(BundleContext context) throws Exception {
65:                 super.start(context);
66:                 this.context = context;
67:                 plugin = this;
68:
69:                 validationObserver = new ValidationObserver();
70:                 ECPUtil.getECPObserverBus().register(validationObserver);
71:         }
72:
73:         /**
74:          * {@inheritDoc}
75:          */
76:         @Override
77:         public void stop(BundleContext context) throws Exception {
78:                 ECPUtil.getECPObserverBus().unregister(validationObserver);
79:                 plugin = null;
80:                 super.stop(context);
81:         }
82:
83:         // END SUPRESS CATCH EXCEPTION
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:          * Returns the validation service.
96:          *
97:          * @param project
98:          * the project for which to return the validation service
99:          *
100:          * @return the validation service
101:          */
102:         public IValidationService getValidationService(ECPProject project) {
103:                 return getValidationServiceProvider().getValidationService(project);
104:         }
105:
106:         private IValidationServiceProvider getValidationServiceProvider() {
107:•                if (validationServiceProvider == null) {
108:                         // Register directly with the service
109:                         final ServiceReference<IValidationServiceProvider> reference = context
110:                                 .getServiceReference(IValidationServiceProvider.class);
111:                         validationServiceProvider = context.getService(reference);
112:                 }
113:                 return validationServiceProvider;
114:         }
115:
116:         /**
117:          * Project change observer that validates changed objects.
118:          */
119:         private class ValidationObserver implements ECPProjectsChangedObserver, ECPProjectContentChangedObserver {
120:
121:                 // BEGIN SUPRESS CATCH EXCEPTION
122:                 /** {@inheritDoc} **/
123:                 @Override
124:                 public void projectsChanged(Collection<ECPProject> oldProjects, Collection<ECPProject> newProjects) {
125:                         // List<ECPProject> newProjectList = Arrays.asList(newProjects);
126:                         for (final ECPProject project : oldProjects) {
127:                                 if (!newProjects.contains(project)) {
128:                                         getValidationServiceProvider().deleteValidationService(project);
129:                                 }
130:                         }
131:                 }
132:
133:                 /** {@inheritDoc} **/
134:                 @Override
135:                 public Collection<Object> objectsChanged(ECPProject project, Collection<Object> objects) {
136:                         final Set<Object> allAffectedElements = new HashSet<Object>();
137:
138:                         for (final Object object : objects) {
139:                                 if (object instanceof EObject) {
140:                                         final EObject eObject = (EObject) object;
141:
142:                                         if (eObject.eContainer() == null && eObject.eResource() == null) {
143:                                                 // if an object was deleted it must be removed from the cachedTree.
144:                                                 for (final EObject childObject : eObject.eContents()) {
145:                                                         getValidationService(project).remove(childObject);
146:                                                 }
147:                                                 getValidationService(project).remove(eObject);
148:                                         } else {
149:                                                 final Set<EObject> affected = getValidationService(project).validate(eObject);
150:                                                 allAffectedElements.addAll(affected);
151:                                         }
152:                                 }
153:                         }
154:                         return allAffectedElements;
155:                 }
156:         }
157:
158:         /**
159:          * Returns an {@link ImageDescriptor} for the image file at the given plug-in
160:          * relative path.
161:          *
162:          * @param path
163:          * the path
164:          * @return the image descriptor
165:          */
166:         public static ImageDescriptor getImageDescriptor(String path) {
167:                 return ImageDescriptor.createFromURL(getDefault().getBundle().getResource(path));
168:                 // return imageDescriptorFromPlugin(PLUGIN_ID, path);
169:         }
170:
171: }