From: <mb...@re...> - 2005-02-09 14:08:02
|
Author: mbooth Date: 2005-02-09 15:07:10 +0100 (Wed, 09 Feb 2005) New Revision: 202 Modified: ccm-cms/trunk/src/com/arsdigita/cms/ui/ItemSearchBrowsePane.java Log: Add the ability to browse and select other content sections in the item search popup. Modified: ccm-cms/trunk/src/com/arsdigita/cms/ui/ItemSearchBrowsePane.java =================================================================== --- ccm-cms/trunk/src/com/arsdigita/cms/ui/ItemSearchBrowsePane.java 2005-02-07 22:45:34 UTC (rev 201) +++ ccm-cms/trunk/src/com/arsdigita/cms/ui/ItemSearchBrowsePane.java 2005-02-09 14:07:10 UTC (rev 202) @@ -18,25 +18,41 @@ */ package com.arsdigita.cms.ui; +import com.arsdigita.bebop.BoxPanel; +import com.arsdigita.bebop.Form; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Page; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.Resettable; +import com.arsdigita.bebop.Tree; import com.arsdigita.bebop.event.ChangeEvent; import com.arsdigita.bebop.event.ChangeListener; +import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.TreeExpansionEvent; import com.arsdigita.bebop.event.TreeExpansionListener; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.SingleSelect; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.OID; +import com.arsdigita.toolbox.ui.OIDParameter; + +import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ContentSectionCollection; import com.arsdigita.cms.Folder; import com.arsdigita.cms.ui.CMSContainer; import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import com.arsdigita.cms.ui.folder.FolderTree; +import com.arsdigita.cms.ui.folder.FolderTreeModelBuilder; import com.arsdigita.cms.util.GlobalizationUtil; import java.math.BigDecimal; +import org.apache.log4j.Logger; + /** * A pane that contains a folder tree on the left and a folder * manipulator on the right. @@ -48,11 +64,15 @@ implements Resettable, TreeExpansionListener, ChangeListener, FormProcessListener, FormSubmissionListener { + private static final Logger s_log = + Logger.getLogger( ItemSearchBrowsePane.class ); + public static final String versionId = "$Id: //cms/dev/src/com/arsdigita/cms/ui/ItemSearchBrowsePane.java#9 $ by $Author: dennis $, $DateTime: 2004/08/17 23:15:09 $"; - FolderSelectionModel m_folderSel; - FolderTree m_tree; - ItemSearchFolderBrowser m_browser; + private FolderSelectionModel m_folderSel; + private Tree m_tree; + private ItemSearchFolderBrowser m_browser; + private SingleSelect m_section; public ItemSearchBrowsePane() { setClassAttr("sidebarNavPanel"); @@ -62,10 +82,28 @@ l.setClassAttr("heading"); add(l); - m_folderSel = new FolderSelectionModel("folder"); + m_folderSel = new FolderSelectionModel("folder") { + protected BigDecimal getRootFolderID( PageState ps ) { + Folder root = getRootFolder( ps ); + + if( null == root ) return super.getRootFolderID( ps ); + return root.getID(); + } + }; m_folderSel.addChangeListener(this); - m_tree = new FolderTree(m_folderSel); + Form sectionForm = getSectionForm(); + add( sectionForm ); + + m_tree = new Tree( new FolderTreeModelBuilder() { + protected Folder getRoot( PageState ps ) { + Folder root = getRootFolder( ps ); + + if( null == root ) return super.getRoot( ps ); + return root; + } + } ); + m_tree.setSelectionModel( m_folderSel ); m_tree.setClassAttr("navbar"); m_tree.addTreeExpansionListener(this); add(m_tree); @@ -80,9 +118,57 @@ add( container ); } + private Form getSectionForm() { + Form sectionForm = new Form( "isfbSectionForm", + new BoxPanel( BoxPanel.HORIZONTAL ) ); + sectionForm.setClassAttr("navbar"); + + m_section = new SingleSelect( new OIDParameter( "isfbSection" ) ); + ContentSectionCollection sections = ContentSection.getAllSections(); + while( sections.next() ) { + ContentSection section = sections.getContentSection(); + m_section.addOption( new Option( section.getOID().toString(), + section.getDisplayName() ) ); + } + + sectionForm.addInitListener( new FormInitListener() { + public void init( FormSectionEvent ev ) { + PageState ps = ev.getPageState(); + + if( null == m_section.getValue( ps ) ) { + ContentSection section = CMS.getContext().getContentSection(); + m_section.setValue( ps, section.getOID() ); + } + } + } ); + + sectionForm.add( m_section ); + sectionForm.add( new Submit( "Change Section" ) ); + + return sectionForm; + } + + private Folder getRootFolder( PageState ps ) { + OID sectionOID = (OID) m_section.getValue( ps ); + if( s_log.isDebugEnabled() ) { + if( null != sectionOID ) + s_log.debug( "Using section " + sectionOID.toString() ); + else + s_log.debug( "Using default section" ); + } + + if( null == sectionOID ) return null; + + ContentSection section = (ContentSection) + DomainObjectFactory.newInstance( sectionOID ); + + return section.getRootFolder(); + } + public void register(Page p) { super.register(p); p.addComponentStateParam(this, m_folderSel.getStateParameter()); + p.addComponentStateParam(this, m_section.getParameterModel()); } public void reset(PageState s) { |