From: Tuukka Lehtonen Date: Tue, 20 Jun 2017 06:29:08 +0000 (+0300) Subject: RouteGraphUtils.readConnectionStyle returns default value if necessary X-Git-Tag: v1.31.0~302 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=e571f799;p=simantics%2Fplatform.git RouteGraphUtils.readConnectionStyle returns default value if necessary Previously the code would crash with NPE if the ontology/model was not created to contain STR.HasConnectionType information accordingly. Now it will just return ExampleConnectionStyle if there is no modelled information available. refs #7323 Change-Id: I3d5b5ba6a4e615d7ae120e42aa003c787617b8d0 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java index 3127b431c..1b7376f96 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/RouteGraphUtils.java @@ -42,6 +42,7 @@ import org.simantics.diagram.connection.RouteTerminal; import org.simantics.diagram.connection.RouteTerminalPosition; import org.simantics.diagram.connection.rendering.BasicConnectionStyle; import org.simantics.diagram.connection.rendering.ConnectionStyle; +import org.simantics.diagram.connection.rendering.ExampleConnectionStyle; import org.simantics.diagram.connection.rendering.StyledRouteGraphRenderer; import org.simantics.diagram.connection.rendering.arrows.ArrowLineEndStyle; import org.simantics.diagram.connection.rendering.arrows.ILineEndStyle; @@ -523,6 +524,8 @@ public class RouteGraphUtils { } } + private static final ConnectionStyle DEFAULT_CONNECTION_STYLE = new ExampleConnectionStyle(); + /** * @param graph * @param canvas @@ -537,7 +540,7 @@ public class RouteGraphUtils { connectionType = modelingRules.getConnectionType(graph, connection); if (connectionType == null) connectionType = graph.getPossibleObject(connection, STR.HasConnectionType); - return readConnectionStyleFromConnectionType(graph, connectionType); + return connectionType != null ? readConnectionStyleFromConnectionType(graph, connectionType) : DEFAULT_CONNECTION_STYLE; } protected static ConnectionStyle readConnectionStyleFromConnectionType(ReadGraph graph, Resource connectionType) throws DatabaseException {