|
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; |
@@ -581,24 +578,14 @@ public List<Action> getActions(Object element) { |
581 | 578 | * @return the list of EClass(es) matching this xpath |
582 | 579 | */ |
583 | 580 | 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 | 581 | 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 | | - } |
| 582 | + return ModelXPathEvaluator.findMatchingElements(application, xpath, MApplicationElement.class) |
| 583 | + .map(EObject.class::cast).map(EObject::eClass) // |
| 584 | + .findFirst().orElse(null); |
597 | 585 | } catch (Exception ex) { |
598 | 586 | // custom xpath functions will throw exceptions |
599 | | - ex.printStackTrace(); |
| 587 | + ILog.get().error("Failed to evaluate xpath: " + xpath, ex); //$NON-NLS-1$ |
600 | 588 | } |
601 | | - |
602 | 589 | return null; |
603 | 590 | } |
604 | 591 |
|
|
0 commit comments