From: Tuukka Lehtonen Date: Mon, 26 Mar 2018 09:30:51 +0000 (+0300) Subject: Prevent NPEs in ViewUtils layout loading code X-Git-Tag: v1.43.0~136^2~520 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=94b6c96f6dafc8db9e7d0c5fc58e334b1aaffa5e;p=simantics%2Fplatform.git Prevent NPEs in ViewUtils layout loading code refs #7843 Change-Id: Ia34be3d08b8a368ed314c56e3af0b4e39aa45cec --- diff --git a/bundles/org.simantics.views/src/org/simantics/views/ViewUtils.java b/bundles/org.simantics.views/src/org/simantics/views/ViewUtils.java index c0a607287..9e6e8b6ff 100644 --- a/bundles/org.simantics.views/src/org/simantics/views/ViewUtils.java +++ b/bundles/org.simantics.views/src/org/simantics/views/ViewUtils.java @@ -88,9 +88,21 @@ public class ViewUtils { public int weight; } - - + private static void readMargins(ExtendedMargins extendedMargins, LayoutBean layout) { + if (extendedMargins != null) { + layout.marginLeft = extendedMargins.left; + layout.marginRight = extendedMargins.right; + layout.marginTop = extendedMargins.top; + layout.marginBottom = extendedMargins.bottom; + } else { + layout.marginLeft = 3; + layout.marginRight = 3; + layout.marginTop = 3; + layout.marginBottom = 3; + } + } + public static GridLayoutBean getLayout(RequestProcessor processor, Resource configuration) throws DatabaseException { return processor.sync(new ResourceRead(configuration) { @@ -106,13 +118,10 @@ public class ViewUtils { ExtendedMargins extendedMargins = graph.getPossibleRelatedValue(resource, VIEW.GridLayout_extendedMargins, EXTENDED_MARGINS_BINDING); GridLayoutBean layout = new GridLayoutBean();//.fillDefaults().numColumns(1).equalWidth(false).margins(0, 0).spacing(0, 0).create(); - layout.numColumns = columns; - layout.horizontalSpacing = horizontalSpacing; - layout.verticalSpacing = verticalSpacing; - layout.marginLeft = extendedMargins.left; - layout.marginRight = extendedMargins.right; - layout.marginTop = extendedMargins.top; - layout.marginBottom = extendedMargins.bottom; + layout.numColumns = columns != null ? columns : 1; + layout.horizontalSpacing = horizontalSpacing != null ? horizontalSpacing : 5; + layout.verticalSpacing = verticalSpacing != null ? verticalSpacing : 5; + readMargins(extendedMargins, layout); return layout; @@ -163,17 +172,14 @@ public class ViewUtils { ExtendedMargins extendedMargins = graph.getPossibleRelatedValue(resource, VIEW.RowLayout_extendedMargins, EXTENDED_MARGINS_BINDING); RowLayoutBean layout = new RowLayoutBean(); - layout.type = type; - layout.spacing = spacing; - layout.center = center; - layout.fill = fill; - layout.justify = justify; - layout.pack = pack; - layout.wrap = wrap; - layout.marginLeft = extendedMargins.left; - layout.marginRight = extendedMargins.right; - layout.marginTop = extendedMargins.top; - layout.marginBottom = extendedMargins.bottom; + layout.type = type != null ? type : 256; + layout.spacing = spacing != null ? spacing : 3; + layout.center = center != null ? center : false; + layout.fill = fill != null ? fill : false; + layout.justify = justify != null ? justify : false; + layout.pack = pack != null ? pack : true; + layout.wrap = wrap != null ? wrap : true; + readMargins(extendedMargins, layout); return layout; } }); @@ -185,8 +191,10 @@ public class ViewUtils { public RowDataBean perform(ReadGraph graph) throws DatabaseException { ViewsResources VIEW = ViewsResources.getInstance(graph); RowDataBean data = new RowDataBean(); - data.width = graph.getPossibleRelatedValue(resource, VIEW.GridLayout_GridData_preferredWidth, Bindings.INTEGER); - data.height = graph.getPossibleRelatedValue(resource, VIEW.GridLayout_GridData_preferredHeight, Bindings.INTEGER); + Integer width = graph.getPossibleRelatedValue(resource, VIEW.GridLayout_GridData_preferredWidth, Bindings.INTEGER); + Integer height = graph.getPossibleRelatedValue(resource, VIEW.GridLayout_GridData_preferredHeight, Bindings.INTEGER); + data.width = width != null ? width : -1; + data.height = height != null ? height : -1; return data; } }); @@ -235,10 +243,10 @@ public class ViewUtils { bean.key = key; bean.label = label; bean.alignment = alignment; - bean.width = width; + bean.width = width != null ? width : -1; bean.tooltip = tooltip; - bean.grab = grab; - bean.weight = weight; + bean.grab = grab != null ? grab : false; + bean.weight = weight != null ? weight : 0; return bean;