Skip to content
Snippets Groups Projects
Commit 8f92faae authored by srosse's avatar srosse
Browse files

OO-529: implement sorting for groups in the member view

parent 92ab6806
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
*/
package org.olat.group.ui.main;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
......@@ -125,6 +126,7 @@ public abstract class AbstractMemberListController extends BasicController imple
private final BusinessGroupModule groupModule;
private final ACService acService;
private final GroupMemberViewComparator memberViewComparator;
private static final CourseMembershipComparator MEMBERSHIP_COMPARATOR = new CourseMembershipComparator();
public AbstractMemberListController(UserRequest ureq, WindowControl wControl, RepositoryEntry repoEntry, String page) {
......@@ -148,6 +150,8 @@ public abstract class AbstractMemberListController extends BasicController imple
businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
groupModule = CoreSpringFactory.getImpl(BusinessGroupModule.class);
acService = CoreSpringFactory.getImpl(ACService.class);
memberViewComparator = new GroupMemberViewComparator(Collator.getInstance(getLocale()));
isAdministrativeUser = securityModule.isUserAllowedAdminProps(ureq.getUserSession().getRoles());
mainVC = createVelocityContainer(page);
......@@ -202,14 +206,23 @@ public abstract class AbstractMemberListController extends BasicController imple
Object b = table.getTableDataModel().getValueAt(rowb,dataColumn);
if(a instanceof CourseMembership && b instanceof CourseMembership) {
return MEMBERSHIP_COMPARATOR.compare((CourseMembership)a, (CourseMembership)b);
} else {
return super.compareTo(rowa, rowb);
}
return super.compareTo(rowa, rowb);
}
});
if(repoEntry != null) {
CustomCellRenderer groupRenderer = new GroupCellRenderer();
memberListCtr.addColumnDescriptor(new CustomRenderColumnDescriptor(Cols.groups.i18n(), Cols.groups.ordinal(), null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, groupRenderer));
memberListCtr.addColumnDescriptor(new CustomRenderColumnDescriptor(Cols.groups.i18n(), Cols.groups.ordinal(), null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, groupRenderer) {
@Override
public int compareTo(final int rowa, final int rowb) {
Object a = table.getTableDataModel().getValueAt(rowa,dataColumn);
Object b = table.getTableDataModel().getValueAt(rowb,dataColumn);
if(a instanceof MemberView && b instanceof MemberView) {
return memberViewComparator.compare((MemberView)a, (MemberView)b);
}
return super.compareTo(rowa, rowb);
}
});
}
memberListCtr.addColumnDescriptor(new GraduateColumnDescriptor("table.header.graduate", TABLE_ACTION_GRADUATE, getTranslator()));
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.group.ui.main;
import java.text.Collator;
import java.util.Comparator;
import java.util.List;
import org.olat.group.BusinessGroupShort;
/**
* Compare the groups of member views based on the group name.<br/>
*
* Initial date: 04.02.2013<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class GroupMemberViewComparator implements Comparator<MemberView> {
private Collator collator;
public GroupMemberViewComparator(Collator collator) {
this.collator = collator;
}
@Override
public int compare(MemberView m1, MemberView m2) {
List<BusinessGroupShort> g1 = m1.getGroups();
List<BusinessGroupShort> g2 = m2.getGroups();
if(g1 == null || g1.isEmpty()) {
if(g2 == null || g2.isEmpty()) return 0;
return -1;
}
if(g2 == null || g2.isEmpty()) return 1;
int maxLevel = Math.max(g1.size(), g2.size());
int compare = 0;
for(int i=0; i<maxLevel && compare==0; i++) {
BusinessGroupShort gs1 = i < g1.size() ? g1.get(i) : null;
BusinessGroupShort gs2 = i < g2.size() ? g2.get(i) : null;
compare = compareLevel(gs1, gs2);
}
return compare;
}
private int compareLevel(BusinessGroupShort g1, BusinessGroupShort g2) {
if(g1 == null) {
if(g2 == null) return 0;
return -1;
}
if(g2 == null) return 1;
String n1 = g1.getName();
String n2 = g2.getName();
if(n1 == null) {
if(n2 == null) return 0;
return -1;
}
if(n2 == null) return 1;
return collator == null ? n1.compareTo(n2) : collator.compare(n1, n2);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment