[410064]Sort function of detailed report view does not work well
diff --git a/plugins/org.eclipse.actf.visualization.eval/src/org/eclipse/actf/visualization/internal/eval/EvaluationItemImpl.java b/plugins/org.eclipse.actf.visualization.eval/src/org/eclipse/actf/visualization/internal/eval/EvaluationItemImpl.java index 8b8c7f4..a39c85f 100644 --- a/plugins/org.eclipse.actf.visualization.eval/src/org/eclipse/actf/visualization/internal/eval/EvaluationItemImpl.java +++ b/plugins/org.eclipse.actf.visualization.eval/src/org/eclipse/actf/visualization/internal/eval/EvaluationItemImpl.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and Others + * Copyright (c) 2005, 2013 IBM Corporation and Others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,8 +11,11 @@ package org.eclipse.actf.visualization.internal.eval; +import java.util.Comparator; import java.util.Iterator; import java.util.TreeSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.actf.util.FileUtils; import org.eclipse.actf.visualization.eval.IEvaluationItem; @@ -129,6 +132,8 @@ private String severityStr = SEV_INFO_STR; + private Pattern pattern = Pattern.compile("\\d+"); + /** * @param id */ @@ -154,11 +159,49 @@ this.guidelines = guidelines; } + private TreeSet<String> getTechniquesSortTree(){ + return new TreeSet<String>(new Comparator<String>() { + public int compare(String arg1, String arg2) { + int result; + String str1, str2; + int num1, num2; + + Matcher matcher1 = pattern.matcher(arg1); + Matcher matcher2 = pattern.matcher(arg2); + + if (matcher1.find()) { + str1 = arg1.substring(0, matcher1.start()); + num1 = Integer.parseInt(matcher1.group()); + } else { + str1 = arg1; + num1 = Integer.MIN_VALUE; + } + + if (matcher2.find()) { + str2 = arg2.substring(0, matcher2.start()); + num2 = Integer.parseInt(matcher2.group()); + } else { + str2 = arg2; + num2 = Integer.MIN_VALUE; + } + + result = str1.compareTo(str2); + if (result != 0) + return result; + result = Integer.compare(num1, num2); + if (result != 0) + return result; + return arg1.compareTo(arg2); + } + }); + } + public void setTechniques(ITechniquesItem[][] techniques) { this.techniques = techniques; // init - TreeSet<String> tmpTree = new TreeSet<String>(); + TreeSet<String> tmpTree = getTechniquesSortTree(); + for (int i = 0; i < techniques.length; i++) { ITechniquesItem[] ti = techniques[i]; for (ITechniquesItem tech : ti) { @@ -199,9 +242,9 @@ } else if (SEV_WARNING_STR.equalsIgnoreCase(_severityStr)) { severity = SEV_WARNING; severityStr = IProblemConst.WARNING; - } else if (SEV_USER_STR.equalsIgnoreCase(_severityStr)){ + } else if (SEV_USER_STR.equalsIgnoreCase(_severityStr)) { severity = SEV_USER; - severityStr = IProblemConst.USER_CHECK; + severityStr = IProblemConst.USER_CHECK; } // else{ // severity = SEV_INFO; @@ -380,7 +423,7 @@ } private void updateTableDataTechniques() { - TreeSet<String> tmpTree = new TreeSet<String>(); + TreeSet<String> tmpTree = getTechniquesSortTree(); for (int i = 0; i < guidelines.length; i++) { if (guidelines[i].isEnabled()) { ITechniquesItem[] ti = techniques[i];
diff --git a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorter.java b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorter.java index fc1d828..d330d34 100644 --- a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorter.java +++ b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorter.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and Others + * Copyright (c) 2005, 2013 IBM Corporation and Others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -73,8 +73,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, - * java.lang.Object, java.lang.Object) + * @see + * org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers + * .Viewer, java.lang.Object, java.lang.Object) */ public int compare(Viewer arg0, Object arg1, Object arg2) { int result = 0; @@ -96,10 +97,13 @@ result = compareGuideline(tmp1, tmp2, curColumn - metricsFinPos); } else if (curColumn == guidelineFinPos) { + result = compareEvalItem(tmp1.getEvaluationItem(), + tmp2.getEvaluationItem()); + } else if (curColumn == guidelineFinPos + 1) { result = compareLine(tmp1, tmp2); } else { - result = compareString(tmp1.getDescription(), tmp2 - .getDescription()); + result = compareString(tmp1.getDescription(), + tmp2.getDescription()); } if (result == 0) {
diff --git a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterBase.java b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterBase.java index 0315fcb..2e99b35 100644 --- a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterBase.java +++ b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterBase.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and Others + * Copyright (c) 2005, 2013 IBM Corporation and Others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,8 +11,11 @@ package org.eclipse.actf.visualization.ui.report.table; import java.util.Comparator; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.eclipse.actf.util.comparator.ChainComparator; +import org.eclipse.actf.visualization.eval.IEvaluationItem; import org.eclipse.actf.visualization.eval.problem.IProblemItem; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.swt.graphics.Image; @@ -29,6 +32,8 @@ public abstract class ResultTableSorterBase extends ViewerSorter implements IResultTableSorter { + private Pattern pattern = Pattern.compile("\\d+"); + /** * Sort {@link IProblemItem} based on it's score */ @@ -196,4 +201,54 @@ return (target1.compareTo(target2)); } + private int compareEvalItem(String arg1, String arg2) { + if (arg1.length() == 0) { + if (arg2.length() > 0) { + return 1; + } + return 0; + } else if (arg2.length() == 0) { + return -1; + } + + int result; + String str1, str2; + int num1, num2; + + Matcher matcher1 = pattern.matcher(arg1); + Matcher matcher2 = pattern.matcher(arg2); + + if (matcher1.find()) { + str1 = arg1.substring(0, matcher1.start()); + num1 = Integer.parseInt(matcher1.group()); + } else { + str1 = arg1; + num1 = Integer.MIN_VALUE; + } + + if (matcher2.find()) { + str2 = arg2.substring(0, matcher2.start()); + num2 = Integer.parseInt(matcher2.group()); + } else { + str2 = arg2; + num2 = Integer.MIN_VALUE; + } + + result = str1.compareTo(str2); + if (result != 0) + return result; + result = Integer.compare(num1, num2); + if (result != 0) + return result; + return compareEvalItem(arg1.substring(matcher1.end()), + arg2.substring(matcher2.end())); + + } + + protected int compareEvalItem(IEvaluationItem target1, + IEvaluationItem target2) { + return compareEvalItem(target1.getTableDataTechniques(), + target2.getTableDataTechniques()); + } + }
diff --git a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterLV.java b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterLV.java index e47d56b..b2395e3 100644 --- a/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterLV.java +++ b/plugins/org.eclipse.actf.visualization.ui.report/src/org/eclipse/actf/visualization/ui/report/table/ResultTableSorterLV.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and Others + * Copyright (c) 2005, 2013 IBM Corporation and Others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,7 +13,6 @@ import org.eclipse.actf.visualization.eval.guideline.GuidelineHolder; import org.eclipse.actf.visualization.eval.problem.IProblemItemImage; import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; /** * Viewer sorter implementation for image related accessibility issues @@ -21,8 +20,7 @@ * @see IResultTableSorter * @see IProblemItemImage */ -public class ResultTableSorterLV extends ViewerSorter implements - IResultTableSorter { +public class ResultTableSorterLV extends ResultTableSorterBase { private GuidelineHolder guidelineHolder = GuidelineHolder.getInstance(); @@ -40,17 +38,6 @@ guidelineFinPos = 1 + guidelineHolder.getGuidelineData().length; } - // TODO levels then itemName - private int compareString(String guide1, String guide2) { - - if (guide1.length() == 0 && guide2.length() != 0) { - return (1); - } else if (guide1.length() != 0 && guide2.length() == 0) { - return (-1); - } - return (guide1.compareTo(guide2)); - } - private int compareInt(int type1, int type2) { return (type1 - type2); } @@ -58,8 +45,9 @@ /* * (non-Javadoc) * - * @see org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers.Viewer, - * java.lang.Object, java.lang.Object) + * @see + * org.eclipse.jface.viewers.ViewerSorter#compare(org.eclipse.jface.viewers + * .Viewer, java.lang.Object, java.lang.Object) */ public int compare(Viewer arg0, Object arg1, Object arg2) { int result = 0; @@ -73,23 +61,21 @@ } else if (curColumn < guidelineFinPos) { // TODO sync with label - result = compareString( - tmp1.getEvaluationItem().getTableDataGuideline()[curColumn - 1], - tmp2.getEvaluationItem().getTableDataGuideline()[curColumn - 1]); + result = compareGuideline(tmp1, tmp2, curColumn - 1); } else { switch (curColumn - guidelineFinPos) { case 0: - result = compareInt(tmp1.getSeverityLV(), tmp2 - .getSeverityLV()); + result = compareInt(tmp1.getSeverityLV(), + tmp2.getSeverityLV()); break; case 1: - result = compareString(tmp1.getForeground(), tmp2 - .getForeground()); + result = compareString(tmp1.getForeground(), + tmp2.getForeground()); break; case 2: - result = compareString(tmp1.getBackground(), tmp2 - .getBackground()); + result = compareString(tmp1.getBackground(), + tmp2.getBackground()); break; case 3: result = compareInt(tmp1.getX(), tmp2.getX()); @@ -101,8 +87,12 @@ result = compareInt(tmp1.getArea(), tmp2.getArea()); break; case 6: - result = compareString(tmp1.getDescription(), tmp2 - .getDescription()); + result = compareEvalItem(tmp1.getEvaluationItem(), + tmp2.getEvaluationItem()); + break; + case 7: + result = compareString(tmp1.getDescription(), + tmp2.getDescription()); break; } }