Index: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowUsabilityEvaluationResultDialog.java
===================================================================
--- trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowUsabilityEvaluationResultDialog.java	(revision 1636)
+++ trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/ShowUsabilityEvaluationResultDialog.java	(revision 1920)
@@ -20,4 +20,5 @@
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -48,6 +49,6 @@
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
-import de.ugoe.cs.autoquest.usability.UsabilityDefect;
-import de.ugoe.cs.autoquest.usability.UsabilityDefectSeverity;
+import de.ugoe.cs.autoquest.usability.UsabilitySmell;
+import de.ugoe.cs.autoquest.usability.UsabilitySmellIntensity;
 import de.ugoe.cs.autoquest.usability.UsabilityEvaluationResult;
 
@@ -55,4 +56,5 @@
  * <p>
  * a dialog to inspect the results of a usability evaluation
+ * TODO update comments
  * </p>
  * 
@@ -64,8 +66,8 @@
     protected Shell shell;
 
-    /** the table containing all defects */
-    private Tree defectList;
-
-    /** the description label of a selected defect */
+    /** the table containing all smells */
+    private Tree smellList;
+
+    /** the description label of a selected smell */
     private StyledText description;
     
@@ -76,5 +78,5 @@
     private Tree involvedTasks;
 
-    /** the displayed task model */
+    /** the displayed usability evaluation result */
     private UsabilityEvaluationResult usabilityEvalResult;
     
@@ -101,5 +103,5 @@
         showTaskTreeDialog = new ShowTaskTreeDialog
             (super.getParent(), SWT.NONE, usabilityEvalResult.getTaskModel(),
-             "task details of usability defects");
+             "task details of usability smells");
 
         createContents();
@@ -140,26 +142,26 @@
         mainSashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
         
-        defectList = new Tree(mainSashForm, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL);
-        defectList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-        defectList.setHeaderVisible(true);
-        defectList.setLinesVisible(true);
-
-        TreeColumn treeColumn = new TreeColumn(defectList, SWT.NONE);
+        smellList = new Tree(mainSashForm, SWT.BORDER | SWT.SINGLE | SWT.VIRTUAL);
+        smellList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
+        smellList.setHeaderVisible(true);
+        smellList.setLinesVisible(true);
+
+        TreeColumn treeColumn = new TreeColumn(smellList, SWT.NONE);
         treeColumn.setWidth(200);
-        treeColumn.setText("defects");
-
-        buildDefectTree();
-        
-        defectList.addSelectionListener(new SelectionAdapter() {
+        treeColumn.setText("smells");
+
+        buildSmellTree();
+        
+        smellList.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
-                TreeItem[] selectedItems = defectList.getSelection();
+                TreeItem[] selectedItems = smellList.getSelection();
                 if ((selectedItems.length == 1) &&
-                    (selectedItems[0].getData() instanceof UsabilityDefect))
+                    (selectedItems[0].getData() instanceof UsabilitySmell))
                 {
-                    displayDefectDetails((UsabilityDefect) selectedItems[0].getData());
+                    displaySmellDetails((UsabilitySmell) selectedItems[0].getData());
                 }
                 else {
-                    clearDefectDetails();
+                    clearSmellDetails();
                 }
             }
@@ -206,5 +208,5 @@
         //severityColumn.pack();
         //descriptionColumn.pack();
-        //defectList.pack();
+        //smellList.pack();
     }
 
@@ -212,33 +214,67 @@
      * convenience method for creating the display of the instances
      */
