Skip to content

Package: E4ModelElementOpener

E4ModelElementOpener

nameinstructionbranchcomplexitylinemethod
E4ModelElementOpener()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
openModelElement(Object, ECPProject)
M: 89 C: 0
0%
M: 14 C: 0
0%
M: 8 C: 0
0%
M: 24 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.application.e4.editor;
16:
17: import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18: import org.eclipse.e4.ui.workbench.modeling.EPartService;
19: import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
20: import org.eclipse.emf.ecp.core.ECPProject;
21: import org.eclipse.emf.ecp.ui.e4.editor.ECPE4Editor;
22: import org.eclipse.emf.ecp.ui.e4.util.EPartServiceHelper;
23: import org.eclipse.emf.ecp.ui.util.ECPModelElementOpener;
24: import org.eclipse.emfforms.spi.common.report.AbstractReport;
25: import org.eclipse.emfforms.spi.common.report.ReportService;
26: import org.osgi.framework.BundleContext;
27: import org.osgi.framework.FrameworkUtil;
28: import org.osgi.framework.ServiceReference;
29:
30: /**
31: * Opens a model element in {@link ECPE4Editor}.
32: *
33: * @author Jonas
34: *
35: */
36: public class E4ModelElementOpener implements ECPModelElementOpener {
37:
38:         private final String partId = "org.eclipse.emf.ecp.e4.application.partdescriptor.editor"; //$NON-NLS-1$
39:
40:         /**
41:          * Opens a model element in {@link ECPE4Editor}. {@inheritDoc}
42:          *
43:          * @see org.eclipse.emf.ecp.ui.util.ECPModelElementOpener#openModelElement(java.lang.Object,
44:          * org.eclipse.emf.ecp.core.ECPProject)
45:          */
46:         @Override
47:         public void openModelElement(Object modelElement, ECPProject ecpProject) {
48:                 final EPartService partService = EPartServiceHelper.getEPartService();
49:•                for (final MPart existingPart : partService.getParts()) {
50:•                        if (!partId.equals(existingPart.getElementId())) {
51:                                 continue;
52:                         }
53:
54:•                        if (existingPart.getContext() == null) {
55:                                 continue;
56:                         }
57:
58:•                        if (existingPart.getContext().get(ECPE4Editor.INPUT) == modelElement) {
59:•                                if (!existingPart.isVisible() || !existingPart.isOnTop()) {
60:                                         partService.showPart(existingPart, PartState.ACTIVATE);
61:                                 }
62:                                 return;
63:                         }
64:                 }
65:
66:                 final MPart part = partService.createPart(partId);
67:•                if (part == null) {
68:                         final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
69:                         final ServiceReference<ReportService> serviceReference = bundleContext
70:                                 .getServiceReference(ReportService.class);
71:                         final ReportService reportService = bundleContext.getService(serviceReference);
72:                         reportService
73:                                 .report(new AbstractReport("There is no partdescription with the id " + partId + " available!")); //$NON-NLS-1$ //$NON-NLS-2$
74:                         bundleContext.ungetService(serviceReference);
75:                         return;
76:                 }
77:                 partService.showPart(part, PartState.ACTIVATE);
78:                 part.getContext().set(ECPProject.class, ecpProject);
79:                 part.getContext().set(ECPE4Editor.INPUT, modelElement);
80:         }
81:
82: }