← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2843: implemented blueprint: custom sort for organisation unit

 

------------------------------------------------------------
revno: 2843
committer: Tri <Tri@Tri-Laptop>
branch nick: dhis2
timestamp: Mon 2011-02-14 15:40:51 +0700
message:
  implemented blueprint: custom sort for organisation unit
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitCustomComparator.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateCustomSortAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitCustomSort.vm
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml
  dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/ExpandSubtreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/GetExpandedTreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/interceptor/OrganisationUnitTreeInterceptor.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module_vi_VN.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-02-02 13:36:42 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java	2011-02-14 08:40:51 +0000
@@ -46,51 +46,57 @@
     extends Source
 {
     public static final String FEATURETYPE_NONE = "None";
+
     public static final String FEATURETYPE_MULTIPOLYGON = "MultiPolygon";
+
     public static final String FEATURETYPE_POLYGON = "Polygon";
+
     public static final String FEATURETYPE_POINT = "Point";
-        
+
     private static final Pattern JSON_COORDINATE_PATTERN = Pattern.compile( "(\\[{3}.*?\\]{3})" );
-    private static final Pattern COORDINATE_PATTERN = Pattern.compile("([\\-0-9.]+,[\\-0-9.]+)");
-    
+
+    private static final Pattern COORDINATE_PATTERN = Pattern.compile( "([\\-0-9.]+,[\\-0-9.]+)" );
+
     private Set<OrganisationUnit> children = new HashSet<OrganisationUnit>();
 
     private OrganisationUnit parent;
-    
+
     private Date openingDate;
 
     private Date closedDate;
 
     private boolean active;
-    
+
     private String comment;
-    
+
     private String geoCode;
 
     private String featureType;
-    
+
     private String coordinates;
-    
+
     private String url;
 
     private Date lastUpdated;
 
     private Set<OrganisationUnitGroup> groups = new HashSet<OrganisationUnitGroup>();
-    
+
     private String contactPerson;
-    
+
     private String address;
-    
+
     private String email;
-    
+
     private String phoneNumber;
 
     private transient int level;
-    
+
     private transient boolean currentParent;
-    
+
     private transient String type;
-    
+
+    private Integer sortOrder;
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -103,42 +109,42 @@
     {
         this.name = name;
     }
-    
-    /**
-     * @param name
-     * @param shortName
-     * @param organisationUnitCode
-     * @param openingDate
-     * @param closedDate
-     * @param active
-     * @param comment
-     */
-    public OrganisationUnit( String name, String shortName, String code, Date openingDate,
+
+    /**
+     * @param name
+     * @param shortName
+     * @param organisationUnitCode
+     * @param openingDate
+     * @param closedDate
+     * @param active
+     * @param comment
+     */
+    public OrganisationUnit( String name, String shortName, String code, Date openingDate, Date closedDate,
+        boolean active, String comment )
+    {
+        this.name = name;
+        this.shortName = shortName;
+        this.code = code;
+        this.openingDate = openingDate;
+        this.closedDate = closedDate;
+        this.active = active;
+        this.comment = comment;
+    }
+
+    /**
+     * @param name
+     * @param parent
+     * @param shortName
+     * @param organisationUnitCode
+     * @param openingDate
+     * @param closedDate
+     * @param active
+     * @param comment
+     */
+    public OrganisationUnit( String name, OrganisationUnit parent, String shortName, String code, Date openingDate,
         Date closedDate, boolean active, String comment )
     {
         this.name = name;
-        this.shortName = shortName;
-        this.code = code;
-        this.openingDate = openingDate;
-        this.closedDate = closedDate;
-        this.active = active;
-        this.comment = comment;
-    }
-
-    /**
-     * @param name
-     * @param parent
-     * @param shortName
-     * @param organisationUnitCode
-     * @param openingDate
-     * @param closedDate
-     * @param active
-     * @param comment
-     */
-    public OrganisationUnit( String name, OrganisationUnit parent, String shortName, String code,
-        Date openingDate, Date closedDate, boolean active, String comment )
-    {
-        this.name = name;
         this.parent = parent;
         this.shortName = shortName;
         this.code = code;
@@ -151,10 +157,10 @@
     // -------------------------------------------------------------------------
     // Logic
     // -------------------------------------------------------------------------
-    
+
     public boolean hasChild()
     {
-    	return !this.children.isEmpty();
+        return !this.children.isEmpty();
     }
 
     public boolean hasChildrenWithCoordinates()
@@ -166,19 +172,19 @@
                 return true;
             }
         }
-        
+
         return false;
     }
