|
20 | 20 | import java.util.ArrayList;
|
21 | 21 | import java.util.Arrays;
|
22 | 22 | import java.util.Collections;
|
23 |
| -import java.util.Iterator; |
24 | 23 | import java.util.List;
|
25 | 24 |
|
26 | 25 | import org.eclipse.core.databinding.observable.list.IObservableList;
|
| 26 | +import org.eclipse.core.runtime.ILog; |
27 | 27 | import org.eclipse.e4.core.contexts.IEclipseContext;
|
28 |
| -import org.eclipse.e4.emf.xpath.EcoreXPathContextFactory; |
29 |
| -import org.eclipse.e4.emf.xpath.XPathContext; |
30 |
| -import org.eclipse.e4.emf.xpath.XPathContextFactory; |
31 | 28 | import org.eclipse.e4.tools.emf.ui.common.IEditorFeature.FeatureClass;
|
32 | 29 | import org.eclipse.e4.tools.emf.ui.common.Util;
|
33 | 30 | import org.eclipse.e4.tools.emf.ui.common.Util.InternalPackage;
|
|
41 | 38 | import org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs.FindParentReferenceElementDialog;
|
42 | 39 | import org.eclipse.e4.tools.emf.ui.internal.common.component.tabs.empty.E;
|
43 | 40 | import org.eclipse.e4.tools.emf.ui.internal.common.component.virtual.VSnippetsEditor;
|
| 41 | +import org.eclipse.e4.ui.model.ModelXPathEvaluator; |
44 | 42 | import org.eclipse.e4.ui.model.application.MApplication;
|
45 | 43 | import org.eclipse.e4.ui.model.application.MApplicationElement;
|
46 |
| -import org.eclipse.e4.ui.model.application.impl.ApplicationElementImpl; |
47 | 44 | import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl;
|
48 | 45 | import org.eclipse.e4.ui.model.fragment.MModelFragment;
|
49 | 46 | import org.eclipse.e4.ui.model.fragment.MStringModelFragment;
|
@@ -157,8 +154,7 @@ public FeaturePath[] getLabelProperties() {
|
157 | 154 |
|
158 | 155 | @Override
|
159 | 156 | public String getDetailLabel(Object element) {
|
160 |
| - if (element instanceof StringModelFragmentImpl) { |
161 |
| - final StringModelFragmentImpl fragment = (StringModelFragmentImpl) element; |
| 157 | + if (element instanceof StringModelFragmentImpl fragment) { |
162 | 158 | String ret = ""; //$NON-NLS-1$
|
163 | 159 | if (E.notEmpty(fragment.getFeaturename())) {
|
164 | 160 | ret += fragment.getFeaturename();
|
@@ -246,17 +242,17 @@ public static EClass findContainerType(MStringModelFragment modelFragment) {
|
246 | 242 |
|
247 | 243 | // Deal with non default MApplication IDs.
|
248 | 244 | if (xpath != null) {
|
249 |
| - if (o instanceof MApplication) { |
250 |
| - EClass found = getTargetClassFromXPath((MApplication) o, xpath); |
| 245 | + if (o instanceof MApplication application) { |
| 246 | + EClass found = getTargetClassFromXPath(application, xpath); |
251 | 247 | if (found != null) {
|
252 | 248 | return found;
|
253 | 249 | }
|
254 | 250 | }
|
255 | 251 | } else {
|
256 | 252 | // This is a standard search with ID.
|
257 |
| - if ((o instanceof MApplicationElement) |
| 253 | + if ((o instanceof MApplicationElement appElement) |
258 | 254 | && (o.eContainingFeature() != FragmentPackageImpl.Literals.MODEL_FRAGMENTS__IMPORTS)
|
259 |
| - && parentElementId.equals(((MApplicationElement) o).getElementId())) { |
| 255 | + && parentElementId.equals(appElement.getElementId())) { |
260 | 256 | return o.eClass();
|
261 | 257 | }
|
262 | 258 | }
|
@@ -581,24 +577,14 @@ public List<Action> getActions(Object element) {
|
581 | 577 | * @return the list of EClass(es) matching this xpath
|
582 | 578 | */
|
583 | 579 | private static EClass getTargetClassFromXPath(MApplication application, String xpath) {
|
584 |
| - |
585 |
| - XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance(); |
586 |
| - XPathContext xpathContext = f.newContext((EObject) application); |
587 |
| - Iterator<Object> i = xpathContext.iterate(xpath); |
588 |
| - |
589 | 580 | try {
|
590 |
| - while (i.hasNext()) { |
591 |
| - Object obj = i.next(); |
592 |
| - if (obj instanceof MApplicationElement) { |
593 |
| - ApplicationElementImpl ae = (ApplicationElementImpl) obj; |
594 |
| - return ae.eClass(); |
595 |
| - } |
596 |
| - } |
| 581 | + return ModelXPathEvaluator.findMatchingElements(application, xpath, MApplicationElement.class) |
| 582 | + .map(EObject.class::cast).map(EObject::eClass) // |
| 583 | + .findFirst().orElse(null); |
597 | 584 | } catch (Exception ex) {
|
598 | 585 | // custom xpath functions will throw exceptions
|
599 |
| - ex.printStackTrace(); |
| 586 | + ILog.get().error("Failed to evaluate xpath: " + xpath, ex); //$NON-NLS-1$ |
600 | 587 | }
|
601 |
| - |
602 | 588 | return null;
|
603 | 589 | }
|
604 | 590 |
|
|
0 commit comments