-    private void buildDefectTree() {
-        List<UsabilityDefect> defects = usabilityEvalResult.getAllDefects();
-
-        final Map<UsabilityDefectSeverity, Map<String, List<UsabilityDefect>>> sortedDefects =
-            new HashMap<UsabilityDefectSeverity, Map<String, List<UsabilityDefect>>>();
-        sortedDefects.put(UsabilityDefectSeverity.HIGH,
-                          new HashMap<String, List<UsabilityDefect>>());
-        sortedDefects.put(UsabilityDefectSeverity.MEDIUM,
-                          new HashMap<String, List<UsabilityDefect>>());
-        sortedDefects.put(UsabilityDefectSeverity.LOW,
-                          new HashMap<String, List<UsabilityDefect>>());
-        sortedDefects.put(UsabilityDefectSeverity.INFO,
-                          new HashMap<String, List<UsabilityDefect>>());
-        
-        for (UsabilityDefect defect : defects) {
-            Map<String, List<UsabilityDefect>> defectMap = sortedDefects.get(defect.getSeverity());
-            
-            List<UsabilityDefect> defectList = defectMap.get(defect.getBriefDescription());
-            
-            if (defectList == null) {
-                defectList = new ArrayList<UsabilityDefect>();
-                defectMap.put(defect.getBriefDescription(), defectList);
-            }
-            
-            defectList.add(defect);
-        }
-        
-        if (defectList.getListeners(SWT.Expand).length == 0) {
-            defectList.addListener(SWT.Expand, new Listener() {
+    private void buildSmellTree() {
+        List<UsabilitySmell> smells = usabilityEvalResult.getAllSmells();
+        
+        int[] eventCoverageQuantileGroups = { 990, 975, 950, 0, -1 };
+        int[] minEventCoverages = new int[eventCoverageQuantileGroups.length];
+        int[] maxEventCoverages = new int[eventCoverageQuantileGroups.length];
+
+        final List<Map<String, List<UsabilitySmell>>> sortedSmells =
+            new LinkedList<Map<String, List<UsabilitySmell>>>();
+        
+        for (int i = 0; i < eventCoverageQuantileGroups.length; i++) {
+            sortedSmells.add(new HashMap<String, List<UsabilitySmell>>());
+        }
+        
+        for (UsabilitySmell smell : smells) {
+            int eventCoverageQuantile = smell.getIntensity().getEventCoverageQuantile();
+            
+            for (int i = 0; i < eventCoverageQuantileGroups.length; i++) {
+                if (eventCoverageQuantile >= eventCoverageQuantileGroups[i]) {
+                    Map<String, List<UsabilitySmell>> smellMap = sortedSmells.get(i);
+                    
+                    List<UsabilitySmell> smellList = smellMap.get(smell.getBriefDescription());
+                    
+                    if (smellList == null) {
+                        smellList = new ArrayList<UsabilitySmell>();
+                        smellMap.put(smell.getBriefDescription(), smellList);
+                    }
+                    
+                    int ratio = smell.getIntensity().getRatio();
+                    int eventCoverage = smell.getIntensity().getEventCoverage();
+                    int index = 0;
+                    for (index = 0; index < smellList.size(); index++) {
+                        UsabilitySmellIntensity candidate = smellList.get(index).getIntensity();
+                        if ((ratio == candidate.getRatio()) &&
+                            (eventCoverage > candidate.getEventCoverage()))
+                        {
+                            break;
+                        }
+                        else if (ratio > candidate.getRatio()) {
+                            break;
+                        }
+                    }
+                    
+                    smellList.add(index, smell);
+                    
+                    if (minEventCoverages[i] == 0) {
+                        minEventCoverages[i] = smell.getIntensity().getEventCoverage();
+                        maxEventCoverages[i] = smell.getIntensity().getEventCoverage();
+                    }
+                    else {
+                        minEventCoverages[i] = Math.min
+                            (minEventCoverages[i], smell.getIntensity().getEventCoverage());
+                        maxEventCoverages[i] = Math.max
+                            (maxEventCoverages[i], smell.getIntensity().getEventCoverage());
+                    }
+                    
+                    break;
+                }
+            }
+        }
+        
+        if (smellList.getListeners(SWT.Expand).length == 0) {
+            smellList.addListener(SWT.Expand, new Listener() {
                public void handleEvent(final Event event) {
                    ensureChildren((TreeItem) event.item);
@@ -248,8 +284,24 @@
         }
 
-        createRootItem("high", sortedDefects.get(UsabilityDefectSeverity.HIGH));
-        createRootItem("medium", sortedDefects.get(UsabilityDefectSeverity.MEDIUM));
-        createRootItem("low", sortedDefects.get(UsabilityDefectSeverity.LOW));
-        createRootItem("info", sortedDefects.get(UsabilityDefectSeverity.INFO));
+        double taskPercentages = 0;
+        double taskPercentagesCoveredByPreceedingGroups = 0;
+        
+        for (int i = 0; i < eventCoverageQuantileGroups.length; i++) {
+            taskPercentages = ((1000 - eventCoverageQuantileGroups[i]) / 10.0) -
+                taskPercentagesCoveredByPreceedingGroups;
+            
+            if (eventCoverageQuantileGroups[i] > -1) {
+                createRootItem("smells for " + taskPercentages + "% of tasks covering " +
+                               minEventCoverages[i] + " to " + maxEventCoverages[i] +
+                               " recorded events", sortedSmells.get(i));
+            }
+            else {
+                createRootItem("other smells not related to specific tasks", sortedSmells.get(i));
+
+            }
+            
+            taskPercentagesCoveredByPreceedingGroups += taskPercentages;
+        }
+        
     }
 
@@ -257,18 +309,18 @@
      * 
      */
-    private void createRootItem(String name, Map<String, List<UsabilityDefect>> defects) {
-        TreeItem defectItem = new TreeItem(defectList, SWT.NULL);
+    private void createRootItem(String name, Map<String, List<UsabilitySmell>> smells) {
+        TreeItem smellItem = new TreeItem(smellList, SWT.NULL);
         
         int count = 0;
-        for (Map.Entry<String, List<UsabilityDefect>> entry : defects.entrySet()) {
+        for (Map.Entry<String, List<UsabilitySmell>> entry : smells.entrySet()) {
             count += entry.getValue().size();
         }
 
-        defectItem.setText(name + " severity (" + count + " defects)");
-        defectItem.setData(defects);
+        smellItem.setText(name + " (" + count + " smells)");
+        smellItem.setData(smells);
         
         if (count > 0) {
             // simulate a child
-            new TreeItem(defectItem, SWT.NULL);
+            new TreeItem(smellItem, SWT.NULL);
         }
     }
@@ -277,5 +329,5 @@
      *
      */
-    private void clearDefectDetails() {
+    private void clearSmellDetails() {
         description.setText("");
         involvedTargetsTree.removeAll();
@@ -286,6 +338,6 @@
      *
      */
-    private void displayDefectDetails(UsabilityDefect defect) {
-        clearDefectDetails();
+    private void displaySmellDetails(UsabilitySmell smell) {
+        clearSmellDetails();
         
         FontData data = description.getFont().getFontData()[0];
@@ -297,5 +349,5 @@
             (description.getDisplay(), data.getName(), height, data.getStyle() | SWT.BOLD);
         
-        for (Object fragment : defect.getDescriptionFragments()) {
+        for (Object fragment : smell.getDescriptionFragments()) {
             int color;
             Font font;
@@ -310,9 +362,5 @@
             }
             
-            StyleRange styleRange = new StyleRange
-                (description.getText().length(), fragment.toString().length(),
-                 description.getDisplay().getSystemColor(color), null);
-
-            styleRange.font = font;
+            int initialLength = description.getText().length();
             
             if (fragment instanceof Collection<?>) {
@@ -328,4 +376,11 @@
                 description.append(fragment.toString());
             }
+            
+            StyleRange styleRange = new StyleRange
+                (initialLength, description.getText().length() - initialLength,
+                 description.getDisplay().getSystemColor(color), null);
+
+            styleRange.font = font;
+                
             description.setStyleRange(styleRange);
             description.append(" ");
@@ -341,5 +396,5 @@
         description.setStyleRange(styleRange);
         
-        List<ITask> involvedTaskList = getInvolvedTasks(defect);
+        List<ITask> involvedTaskList = getInvolvedTasks(smell);
         for (ITask involvedTask : involvedTaskList) {
             VisualizationUtils.createTreeItemFor
@@ -347,5 +402,5 @@
         }
         
-        List<IEventTarget> involvedTargets = getInvolvedTargets(defect);
+        List<IEventTarget> involvedTargets = getInvolvedTargets(smell);
         if (involvedTargets.size() <= 0) {
             for (ITask involvedTask : involvedTaskList) {
@@ -380,10 +435,10 @@
         if (parent.getData() instanceof Map<?, ?>) {
             @SuppressWarnings("unchecked")
-            Map<String, List<UsabilityDefect>> map =
-                (Map<String, List<UsabilityDefect>>) parent.getData();
-            
-            for (Map.Entry<String, List<UsabilityDefect>> entry : map.entrySet()) {
+            Map<String, List<UsabilitySmell>> map =
+                (Map<String, List<UsabilitySmell>>) parent.getData();
+            
+            for (Map.Entry<String, List<UsabilitySmell>> entry : map.entrySet()) {
                 TreeItem child = new TreeItem(parent, SWT.NULL);        
-                child.setText(entry.getKey() + " (" + entry.getValue().size() + " defects)");
+                child.setText(entry.getKey() + " (" + entry.getValue().size() + " smells)");
                 child.setData(entry);
                 
@@ -396,12 +451,13 @@
         else if (parent.getData() instanceof Map.Entry<?, ?>) {
             @SuppressWarnings("unchecked")
-            Map.Entry<String, List<UsabilityDefect>> entry =
-                (Map.Entry<String, List<UsabilityDefect>>) parent.getData();
+            Map.Entry<String, List<UsabilitySmell>> entry =
+                (Map.Entry<String, List<UsabilitySmell>>) parent.getData();
             
             int count = 0;
-            for (UsabilityDefect defect : entry.getValue()) {
+            for (UsabilitySmell smell : entry.getValue()) {
                 TreeItem child = new TreeItem(parent, SWT.NULL);        
-                child.setData(defect);
-                child.setText("defect " + ++count);
+                child.setData(smell);
+                child.setText(++count + ": ratio = " + smell.getIntensity().getRatio() +
+                              ", covered events = " + smell.getIntensity().getEventCoverage());
             }
         }
@@ -426,6 +482,6 @@
      *
      */
-    private List<ITask> getInvolvedTasks(UsabilityDefect defect) {
-        List<Object> fragments = defect.getDescriptionFragments();
+    private List<ITask> getInvolvedTasks(UsabilitySmell smell) {
+        List<Object> fragments = smell.getDescriptionFragments();
         List<ITask> involvedTasks = new ArrayList<ITask>();
         
@@ -442,6 +498,6 @@
      *
      */
-    private List<IEventTarget> getInvolvedTargets(UsabilityDefect defect) {
-        List<Object> fragments = defect.getDescriptionFragments();
+    private List<IEventTarget> getInvolvedTargets(UsabilitySmell smell) {
+        List<Object> fragments = smell.getDescriptionFragments();
         List<IEventTarget> involvedTargets = new ArrayList<IEventTarget>();
         
