Browse Source

Fixed NPE that occured while resolving semantic element for NoteEditParts

terfloth@itemis.de 11 years ago
parent
commit
d528871b77

+ 15 - 7
de.itemis.gmf.utils/plugins/de.itemis.gmf.runtime.commons/src/de/itemis/gmf/runtime/commons/util/EditPartUtils.java

@@ -13,20 +13,25 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
 public class EditPartUtils {
 
 	@SuppressWarnings("unchecked")
-	public static IGraphicalEditPart findEditPartForSemanticElement(EditPart editPart, EObject semanticElement) {
+	public static IGraphicalEditPart findEditPartForSemanticElement(
+			EditPart editPart, EObject semanticElement) {
 		if (semanticElement == null) {
 			return null;
 		}
 		if (editPart instanceof IGraphicalEditPart) {
-			EObject resolveSemanticElement = ((IGraphicalEditPart) editPart).resolveSemanticElement();
+			EObject resolveSemanticElement = ((IGraphicalEditPart) editPart)
+					.resolveSemanticElement();
 
-			if (EcoreUtil.getURI(resolveSemanticElement).equals(EcoreUtil.getURI(semanticElement))) {
+			if (resolveSemanticElement != null
+					&& EcoreUtil.getURI(resolveSemanticElement).equals(
+							EcoreUtil.getURI(semanticElement))) {
 				return (IGraphicalEditPart) editPart;
 			}
 		}
 
 		for (Object child : editPart.getChildren()) {
-			IGraphicalEditPart recursiveEditPart = findEditPartForSemanticElement((EditPart) child, semanticElement);
+			IGraphicalEditPart recursiveEditPart = findEditPartForSemanticElement(
+					(EditPart) child, semanticElement);
 			if (recursiveEditPart != null) {
 				return recursiveEditPart;
 			}
@@ -34,10 +39,13 @@ public class EditPartUtils {
 
 		if (editPart instanceof NodeEditPart) {
 			List<Connection> connections = new ArrayList<Connection>();
-			connections.addAll(((NodeEditPart) editPart).getSourceConnections());
-			connections.addAll(((NodeEditPart) editPart).getTargetConnections());
+			connections
+					.addAll(((NodeEditPart) editPart).getSourceConnections());
+			connections
+					.addAll(((NodeEditPart) editPart).getTargetConnections());
 			for (Object connection : connections) {
-				EObject resolveSemanticElement = ((IGraphicalEditPart) connection).resolveSemanticElement();
+				EObject resolveSemanticElement = ((IGraphicalEditPart) connection)
+						.resolveSemanticElement();
 				if (EcoreUtil.equals(resolveSemanticElement, semanticElement)) {
 					return (IGraphicalEditPart) connection;
 				}