Bold headlines in report preview

Change-Id: Ieb0303e022436486fa399276dc99ab57b9bb3a7c
Signed-off-by: Daniel Haftstein <haftsteind@gmail.com>
diff --git a/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/dialogs/ReportPreview.java b/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/dialogs/ReportPreview.java
index 8b8cf6e..dd24608 100644
--- a/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/dialogs/ReportPreview.java
+++ b/bundles/org.eclipse.epp.logging.aeri.ide/src/org/eclipse/epp/internal/logging/aeri/ide/dialogs/ReportPreview.java
@@ -32,6 +32,7 @@
 import org.eclipse.epp.logging.aeri.core.IThrowable;
 import org.eclipse.epp.logging.aeri.core.util.ModelSwitch;
 import org.eclipse.epp.logging.aeri.core.util.Reports;
+import org.eclipse.jface.resource.FontRegistry;
 import org.eclipse.jface.resource.JFaceColors;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.swt.SWT;
@@ -42,6 +43,8 @@
 import org.eclipse.swt.events.MouseMoveListener;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.graphics.Point;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
@@ -53,8 +56,10 @@
 public class ReportPreview {
 
     private static final int RIGHT_PADDING_ATTRIBUTES = 20;
-    private static final int RIGHT_PADDING_EDIT = 60;
+    private static final int RIGHT_PADDING_EDIT = 50;
+    private static final String LINE_SEPARATOR = System.lineSeparator();
     private StyledText styledText;
+    private final Font headlineFont;
 
     private List<SectionsProvider> sectionProviders = ImmutableList.of(new ReportSectionProvider(), new StatusSectionProvider(),
             new BundlesSectionProvider(), new AuxiliaryInformationSectionProvider());
@@ -109,6 +114,15 @@
                 }
             }
         });