-    
+
     public boolean hasCoordinates()
     {
         return coordinates != null && coordinates.trim().length() > 0;
     }
-    
+
     public List<CoordinatesTuple> getCoordinatesAsList()
     {
         List<CoordinatesTuple> list = new ArrayList<CoordinatesTuple>();
-        
+
         if ( coordinates != null && !coordinates.trim().isEmpty() )
         {
             Matcher jsonMatcher = JSON_COORDINATE_PATTERN.matcher( coordinates );
@@ -186,29 +192,29 @@
             while ( jsonMatcher.find() )
             {
                 CoordinatesTuple tuple = new CoordinatesTuple();
-                
+
                 Matcher matcher = COORDINATE_PATTERN.matcher( jsonMatcher.group() );
-                
+
                 while ( matcher.find() )
                 {
                     tuple.addCoordinates( matcher.group() );
                 }
-                
+
                 list.add( tuple );
             }
         }
-        
+
         return list;
     }
-    
+
     public void setMultiPolygonCoordinatesFromList( List<CoordinatesTuple> list )
     {
         StringBuilder builder = new StringBuilder();
-        
+
         if ( list != null && list.size() > 0 )
         {
             builder.append( "[" );
-            
+
             for ( CoordinatesTuple tuple : list )
             {
                 builder.append( "[[" );
@@ -217,22 +223,22 @@
                 {
                     builder.append( "[" + coordinates + "]," );
                 }
-                
-                builder.deleteCharAt( builder.lastIndexOf( "," ) );            
+
+                builder.deleteCharAt( builder.lastIndexOf( "," ) );
                 builder.append( "]]," );
             }
-            
+
             builder.deleteCharAt( builder.lastIndexOf( "," ) );
             builder.append( "]" );
         }
-        
+
         this.coordinates = StringUtils.trimToNull( builder.toString() );
     }
-    
+
     public void setPointCoordinatesFromList( List<CoordinatesTuple> list )
     {
         StringBuilder builder = new StringBuilder();
-        
+
         if ( list != null && list.size() > 0 )
         {
             for ( CoordinatesTuple tuple : list )
@@ -243,10 +249,10 @@
                 }
             }
         }
-        
+
         this.coordinates = StringUtils.trimToNull( builder.toString() );
     }
-    
+
     public String getChildrenFeatureType()
     {
         for ( OrganisationUnit child : children )
@@ -256,15 +262,15 @@
                 return child.getFeatureType();
             }
         }
-        
+
         return FEATURETYPE_NONE;
     }
-    
+
     public String getValidCoordinates()
     {
         return coordinates != null && !coordinates.isEmpty() ? coordinates : "[]";
     }
-    
+
     public OrganisationUnitGroup getGroupInGroupSet( OrganisationUnitGroupSet groupSet )
     {
         if ( groupSet != null )
@@ -274,20 +280,20 @@
                 if ( groupSet.getOrganisationUnitGroups().contains( group ) )
                 {
                     return group;
-                }   
+                }
             }
         }
-        
+
         return null;
     }
-    
+
     public String getGroupNameInGroupSet( OrganisationUnitGroupSet groupSet )
     {
         final OrganisationUnitGroup group = getGroupInGroupSet( groupSet );
-        
+
         return group != null ? group.getName() : null;
     }
-    
+
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------
@@ -370,17 +376,17 @@
     {
         this.code = code;
     }
-    
+
     public String getAlternativeName()
     {
         return getShortName();
     }
-    
+
     public void setAlternativeName( String alternativeName )
     {
         throw new UnsupportedOperationException( "Cannot set alternativename on OrganisationUnit: " + alternativeName );
     }
