AW: [opencms-dev] Sort in Explorer View (Workaround)
Nick Panienski
panienski at codecentric.de
Tue Apr 19 09:01:25 CEST 2005
Thanks for all the hints, I also suggest a feature for a later version where
you can change Prefs -> Explorer -> Sort (Alpha/Navi) or something.
> -----Ursprüngliche Nachricht-----
> Von: opencms-dev-bounces at opencms.org [mailto:opencms-dev-
> bounces at opencms.org] Im Auftrag von Stefano Suzzi
> Gesendet: Montag, 18. April 2005 10:57
> An: 'The OpenCms mailing list'
> Betreff: R: [opencms-dev] Sort in Explorer View (Workaround)
>
> Hi, I had the same problem and i've solved by creating in my module, a new
> class navEleSortNavText extending the CmsJspNavElement class and changing
> the compareTo method used in the sort method of a Collection and adding
> the
> contructor.
> Then in another class I've cut and paste the src of three methods
> getSiteNavigation getNavigationForFolder getNavigationForResource
> and changed the name (added NavText ) and the code to create a list of the
> new navEleSortNavText class.
> So now when I call getNavigationForFolderNavText(...) I get the tree
> ordered
> by NavText, if you change the compareTo method you can sort as you like.
>
> Hope it helps.
> Ciao.
> Stefano.
>
> Here the code of the new class e the three methods.
>
> /*
> * Created on 12-apr-2005
> *
> */
> package protesa.it.kbm;
>
> import org.opencms.jsp.CmsJspNavElement;
> import java.util.*;
> /**
> * @author s.suzzi protesa srl (www.protesa.it)
> *
> */
> public class navEleSortNavText extends CmsJspNavElement{
>
>
> /**
> * Create a new instance of the bean and calls the init method
> * with the provided parametes.<p>
> *
> * @param resource will be passed to <code>init</code>
> * @param properties will be passed to <code>init</code>
> * @param navTreeLevel will be passed to <code>init</code>
> *
> * @see #init(String, Map, int)
> */
> public navEleSortNavText(String resource, Map properties, int
> navTreeLevel) {
>
> init(resource, properties, navTreeLevel);
> }
>
>
> /**
> * @see java.lang.Comparable#compareTo(Object)
> */
> public int compareTo(Object o) {
>
> if (o == null) {
> return 0;
> }
> if (!(o instanceof navEleSortNavText)) {
> return 0;
> }
> navEleSortNavText ne = (navEleSortNavText)o;
> return this.getNavText().toLowerCase().compareTo(
> ne.getNavText().toLowerCase() ) ;
>
> }
> }
>
> --------------------------------
>
> // ricavo il nav tree ordinato per nav text.
> /**
> * This method builds a complete navigation tree with entries of all
> branches
> * from the specified folder.<p>
> *
> * For an unlimited depth of the navigation (i.e. no endLevel), set
> the
> endLevel to
> * a value < 0.<p>
> *
> *
> * @param cms the current CmsJspActionElement.
> * @param folder the root folder of the navigation tree.
> * @param endLevel the end level of the navigation.
> * @return ArrayList of CmsJspNavElement, in depth first order.
> */
> public List getSiteNavigationNavText(CmsObject cms, String folder, int
> endLevel) {
>
> // check if a specific end level was given, if not, build the
> complete navigation
> boolean noLimit = false;
> if (endLevel < 0) {
> noLimit = true;
> }
> ArrayList list = new ArrayList();
> // get the navigation for this folder SORTED BY NAVTEXT
> List curnav = getNavigationForFolderNavText(cms, folder);
> // loop through all nav entrys
> for (int i = 0; i < curnav.size(); i++) {
> CmsJspNavElement ne = (CmsJspNavElement)curnav.get(i);
> // add the naventry to the result list
> list.add(ne);
> // check if naventry is a folder and below the max level -> if
> so, get the navigation from this folder as well
> if (ne.isFolderLink() && (noLimit || (ne.getNavTreeLevel() <
> endLevel))) {
> List subnav = getSiteNavigationNavText(cms,
> ne.getResourceName(), endLevel);
> // copy the result of the subfolder to the result list
> list.addAll(subnav);
> }
> }
> return list;
> }
>
> /**
> * Collect all navigation elements from the files in the given folder,
> * navigation elements are of class CmsJspNavElement.<p>
> *
> * @param cms context provider for the current request
> * @param folder the selected folder
> * @return a sorted (ascending to nav position) ArrayList of
> navigation
> elements
> */
> public List getNavigationForFolderNavText(CmsObject cms, String
> folder)
> {
>
> folder = CmsResource.getFolderPath(folder);
> List result = new ArrayList();
>
> List resources;
> try {
> resources = cms.getResourcesInFolder(folder,
> CmsResourceFilter.DEFAULT);
> } catch (Exception e) {
> return Collections.EMPTY_LIST;
> }
>
> for (int i = 0; i < resources.size(); i++) {
> CmsResource r = (CmsResource)resources.get(i);
> navEleSortNavText element =
> getNavigationForResourceNavText(cms,
> cms.getSitePath(r));
> if ((element != null) && element.isInNavigation()) {
> result.add(element);
> }
> }
> Collections.sort(result);
> return result;
> }
>
> /**
> * Returns a CmsJspNavElement for the named resource.<p>
> *
> * @param cms context provider for the current request
> * @param resource the resource name to get the nav information for,
> * must be a full path name, e.g. "/docs/index.html".
> * @return a CmsJspNavElement for the given resource
> */
>
> public navEleSortNavText getNavigationForResourceNavText(CmsObject
> cms,
> String resource) {
>
> List properties;
> try {
> properties = cms.readPropertyObjects(resource, false);
> } catch (Exception e) {
> return null;
> }
> int level = CmsResource.getPathLevel(resource);
> if (resource.endsWith("/")) {
> level--;
> }
> return new navEleSortNavText(resource,
> CmsProperty.toMap(properties), level);
> }
>
>
>
>
> -----Messaggio originale-----
> Da: Claus Priisholm [mailto:cpr at codedroids.com]
> Inviato: domenica 17 aprile 2005 9.55
> A: The OpenCms mailing list
> Oggetto: Re: [opencms-dev] Sort in Explorer View
>
> Well, maybe that is what he is concerned about... And thusly he wants
> to know about the order just by looking at the order of contents of the
> folder. I've heard a similar request and ideally one should have the
> option to switch between standard (alphabetically) and NavPos-based
> ordering of the listing or maybe even some sort of generic
> ordering-function applicable to all display columns. Maybe something
> for 6.1...
>
> Luckily, the workarounds are not that bad, i.e. click on a file in the
> folder and look at the resulting page, or lock a file and use the
> "change navigation" to inspect the ordering. Most users can come to
> terms with either of these "hacks".
>
>
> On 15/4-2005, at 13.22, Oliver Pereira wrote:
>
> > I think that will mean changing the opencms code and why does the
> > customer want to do that???
> >
> > He should be more concerned about what is displayed on the final
> > website.. :-)
> >
> > -----Original Message-----
> > From: opencms-dev-bounces at opencms.org
> > [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Nick Panienski
> > Sent: 15 April 2005 12:18
> > To: 'The OpenCms mailing list'
> > Subject: AW: [opencms-dev] Sort in Explorer View
> >
> >> Set the NavPos property accordingly
> > The NavPos is fine, in the Navigation we see C A B, but the costumer
> > also wants the corresponding dirs in the Explorer view to be C A B
> > rather then alphabetically A B C.
> >
> >> -----Original Message-----
> >> From: opencms-dev-bounces at opencms.org
> >> [mailto:opencms-dev-bounces at opencms.org] On Behalf Of Nick Panienski
> >> Sent: 15 April 2005 12:04
> >> To: opencms-dev at opencms.org
> >> Subject: [opencms-dev] Sort in Explorer View
> >>
> >> Hi, a costumer recently wanted me to change the alphabetical order in
> >> the explorer view to resemble the site navigation order.
> >>
> >> A (NavPos2)
> >> B (NavPos3)
> >> C (NavPos1)
> >>
> >> To be
> >>
> >> C
> >> A
> >> B
> >>
> >> Is there any way to achieve this?
> >>
> >> Regards
> >> Nick
> >>
> >>
> >>
> >> _______________________________________________
> >> This mail is send to you from the opencms-dev mailing list To change
> >> your list options, or to unsubscribe from the list, please visit
> >> http://mail.opencms.org/mailman/listinfo/opencms-dev
> >>
> >> _____________________________________________________________________
> >> This e-mail has been scanned for viruses by MCI's Internet Managed
> >> Scanning Services - powered by MessageLabs. For further information
> >> visit http://www.mci.com
> >>
> >>
> >> _______________________________________________
> >> This mail is send to you from the opencms-dev mailing list To change
> >> your list options, or to unsubscribe from the list, please visit
> >> http://mail.opencms.org/mailman/listinfo/opencms-dev
> >
> >
> >
> > _______________________________________________
> > This mail is send to you from the opencms-dev mailing list To change
> > your list options, or to unsubscribe from the list, please visit
> > http://mail.opencms.org/mailman/listinfo/opencms-dev
> >
> > _____________________________________________________________________
> > This e-mail has been scanned for viruses by MCI's Internet Managed
> > Scanning Services - powered by MessageLabs. For further information
> > visit http://www.mci.com
> >
> >
> > _______________________________________________
> > This mail is send to you from the opencms-dev mailing list
> > To change your list options, or to unsubscribe from the list, please
> > visit
> > http://mail.opencms.org/mailman/listinfo/opencms-dev
> >
> >
> --
> Claus Priisholm, CodeDroids ApS
> +45 48 22 46 46
> email: cpr (you-know-what) interlet.dk - cpr (you-know-what)
> codedroids.com
> skype: claus_priisholm
> http://www.interlet.dk - http://www.codedroids.com
>
>
>
>
> _______________________________________________
> This mail is send to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://mail.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list