Personal Planner - default sort by Project name
Brought to you by:
acarmichael,
t_shelley
At the moment the Personal Planner does not support sort. The list of Projects it displays is directly from the array of projects in xProcess and this of course means the order cannot be certain. As a first step, provide a default sort by Project name
This applied to things in the project explorer too.
In cases in which the alphabetical sorting of tasks not appropriate I prefix tasks names with account codes to get some control over the sorting. For that usecase I would find it helpful if a natural order string comparison could be applied (see http://sourcefrog.net/projects/natsort/\). Currently "1.11.1 Some work package" would be listed before "1.2.1 Some other work package" so that I have to work with leading zeroes. I have written an OGNL script to add or remove account codes to some or all of the task tree.
I've found a natural sorting class that we could use here - http://www.java2s.com/Code/Java/Collections-Data-Structure/NaturalOrderComparator.htm
That looks good to me. I you want, I could have a go at integrating it and send you a patch.
If you want to have a go then I think you need to look at the PersonalPlannerContentProvider class and the getChildren() method where it collects the projects for a person into a normal array.
Do you have any experience running the UI tests on linux?
I have now finally managed to get them started (in a VM running Fedora 11 and using Eclipse Ganymede (3.4.2)). Unfortunately almost all of the tests fail - I think due to the fact, that Elements are not found.
Unfortunately we were never able to get Abbot (the testing framework) to run under Linux. I vaguely remember that Abbot uses some SWT work-arounds specific for Windows and therefore does not work on Linux.
If the change is just in the class PersonalPlannerContentProvider you could just send me the java file via email. Then I can insert it and run the UI tests this end.
I have had a look at the sorting in xProcess and realize that to implement "natural order" sorting would be quite a lot of work - too much for me to start on at the moment. I have therefore added simple alphabetical sorting of the projects in the PersonalPlannerContentProvider. I have also added a corresponding test method to "TestPersonalPlanner".
I'm not sure what Andy meant by his comment "This applied to things in the project explorer too." so have not done anything about that.
See my changes in patch0.patch (to be applied to r3417)
Hmm, I don't seem to be able to attach files, so add the patch in a separate comment ...
diff --git a/com.ivis.xprocess.ui/src/com/ivis/xprocess/ui/view/providers/PersonalPlannerContentProvider.java b/com.ivis.xprocess.ui/src/com/ivis/xprocess/ui/view/providers/PersonalPlannerContentProvider.java
index 30868ba..bb0c9df 100644
--- a/com.ivis.xprocess.ui/src/com/ivis/xprocess/ui/view/providers/PersonalPlannerContentProvider.java
+++ b/com.ivis.xprocess.ui/src/com/ivis/xprocess/ui/view/providers/PersonalPlannerContentProvider.java
@@ -27,6 +27,8 @@
package com.ivis.xprocess.ui.view.providers;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
@@ -41,13 +43,21 @@ import com.ivis.xprocess.ui.util.ElementUtil;
public class PersonalPlannerContentProvider implements ITreeContentProvider {
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof PersonWrapper) {
- ArrayList<Object> projectAvailablityAndAssignments = new ArrayList<Object>();
+ ArrayList<ProjectAvailabilityAndAssignmentWrapper> projectAvailablityAndAssignments = new ArrayList<ProjectAvailabilityAndAssignmentWrapper>();
Person person = ((PersonWrapper) parentElement).getPerson();
for (Xproject project : person.getProjects()) {
ProjectAvailabilityAndAssignmentWrapper projectAvailabilityAndAssignmentWrapper = new ProjectAvailabilityAndAssignmentWrapper((IElementWrapper) parentElement, project, person);
projectAvailablityAndAssignments.add(projectAvailabilityAndAssignmentWrapper);
}
+
+ Collections.sort(projectAvailablityAndAssignments, new Comparator<ProjectAvailabilityAndAssignmentWrapper>() {
+ @Override
+ public int compare(ProjectAvailabilityAndAssignmentWrapper o1,
+ ProjectAvailabilityAndAssignmentWrapper o2) {
+ return o1.getLabel().compareTo(o2.getLabel());
+ }
+ });
return projectAvailablityAndAssignments.toArray();
}
diff --git a/tests.com.ivis.xprocess.ui/src/tests/com/ivis/xprocess/abbot/editors/TestPersonalPlanner.java b/tests.com.ivis.xprocess.ui/src/tests/com/ivis/xprocess/abbot/editors/TestPersonalPlanner.java
index 76df443..532de93 100644
--- a/tests.com.ivis.xprocess.ui/src/tests/com/ivis/xprocess/abbot/editors/TestPersonalPlanner.java
+++ b/tests.com.ivis.xprocess.ui/src/tests/com/ivis/xprocess/abbot/editors/TestPersonalPlanner.java
@@ -26,6 +26,8 @@
package tests.com.ivis.xprocess.abbot.editors;
+import java.util.Arrays;
+
import junit.extensions.ForkedPDETestCase;
import org.eclipse.swt.SWT;
@@ -157,6 +159,64 @@ public class TestPersonalPlanner extends ForkedPDETestCase {
assertFalse(EditorHelper.isEditorOpen(personName));
}
+ public void testProjectSortInPersonalPlanner() throws WidgetNotFoundException, MultipleWidgetsFoundException {
+
+ uitu.ensureDatasourceAvailable("testProjectSortInPersonalPlanner");
+
+ String personName = Helper.getNewPersonName();
+ OrganizationHelper.createPerson(personName, OrganizationHelper.getDefaultOrganization());
+
+ // Names entered in the order we would expect them if we sorted by "natural order"
+ String[] projectNames = new String[] { "3.4 aa", "3.4 ab", "3.10 ab", "10.1 ab", "ab9a", "ab10a", "ab10b" };
+
+ // ... until we support "natural order" sorting we sort the names alphabetically
+ Arrays.sort(projectNames);
+
+ String message = "Expected:";
+ for (String projectName : projectNames) {
+ message += " \"" + projectName + "\"";
+ ProjectHelper.createProject(projectName);
+
+ String taskName = Helper.getNewTaskName();
+ TaskHelper.createTask(taskName, Helper.getRootElementName() + "/" + projectName);
+
+ ProjectHelper.addPersonToProject(projectName, personName);
+ }
+
+ EditorHelper.openEditor(Helper.getRootElementName() + "/" + OrganizationHelper.getDefaultOrganization(), personName);
+
+
+ Tree personalPlannerTree = (Tree) uitu.getBasicFinder().find(new NameMatcher(TestHarness.PERSONAL_PLANNER_TREE));
+
+ // Check the number and order of the (collapsed) projects
+ TreeItem[] treeItems = uitu.getTreeTester().getItems(personalPlannerTree);
+ assertEquals("Unexpected number of projects found", projectNames.length, treeItems.length);
+
+ message += ". Found:";
+ boolean orderOk = true;
+ int counter = 0;
+ for (TreeItem treeItem : treeItems) {
+ String actualProject = EditorHelper.getText(treeItem, 0);
+ message += " \"" + actualProject + "\"";
+ if (!actualProject.equals(projectNames[counter])) {
+ orderOk = false;
+ }
+ counter++;
+ }
+
+ assertTrue("Order not OK. " + message + ".", orderOk);
+
+ // Cleanup
+ for (String projectName : projectNames) {
+ ExplorerTreeHelper.deleteItem(Helper.getRootElementName() + "/" + projectName);
+ }
+
+ ExplorerTreeHelper.deleteItem(Helper.getRootElementName() + "/" + OrganizationHelper.getDefaultOrganization() + "/" + personName);
+
+ assertTrue(ExplorerTreeHelper.treeItemDoesNotExists(Helper.getRootElementName() + "/" + OrganizationHelper.getDefaultOrganization(), personName));
+ assertFalse(EditorHelper.isEditorOpen(personName));
+ }
+
// public void testSaveAndCancelPersonalPlannerAvailability() throws
// WidgetNotFoundException, MultipleWidgetsFoundException,
// ElementCreationException {
Well that was not a good idea. I'll send you the patch by mail.