[opencms-dev] Order of the files in the Workplace

maria.freixes_graells at alcatel.es maria.freixes_graells at alcatel.es
Thu Aug 17 12:32:34 CEST 2006


Thanks very much Federico!!! I'll try to implement something similar, 
I'll keep informed.
Have a nice day and the best wishes,
Maria

Federico Larumbe wrote:
> Hello Maria.
>
> I developed a quick solution for the issue we had here. We needed to order
> files by "Last Modified Time".
>
> To do this, I have added a Resources comparator first:
>
> --------------------- org.opencms.file.CmsResource  ----------------------
>    /**
>      * A comparator for 2 resources. First the folders, alphabetically by
> name ignoring case differences. Then, files by dateLastModified.
>      * If two files have the same dateLastModified, compare by name.<p>
>      */
>     public static final Comparator
> COMPARE_DATE_MODIFIED_FOLDERS_FIRST_ALPHABETICALLY = new Comparator() {
>
>         /**
>          * @see java.util.Comparator#compare(java.lang.Object,
> java.lang.Object)
>          */
>         public int compare(Object o1, Object o2) {
>
>             if ((o1 == o2) || !(o1 instanceof CmsResource) || !(o2
> instanceof CmsResource)) {
>                 return 0;
>             }
>
>             CmsResource r1 = (CmsResource)o1;
>             CmsResource r2 = (CmsResource)o2;
>
>             if (r1.isFolder() && !r2.isFolder()) {
>                 return -1;
>             } else if (r2.isFolder() && !r1.isFolder()) {
>                 return 1;
>             }
>             if(r1.isFolder() && r2.isFolder()) {
>             	// if they are folders, compare the name of the resource
>             	return
> r1.getRootPath().compareToIgnoreCase(r2.getRootPath());
>             }
>             else {
>             	long date1 = r1.getDateLastModified();
>                 long date2 = r2.getDateLastModified();
>
>                 return (date1 < date2) ? -1 : 
>                 		(date1 > date2) ? 1 : 
>  
> r1.getRootPath().compareToIgnoreCase(r2.getRootPath());
>             }
>         }
>     };
> ------------------------------------------------------------------------
>
>
> Then I change VFS Driver to use this Comparator to sort files:
>
> ------------------------------------------------------------------------
> org.opencms.db.generic.CmsVfsDriver. Method readChildResources(...).
> I replaced line previous to "return result;" to:
> ------------------------------------------------------------------------
> Collections.sort(result,
> CmsResource.COMPARE_DATE_MODIFIED_FOLDERS_FIRST_ALPHABETICALLY);
>
>
> Regards,
> Federico.
>
> ------------------------------------------------------------------------
> -----Original Message-----
> From: opencms-dev-bounces at opencms.org
> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of
> maria.freixes_graells at alcatel.es
> Sent: Wednesday, August 16, 2006 7:45 AM
> To: The OpenCms mailing list
> Subject: Re: [opencms-dev] Order of the files in the Workplace
>
> Hello everybody!!
>
> Has anyone implemented in their workplace the feature of sorting the 
> files and folders in the workplace clicking to the titles?
> Something similar will be very usefully for me.
> Thanks in advance and have a nice day!!
>
> Maria
>
> maria.freixes_graells at alcatel.es wrote:
>   
>> Hello people!!
>>
>> One question:
>>
>> In the workplace, the files are listed in alphabetical order, is there 
>> anyway to fix another order?
>>
>> Thanks!!
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please 
>> visit
>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>>     
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
>   



More information about the opencms-dev mailing list