-    
+
     public Date getOpeningDate()
     {
         return openingDate;
@@ -550,4 +556,15 @@
     {
         this.type = type;
     }
+
+    public Integer getSortOrder()
+    {
+        return sortOrder;
+    }
+
+    public void setSortOrder( Integer sortOrder )
+    {
+        this.sortOrder = sortOrder;
+    }
+
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitCustomComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitCustomComparator.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitCustomComparator.java	2011-02-14 08:40:51 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.organisationunit.comparator;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+import java.util.Comparator;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id$
+ */
+public class OrganisationUnitCustomComparator
+    implements Comparator<OrganisationUnit>
+{
+
+    @Override
+    public int compare( OrganisationUnit arg0, OrganisationUnit arg1 )
+    {
+        if ( arg0.getSortOrder() == null || arg1.getSortOrder() == null )
+        {
+            return 0;
+        }
+
+        return arg0.getSortOrder().compareTo( arg1.getSortOrder() );
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml	2010-12-14 03:56:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml	2011-02-14 08:40:51 +0000
@@ -55,6 +55,8 @@
       <key column="organisationunitid"/>
       <many-to-many class="org.hisp.dhis.organisationunit.OrganisationUnitGroup" column="orgunitgroupid"/>
     </set>
+    
+    <property name="sortOrder" column="sortorder"/>
 	
 	<!-- Contact info -->
 	

=== modified file 'dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java'
--- dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-options/src/main/java/org/hisp/dhis/options/sortorder/DefaultSortOrderManager.java	2011-02-14 08:40:51 +0000
@@ -52,6 +52,7 @@
 import org.hisp.dhis.indicator.comparator.IndicatorSortOrderComparator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitCodeComparator;
+import org.hisp.dhis.organisationunit.comparator.OrganisationUnitCustomComparator;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitShortNameComparator;
 import org.hisp.dhis.user.NoCurrentUserException;
@@ -92,7 +93,7 @@
         organisationUnitComparators.put( SORT_ORDER_SHORTNAME, new OrganisationUnitShortNameComparator() );
         organisationUnitComparators.put( SORT_ORDER_ALTERNATIVENAME, new OrganisationUnitNameComparator() ); // SIC
         organisationUnitComparators.put( SORT_ORDER_CODE, new OrganisationUnitCodeComparator() );
-        organisationUnitComparators.put( SORT_ORDER_CUSTOM, new OrganisationUnitNameComparator() ); // SIC
+        organisationUnitComparators.put( SORT_ORDER_CUSTOM, new OrganisationUnitCustomComparator() ); // SIC
         
         dataSetComparators = new HashMap<String, Comparator<DataSet>>();        
         dataSetComparators.put( SORT_ORDER_NAME, new DataSetNameComparator() );

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/ExpandSubtreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/ExpandSubtreeAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/ExpandSubtreeAction.java	2011-02-14 08:40:51 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,7 +38,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 
 import com.opensymphony.xwork2.Action;
 
@@ -60,6 +60,17 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    // -------------------------------------------------------------------------
+    // Comparator
+    // -------------------------------------------------------------------------
+
+    private Comparator<OrganisationUnit> organisationUnitComparator;
+
+    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
+    {
+        this.organisationUnitComparator = organisationUnitComparator;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -140,7 +151,7 @@
     {
         List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
 
-        Collections.sort( children, new OrganisationUnitNameComparator() );
+        Collections.sort( children, organisationUnitComparator );
 
         return children;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/GetExpandedTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/GetExpandedTreeAction.java	2010-09-14 09:03:41 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/oust/action/GetExpandedTreeAction.java	2011-02-14 08:40:51 +0000
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -39,7 +40,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.oust.manager.SelectionTreeManager;
 
 import com.opensymphony.xwork2.Action;
@@ -62,7 +62,18 @@
     public void setSelectionTreeManager( SelectionTreeManager selectionTreeManager )
     {
         this.selectionTreeManager = selectionTreeManager;
-    }  
+    }
+    
+    // -------------------------------------------------------------------------
+    // Comparator
+    // -------------------------------------------------------------------------
+
+    private Comparator<OrganisationUnit> organisationUnitComparator;
+
+    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
+    {
+        this.organisationUnitComparator = organisationUnitComparator;
+    }
 
     // -------------------------------------------------------------------------
     // Output
@@ -106,7 +117,7 @@
         
         roots = new ArrayList<OrganisationUnit>( selectionTreeManager.getRootOrganisationUnits() );
 
-        Collections.sort( roots, new OrganisationUnitNameComparator() );
+        Collections.sort( roots, organisationUnitComparator );
 
         // ---------------------------------------------------------------------
         // Get the units that need to be expanded in order for the selected
@@ -162,7 +173,7 @@
     {
         List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
 
-        Collections.sort( children, new OrganisationUnitNameComparator() );
+        Collections.sort( children, organisationUnitComparator );
 
         return children;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/ExpandSubtreeAction.java	2011-02-14 08:40:51 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,7 +38,6 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.TreeStateManager;
 
 import com.opensymphony.xwork2.Action;
@@ -68,6 +68,17 @@
     {
         this.treeStateManager = treeStateManager;
     }
+    
+    // -------------------------------------------------------------------------
+    // Comparator
+    // -------------------------------------------------------------------------
+
+    private Comparator<OrganisationUnit> organisationUnitComparator;
+
+    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
+    {
+        this.organisationUnitComparator = organisationUnitComparator;
+    }
 
     // -------------------------------------------------------------------------
     // Input
@@ -154,7 +165,7 @@
     {
         List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
 
-        Collections.sort( children, new OrganisationUnitNameComparator() );
+        Collections.sort( children, organisationUnitComparator );
 
         return children;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/action/GetExpandedTreeAction.java	2011-02-14 08:40:51 +0000
@@ -30,6 +30,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -37,7 +38,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.ouwt.manager.TreeStateManager;
 
@@ -71,6 +71,17 @@
     }
 
     // -------------------------------------------------------------------------
+    // Comparator
+    // -------------------------------------------------------------------------
+
+    private Comparator<OrganisationUnit> organisationUnitComparator;
+
+    public void setOrganisationUnitComparator( Comparator<OrganisationUnit> organisationUnitComparator )
+    {
+        this.organisationUnitComparator = organisationUnitComparator;
+    }
+
+    // -------------------------------------------------------------------------
     // Output
     // -------------------------------------------------------------------------
 
@@ -115,7 +126,7 @@
 
         roots = new ArrayList<OrganisationUnit>( selectionManager.getRootOrganisationUnits() );
 
-        Collections.sort( roots, new OrganisationUnitNameComparator() );
+        Collections.sort( roots, organisationUnitComparator );
 
         // ---------------------------------------------------------------------
         // Get the children of the roots
@@ -123,7 +134,8 @@
 
         for ( OrganisationUnit root : roots )
         {
-            boolean hasChildren = root.getChildren().size() > 0; // Dirty loading
+            boolean hasChildren = root.getChildren().size() > 0; // Dirty
+                                                                 // loading
 
             LOG.debug( "OrganisationUnit " + root.getId() + " has children = " + hasChildren );
 
@@ -153,7 +165,8 @@
 
         for ( OrganisationUnit child : children )
         {
-            boolean hasChildren = child.getChildren().size() > 0; // Dirty loading
+            boolean hasChildren = child.getChildren().size() > 0; // Dirty
+                                                                  // loading
 
             LOG.debug( "OrganisationUnit " + child.getId() + " has children = " + hasChildren );
 
@@ -168,7 +181,7 @@
     {
         List<OrganisationUnit> children = new ArrayList<OrganisationUnit>( parent.getChildren() );
 
-        Collections.sort( children, new OrganisationUnitNameComparator() );
+        Collections.sort( children, organisationUnitComparator );
 
         return children;
     }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/interceptor/OrganisationUnitTreeInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/interceptor/OrganisationUnitTreeInterceptor.java	2010-09-17 12:11:18 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/ouwt/interceptor/OrganisationUnitTreeInterceptor.java	2011-02-14 08:40:51 +0000
@@ -37,8 +37,8 @@
 import java.util.Set;
 
 import org.hisp.dhis.interceptor.AbstractPreResultListener;
+import org.hisp.dhis.options.sortorder.SortOrderManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.ouwt.manager.TreeStateManager;
 
@@ -71,7 +71,14 @@
     {
         this.treeStateManager = treeStateManager;
     }
+    
+    private SortOrderManager sortOrderManager;
 
+    public void setSortOrderManager( SortOrderManager sortOrderManager )
+    {
+        this.sortOrderManager = sortOrderManager;
+    }    
+   
     // -------------------------------------------------------------------------
     // PreResult implementation
     // -------------------------------------------------------------------------
@@ -111,7 +118,8 @@
         throws Exception
     {
         List<OrganisationUnit> childUnitsSorted = new ArrayList<OrganisationUnit>( childUnits );
-        Collections.sort( childUnitsSorted, new OrganisationUnitNameComparator() );
+      
+        Collections.sort( childUnitsSorted, sortOrderManager.getCurrentOrganisationUnitSortOrderComparator() );
 
         List<TreeNode> childNodes = new ArrayList<TreeNode>();
 

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-01-19 14:18:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2011-02-14 08:40:51 +0000
@@ -122,7 +122,9 @@
 		</property>
 		<property name="treeStateManager">
 			<ref local="org.hisp.dhis.ouwt.manager.TreeStateManager" />
-		</property>		
+		</property>
+		<property name="sortOrderManager"
+			ref="org.hisp.dhis.options.sortorder.SortOrderManager" />
 	</bean>
 
 	<bean id="org.hisp.dhis.ouwt.action.ExpandSubtreeAction" class="org.hisp.dhis.ouwt.action.ExpandSubtreeAction"

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateCustomSortAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateCustomSortAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/UpdateCustomSortAction.java	2011-02-14 08:40:51 +0000
@@ -0,0 +1,81 @@
+package org.hisp.dhis.oum.action.organisationunit;
+
+/*
+ * Copyright (c) 2004-2010, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Tran Thanh Tri
+ * @version $Id: UpdateCustomSortAction 2011-02-14
+ */
+public class UpdateCustomSortAction
+    implements Action
+{
+    // -------------------------------------------------------------------------
+    // Dependencies
+    // -------------------------------------------------------------------------
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    // -------------------------------------------------------------------------
+    // Input
+    // -------------------------------------------------------------------------
+
+    private List<Integer> selectedList = new ArrayList<Integer>();
+
+    public void setSelectedList( List<Integer> selectedList )
+    {
+        this.selectedList = selectedList;
+    }
+
+    @Override
+    public String execute()
+        throws Exception
+    {
+        for ( int i = 0; i < selectedList.size(); i++ )
+        {
+            OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( selectedList.get( i ) );
+            organisationUnit.setSortOrder( i );
+
+            organisationUnitService.updateOrganisationUnit( organisationUnit );
+        }
+        return SUCCESS;
+    }
+
+}

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2010-12-13 17:03:08 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2011-02-14 08:40:51 +0000
@@ -95,6 +95,17 @@
 		class="org.hisp.dhis.oum.action.organisationunit.PrepareAddOrganisationUnitAction"
 		scope="prototype">
 	</bean>
+	
+	<bean
+		id="org.hisp.dhis.oum.action.organisationunit.UpdateCustomSortAction"
+		class="org.hisp.dhis.oum.action.organisationunit.UpdateCustomSortAction"
+		scope="prototype">
+		<property name="organisationUnitService">
+			<ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		</property>
+	</bean>
+	
+	
 
 	<!-- OrganisationUnitGroup -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-01-19 11:18:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties	2011-02-14 08:40:51 +0000
@@ -108,4 +108,5 @@
 found												= Found
 all													= All
 please_select_from_tree								= Please select from tree (optional)
-feature_type										= Feature type
\ No newline at end of file
+feature_type										= Feature type
+sort_order											= Sort Order
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module_vi_VN.properties	2010-12-09 06:15:40 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module_vi_VN.properties	2011-02-14 08:40:51 +0000
@@ -68,4 +68,5 @@
 closed_date_cannot_be_before_opening_date=Ng\u00e0y \u0111\u00f3ng kh\u00f4ng th\u1ec3 tr\u01b0\u1edbc ng\u00e0y m\u1edf
 adding_the_org_unit_group_failed=Th\u00eam m\u1edbi \u0111\u01a1n v\u1ecb kh\u00f4ng th\u00e0nh c\u00f4ng v\u1edbi l\u1ed7i sau
 an_org_unit_cannot_be_moved_to_be_its_own_child=M\u1ed9t \u0111\u01a1n v\u1ecb kh\u00f4ng th\u1ec3 di chuy\u1ec3n \u0111\u1ebfn con c\u1ee7a ch\u00ednh n\u00f3. Xin ch\u1ecdn m\u1ed9t \u0111\u01a1n v\u1ecb cha m\u1edbi
-saving_the_org_unit_failed=L\u01b0u \u0111\u01a1n v\u1ecb kh\u00f4ng th\u00e0nh c\u00f4ng v\u1edbi l\u1ed7i sau
\ No newline at end of file
+saving_the_org_unit_failed=L\u01b0u \u0111\u01a1n v\u1ecb kh\u00f4ng th\u00e0nh c\u00f4ng v\u1edbi l\u1ed7i sau
+sort_order=S\u1eafp x\u1ebfp
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2010-12-28 17:49:37 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2011-02-14 08:40:51 +0000
@@ -93,6 +93,24 @@
 			<param name="onExceptionReturn">plainTextError</param>
 			<param name="requiredAuthorities">F_ORGANISATIONUNIT_DELETE</param>
 		</action>
+		
+		<action name="organisationUnitCustomSort"
+			class="org.hisp.dhis.oum.action.organisationunit.GetOrganisationUnitListAction">
+			<result name="success" type="velocity">/main.vm</result>
+			<param name="page">/dhis-web-maintenance-organisationunit/organisationUnitCustomSort.vm</param>
+			<param name="menu">/dhis-web-maintenance-organisationunit/menuWithTree.vm</param>
+			<param name="menuTreeHeight">328</param>
+			<param name="javascripts">
+					../dhis-web-commons/ouwt/ouwt.js					
+			</param>			
+			<interceptor-ref name="organisationUnitTreeStack" />
+		</action>
+		
+		<action name="updateCustomSort"
+			class="org.hisp.dhis.oum.action.organisationunit.UpdateCustomSortAction">
+			<result name="success" type="redirect">organisationUnit.action</result>			
+		</action>
+		
 
 		<!-- OrganisationUnitGroup -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm	2011-01-20 15:03:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm	2011-02-14 08:40:51 +0000
@@ -7,7 +7,10 @@
 			<table width="100%">
 				<tr>
 					<td>#filterDiv( "organisationUnit" )</td>
-					<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddOrganisationUnitForm.action'"/></td>
+					<td colspan="3" style="text-align:right">
+						<input type="button" value="$i18n.getString( 'sort_order' )" onclick="window.location.href='organisationUnitCustomSort.action'"/>
+						<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddOrganisationUnitForm.action'"/>
+					</td>
 				</tr>
 			</table>
 			<table class="listTable" id="listTable">
@@ -79,6 +82,6 @@
 	var no = '$encoder.jsEscape( $i18n.getString( "no" ) , "'" )';
 	var confirm_to_delete_org_unit = '$encoder.jsEscape( $i18n.getString( "confirm_to_delete_org_unit" ) , "'" )';
 	jQuery(document).ready(function(){	
-		tableSorter( 'listTable' );	
+		//tableSorter( 'listTable' );	
 	});
 </script>
\ No newline at end of file

=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitCustomSort.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitCustomSort.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitCustomSort.vm	2011-02-14 08:40:51 +0000
@@ -0,0 +1,36 @@
+<h3>$i18n.getString( "sort_order" )</h3>
+
+<form id="organisationUnitSort" action="updateCustomSort.action" method="POST" onsubmit="selectAllById('selectedList')">
+<p>
+	<input type="button" value="$i18n.getString( 'move_up' )" style="width:130px" onclick="moveUpSelectedOption( 'selectedList' )"/><input 
+	type="button" value="$i18n.getString( 'move_down' )" style="width:130px" onclick="moveDownSelectedOption( 'selectedList' )"/><input
+	type="button" value="$i18n.getString( 'move_to_top' )" style="width:130px" onclick="moveSelectedOptionToTop( 'selectedList' )"/><input
+	type="button" value="$i18n.getString( 'move_to_bottom' )" style="width:130px" onclick="moveSelectedOptionToBottom( 'selectedList' )"/>
+</p>
+<p>
+	<select size="25" id="selectedList" name="selectedList" multiple="multiple" size="25" style="width:680px">
+	#foreach( $organisationUnit in $organisationUnits )
+		<option value="$organisationUnit.id">$encoder.htmlEncode( $organisationUnit.name )</option>				
+	#end
+	</select>
+</p>
+<p>
+	<input type="submit" value="$i18n.getString( 'save' )" style="width:100px"/>
+	<input type="button" value="$i18n.getString( 'cancel' )" style="width:100px" onclick="window.location.href='organisationUnit.action'"/>
+</p>
+</form>
+
+<script>
+
+// -----------------------------------------------------------------------------
+// Organisation unit selection listener
+// -----------------------------------------------------------------------------
+
+function organisationUnitSelected( orgUnitIds )
+{
+    window.location.href = 'organisationUnitCustomSort.action';
+}
+
+selection.setListenerFunction( organisationUnitSelected );
+</script>
+