Skip to content

Feature Notes: Task Sorting

Dmitry Barashev edited this page Mar 27, 2017 · 1 revision

Summary

We'd like to implement sorting of tasks in the task table by start/end date in ascending/descending order. This document describes user interface and technical aspects of the implementation.

Partial order

The order of tasks is actually partial because tasks form a tree rather than a list. We can't compare two tasks from different subtrees by start dates, we can only compare sibling tasks. So, when we say "tasks are ordered by start date" we actually mean "sibling tasks are ordered by start date [and it applies recursively to subtasks]"

User interface

User can request task ordering by clicking column header in the table. When user clicks say "Begin date" header we should order tasks by begin date in ascending order and add arrow up icon to the header. If user clicks the header once again, we should change the ordering to descending and change the icon to arrow down.

We do not maintain the order. If user modifies the tree by adding a new task or removing/reordering existing tasks, the tree becomes unordered and subsequent clicks on the header behave like described above.

Technical details

Relevant classes in GanttProject codebase:

  • Classes which store the tree: GanttTreeTableModel, TaskNode.
  • Classes which provide functions for manipulating and searching the tree: TaskContainmentHierarchyFacadeImpl. It implements TaskContainmentHierarchyFacade interface and its instance is available via TaskManager.getTaskHierarchy() instance method.
  • Classes which wrap the tree model into treetable component: GanttTree2, GanttTreeTable, GPTreeTableBase. The latter registers MouseListener instance on the column headers.
  • Class TaskDefaultColumn provides an enumeration of predefined columns with some specific properties for each column.

It seems that the best and cleanest way to implement this feature is:

  • add a new method TaskContainmentHierarchy::sort(Comparator), implement it properly
  • add sortComparator property to TaskDefaultColumn interface and its implementation in BEGIN_DATE and END_DATE
  • register sorting actions in the table header on those columns which have sorting feature

Source code location

This feature should eventually be merged into BRANCH_2_8_X and published in GanttProject 2.8.5. The base integration branch for pull requests is tkt_1216_master. Please target on using Java 7 (that is, do not use laguage features and libraries added in Java 8 and Java 9)