diff --git a/ccm-cms/src/com/arsdigita/cms/ui/SortableList.java b/ccm-cms/src/com/arsdigita/cms/ui/SortableList.java index 3589120f3..2d8bb4cdf 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/SortableList.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/SortableList.java @@ -31,49 +31,48 @@ import com.arsdigita.util.Assert; import com.arsdigita.xml.Element; import java.io.IOException; - /** - * This list offers the option for the code to provide the developer - * with links to sort the given categories. + * This list offers the option for the code to provide the developer with links + * to sort the given categories. * - * NOTE: This UI currently does not scale well with large numbers of items - * since it just lists all of them. It would probably be nice to integrate - * a paginator as well to as to allow the user to move an item in large - * distances and to insert an item in the middle. Right now, when you add - * an item it is just placed at the end. However, if you want the item to - * appear in the middle then you must hit the "up" arrow n/2 times where - * n is the number of items in the list. This clearly is not a good setup. + * NOTE: This UI currently does not scale well with large numbers of items since + * it just lists all of them. It would probably be nice to integrate a paginator + * as well to as to allow the user to move an item in large distances and to + * insert an item in the middle. Right now, when you add an item it is just + * placed at the end. However, if you want the item to appear in the middle then + * you must hit the "up" arrow n/2 times where n is the number of items in the + * list. This clearly is not a good setup. * * @author Randy Graebner (randyg@alum.mit.edu) * @version $Id: SortableList.java 1618 2007-09-13 12:14:51Z chrisg23 $ */ public abstract class SortableList extends List { - private static final org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger(SortableList.class); + private static final org.apache.log4j.Logger s_log + = org.apache.log4j.Logger.getLogger(SortableList.class); // It would be really nice if this used the save variable as is // used by List but because List has it as private, we cannot do that. private static final String SELECT_EVENT = "s"; protected static final String PREV_EVENT = "prev"; protected static final String NEXT_EVENT = "next"; - private boolean m_sortItems; + public boolean m_sortItems; /** - * This just makes a standard - * {@link SortableList} + * This just makes a standard {@link SortableList} */ public SortableList(ParameterSingleSelectionModel model) { this(model, false); } - public SortableList(ParameterSingleSelectionModel model, boolean suppressSort) { - super(model); - m_sortItems = !suppressSort; - } + public SortableList(ParameterSingleSelectionModel model, boolean suppressSort) { + super(model); + m_sortItems = !suppressSort; + } + /** - * This geneates the XML as specified by the arguments pass in to - * the constructor. + * This geneates the XML as specified by the arguments pass in to the + * constructor. */ public void generateXML(PageState state, Element parent) { if (!isVisible(state)) { @@ -90,8 +89,7 @@ public abstract class SortableList extends List { // because m.next() returned true, we know there are items // in the list - Element list = parent.newChildElement - ("cms:sortableList", CMS.CMS_XML_NS); + Element list = parent.newChildElement("cms:sortableList", CMS.CMS_XML_NS); exportAttributes(list); Component c; @@ -99,26 +97,25 @@ public abstract class SortableList extends List { int i = 0; boolean hasNext; do { - Element item = list.newChildElement - (BebopConstants.BEBOP_CELL, BEBOP_XML_NS); - if (m_sortItems) { + Element item = list.newChildElement(BebopConstants.BEBOP_CELL, BEBOP_XML_NS); + if (m_sortItems) { - item.addAttribute("configure", "true"); - } + item.addAttribute("configure", "true"); + } String key = m.getKey(); Assert.exists(key); // Converting both keys to String for comparison // since ListModel.getKey returns a String - boolean selected = (selKey != null) && - key.equals(selKey.toString()); + boolean selected = (selKey != null) + && key.equals(selKey.toString()); - if ( selected ) { + if (selected) { item.addAttribute("selected", "selected"); } generateLabelXML(state, item, - new Label(m.getElement().toString()), key); + new Label(m.getElement().toString()), key, m.getElement()); hasNext = m.next(); @@ -138,17 +135,17 @@ public abstract class SortableList extends List { } } catch (IOException ex) { - throw new IllegalStateException("Caught IOException: " + - ex.getMessage()); + throw new IllegalStateException("Caught IOException: " + + ex.getMessage()); } i++; - } while (hasNext); + } while (hasNext); state.clearControlEvent(); } protected void generateLabelXML(PageState state, Element parent, - Label label, String key) { + Label label, String key, Object element) { state.setControlEvent(this, SELECT_EVENT, key); Component c = new ControlLink(label); c.generateXML(state, parent); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/category/CategorizedObjectsList.java b/ccm-cms/src/com/arsdigita/cms/ui/category/CategorizedObjectsList.java index c9cd22f4c..d8f136c71 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/category/CategorizedObjectsList.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/category/CategorizedObjectsList.java @@ -18,7 +18,9 @@ */ package com.arsdigita.cms.ui.category; +import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Link; import com.arsdigita.bebop.List; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.list.ListModel; @@ -26,11 +28,15 @@ import com.arsdigita.bebop.list.ListModelBuilder; import com.arsdigita.categorization.Category; import com.arsdigita.categorization.CategorizedCollection; import com.arsdigita.cms.CMS; +import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.dispatcher.ItemResolver; import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.kernel.ACSObject; import com.arsdigita.util.LockableImpl; +import com.arsdigita.xml.Element; import java.math.BigDecimal; import javax.servlet.ServletException; @@ -40,7 +46,8 @@ import javax.servlet.ServletException; * * @author Randy Graebner (randyg@redhat.com) * @version $Revision: #18 $ $DateTime: 2004/08/17 23:15:09 $ - * @version $Revision: #18 $Id: CategorizedObjectsList.java 2090 2010-04-17 08:04:14Z pboy $ + * @version $Revision: #18 $Id: CategorizedObjectsList.java 2090 2010-04-17 + * 08:04:14Z pboy $ */ public class CategorizedObjectsList extends SortableCategoryList { @@ -50,7 +57,6 @@ public class CategorizedObjectsList extends SortableCategoryList { super(category); setModelBuilder(new CategorizedObjectsModelBuilder()); - Label label = new Label(GlobalizationUtil.globalize("cms.ui.category.item.none")); label.setFontWeight(Label.ITALIC); setEmptyView(label); @@ -68,19 +74,19 @@ public class CategorizedObjectsList extends SortableCategoryList { final ContentItem selectedItem = new ContentItem(selectedID); final BigDecimal selectedDraftId = selectedItem.getDraftVersion().getID(); - + if (CMS.getContext().getSecurityManager().canAccess(SecurityManager.CATEGORY_ADMIN)) { final BigDecimal swapId = getSwapID(parent, selectedID, event); parent.swapSortKeys(selectedID, swapId); final ContentItem swapItem = new ContentItem(swapId); final BigDecimal swapDraftId = swapItem.getDraftVersion().getID(); - + final BigDecimal sortKey1 = parent.getSortKey(selectedItem); final BigDecimal sortKey2 = parent.getSortKey(swapItem); - + parent.setSortKey(new ContentItem(selectedDraftId), sortKey1); parent.setSortKey(new ContentItem(swapDraftId), sortKey2); - + } } else { super.respond(ps); @@ -118,11 +124,38 @@ public class CategorizedObjectsList extends SortableCategoryList { return swapID; } + @Override + protected void generateLabelXML(PageState state, Element parent, Label label, String key, Object element) { + SecurityManager securityManager = CMS.getSecurityManager(state); + ContentBundle item = (ContentBundle) element; + + boolean canEdit = securityManager.canAccess( + state.getRequest(), + SecurityManager.EDIT_ITEM, + item); + + if (canEdit) { + + ContentSection section = item.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + + Link link = new Link( + item.getDisplayName(), + resolver.generateItemURL( + state, + ((ContentBundle) item.getDraftVersion()).getPrimaryInstance(), + section, + ((ContentBundle) item.getDraftVersion()).getPrimaryInstance().getVersion())); + Component c = link; + c.generateXML(state, parent); + } + } + private class CategorizedObjectsModelBuilder extends LockableImpl implements ListModelBuilder { public final ListModel makeModel(final List list, - final PageState state) { + final PageState state) { final Category category = getCategory(state); if (category != null && category.hasChildObjects()) { @@ -137,7 +170,8 @@ public class CategorizedObjectsList extends SortableCategoryList { } /** - * A {@link ListModel} that iterates over categorized objects via an iterator + * A {@link ListModel} that iterates over categorized objects via an + * iterator */ private static class CategorizedCollectionListModel implements ListModel { @@ -147,8 +181,10 @@ public class CategorizedObjectsList extends SortableCategoryList { public CategorizedCollectionListModel(CategorizedCollection coll) { m_objs = coll; m_object = null; + } + @Override public boolean next() { if (m_objs.next()) { m_object = (ACSObject) m_objs.getDomainObject(); @@ -158,10 +194,12 @@ public class CategorizedObjectsList extends SortableCategoryList { } } + @Override public Object getElement() { - return m_object.getDisplayName(); + return m_object; } + @Override public String getKey() { return m_object.getID().toString(); } diff --git a/ccm-cms/src/com/arsdigita/cms/ui/category/IndexItemSelectionForm.java b/ccm-cms/src/com/arsdigita/cms/ui/category/IndexItemSelectionForm.java index f6c8f647a..6d7d838ef 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/category/IndexItemSelectionForm.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/category/IndexItemSelectionForm.java @@ -19,10 +19,12 @@ package com.arsdigita.cms.ui.category; import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Form; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.Link; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SaveCancelSection; import com.arsdigita.bebop.event.FormProcessListener; @@ -37,8 +39,11 @@ import com.arsdigita.bebop.parameters.ParameterData; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.categorization.Category; import com.arsdigita.categorization.CategorizedCollection; +import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.SecurityManager; +import com.arsdigita.cms.dispatcher.ItemResolver; import com.arsdigita.cms.ui.CMSForm; import com.arsdigita.cms.ui.FormSecurityListener; import com.arsdigita.cms.util.GlobalizationUtil; @@ -49,17 +54,17 @@ import com.arsdigita.util.UncheckedWrapperException; import java.math.BigDecimal; /** - * Allows the user to select an index item to display when the - * front end user is browsing by Category + * Allows the user to select an index item to display when the front end user is + * browsing by Category * * @author Randy Graebner (randyg@alum.mit.edu) * @version $Revision: #18 $ $DateTime: 2004/08/17 23:15:09 $ */ public class IndexItemSelectionForm extends CMSForm { - private static org.apache.log4j.Logger s_log = - org.apache.log4j.Logger.getLogger( - IndexItemSelectionForm.class); + private static org.apache.log4j.Logger s_log + = org.apache.log4j.Logger.getLogger( + IndexItemSelectionForm.class); private final CategoryRequestLocal m_category; private RadioGroup m_options; private static final String NULL_OPTION_VALUE = ""; @@ -94,25 +99,39 @@ public class IndexItemSelectionForm extends CMSForm { ContentItem.BASE_DATA_OBJECT_TYPE); group.clearOptions(); - + // option for NO index Object group.addOption(new Option(NONE_OPTION_VALUE, - new Label(NONE_OPTION_VALUE))); + new Label(NONE_OPTION_VALUE))); // option for inheriting from the parent category if (category.getParentCategoryCount() > 0) { group.addOption(new Option(NULL_OPTION_VALUE, - new Label("Inherit Index from Parent Category"))); + new Label("Inherit Index from Parent Category"))); } while (children.next()) { - ACSObject item = - (ACSObject) children.getDomainObject(); + ACSObject item + = (ACSObject) children.getDomainObject(); if ((item instanceof ContentItem) && ((ContentItem) item).getVersion(). equals(ContentItem.DRAFT)) { + + //create a link to the item: + ContentBundle bundleItem = (ContentBundle) item; + ContentSection section = bundleItem.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + + Link link = new Link( + bundleItem.getDisplayName(), + resolver.generateItemURL(state, + ((ContentBundle) bundleItem.getDraftVersion()).getPrimaryInstance(), + section, + ((ContentBundle) bundleItem.getDraftVersion()).getPrimaryInstance().getVersion())); + Component linkComponent = link; + //add the option with the link group.addOption(new Option(item.getID().toString(), - ((ContentItem) item).getName())); + linkComponent)); } } // get currently selected item @@ -124,7 +143,7 @@ public class IndexItemSelectionForm extends CMSForm { } else { String value = NONE_OPTION_VALUE; if (!category.ignoreParentIndexItem() - && category.getParentCategoryCount() > 0) { + && category.getParentCategoryCount() > 0) { value = NULL_OPTION_VALUE; } group.setValue(state, value); @@ -154,8 +173,8 @@ public class IndexItemSelectionForm extends CMSForm { ParameterData param = data.getParameter(m_options.getParameterModel().getName()); String selectedValue = (String) param.getValue(); - Category category = - getCategory(event.getPageState()); + Category category + = getCategory(event.getPageState()); ContentItem item = null; if (selectedValue != null) {