Index: trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java
===================================================================
--- trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java	(revision 1918)
+++ trunk/autoquest-core-usability/src/main/java/de/ugoe/cs/autoquest/usability/CheckBoxMultipleSelectionRule.java	(revision 2042)
@@ -15,22 +15,26 @@
 package de.ugoe.cs.autoquest.usability;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import de.ugoe.cs.autoquest.eventcore.IEventTarget;
+import de.ugoe.cs.autoquest.eventcore.gui.MouseClick;
+import de.ugoe.cs.autoquest.eventcore.gui.ValueSelection;
 import de.ugoe.cs.autoquest.eventcore.guimodel.ICheckBox;
 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskTraversingVisitor;
+import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIView;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.DefaultTaskInstanceTraversingVisitor;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance;
 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
-import de.ugoe.cs.autoquest.tasktrees.treeifc.TaskMetric;
+import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
 
 /**
@@ -68,124 +72,117 @@
                                    UsabilityEvaluationResult results)
     {
+        System.out.println("\n\n########################################\n");
+        final List<List<IEventTaskInstance>> actionInstancesInSameView = new LinkedList<>();
+        
+        for (IUserSession session : taskModel.getUserSessions()) {
+            for (ITaskInstance instance : session) {
+                final LinkedList<IEventTaskInstance> currentList = new LinkedList<>();
+                
+                instance.accept(new DefaultTaskInstanceTraversingVisitor() {
+                    @Override
+                    public void visit(IEventTaskInstance eventTaskInstance) {
+                        if (eventTaskInstance.getEvent().getTarget() instanceof IGUIElement) {
+                            IEventTarget target = eventTaskInstance.getEvent().getTarget();
+                            IGUIView currentView = ((IGUIElement) target).getView();
+                            
+                            IGUIView previousView = null;
+                            if (currentList.size() > 0) {
+                                target = currentList.getLast().getEvent().getTarget();
+                                previousView = ((IGUIElement) target).getView();
+                            }
+                            
+                            if ((previousView == currentView) ||
+                                ((previousView != null) && (previousView.equals(currentView))))
+                            {
+                                currentList.add(eventTaskInstance);
+                            }
+                            else {
+                                if (currentList.size() > 0) {
+                                    actionInstancesInSameView.add(new ArrayList<>(currentList));
+                                }
+                                currentList.clear();
+                                currentList.add(eventTaskInstance);
+                            }
+                        }
+                    }
+                });
+                
+                if (currentList.size() > 0) {
+                    actionInstancesInSameView.add(new ArrayList<>(currentList));
+                }
+            }
+        }
+
+        
         Map<IGUIElement, List<IGUIElement>> checkBoxGroups = statistics.getCheckBoxGroups();
         
-        CHECK_NEXT_GROUP:
-        for (List<IGUIElement> group : checkBoxGroups.values()) {
-            Set<ITask> tasksUsingGroup = new HashSet<>();
-            
-            for (IGUIElement checkBox : group) {
-                Set<ITask> tasksUsingCheckBox = getTasksUsingCheckBox(checkBox, taskModel);
+        for (Map.Entry<IGUIElement, List<IGUIElement>> group : checkBoxGroups.entrySet()) {
+            IGUIView currentView = group.getKey().getView();
+            int noOfEvents = 0;
+            int noOfGroupUsages = 0;
+            int noOfSingleCheckBoxUsages = 0;
+            
+            for (List<IEventTaskInstance> actionInstanceList : actionInstancesInSameView) {
+                IEventTarget target = actionInstanceList.get(0).getEvent().getTarget();
+                IGUIView viewOfList = ((IGUIElement) target).getView();
                 
-                for (ITask taskUsingCheckBox : tasksUsingCheckBox) {
-                    if (tasksUsingGroup.contains(taskUsingCheckBox)) {
-                        continue CHECK_NEXT_GROUP;
-                    }
-                    else {
-                        tasksUsingGroup.add(taskUsingCheckBox);
+                if ((viewOfList == currentView) ||
+                    ((viewOfList != null) && (viewOfList.equals(currentView))))
+                {
+                    noOfGroupUsages++;
+                    boolean[] checkBoxUsages = new boolean[group.getValue().size()];
+                    
+                    for (IEventTaskInstance actionInstance : actionInstanceList) {
+                        int index = 0;
+                        for (IGUIElement checkBox : group.getValue()) {
+                            if ((("JFC".equals(actionInstance.getEvent().getTarget().getPlatform())) &&
+                                 (actionInstance.getEvent().getType() instanceof MouseClick) &&
+                                 (actionInstance.getEvent().getTarget().equals(checkBox))) ||
+                                ((actionInstance.getEvent().getType() instanceof ValueSelection<?>) &&
+                                 (actionInstance.getEvent().getTarget().equals(checkBox))))
+                            {
+                                checkBoxUsages[index] = !checkBoxUsages[index];
+                                noOfEvents++;
+                            }
+                            index++;
+                        }
+                    }
+                    
+                    int noOfCheckedBoxes = 0;
+                    
+                    for (int i = 0; i < checkBoxUsages.length; i++) {
+                        if (checkBoxUsages[i]) {
+                            noOfCheckedBoxes++;
+                        }
+                    }
+                    
+                    if (noOfCheckedBoxes == 1) {
+                        noOfSingleCheckBoxUsages++;
                     }
                 }
             }
             
-            if (tasksUsingGroup.size() > 0) {
-                int eventCoverage = 0;
-                int allRecordedEvents = 0;
-                
-                for (ITask task : tasksUsingGroup) {
-                    if (task instanceof IEventTask) {
-                        eventCoverage +=
-                            taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE);
-                    }
-                }
-                
-                for (ITask task : taskModel.getTasks()) {
-                    if (task instanceof IEventTask) {
-                        allRecordedEvents +=
-                            taskModel.getTaskInfo(task).getMeasureValue(TaskMetric.EVENT_COVERAGE);
-                    }
-                }
-                
-                
-                UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity
-                    ((int) (1000 * eventCoverage / allRecordedEvents), eventCoverage, -1);
-                    
-                if (intensity != null) {
-                    Map<String, Object> parameters = new HashMap<String, Object>();
-                    parameters.put("radioButtons", group);
-
-                    results.addSmell
-                        (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION,
-                         parameters);
-                }
-            }
-        }
-    }
-
-    /**
-     * 
-     */
-    private Set<ITask> getTasksUsingCheckBox(final IGUIElement checkBox, ITaskModel taskModel) {
-        final Set<ITask> tasksUsingCheckBox = new HashSet<ITask>();
-        
-        for (ITask candidate : taskModel.getTasks()) {
-            candidate.accept(new DefaultTaskTraversingVisitor() {
-                @Override
-                public void visit(IEventTask eventTask) {
-                    if (!eventTask.getInstances().isEmpty()) {
-                        IEventTaskInstance instance =
-                            (IEventTaskInstance) eventTask.getInstances().iterator().next();
-                        
-                        if (checkBox.equals(instance.getEvent().getTarget())) {
-                            tasksUsingCheckBox.add(eventTask);
-                        }
-                    }
-                }
-                
-                @Override
-                public void visit(IStructuringTemporalRelationship relationship) {
-                    if (tasksUsingCheckBox.contains(relationship)) {
-                        return;
-                    }
-                    else {
-                        for (ITask child : relationship.getChildren()) {
-                            if (tasksUsingCheckBox.contains(child)) {
-                                tasksUsingCheckBox.add(relationship);
-                                return;
-                            }
-                        }
-                        
-                        super.visit(relationship);
-                        
-                        for (ITask child : relationship.getChildren()) {
-                            if (tasksUsingCheckBox.contains(child)) {
-                                tasksUsingCheckBox.add(relationship);
-                                break;
-                            }
-                        }
-                    }
-                }
-
-                @Override
-                public void visit(IMarkingTemporalRelationship relationship) {
-                    if (tasksUsingCheckBox.contains(relationship)) {
-                        return;
-                    }
-                    else {
-                        if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) {
-                            tasksUsingCheckBox.add(relationship);
-                            return;
-                        }
-                        
-                        super.visit(relationship);
-                        
-                        if (tasksUsingCheckBox.contains(relationship.getMarkedTask())) {
-                            tasksUsingCheckBox.add(relationship);
-                            return;
-                        }
-                    }
-                }
-            });
-        }
-        
-        return tasksUsingCheckBox;
+            // get a value that is 1 if for one group usage there is on average one check box usage
+            // get a value of 0 if for one group usage there is on average two check box usages
+            
+            int ratio = noOfGroupUsages > 0 ? 1000 * noOfSingleCheckBoxUsages / noOfGroupUsages : 0;
+            
+            System.out.println(currentView + "  " + ratio + "  " + noOfGroupUsages + "  " +
+                               noOfSingleCheckBoxUsages);
+            
+            UsabilitySmellIntensity intensity = UsabilitySmellIntensity.getIntensity
+                (ratio, noOfEvents, -1);
+                    
+            if (intensity != null) {
+                Map<String, Object> parameters = new HashMap<String, Object>();
+                parameters.put("allUsages", noOfGroupUsages);
+                parameters.put("singleUsages", noOfSingleCheckBoxUsages);
+                parameters.put("ratio", 100 * noOfSingleCheckBoxUsages / noOfGroupUsages);
+                parameters.put("radioButtons", group.getValue());
+
+                results.addSmell
+                    (intensity, UsabilitySmellDescription.CHECK_BOX_SINGLE_SELECTION, parameters);
+            }
+        }
     }
 
