diff options
| author | Ovidiu Buligan | 2013-05-13 15:47:54 +0000 |
|---|---|---|
| committer | Johan Compagner | 2013-05-13 15:49:54 +0000 |
| commit | 32b75b974b61decdc58476797d93e715d193fe87 (patch) | |
| tree | 4ed3e0e78a5d490b817aabeef44d4a126caeabfe | |
| parent | e0d1c620f3e4dbede5d5ef2b264bd4e68320f13f (diff) | |
| download | org.eclipse.dltk.core-32b75b974b61decdc58476797d93e715d193fe87.tar.gz org.eclipse.dltk.core-32b75b974b61decdc58476797d93e715d193fe87.tar.xz org.eclipse.dltk.core-32b75b974b61decdc58476797d93e715d193fe87.zip | |
sorting support in the testing view
5 files changed, 114 insertions, 1 deletions
diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestRunnerViewPart.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestRunnerViewPart.java index 7c13fbab9..50bba60b9 100755 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestRunnerViewPart.java +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestRunnerViewPart.java @@ -149,6 +149,8 @@ public class TestRunnerViewPart extends ViewPart { */ private int fLayout = LAYOUT_HIERARCHICAL; + + private int fSortDirection = SORT_DIRECTION_NO_SORT; // private boolean fTestIsRunning= false; protected DLTKTestingProgressBar fProgressBar; @@ -184,6 +186,7 @@ public class TestRunnerViewPart extends ViewPart { private Action fFailuresOnlyFilterAction; private ScrollLockAction fScrollLockAction; private ToggleOrientationAction[] fToggleOrientationActions; + private ToggleSortDirectionAction[] fToggleSortDirectionActions; private ShowTestHierarchyAction fShowTestHierarchyAction; private ShowTimeAction fShowTimeAction; private ActivateOnErrorAction fActivateOnErrorAction; @@ -276,6 +279,8 @@ public class TestRunnerViewPart extends ViewPart { static final String TAG_PAGE = "page"; //$NON-NLS-1$ static final String TAG_RATIO = "ratio"; //$NON-NLS-1$ static final String TAG_ORIENTATION = "orientation"; //$NON-NLS-1$ + static final String TAG_SORT_DIRECTION = "sort_direction"; //$NON-NLS-1$ + static final String TAG_SCROLL = "scroll"; //$NON-NLS-1$ /** * @since 3.2 @@ -293,6 +298,11 @@ public class TestRunnerViewPart extends ViewPart { static final int VIEW_ORIENTATION_HORIZONTAL = 1; static final int VIEW_ORIENTATION_AUTOMATIC = 2; + //sort direction + static final int SORT_DIRECTION_NO_SORT = 0; + static final int SORT_DIRECTION_ASCENDING = 1; + static final int SORT_DIRECTION_DESCENDING = 2; + private IMemento fMemento; Image fOriginalViewImage; @@ -879,6 +889,36 @@ public class TestRunnerViewPart extends ViewPart { } } } + + private class ToggleSortDirectionAction extends Action { + private final int fActionSortDirection; + + public ToggleSortDirectionAction(int sortDirection) { + super("", AS_RADIO_BUTTON); //$NON-NLS-1$ + if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_NO_SORT) { + setText(DLTKTestingMessages.TestRunnerViewPart_toggle_sort_no_sort); +// setImageDescriptor(DLTKTestingPlugin +// .getImageDescriptor("elcl16/th_horizontal.gif")); //$NON-NLS-1$ + } else if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_ASCENDING) { + setText(DLTKTestingMessages.TestRunnerViewPart_toggle_sort_ascending); +// setImageDescriptor(DLTKTestingPlugin +// .getImageDescriptor("elcl16/th_vertical.gif")); //$NON-NLS-1$ + } else if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_DESCENDING) { + setText(DLTKTestingMessages.TestRunnerViewPart_toggle_sort_descending); +// setImageDescriptor(DLTKTestingPlugin +// .getImageDescriptor("elcl16/th_automatic.gif")); //$NON-NLS-1$ + } + fActionSortDirection = sortDirection; + } + public int getSortDirection(){ + return fActionSortDirection; + } + + public void run() { + fSortDirection =fActionSortDirection; + fTestViewer.setSortDirection(fActionSortDirection); + } + } /** * Listen for for modifications to Java elements @@ -1027,11 +1067,13 @@ public class TestRunnerViewPart extends ViewPart { int ratio = (weigths[0] * 1000) / (weigths[0] + weigths[1]); memento.putInteger(TAG_RATIO, ratio); memento.putInteger(TAG_ORIENTATION, fOrientation); - + memento.putInteger(TAG_SORT_DIRECTION, fSortDirection); + memento.putString(TAG_FAILURES_ONLY, fFailuresOnlyFilterAction .isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ memento.putInteger(TAG_LAYOUT, fLayout); memento.putString(TAG_SHOW_TIME, fShowTimeAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ + } private void restoreLayoutState(IMemento memento) { @@ -1052,6 +1094,18 @@ public class TestRunnerViewPart extends ViewPart { if (orientation != null) fOrientation = orientation.intValue(); computeOrientation(); + Integer sortDirection = memento.getInteger(TAG_SORT_DIRECTION); + if(sortDirection !=null) { + fSortDirection = sortDirection.intValue(); + fTestViewer.setSortDirection(fSortDirection); + for(ToggleSortDirectionAction act :fToggleSortDirectionActions){ + if(act.getSortDirection() ==fSortDirection){ + act.setChecked(true); + break; + } + } + } + String scrollLock = memento.getString(TAG_SCROLL); if (scrollLock != null) { fScrollLockAction.setChecked(scrollLock.equals("true")); //$NON-NLS-1$ @@ -1756,6 +1810,12 @@ public class TestRunnerViewPart extends ViewPart { new ToggleOrientationAction(VIEW_ORIENTATION_HORIZONTAL), new ToggleOrientationAction(VIEW_ORIENTATION_AUTOMATIC) }; + fToggleSortDirectionActions = new ToggleSortDirectionAction[]{ + new ToggleSortDirectionAction(SORT_DIRECTION_NO_SORT), + new ToggleSortDirectionAction(SORT_DIRECTION_ASCENDING), + new ToggleSortDirectionAction(SORT_DIRECTION_DESCENDING) + }; + fShowTestHierarchyAction = new ShowTestHierarchyAction(); fShowTimeAction= new ShowTimeAction(); @@ -1779,6 +1839,12 @@ public class TestRunnerViewPart extends ViewPart { layoutSubMenu.add(fToggleOrientationActions[i]); } viewMenu.add(layoutSubMenu); + layoutSubMenu = new MenuManager( + DLTKTestingMessages.TestRunnerViewPart_sort_direction_menu); + for (int i = 0; i < fToggleSortDirectionActions.length; ++i) { + layoutSubMenu.add(fToggleSortDirectionActions[i]); + } + viewMenu.add(layoutSubMenu); viewMenu.add(new Separator()); viewMenu.add(fFailuresOnlyFilterAction); diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestTreeComparator.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestTreeComparator.java index 08e406f84..6d43210a2 100644 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestTreeComparator.java +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestTreeComparator.java @@ -11,12 +11,16 @@ *******************************************************************************/ package org.eclipse.dltk.internal.testing.ui; +import org.eclipse.dltk.internal.testing.model.TestCaseElement; import org.eclipse.dltk.internal.testing.model.TestCategoryElement; import org.eclipse.dltk.internal.testing.model.TestSuiteElement; +import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerComparator; public class TestTreeComparator extends ViewerComparator { + private int sortDirection = TestRunnerViewPart.SORT_DIRECTION_NO_SORT; + public int category(Object element) { if (element instanceof TestCategoryElement) { return 0; @@ -27,4 +31,31 @@ public class TestTreeComparator extends ViewerComparator { } } + public void setSortDirection(int sortDirection) { + this.sortDirection = sortDirection; + } + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + String left = ""; + String right = ""; + if (e1 instanceof TestSuiteElement && e2 instanceof TestSuiteElement) { + left = ((TestSuiteElement) e1).getTestName(); + right = ((TestSuiteElement) e2).getTestName(); + } else if (e1 instanceof TestCaseElement + && e2 instanceof TestCaseElement) { + left = ((TestCaseElement) e1).getTestName(); + right = ((TestCaseElement) e2).getTestName(); + } else + return super.compare(viewer, e1, e2); + + if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_NO_SORT) { + return 0; + } else if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_ASCENDING) { + return left.compareTo(right); + } else if (sortDirection == TestRunnerViewPart.SORT_DIRECTION_DESCENDING) { + return -1 * left.compareTo(right); + } + return 0; + } } diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestViewer.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestViewer.java index a95b16f2e..8f38d9961 100755 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestViewer.java +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/internal/testing/ui/TestViewer.java @@ -48,6 +48,7 @@ import org.eclipse.jface.viewers.StructuredViewer; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; @@ -730,5 +731,11 @@ public class TestViewer { public void expandFirstLevel() { fTreeViewer.expandToLevel(2); } + public void setSortDirection(int sortDirection){ + ViewerComparator comparator = fTreeViewer.getComparator(); + if(comparator instanceof TestTreeComparator){ + ((TestTreeComparator) comparator).setSortDirection(sortDirection); + } + } } diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/DLTKTestingMessages.java b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/DLTKTestingMessages.java index a6beafd0d..af47b9f8b 100644 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/DLTKTestingMessages.java +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/DLTKTestingMessages.java @@ -329,4 +329,9 @@ public final class DLTKTestingMessages extends NLS { public static String InternalError; public static String TestingNoEngineConfigured; + + public static String TestRunnerViewPart_sort_direction_menu; + public static String TestRunnerViewPart_toggle_sort_ascending; + public static String TestRunnerViewPart_toggle_sort_no_sort; + public static String TestRunnerViewPart_toggle_sort_descending; } diff --git a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingMessages.properties b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingMessages.properties index 48f6aadf6..81fb6a6e8 100644 --- a/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingMessages.properties +++ b/core/plugins/org.eclipse.dltk.testing/src/org/eclipse/dltk/testing/TestingMessages.properties @@ -114,6 +114,10 @@ TestRunnerViewPart_terminate_title=Rerun Test TestRunnerViewPart_terminate_message=Terminate currently running tests? TestRunnerViewPart_test_run_history=Test Run History... TestRunnerViewPart_testName_startTime={0} ({1}) +TestRunnerViewPart_sort_direction_menu=Sort Direction +TestRunnerViewPart_toggle_sort_no_sort=No sort +TestRunnerViewPart_toggle_sort_ascending=Ascending +TestRunnerViewPart_toggle_sort_descending=Descending # The first parameter is the test name and the second is the JUnit version TestRunnerViewPart_titleToolTip={0} - {1} |
