Refactored CategorizedObjectsList, but removed sorting for now

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4568 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
baka 2017-02-15 10:18:50 +00:00
parent 6350bee8e4
commit d804ced147
2 changed files with 28 additions and 31 deletions

View File

@ -23,21 +23,16 @@ import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder; import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.util.GlobalizationUtil; import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import org.libreccm.categorization.Categorization; import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants; import org.librecms.contentsection.*;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AdminPrivileges;
import org.librecms.dispatcher.ItemResolver;
import java.math.BigDecimal;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -46,13 +41,11 @@ import javax.servlet.ServletException;
* A List of all objects currently categorized under this category * A List of all objects currently categorized under this category
* *
* @author Randy Graebner (randyg@redhat.com) * @author Randy Graebner (randyg@redhat.com)
* @version $Revision: #18 $ $DateTime: 2004/08/17 23:15:09 $ * @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @version $Revision: #18 $Id: CategorizedObjectsList.java 2090 2010-04-17
* 08:04:14Z pboy $
*/ */
public class CategorizedObjectsList extends SortableCategoryList { public class CategorizedObjectsList extends SortableCategoryList {
public final static String CATEGORIZED_OBJECTS = "co"; //public final static String CATEGORIZED_OBJECTS = "co";
public CategorizedObjectsList(final CategoryRequestLocal category) { public CategorizedObjectsList(final CategoryRequestLocal category) {
super(category); super(category);
@ -67,20 +60,23 @@ public class CategorizedObjectsList extends SortableCategoryList {
* This actually performs the sorting * This actually performs the sorting
*/ */
public void respond(PageState ps) throws ServletException { public void respond(PageState ps) throws ServletException {
/* TODO Reimplement sorting
final String event = ps.getControlEventName(); final String event = ps.getControlEventName();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItemRepository contentItemRepository = cdiUtil.findBean(ContentItemRepository.class); final ContentItemRepository contentItemRepository = cdiUtil.findBean(ContentItemRepository.class);
final ContentItemManager contentItemManager = cdiUtil.findBean(ContentItemManager.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
/*
if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) { if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) {
final long selectedID = Long.parseLong(ps.getControlEventValue()); final long selectedID = Long.parseLong(ps.getControlEventValue());
final Category parent = getCategory(ps); final Category parent = getCategory(ps);
final ContentItem selectedItem = contentItemRepository.findById(selectedID).get(); final ContentItem selectedItem = contentItemRepository.findById(selectedID).get();
final BigDecimal selectedDraftId = selectedItem.getDraftVersion().getID(); final Long selectedDraftId = contentItemManager.getDraftVersion(selectedItem, ContentItem.class).getObjectId();
if (CMS.getContext().getSecurityManager().canAccess(SecurityManager.CATEGORY_ADMIN)) { if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES)) {
final BigDecimal swapId = getSwapID(parent, selectedID, event); final Long swapId = getSwapID(parent, selectedID, event);
parent.swapSortKeys(selectedID, swapId); parent.swapSortKeys(selectedID, swapId);
final ContentItem swapItem = new ContentItem(swapId); final ContentItem swapItem = new ContentItem(swapId);
final BigDecimal swapDraftId = swapItem.getDraftVersion().getID(); final BigDecimal swapDraftId = swapItem.getDraftVersion().getID();
@ -104,11 +100,10 @@ public class CategorizedObjectsList extends SortableCategoryList {
boolean foundSelectedID = false; boolean foundSelectedID = false;
if (category != null && !category.getObjects().isEmpty()) { if (category != null && !category.getObjects().isEmpty()) {
Iterator<Categorization> items = category.getObjects().iterator();
//items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE); TODO //items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE); TODO
//items.sort(true); //items.sort(true);
while (items.hasNext()) { for (Categorization categorization : category.getObjects()) {
long thisID = items.next().getCategorizationId(); long thisID = categorization.getCategorizationId();
if (foundSelectedID && NEXT_EVENT.equals(event)) { if (foundSelectedID && NEXT_EVENT.equals(event)) {
swapID = thisID; swapID = thisID;
break; break;
@ -132,23 +127,25 @@ public class CategorizedObjectsList extends SortableCategoryList {
protected void generateLabelXML(PageState state, Element parent, Label label, String key, Object element) { protected void generateLabelXML(PageState state, Element parent, Label label, String key, Object element) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final ContentSectionManager contentSectionManager = cdiUtil.findBean(ContentSectionManager.class);
ContentBundle item = (ContentBundle) element; ContentItem item = (ContentItem) element;
boolean canEdit = permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES); boolean canEdit = permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
if (canEdit) { if (canEdit) {
ContentSection section = CMS.getContext().getContentSection();
ContentSection section = item.getContentSection(); ItemResolver resolver = contentSectionManager.getItemResolver(section);
ItemResolver resolver = section.getItemResolver();
Link link = new Link( Link link = new Link(
item.getDisplayName(), new Text(item.getDisplayName()),
resolver.generateItemURL( resolver.generateItemURL(
state, state,
((ContentBundle) item.getDraftVersion()).getPrimaryInstance(), item.getObjectId(),
item.getDisplayName(),
section, section,
((ContentBundle) item.getDraftVersion()).getPrimaryInstance().getVersion())); item.getVersion().name()
)
);
Component c = link; Component c = link;
c.generateXML(state, parent); c.generateXML(state, parent);
} }
@ -161,10 +158,10 @@ public class CategorizedObjectsList extends SortableCategoryList {
final PageState state) { final PageState state) {
final Category category = getCategory(state); final Category category = getCategory(state);
if (category != null && category.hasChildObjects()) { if (category != null && !category.getObjects().isEmpty()) {
CategorizedCollection items = category.getObjects(); Collection<Categorization> items = category.getObjects();
items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE); //items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE);
items.sort(true); //items.sort(true);
return new CategorizedCollectionListModel(items); return new CategorizedCollectionListModel(items);
} else { } else {
return List.EMPTY_MODEL; return List.EMPTY_MODEL;

View File

@ -130,7 +130,7 @@ public class IndexItemSelectionForm extends CMSForm {
); );
Component linkComponent = link; Component linkComponent = link;
//add the option with the link //add the option with the link
group.addOption(new Option(item.getItemUuid(), //TODO group.addOption(new Option(item.getItemUuid(),
linkComponent)); linkComponent));
} }