Search in sources :

Example 1 with LockComparator

use of org.olat.core.commons.modules.bc.meta.tagged.LockComparator in project OpenOLAT by OpenOLAT.

the class FolderComponent method sort.

/**
 * Sorts the bc folder components table
 *
 * @param col The column to sort
 */
private void sort(String col) {
    currentSortOrder = col;
    if (col.equals(SORT_NAME)) {
        // sort after file name?
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (sortAsc) {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o1.getName(), o2.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                } else {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o2.getName(), o1.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                }
            }
        };
    } else if (col.equals(SORT_DATE)) {
        // sort after modification date (if same, then name)
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (o1.getLastModified() < o2.getLastModified())
                    return ((sortAsc) ? -1 : 1);
                else if (o1.getLastModified() > o2.getLastModified())
                    return ((sortAsc) ? 1 : -1);
                else {
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                }
            }
        };
    } else if (col.equals(SORT_SIZE)) {
        // sort after file size, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                VFSLeaf leaf1 = null;
                if (o1 instanceof VFSLeaf) {
                    leaf1 = (VFSLeaf) o1;
                }
                VFSLeaf leaf2 = null;
                if (o2 instanceof VFSLeaf) {
                    leaf2 = (VFSLeaf) o2;
                }
                if (// folders are always smaller
                leaf1 == null && leaf2 != null)
                    // folders are always smaller
                    return -1;
                else if (// folders are always smaller
                leaf1 != null && leaf2 == null)
                    // folders are always smaller
                    return 1;
                else if (// if two folders, sort after name
                leaf1 == null && leaf2 == null)
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                else // if two leafes, sort after size
                if (sortAsc)
                    return ((leaf1.getSize() < leaf2.getSize()) ? -1 : 1);
                else
                    return ((leaf1.getSize() < leaf2.getSize()) ? 1 : -1);
            }
        };
    } else if (col.equals(SORT_REV)) {
        // sort after revision number, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                Versionable v1 = null;
                Versionable v2 = null;
                if (o1 instanceof Versionable) {
                    v1 = (Versionable) o1;
                }
                if (o2 instanceof Versionable) {
                    v2 = (Versionable) o2;
                }
                if (v1 == null) {
                    return -1;
                } else if (v2 == null) {
                    return 1;
                }
                String r1 = v1.getVersions().getRevisionNr();
                String r2 = v2.getVersions().getRevisionNr();
                if (r1 == null) {
                    return -1;
                } else if (r2 == null) {
                    return 1;
                }
                return (sortAsc) ? collator.compare(r1, r2) : collator.compare(r2, r1);
            }
        };
    } else if (col.equals(SORT_LOCK)) {
        // sort after modification date (if same, then name)
        comparator = new LockComparator(sortAsc, collator);
    }
    // if not empty the update list
    if (currentContainerChildren != null)
        updateChildren();
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) Comparator(java.util.Comparator)

Example 2 with LockComparator

use of org.olat.core.commons.modules.bc.meta.tagged.LockComparator in project openolat by klemens.

the class FolderComponent method sort.

/**
 * Sorts the bc folder components table
 *
 * @param col The column to sort
 */
private void sort(String col) {
    currentSortOrder = col;
    if (col.equals(SORT_NAME)) {
        // sort after file name?
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (sortAsc) {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o1.getName(), o2.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                } else {
                    if ((o1 instanceof VFSLeaf && o2 instanceof VFSLeaf) || (!(o1 instanceof VFSLeaf) && !(o2 instanceof VFSLeaf))) {
                        return collator.compare(o2.getName(), o1.getName());
                    } else {
                        if (!(o1 instanceof VFSLeaf)) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                }
            }
        };
    } else if (col.equals(SORT_DATE)) {
        // sort after modification date (if same, then name)
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                if (o1.getLastModified() < o2.getLastModified())
                    return ((sortAsc) ? -1 : 1);
                else if (o1.getLastModified() > o2.getLastModified())
                    return ((sortAsc) ? 1 : -1);
                else {
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                }
            }
        };
    } else if (col.equals(SORT_SIZE)) {
        // sort after file size, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                VFSLeaf leaf1 = null;
                if (o1 instanceof VFSLeaf) {
                    leaf1 = (VFSLeaf) o1;
                }
                VFSLeaf leaf2 = null;
                if (o2 instanceof VFSLeaf) {
                    leaf2 = (VFSLeaf) o2;
                }
                if (// folders are always smaller
                leaf1 == null && leaf2 != null)
                    // folders are always smaller
                    return -1;
                else if (// folders are always smaller
                leaf1 != null && leaf2 == null)
                    // folders are always smaller
                    return 1;
                else if (// if two folders, sort after name
                leaf1 == null && leaf2 == null)
                    if (sortAsc)
                        return collator.compare(o1.getName(), o2.getName());
                    else
                        return collator.compare(o2.getName(), o1.getName());
                else // if two leafes, sort after size
                if (sortAsc)
                    return ((leaf1.getSize() < leaf2.getSize()) ? -1 : 1);
                else
                    return ((leaf1.getSize() < leaf2.getSize()) ? 1 : -1);
            }
        };
    } else if (col.equals(SORT_REV)) {
        // sort after revision number, folders always on top
        comparator = new Comparator<VFSItem>() {

            @Override
            public int compare(VFSItem o1, VFSItem o2) {
                Versionable v1 = null;
                Versionable v2 = null;
                if (o1 instanceof Versionable) {
                    v1 = (Versionable) o1;
                }
                if (o2 instanceof Versionable) {
                    v2 = (Versionable) o2;
                }
                if (v1 == null) {
                    return -1;
                } else if (v2 == null) {
                    return 1;
                }
                String r1 = v1.getVersions().getRevisionNr();
                String r2 = v2.getVersions().getRevisionNr();
                if (r1 == null) {
                    return -1;
                } else if (r2 == null) {
                    return 1;
                }
                return (sortAsc) ? collator.compare(r1, r2) : collator.compare(r2, r1);
            }
        };
    } else if (col.equals(SORT_LOCK)) {
        // sort after modification date (if same, then name)
        comparator = new LockComparator(sortAsc, collator);
    }
    // if not empty the update list
    if (currentContainerChildren != null)
        updateChildren();
}
Also used : Versionable(org.olat.core.util.vfs.version.Versionable) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) LockComparator(org.olat.core.commons.modules.bc.meta.tagged.LockComparator) Comparator(java.util.Comparator)

Aggregations

Comparator (java.util.Comparator)2 LockComparator (org.olat.core.commons.modules.bc.meta.tagged.LockComparator)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 Versionable (org.olat.core.util.vfs.version.Versionable)2