Skip to content

Package: GotoMarkerAdapter

GotoMarkerAdapter

nameinstructionbranchcomplexitylinemethod
GotoMarkerAdapter(ViewModelContext, EditingDomain)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getEObject(List)
M: 11 C: 13
54%
M: 4 C: 2
33%
M: 3 C: 1
25%
M: 4 C: 4
50%
M: 0 C: 1
100%
getEStructuralFeature(List)
M: 0 C: 23
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 6
100%
M: 0 C: 1
100%
gotoMarker(IMarker)
M: 0 C: 38
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 11
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2019 Christian W. Damus 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: * Christian W. Damus - initial API and implementation
13: ******************************************************************************/
14: package org.eclipse.emfforms.spi.editor;
15:
16: import java.util.Iterator;
17: import java.util.List;
18:
19: import org.eclipse.core.resources.IMarker;
20: import org.eclipse.emf.common.ui.MarkerHelper;
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecore.EStructuralFeature;
23: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
24: import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
25: import org.eclipse.emf.edit.domain.EditingDomain;
26: import org.eclipse.emf.edit.ui.util.EditUIMarkerHelper;
27: import org.eclipse.emfforms.spi.core.services.reveal.EMFFormsRevealService;
28: import org.eclipse.ui.ide.IGotoMarker;
29:
30: /**
31: * Adapter for the {@link IGotoMarker} protocol that delegates to the
32: * {@link EMFFormsRevealService}.
33: *
34: * @since 1.22
35: */
36: public class GotoMarkerAdapter implements IGotoMarker {
37:
38:         private final MarkerHelper helper = new EditUIMarkerHelper();
39:
40:         private final ViewModelContext context;
41:         private final EditingDomain editingDomain;
42:
43:         /**
44:          * Initializes me.
45:          *
46:          * @param context the editor's view model context
47:          * @param editingDomain the eeditor's editing domain
48:          */
49:         public GotoMarkerAdapter(ViewModelContext context, EditingDomain editingDomain) {
50:                 super();
51:
52:                 this.context = context;
53:                 this.editingDomain = editingDomain;
54:         }
55:
56:         @Override
57:         public void gotoMarker(IMarker marker) {
58:                 final List<?> targets = helper.getTargetObjects(editingDomain, marker);
59:                 final EObject object = getEObject(targets);
60:
61:•                if (object != null) {
62:                         final EMFFormsRevealService reveal = context.getService(EMFFormsRevealService.class);
63:•                        if (reveal != null) {
64:                                 final EStructuralFeature feature = getEStructuralFeature(targets);
65:•                                if (feature != null) {
66:                                         reveal.reveal(object, feature);
67:                                 } else {
68:                                         reveal.reveal(object);
69:                                 }
70:                         }
71:                 }
72:         }
73:
74:         /**
75:          * Extract a domain model element in our editor from a marker's {@code targets}.
76:          *
77:          * @param targets the target objects resolved from a marker to navigate
78:          * @return the domain model object to reveal
79:          */
80:         protected EObject getEObject(List<?> targets) {
81:•                if (!targets.isEmpty()) {
82:                         final Object first = targets.get(0);
83:•                        if (first instanceof EObject) {
84:                                 return (EObject) first;
85:                         }
86:                         final Object unwrapped = AdapterFactoryEditingDomain.unwrap(first);
87:•                        if (unwrapped instanceof EObject) {
88:                                 return (EObject) unwrapped;
89:                         }
90:                 }
91:
92:                 return null;
93:         }
94:
95:         /**
96:          * Extract a domain model feature in our editor from a marker's {@code targets}.
97:          *
98:          * @param targets the target objects resolved from a marker to navigate
99:          * @return the feature of the domain model object to reveal, or {@code null} if none
100:          */
101:         protected EStructuralFeature getEStructuralFeature(List<?> targets) {
102:•                if (targets.size() > 1) {
103:•                        for (final Iterator<?> iter = targets.listIterator(1); iter.hasNext();) {
104:                                 final Object next = iter.next();
105:•                                if (next instanceof EStructuralFeature) {
106:                                         return (EStructuralFeature) next;
107:                                 }
108:                         }
109:                 }
110:
111:                 return null;
112:         }
113:
114: }