From e306193f685ba72fea402b8e80875b8cd9c5341a Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Mon, 16 Nov 2015 15:14:34 +0100 Subject: [PATCH] Improve report viewer --- .../batch/protocol/viewer/ViewerApplication.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/ViewerApplication.java b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/ViewerApplication.java index e17e2363eb3..a2f9352f6d2 100644 --- a/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/ViewerApplication.java +++ b/sonar-batch-protocol/src/main/java/org/sonar/batch/protocol/viewer/ViewerApplication.java @@ -20,6 +20,7 @@ package org.sonar.batch.protocol.viewer; import java.awt.BorderLayout; +import java.awt.Cursor; import java.awt.Dimension; import java.awt.EventQueue; import java.io.File; @@ -30,6 +31,7 @@ import java.nio.charset.StandardCharsets; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.Scanner; + import javax.swing.JEditorPane; import javax.swing.JFileChooser; import javax.swing.JFrame; @@ -46,6 +48,7 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; + import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReport.Component; import org.sonar.batch.protocol.output.BatchReport.Metadata; @@ -200,16 +203,18 @@ public class ViewerApplication { private void updateSource(Component component) { File sourceFile = reader.getFileStructure().fileFor(Domain.SOURCE, component.getRef()); + sourceEditor.setText(""); + if (sourceFile.exists()) { try (Scanner s = new Scanner(sourceFile, StandardCharsets.UTF_8.name()).useDelimiter("\\Z")) { - sourceEditor.setText(s.next()); + if (s.hasNext()) { + sourceEditor.setText(s.next()); + } } catch (IOException ex) { StringWriter errors = new StringWriter(); ex.printStackTrace(new PrintWriter(errors)); sourceEditor.setText(errors.toString()); } - } else { - sourceEditor.setText(""); } } @@ -301,7 +306,9 @@ public class ViewerApplication { return; } + frame.setCursor(new Cursor(Cursor.WAIT_CURSOR)); updateDetails((Component) node.getUserObject()); + frame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } -- 2.39.5