Bläddra i källkod

Bugfix: SCTDiagnosticConverter can handle multiple Diagrams per Resource

Andreas Mülder 12 år sedan
förälder
incheckning
374b13f5c3

+ 19 - 18
plugins/org.yakindu.sct.model.stext.ui/src/org/yakindu/sct/model/stext/ui/validation/SCTDiagnosticConverterImpl.java

@@ -10,10 +10,13 @@
  */
 package org.yakindu.sct.model.stext.ui.validation;
 
+import java.util.Collection;
+
 import org.eclipse.emf.common.util.Diagnostic;
 import org.eclipse.emf.common.util.TreeIterator;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.notation.Diagram;
 import org.eclipse.gmf.runtime.notation.NotationPackage;
 import org.eclipse.gmf.runtime.notation.View;
 import org.eclipse.xtext.EcoreUtil2;
@@ -32,8 +35,7 @@ import org.yakindu.sct.model.sgraph.ui.validation.SCTMarkerCreator;
 public class SCTDiagnosticConverterImpl extends DiagnosticConverterImpl {
 
 	@Override
-	public void convertValidatorDiagnostic(final Diagnostic diagnostic,
-			final IAcceptor<Issue> acceptor) {
+	public void convertValidatorDiagnostic(final Diagnostic diagnostic, final IAcceptor<Issue> acceptor) {
 		super.convertValidatorDiagnostic(diagnostic, new IAcceptor<Issue>() {
 			public void accept(Issue t) {
 				boolean notAccepted = true;
@@ -41,16 +43,13 @@ public class SCTDiagnosticConverterImpl extends DiagnosticConverterImpl {
 					EObject eObject = (EObject) diagnostic.getData().get(0);
 					if (eObject != null && eObject.eResource() != null) {
 						if (NodeModelUtils.getNode(eObject) != null) {
-							eObject = EcoreUtil2.getContainerOfType(eObject,
-									SpecificationElement.class);
+							eObject = EcoreUtil2.getContainerOfType(eObject, SpecificationElement.class);
 						}
 						if (eObject != null && eObject.eResource() != null) {
 							View notationView = findNotationView(eObject);
-							if (notationView != null
-									&& notationView.eResource() != null) {
-								acceptor.accept(new SCTMarkerCreator.WrappingIssue(
-										t, notationView.eResource()
-												.getURIFragment(notationView)));
+							if (notationView != null && notationView.eResource() != null) {
+								acceptor.accept(new SCTMarkerCreator.WrappingIssue(t, notationView.eResource()
+										.getURIFragment(notationView)));
 								notAccepted = false;
 							}
 						}
@@ -64,15 +63,17 @@ public class SCTDiagnosticConverterImpl extends DiagnosticConverterImpl {
 	}
 
 	protected View findNotationView(EObject semanticElement) {
-		EObject diagram = (EObject) EcoreUtil.getObjectByType(semanticElement
-				.eResource().getContents(), NotationPackage.eINSTANCE
-				.getDiagram());
-		TreeIterator<EObject> iterator = diagram.eAllContents();
-		while (iterator.hasNext()) {
-			EObject eObject = iterator.next();
-			if (eObject instanceof View
-					&& semanticElement.equals(((View) eObject).getElement())) {
-				return (View) eObject;
+		Collection<Diagram> objects = EcoreUtil.getObjectsByType(semanticElement.eResource().getContents(),
+				NotationPackage.Literals.DIAGRAM);
+		for (Diagram diagram : objects) {
+			TreeIterator<EObject> eAllContents = diagram.eAllContents();
+			while (eAllContents.hasNext()) {
+				EObject next = eAllContents.next();
+				if (next instanceof View) {
+					if (EcoreUtil.equals(((View) next).getElement(), semanticElement)) {
+						return ((View) next);
+					}
+				}
 			}
 		}
 		return null;