From b507c11b45973ea060a69339a9ffb167020dd52a Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Sun, 6 May 2012 17:00:50 +0200 Subject: [PATCH] More null checks. --- ChangeLog | 4 ++++ src/main/java/org/glom/web/client/StringUtils.java | 12 ++++++++++++ .../org/glom/web/client/ui/details/DetailsCell.java | 17 ++++++++++++++--- .../java/org/glom/web/client/ui/details/FlowTable.java | 4 ++++ .../java/org/glom/web/server/libglom/DocumentTest.java | 4 +++- 5 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 815b432..29f3695 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2012-05-06 Murray Cumming + More null checks. + +2012-05-06 Murray Cumming + Translatable: Use Hashmap instead of Treemap because GWT supports it. * src/main/java/org/glom/web/shared/libglom/Translatable.java: diff --git a/src/main/java/org/glom/web/client/StringUtils.java b/src/main/java/org/glom/web/client/StringUtils.java index 580ad4f..b137707 100644 --- a/src/main/java/org/glom/web/client/StringUtils.java +++ b/src/main/java/org/glom/web/client/StringUtils.java @@ -46,4 +46,16 @@ public class StringUtils { return a.equals(b); } + /** + * @param text + * @return + */ + public static String defaultString(String text) { + if (text == null) { + return ""; + } else { + return text; + } + } + } diff --git a/src/main/java/org/glom/web/client/ui/details/DetailsCell.java b/src/main/java/org/glom/web/client/ui/details/DetailsCell.java index 6854c48..38ed269 100644 --- a/src/main/java/org/glom/web/client/ui/details/DetailsCell.java +++ b/src/main/java/org/glom/web/client/ui/details/DetailsCell.java @@ -76,6 +76,10 @@ public class DetailsCell extends Composite { detailsData.setStyleName("details-data"); Formatting formatting = layoutItemField.getFormatting(); + if (formatting == null) { + GWT.log("setData(): formatting is null"); + formatting = new Formatting(); // To avoid checks later. + } // set the height based on the number of lines detailsData.setHeight(formatting.getTextFormatMultilineHeightLines() + "em"); @@ -130,6 +134,8 @@ public class DetailsCell extends Composite { if (dataItem == null) return; + Formatting formatting = layoutItemField.getFormatting(); + // FIXME use the cell renderers from the list view to render the inforamtion here switch (layoutItemField.getGlomType()) { case TYPE_BOOLEAN: @@ -146,7 +152,11 @@ public class DetailsCell extends Composite { detailsData.add(checkBox); break; case TYPE_NUMERIC: - NumericFormat numericFormat = layoutItemField.getFormatting().getNumericFormat(); + if (formatting == null) { + GWT.log("setData(): formatting is null"); + formatting = new Formatting(); // To avoid checks later. + } + NumericFormat numericFormat = formatting.getNumericFormat(); NumberFormat gwtNumberFormat = Utils.getNumberFormat(numericFormat); // set the foreground color to red if the number is negative and this is requested @@ -163,9 +173,10 @@ public class DetailsCell extends Composite { case TYPE_DATE: case TYPE_TIME: case TYPE_TEXT: - String text = dataItem.getText(); + final String text = StringUtils.defaultString(dataItem.getText()); + // Deal with multiline text differently than single line text. - if (layoutItemField.getFormatting().getTextFormatMultilineHeightLines() > 1) { + if ((formatting != null) && (formatting.getTextFormatMultilineHeightLines() > 1)) { detailsData.getElement().getStyle().setOverflow(Overflow.AUTO); // Convert '\n' to
escaping the data so that it won't be rendered as HTML. try { diff --git a/src/main/java/org/glom/web/client/ui/details/FlowTable.java b/src/main/java/org/glom/web/client/ui/details/FlowTable.java index 87732fb..c3a50dd 100644 --- a/src/main/java/org/glom/web/client/ui/details/FlowTable.java +++ b/src/main/java/org/glom/web/client/ui/details/FlowTable.java @@ -95,6 +95,10 @@ public class FlowTable extends Composite { table.getElement().getStyle().setProperty("borderCollapse", "collapse"); table.setBorderWidth(0); + if (columnCount < 1) { + columnCount = 1; // Avoid a division by zero. + } + // The column widths are evenly distributed amongst the number of columns with 1% padding between the columns. double columnWidth = (100 - (columnCount - 1)) / columnCount; for (int i = 0; i < columnCount; i++) { diff --git a/src/test/java/org/glom/web/server/libglom/DocumentTest.java b/src/test/java/org/glom/web/server/libglom/DocumentTest.java index 2d3afd5..31737df 100644 --- a/src/test/java/org/glom/web/server/libglom/DocumentTest.java +++ b/src/test/java/org/glom/web/server/libglom/DocumentTest.java @@ -192,7 +192,9 @@ public class DocumentTest { final String table = tableNames.get(i); final List layoutList = document.getDataLayoutGroups("list", table); assertTrue(!layoutList.isEmpty()); - final List layoutItems = layoutList.get(0).getItems(); + LayoutGroup firstgroup = layoutList.get(0); + assertTrue(firstgroup != null); + final List layoutItems = firstgroup.getItems(); final int numItems = safeLongToInt(layoutItems.size()); for (int j = 0; j < numItems; j++) { final LayoutItem item = layoutItems.get(j); -- 2.1.4