]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2752 Improve UI to show duplications with other projects
authorEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 2 Sep 2011 08:07:41 +0000 (12:07 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Fri, 2 Sep 2011 08:08:02 +0000 (12:08 +0400)
plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/duplicationsviewer/client/DuplicationsPanel.java

index cad1b96cbc3c25e00cdf7b43b6c8d4045e845165..681205f4679ca7525db0c070192f69ea8ec7b0e0 100644 (file)
@@ -91,13 +91,15 @@ public class DuplicationsPanel extends Composite {
       
       panel.add(table);
       int rowCounter = 1;
+
+      String projectKey = resource.getKey().substring(0, resource.getKey().lastIndexOf(':'));
       for (int i = 0; i < duplicationsXML.getLength(); i++) {
         Element duplicationXML = (Element) duplicationsXML.item(i);
         String lines = duplicationXML.getAttribute("lines");
         String startLine = duplicationXML.getAttribute("start");
         String targetStartLine = duplicationXML.getAttribute("target-start");
         String targetResourceKey = duplicationXML.getAttribute("target-resource");
-        renderDuplication(rowCounter, i, table, lines, startLine, targetStartLine, targetResourceKey, resource);
+        renderDuplication(rowCounter, i, table, lines, startLine, targetStartLine, targetResourceKey, resource, projectKey);
         rowCounter+=2;
       }
     }
@@ -121,7 +123,7 @@ public class DuplicationsPanel extends Composite {
       return table;
     }
 
-    private void renderDuplication(int row, int duplicationCounter, FlexTable table, String lines, String startLine, String targetStartLine, String targetResourceKey, final Resource resource) {
+    private void renderDuplication(int row, int duplicationCounter, FlexTable table, String lines, String startLine, String targetStartLine, String targetResourceKey, final Resource resource, String projectKey) {
       String style = (duplicationCounter % 2 == 0) ? "odd" : "even";
       
       SourcePanel src = new DefaultSourcePanel(resource, new Integer(startLine), new Integer(lines));
@@ -137,9 +139,18 @@ public class DuplicationsPanel extends Composite {
         targetResourceKey = "Same file";
       }
       if (targetResourceKey.contains(":")) {
-        targetResourceKey = targetResourceKey.substring(targetResourceKey.lastIndexOf(':') + 1);
+        int i = targetResourceKey.lastIndexOf(':');
+        String targetProjectKey = targetResourceKey.substring(0, i);
+        String targetFileKey = targetResourceKey.substring(i + 1);
+        if (targetProjectKey.equals(projectKey)) {
+          // same project
+          targetResourceKey = targetFileKey;
+        } else {
+          // another project
+          targetResourceKey = targetProjectKey + "<br/>" + targetFileKey;
+        }
       }
-      table.setText(row, 3, targetResourceKey);
+      table.setHTML(row, 3, targetResourceKey);
       table.setText(row, 4, targetStartLine);
       setRowStyle(row, table, style, false);