+
+        FontData[] fd = styledText.getFont().getFontData();
+        FontRegistry fontRegistry = JFaceResources.getFontRegistry();
+        // take the first name in case of composed fonts
+        String name = fd[0].getName();
+        if (!fontRegistry.hasValueFor(name)) {
+            fontRegistry.put(name, fd);
+        }
+        headlineFont = fontRegistry.getBold(name);
     }
 
     public void setEditListener(IEditListener editCallback) {
@@ -122,31 +136,37 @@
     public void preview(IReport report, IStatus status, String serverName, List<IProcessorDescriptor> descriptors, IEclipseContext context,
             Shell parent) {
         StringBuilder text = new StringBuilder();
-        text.append("The following will be send to: ").append(serverName).append("\n\n");
+        text.append("The following will be send to: ").append(serverName).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
         List<StyleRange> styleRanges = new ArrayList<>();
         for (SectionsProvider sectionsProvider : sectionProviders) {
             for (Section section : sectionsProvider.createSections(report, status, serverName, descriptors, context, parent)) {
                 if (text.length() > 0) {
-                    text.append("\n");
+                    text.append(LINE_SEPARATOR);
                 }
-                appendHeadlineSeparator(section.getHeadline(), text);
                 // shift relative headline style ranges for absolute text position
+                if (section.getHeadlineStyleRanges().isEmpty()) {
+                    section.getHeadlineStyleRanges().add(createHeadlineStyleRange(section.getHeadline()));
+                }
                 section.getHeadlineStyleRanges().forEach(x -> x.start += text.length());
                 styleRanges.addAll(section.getHeadlineStyleRanges());
-                text.append(section.getHeadline()).append("\n");
-                appendHeadlineSeparator(section.getHeadline(), text);
+                text.append(section.getHeadline()).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
                 // shift relative style ranges for absolute text position
                 section.getTextStyleRanges().forEach(x -> x.start += text.length());
                 styleRanges.addAll(section.getTextStyleRanges());
-                text.append(section.getText());
+                text.append(section.getText().trim()).append(LINE_SEPARATOR).append(LINE_SEPARATOR);
+
             }
         }
         styledText.setText(text.toString());
         styledText.setStyleRanges(styleRanges.toArray(new StyleRange[0]));
     }
 
-    private void appendHeadlineSeparator(String headline, StringBuilder builder) {
-        builder.append(headline.replaceAll(".", "-") + "\n");
+    private StyleRange createHeadlineStyleRange(String headline) {
+        StyleRange range = new StyleRange();
+        range.start = 0;
+        range.length = headline.length();
+        range.font = headlineFont;
+        return range;
     }
 
     private void appendAttributes(EObject object, StringBuilder builder) {
@@ -154,9 +174,9 @@
             Object value = firstNonNull(object.eGet(attribute), "");
             builder.append(StringUtils.rightPad(attribute.getName(), RIGHT_PADDING_ATTRIBUTES));
             builder.append(value);
-            builder.append('\n');
+            builder.append(LINE_SEPARATOR);
         }
-        builder.append("\n");
+        builder.append(LINE_SEPARATOR);
     }
 
     private class ReportSectionProvider implements SectionsProvider {
@@ -194,10 +214,10 @@
                 }
 
                 private void appendStackTrace(IThrowable throwable, StringBuilder builder) {
-                    builder.append(String.format("%s: %s\n", throwable.getClassName(), throwable.getMessage()));
+                    builder.append(String.format("%s: %s", throwable.getClassName(), throwable.getMessage())).append(LINE_SEPARATOR);
                     for (IStackTraceElement element : throwable.getStackTrace()) {
-                        builder.append(String.format("\t at %s.%s(%s:%s)\n", element.getClassName(), element.getMethodName(),
-                                element.getFileName(), element.getLineNumber()));
+                        builder.append(String.format("\t at %s.%s(%s:%s)", element.getClassName(), element.getMethodName(),
+                                element.getFileName(), element.getLineNumber())).append(LINE_SEPARATOR);
                     }
                     IThrowable cause = throwable.getCause();
                     if (cause != null) {
@@ -249,18 +269,19 @@
                 IProcessorDescriptor directiveDescriptor = directiveToDescriptor.get(directive);
                 String headline;
                 if (directiveDescriptor != null) {
-                    headline = StringUtils.abbreviate(directiveDescriptor.getName(), RIGHT_PADDING_EDIT - 5);
+                    headline = StringUtils.abbreviate(directiveDescriptor.getName(), RIGHT_PADDING_EDIT - 1);
                 } else {
                     // fallback if a processor adds another key than the directive
                     headline = directive;
                 }
-                String information = entry.getValue();
-                String text = information + "\n";
+                String information = entry.getValue().trim();
+                String text = information + LINE_SEPARATOR + LINE_SEPARATOR;
                 ArrayList<StyleRange> headlineStyleRanges = new ArrayList<>();
                 if (directiveDescriptor != null && directiveDescriptor.getProcessor() instanceof IEditableReportProcessor) {
                     boolean showReset = editedDescriptors.contains(directiveDescriptor);
                     if (showReset) {
                         headline = StringUtils.rightPad(headline, RIGHT_PADDING_EDIT);
+                        headlineStyleRanges.add(createHeadlineStyleRange(headline));
                         String reset = LABEL_RESET;
                         StyleRange resetStyleRange = new StyleRange();
                         resetStyleRange.start = headline.length();
@@ -285,6 +306,7 @@
                     } else {
                         // no reset, increase right padding size to have edit always at the same location
                         headline = StringUtils.rightPad(headline, RIGHT_PADDING_EDIT + LABEL_RESET.length() + 1);
+                        headlineStyleRanges.add(createHeadlineStyleRange(headline));
                     }
                     String edit = LABEL_EDIT;
                     StyleRange editStyleRange = new StyleRange();
@@ -311,6 +333,7 @@
                 } else {
                     // same length for headlines without edit or reset
                     headline = StringUtils.rightPad(headline, RIGHT_PADDING_EDIT + LABEL_EDIT.length() + LABEL_RESET.length() + 1);
+                    headlineStyleRanges.add(createHeadlineStyleRange(headline));
                     sections.add(new Section(headline, text));
                 }
             }