CCM NG: Setting index item for a category in the category of the Content Section Editor
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5168 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: 6a1b408109
pull/2/head
parent
a9d2efbe09
commit
2f090ae6b1
|
|
@ -18,17 +18,29 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.category;
|
package com.arsdigita.cms.ui.category;
|
||||||
|
|
||||||
|
import org.libreccm.categorization.Categorization;
|
||||||
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.categorization.CategoryManager;
|
||||||
|
import org.libreccm.categorization.CategoryRepository;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
import javax.enterprise.context.RequestScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
import org.libreccm.categorization.DomainOwnership;
|
import org.libreccm.categorization.DomainOwnership;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
|
import org.librecms.contentsection.ContentItemVersion;
|
||||||
import org.librecms.contentsection.ContentSection;
|
import org.librecms.contentsection.ContentSection;
|
||||||
import org.librecms.contentsection.ContentSectionRepository;
|
import org.librecms.contentsection.ContentSectionRepository;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -37,13 +49,22 @@ import org.librecms.contentsection.ContentSectionRepository;
|
||||||
class CategoryAdminController {
|
class CategoryAdminController {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private ContentSectionRepository sectionRepo;
|
private CategoryManager categoryManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EntityManager entityManager;
|
private CategoryRepository categoryRepo;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentItemManager itemManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private GlobalizationHelper globalizationHelper;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ContentSectionRepository sectionRepo;
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
public List<DomainOwnership> retrieveDomains(final ContentSection section) {
|
protected List<DomainOwnership> retrieveDomains(final ContentSection section) {
|
||||||
|
|
||||||
Objects.requireNonNull(section);
|
Objects.requireNonNull(section);
|
||||||
|
|
||||||
|
|
@ -57,4 +78,56 @@ class CategoryAdminController {
|
||||||
return new ArrayList<>(contentSection.getDomains());
|
return new ArrayList<>(contentSection.getDomains());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected List<CategoryListItem> generateSubCategoryList(
|
||||||
|
final Category forCategory) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(forCategory);
|
||||||
|
|
||||||
|
final Category category = categoryRepo
|
||||||
|
.findById(forCategory.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Category with ID %d in the datbase.",
|
||||||
|
forCategory.getObjectId())));
|
||||||
|
|
||||||
|
return category
|
||||||
|
.getSubCategories()
|
||||||
|
.stream()
|
||||||
|
.map(this::createCategoryListItem)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private CategoryListItem createCategoryListItem(final Category category) {
|
||||||
|
|
||||||
|
final CategoryListItem item = new CategoryListItem();
|
||||||
|
item.setCategoryId(category.getObjectId());
|
||||||
|
|
||||||
|
final String label = globalizationHelper
|
||||||
|
.getValueFromLocalizedString(category.getTitle(), category::getName);
|
||||||
|
item.setLabel(label);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
protected List<ContentItem> retrieveAssignedContentItems(
|
||||||
|
final Category fromCategory) {
|
||||||
|
|
||||||
|
final Category category = categoryRepo
|
||||||
|
.findById(fromCategory.getObjectId())
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Category with ID %d in the datbase.",
|
||||||
|
fromCategory.getObjectId())));
|
||||||
|
|
||||||
|
return category
|
||||||
|
.getObjects()
|
||||||
|
.stream()
|
||||||
|
.map(Categorization::getCategorizedObject)
|
||||||
|
.filter(obj -> obj instanceof ContentItem)
|
||||||
|
.map(obj -> (ContentItem) obj)
|
||||||
|
.filter(item -> itemManager.isLive(item))
|
||||||
|
.filter(item -> item.getVersion() == ContentItemVersion.LIVE)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -272,15 +272,23 @@ public final class CategoryAdminPane extends BaseAdminPane<String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final Object initialValue(final PageState state) {
|
protected final Object initialValue(final PageState state) {
|
||||||
final String id = selectedCategory.getSelectedKey(state);
|
|
||||||
|
final String selectedCatetoryIdStr = selectedCategory
|
||||||
|
.getSelectedKey(state);
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final CategoryRepository repository = cdiUtil.findBean(
|
final CategoryRepository repository = cdiUtil.findBean(
|
||||||
CategoryRepository.class);
|
CategoryRepository.class);
|
||||||
if (id == null) {
|
final Category category;
|
||||||
return null;
|
if (selectedCatetoryIdStr == null) {
|
||||||
|
category = null;
|
||||||
} else {
|
} else {
|
||||||
return repository.findById(Long.parseLong(id));
|
category = repository
|
||||||
|
.findById(Long.parseLong(selectedCatetoryIdStr))
|
||||||
|
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||||
|
.format("No Category with ID %s in the database.",
|
||||||
|
selectedCatetoryIdStr)));
|
||||||
}
|
}
|
||||||
|
return category;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@ import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
import com.arsdigita.bebop.form.Submit;
|
import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
|
||||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
|
||||||
import com.arsdigita.cms.ui.BaseItemPane;
|
import com.arsdigita.cms.ui.BaseItemPane;
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
import com.arsdigita.cms.ui.CMSForm;
|
||||||
import com.arsdigita.cms.ui.ContentItemPage;
|
import com.arsdigita.cms.ui.ContentItemPage;
|
||||||
import com.arsdigita.cms.ui.VisibilityComponent;
|
import com.arsdigita.cms.ui.VisibilityComponent;
|
||||||
import com.arsdigita.cms.ui.templates.CategoryTemplates;
|
import com.arsdigita.cms.ui.templates.CategoryTemplates;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||||
import com.arsdigita.toolbox.ui.Property;
|
import com.arsdigita.toolbox.ui.Property;
|
||||||
|
|
@ -45,7 +45,6 @@ import com.arsdigita.toolbox.ui.PropertyList;
|
||||||
import com.arsdigita.toolbox.ui.Section;
|
import com.arsdigita.toolbox.ui.Section;
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
@ -56,12 +55,17 @@ import org.libreccm.categorization.CategoryManager;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edits a single category.
|
* Edits a single category.
|
||||||
*
|
*
|
||||||
|
|
@ -100,7 +104,12 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
if (!super.isVisible(state)) {
|
if (!super.isVisible(state)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return !m_category.getCategory(state).getObjects().isEmpty();
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CategoryManager categoryManager = cdiUtil
|
||||||
|
.findBean(CategoryManager.class);
|
||||||
|
final Category category = m_category.getCategory(state);
|
||||||
|
return categoryManager.hasObjects(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -276,6 +285,7 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
final BaseLink viewIndexItem,
|
final BaseLink viewIndexItem,
|
||||||
final BaseLink editIndexItem,
|
final BaseLink editIndexItem,
|
||||||
final ActionLink orderItemsLink) {
|
final ActionLink orderItemsLink) {
|
||||||
|
|
||||||
setHeading(new Label(gz("cms.ui.category.details")));
|
setHeading(new Label(gz("cms.ui.category.details")));
|
||||||
|
|
||||||
final ActionGroup group = new ActionGroup();
|
final ActionGroup group = new ActionGroup();
|
||||||
|
|
@ -295,36 +305,67 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
private class Properties extends PropertyList {
|
private class Properties extends PropertyList {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final java.util.List properties(final PageState state) {
|
protected final java.util.List<Property> properties(
|
||||||
final java.util.List props = super.properties(state);
|
final PageState state) {
|
||||||
final Category category = m_category.getCategory(state);
|
|
||||||
|
|
||||||
String itemTitle = "None";
|
final java.util.List<Property> properties = super.properties(
|
||||||
|
state);
|
||||||
|
final Category category = m_category
|
||||||
|
.getCategory(state);
|
||||||
|
|
||||||
if (category != null) {
|
final String itemTitle;
|
||||||
itemTitle = category.getDisplayName();
|
|
||||||
|
if (category == null) {
|
||||||
|
itemTitle = "None";
|
||||||
|
} else {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CategoryManager categoryManager = cdiUtil
|
||||||
|
.findBean(CategoryManager.class);
|
||||||
|
final List<CcmObject> indexObjects = categoryManager
|
||||||
|
.getIndexObject(category);
|
||||||
|
|
||||||
|
final Optional<ContentItem> indexItem = indexObjects
|
||||||
|
.stream()
|
||||||
|
.filter(obj -> obj instanceof ContentItem)
|
||||||
|
.map(obj -> (ContentItem) obj)
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
if (indexItem.isPresent()) {
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
|
||||||
|
final ContentItem item = indexItem.get();
|
||||||
|
itemTitle = globalizationHelper
|
||||||
|
.getValueFromLocalizedString(item.getTitle(),
|
||||||
|
item::getDisplayName);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
final CcmObject indexObj = indexObjects.get(0);
|
||||||
|
itemTitle = Objects.toString(indexObj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
props.add(new Property(gz("cms.ui.name"),
|
properties.add(new Property(gz("cms.ui.name"),
|
||||||
category.getName()));
|
category.getName()));
|
||||||
props.add(new Property(gz("cms.ui.description"),
|
properties.add(new Property(gz("cms.ui.description"),
|
||||||
category.getDescription().getValue()));
|
category.getDescription().getValue()));
|
||||||
props.add(new Property(gz("cms.ui.category.is_not_abstract"),
|
properties.add(new Property(
|
||||||
category.isAbstractCategory()
|
gz("cms.ui.category.is_not_abstract"),
|
||||||
? gz("cms.ui.no")
|
category.isAbstractCategory()
|
||||||
: gz("cms.ui.yes")));
|
? gz("cms.ui.no")
|
||||||
props.add(new Property(gz("cms.ui.cateogry.is_visible"),
|
: gz("cms.ui.yes")));
|
||||||
category.isVisible()
|
properties.add(new Property(gz("cms.ui.cateogry.is_visible"),
|
||||||
? gz("cms.ui.yes")
|
category.isVisible()
|
||||||
: gz("cms.ui.no")));
|
? gz("cms.ui.yes")
|
||||||
props.add(new Property(gz("cms.ui.category.is_enabled"),
|
: gz("cms.ui.no")));
|
||||||
category.isEnabled()
|
properties.add(new Property(gz("cms.ui.category.is_enabled"),
|
||||||
? gz("cms.ui.yes")
|
category.isEnabled()
|
||||||
: gz("cms.ui.no")));
|
? gz("cms.ui.yes")
|
||||||
props.add(new Property(gz("cms.ui.category.index_item"),
|
: gz("cms.ui.no")));
|
||||||
itemTitle));
|
properties.add(new Property(gz("cms.ui.category.index_item"),
|
||||||
|
itemTitle));
|
||||||
|
|
||||||
return props;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -398,7 +439,13 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean isVisible(final PageState state) {
|
public final boolean isVisible(final PageState state) {
|
||||||
return m_category.getCategory(state).getParentCategory().isVisible();
|
|
||||||
|
final Category category = m_category.getCategory(state);
|
||||||
|
if (category.getParentCategory() == null) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return category.getParentCategory().isVisible();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -567,17 +614,20 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
// the content. The prepareURL method is called by the printwriter
|
// the content. The prepareURL method is called by the printwriter
|
||||||
@Override
|
@Override
|
||||||
protected String prepareURL(final PageState state, String location) {
|
protected String prepareURL(final PageState state, String location) {
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final CategoryManager manager = cdiUtil.findBean(
|
final CategoryManager manager = cdiUtil.findBean(
|
||||||
CategoryManager.class);
|
CategoryManager.class);
|
||||||
|
final Category category = m_category.getCategory(state);
|
||||||
|
|
||||||
ContentItem indexItem = (ContentItem) manager
|
final ContentItem indexItem = (ContentItem) manager
|
||||||
.getIndexObject(m_category.getCategory(state))
|
.getIndexObject(category)
|
||||||
.stream()
|
.stream()
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.get();
|
.get();
|
||||||
return "/redirect/?oid=" + URLEncoder.encode(Long.toString(indexItem
|
|
||||||
.getObjectId()));
|
return String.format("/redirect/?oid=%s",
|
||||||
|
Long.toString(indexItem.getObjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We only show this link when an index item exists for this category
|
// We only show this link when an index item exists for this category
|
||||||
|
|
@ -586,13 +636,12 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
if (!super.isVisible(state)) {
|
if (!super.isVisible(state)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Category /*ACSObject*/ indexItem = m_category
|
|
||||||
.getCategory(state);//.getDirectIndexObject();
|
final Category category = m_category.getCategory(state);
|
||||||
if (indexItem == null) {
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
return false;
|
final CategoryManager categoryManager = cdiUtil
|
||||||
} else {
|
.findBean(CategoryManager.class);
|
||||||
return true;
|
return categoryManager.hasIndexObject(category);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
@ -677,8 +726,9 @@ class CategoryItemPane extends BaseItemPane {
|
||||||
|
|
||||||
public MoveLink(final Label label) {
|
public MoveLink(final Label label) {
|
||||||
super(label);
|
super(label);
|
||||||
alternativeLabel = new Label(GlobalizationUtil.globalize(
|
alternativeLabel = new Label(new GlobalizedMessage(
|
||||||
"cms.ui.category.cantmoved"));
|
"cms.ui.category.cantmoved",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,12 @@ import com.arsdigita.bebop.list.ListModelBuilder;
|
||||||
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
import com.arsdigita.bebop.parameters.BigDecimalParameter;
|
||||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import org.libreccm.categorization.Category;
|
||||||
import java.util.HashSet;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A List of all secondary parents of the current category.
|
* A List of all secondary parents of the current category.
|
||||||
|
|
@ -81,13 +83,27 @@ public class CategoryLinks extends List {
|
||||||
// Since this part is for non default parents, but there is only one... this is not needed anymore, i guess
|
// Since this part is for non default parents, but there is only one... this is not needed anymore, i guess
|
||||||
private class LinkedCategoryModelBuilder extends LockableImpl
|
private class LinkedCategoryModelBuilder extends LockableImpl
|
||||||
implements ListModelBuilder {
|
implements ListModelBuilder {
|
||||||
|
|
||||||
|
@Override
|
||||||
public ListModel makeModel(List list, PageState state) {
|
public ListModel makeModel(List list, PageState state) {
|
||||||
final Category category = m_parent.getCategory(state);
|
final Category category = m_parent.getCategory(state);
|
||||||
|
|
||||||
if (category != null && category.getParentCategory() != null) {
|
if (category != null && category.getParentCategory() != null) {
|
||||||
|
|
||||||
java.util.List<Category> categories = new java.util.ArrayList<>();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
categories.add(category.getParentCategory());
|
final GlobalizationHelper globalizationHelper =cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final Category parent = category.getParentCategory();
|
||||||
|
|
||||||
|
java.util.List<CategoryListItem> categories = new ArrayList<>();
|
||||||
|
final CategoryListItem parentItem = new CategoryListItem();
|
||||||
|
parentItem.setCategoryId(parent.getObjectId());
|
||||||
|
final String label = globalizationHelper
|
||||||
|
.getValueFromLocalizedString(parent.getTitle(),
|
||||||
|
parent::getName);
|
||||||
|
parentItem.setLabel(label);
|
||||||
|
|
||||||
|
categories.add(parentItem);
|
||||||
|
|
||||||
return new CategoryListModel
|
return new CategoryListModel
|
||||||
(categories,
|
(categories,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package com.arsdigita.cms.ui.category;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class CategoryListItem implements Comparable<CategoryListItem> {
|
||||||
|
|
||||||
|
private long categoryId;
|
||||||
|
private String label;
|
||||||
|
|
||||||
|
public long getCategoryId() {
|
||||||
|
return categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryId(final long categoryId) {
|
||||||
|
this.categoryId = categoryId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLabel(final String label) {
|
||||||
|
this.label = label;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(final CategoryListItem other) {
|
||||||
|
|
||||||
|
final int result = label.compareTo(other.getLabel());
|
||||||
|
if (result == 0) {
|
||||||
|
return Long.compare(categoryId, other.getCategoryId());
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 7;
|
||||||
|
hash = 67 * hash + (int) (categoryId ^ (categoryId >>> 32));
|
||||||
|
hash = 67 * hash + Objects.hashCode(label);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!(obj instanceof CategoryListItem)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final CategoryListItem other = (CategoryListItem) obj;
|
||||||
|
if (!other.canEqual(this)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (categoryId != other.getCategoryId()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Objects.equals(label, other.getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canEqual(final Object obj) {
|
||||||
|
return obj instanceof CategoryListItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final String toString() {
|
||||||
|
return toString("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString(final String data) {
|
||||||
|
return String.format("%s{ "
|
||||||
|
+ "categoryId = %d,"
|
||||||
|
+ "label = \"%s\"%s"
|
||||||
|
+ " }",
|
||||||
|
super.toString(),
|
||||||
|
categoryId,
|
||||||
|
label,
|
||||||
|
data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,8 +19,8 @@
|
||||||
package com.arsdigita.cms.ui.category;
|
package com.arsdigita.cms.ui.category;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
import com.arsdigita.bebop.list.ListModel;
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
|
@ -28,39 +28,44 @@ import java.util.Iterator;
|
||||||
* A {@link ListModel} that iterates over categories via a cursor.
|
* A {@link ListModel} that iterates over categories via a cursor.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public final class CategoryListModel implements ListModel {
|
class CategoryListModel implements ListModel {
|
||||||
|
|
||||||
private Category m_cat;
|
|
||||||
private long m_excludedID;
|
|
||||||
private Iterator<Category> iterator;
|
|
||||||
|
|
||||||
|
private final Iterator<CategoryListItem> iterator;
|
||||||
|
private CategoryListItem currentCategory;
|
||||||
|
private Long excludedCategoryId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>CategoryListModel</code>
|
* Constructs a new <code>CategoryListModel</code>
|
||||||
|
*
|
||||||
|
* @param categories
|
||||||
*/
|
*/
|
||||||
public CategoryListModel(List<Category> coll) {
|
public CategoryListModel(final List<CategoryListItem> categories) {
|
||||||
this(coll, -1); //Hopefully a decent replacement for null in BigDecimal. Negative ids would be weird...
|
this(categories, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>CategoryListModel</code>
|
* Constructs a new <code>CategoryListModel</code>
|
||||||
*/
|
*/
|
||||||
public CategoryListModel(List<Category> coll,
|
public CategoryListModel(final List<CategoryListItem> categories,
|
||||||
long excludedID) {
|
final Long excludedCategoryId) {
|
||||||
|
|
||||||
m_excludedID = excludedID;
|
iterator = categories.iterator();
|
||||||
m_cat = null;
|
this.excludedCategoryId = excludedCategoryId;
|
||||||
iterator = coll.iterator();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean next() {
|
public boolean next() {
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
final Category category = iterator.next();
|
|
||||||
if (Long.parseLong(category.getUniqueId()) == m_excludedID) {
|
final CategoryListItem next = iterator.next();
|
||||||
|
if (excludedCategoryId != null
|
||||||
|
&& next.getCategoryId() == excludedCategoryId) {
|
||||||
|
|
||||||
return next();
|
return next();
|
||||||
} else {
|
} else {
|
||||||
m_cat = category;
|
currentCategory = next;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -68,26 +73,19 @@ public final class CategoryListModel implements ListModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Category getCategory() {
|
|
||||||
if ( m_cat == null ) {
|
|
||||||
throw new IllegalStateException("call next() first");
|
|
||||||
}
|
|
||||||
return m_cat;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the name of the category.
|
* Reads the label of the {@link CategoryListItem}.
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* Quasimodo:
|
|
||||||
* Modified to ensure that the value is read from Category (and not the
|
|
||||||
* localized version). This is necessary because we are in the admin GUI,
|
|
||||||
* a localized version would be confusing.
|
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Object getElement() {
|
public Object getElement() {
|
||||||
return getCategory().getName();
|
return currentCategory.getLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return getCategory().getUniqueId();
|
return Long.toString(currentCategory.getCategoryId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,14 @@ import com.arsdigita.bebop.table.TableModel;
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
import com.arsdigita.bebop.util.GlobalizationUtil;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
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.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.l10n.GlobalizedMessagesUtil;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
import org.libreccm.security.PermissionChecker;
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -54,18 +58,22 @@ import java.util.Locale;
|
||||||
* @author Sören Bernstein <quasi@quasiweb.de>
|
* @author Sören Bernstein <quasi@quasiweb.de>
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
*/
|
*/
|
||||||
public class CategoryLocalizationTable extends Table implements TableActionListener {
|
public class CategoryLocalizationTable extends Table implements
|
||||||
|
TableActionListener {
|
||||||
|
|
||||||
|
private static final String TABLE_COL_LANG = "table_col_lang";
|
||||||
|
private static final String TABLE_COL_DEL = "table_col_del";
|
||||||
|
|
||||||
private final CategoryRequestLocal m_category;
|
private final CategoryRequestLocal m_category;
|
||||||
private final SingleSelectionModel m_model;
|
private final SingleSelectionModel m_model;
|
||||||
private final String TABLE_COL_LANG = "table_col_lang";
|
|
||||||
private final String TABLE_COL_DEL = "table_col_del";
|
|
||||||
private final SingleSelectionModel m_catLocale;
|
private final SingleSelectionModel m_catLocale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of CategoryLocalizationTable
|
* Creates a new instance of CategoryLocalizationTable
|
||||||
*/
|
*/
|
||||||
public CategoryLocalizationTable(final CategoryRequestLocal category, final SingleSelectionModel model, SingleSelectionModel catLocale) {
|
public CategoryLocalizationTable(final CategoryRequestLocal category,
|
||||||
|
final SingleSelectionModel model,
|
||||||
|
final SingleSelectionModel catLocale) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
|
@ -73,30 +81,52 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
m_model = model;
|
m_model = model;
|
||||||
m_catLocale = catLocale;
|
m_catLocale = catLocale;
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
|
||||||
|
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
|
||||||
|
|
||||||
// if table is empty:
|
// if table is empty:
|
||||||
setEmptyView(new Label(GlobalizationUtil.globalize(
|
setEmptyView(new Label(messagesUtil
|
||||||
"cms.ui.category.localization_none")));
|
.getGlobalizedMessage("cms.ui.category.localization_none")));
|
||||||
TableColumnModel tab_model = getColumnModel();
|
final TableColumnModel columnModel = getColumnModel();
|
||||||
|
|
||||||
// define columns
|
// define columns
|
||||||
// XXX globalize
|
columnModel.add(new TableColumn(
|
||||||
tab_model.add(new TableColumn(0, GlobalizationUtil.globalize(
|
0,
|
||||||
"cms.ui.category.localization.locale").localize(), TABLE_COL_LANG));
|
messagesUtil.getGlobalizedMessage(
|
||||||
tab_model.add(new TableColumn(1, GlobalizationUtil.globalize(
|
"cms.ui.category.localization.locale")
|
||||||
"cms.ui.category.localization_name").localize()));
|
.localize(),
|
||||||
tab_model.add(new TableColumn(2, GlobalizationUtil.globalize(
|
TABLE_COL_LANG));
|
||||||
"cms.ui.category.localization_description").localize()));
|
columnModel.add(new TableColumn(
|
||||||
tab_model.add(new TableColumn(3, GlobalizationUtil.globalize(
|
1,
|
||||||
"cms.ui.category.localization_url").localize()));
|
messagesUtil
|
||||||
tab_model.add(new TableColumn(4, GlobalizationUtil.globalize(
|
.getGlobalizedMessage("cms.ui.category.localization_name")
|
||||||
"cms.ui.category.localization_action").localize(), TABLE_COL_DEL));
|
.localize()));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
2,
|
||||||
|
messagesUtil.getGlobalizedMessage(
|
||||||
|
"cms.ui.category.localization_description")
|
||||||
|
.localize()));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
3,
|
||||||
|
messagesUtil
|
||||||
|
.getGlobalizedMessage("cms.ui.category.localization_url")
|
||||||
|
.localize()));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
4,
|
||||||
|
messagesUtil
|
||||||
|
.getGlobalizedMessage("cms.ui.category.localization_action")
|
||||||
|
.localize(),
|
||||||
|
TABLE_COL_DEL));
|
||||||
|
|
||||||
setModelBuilder(new CategoryLocalizationTableModelBuilder());
|
super.setModelBuilder(new CategoryLocalizationTableModelBuilder());
|
||||||
|
|
||||||
tab_model.get(0).setCellRenderer(new EditCellRenderer());
|
columnModel.get(0).setCellRenderer(new EditCellRenderer());
|
||||||
tab_model.get(4).setCellRenderer(new DeleteCellRenderer());
|
columnModel.get(4).setCellRenderer(new DeleteCellRenderer());
|
||||||
|
|
||||||
addTableActionListener(this);
|
super.addTableActionListener(this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,7 +135,7 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private class CategoryLocalizationTableModelBuilder extends LockableImpl
|
private class CategoryLocalizationTableModelBuilder extends LockableImpl
|
||||||
implements TableModelBuilder {
|
implements TableModelBuilder {
|
||||||
|
|
||||||
public TableModel makeModel(Table table, PageState state) {
|
public TableModel makeModel(Table table, PageState state) {
|
||||||
final Category category = m_category.getCategory(state);
|
final Category category = m_category.getCategory(state);
|
||||||
|
|
@ -116,6 +146,7 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
return Table.EMPTY_MODEL;
|
return Table.EMPTY_MODEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -128,7 +159,8 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
private ArrayList<LocalizedString> localizedStringCollection;
|
private ArrayList<LocalizedString> localizedStringCollection;
|
||||||
private LocalizedString m_categoryLocalization;
|
private LocalizedString m_categoryLocalization;
|
||||||
|
|
||||||
private CategoryLocalizationTableModel(Table t, PageState ps, Category category) {
|
private CategoryLocalizationTableModel(Table t, PageState ps,
|
||||||
|
Category category) {
|
||||||
m_table = t;
|
m_table = t;
|
||||||
localizedStringCollection = new ArrayList<>();
|
localizedStringCollection = new ArrayList<>();
|
||||||
localizedStringCollection.add(category.getTitle());
|
localizedStringCollection.add(category.getTitle());
|
||||||
|
|
@ -194,41 +226,52 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
return null;
|
return null;
|
||||||
// return m_categoryLocalization.getID();
|
// return m_categoryLocalization.getID();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EditCellRenderer extends LockableImpl implements TableCellRenderer {
|
private class EditCellRenderer extends LockableImpl implements
|
||||||
|
TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(Table table, PageState state, Object value,
|
public Component getComponent(Table table, PageState state, Object value,
|
||||||
boolean isSelected, final Object key,
|
boolean isSelected, final Object key,
|
||||||
int row, int column) {
|
int row, int column) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||||
|
PermissionChecker.class);
|
||||||
|
|
||||||
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(state))) {
|
if (permissionChecker.isPermitted(
|
||||||
|
AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(
|
||||||
|
state))) {
|
||||||
return new ControlLink(value.toString());
|
return new ControlLink(value.toString());
|
||||||
} else {
|
} else {
|
||||||
return new Label(GlobalizationUtil.globalize(value.toString()));
|
return new Label(GlobalizationUtil.globalize(value.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer {
|
private class DeleteCellRenderer extends LockableImpl implements
|
||||||
|
TableCellRenderer {
|
||||||
|
|
||||||
public Component getComponent(Table table, PageState state, Object value,
|
public Component getComponent(Table table, PageState state, Object value,
|
||||||
boolean isSelected, Object key,
|
boolean isSelected, Object key,
|
||||||
int row, int column) {
|
int row, int column) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
||||||
|
PermissionChecker.class);
|
||||||
|
|
||||||
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(state))) {
|
if (permissionChecker.isPermitted(
|
||||||
|
AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(
|
||||||
|
state))) {
|
||||||
ControlLink link = new ControlLink(value.toString());
|
ControlLink link = new ControlLink(value.toString());
|
||||||
link.setConfirmation(GlobalizationUtil.globalize(
|
link.setConfirmation(GlobalizationUtil.globalize(
|
||||||
"cms.ui.category.localization_confirm_delete"));
|
"cms.ui.category.localization_confirm_delete"));
|
||||||
return link;
|
return link;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -259,7 +302,6 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
// if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
|
// if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
|
||||||
// category.delLanguage(categoryLocalization.getLocale());
|
// category.delLanguage(categoryLocalization.getLocale());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -269,4 +311,5 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
|
||||||
public void headSelected(TableActionEvent e) {
|
public void headSelected(TableActionEvent e) {
|
||||||
throw new UnsupportedOperationException("Not Implemented");
|
throw new UnsupportedOperationException("Not Implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,17 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.cms.ui.category;
|
package com.arsdigita.cms.ui.category;
|
||||||
|
|
||||||
import com.arsdigita.bebop.*;
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
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.Text;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.PrintEvent;
|
||||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
import com.arsdigita.bebop.form.FormErrorDisplay;
|
||||||
import com.arsdigita.bebop.form.Option;
|
import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.bebop.form.RadioGroup;
|
import com.arsdigita.bebop.form.RadioGroup;
|
||||||
|
|
@ -28,182 +36,223 @@ import com.arsdigita.bebop.form.Submit;
|
||||||
import com.arsdigita.bebop.parameters.ParameterData;
|
import com.arsdigita.bebop.parameters.ParameterData;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
|
||||||
import com.arsdigita.bebop.util.GlobalizationUtil;
|
|
||||||
import com.arsdigita.cms.CMS;
|
import com.arsdigita.cms.CMS;
|
||||||
import com.arsdigita.cms.ui.CMSForm;
|
import com.arsdigita.cms.ui.CMSForm;
|
||||||
import com.arsdigita.cms.ui.FormSecurityListener;
|
import com.arsdigita.cms.ui.FormSecurityListener;
|
||||||
import com.arsdigita.util.Assert;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.categorization.*;
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.categorization.CategoryManager;
|
||||||
|
import org.libreccm.categorization.CategoryRepository;
|
||||||
|
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.core.CcmObject;
|
import org.libreccm.core.CcmObject;
|
||||||
import org.librecms.contentsection.*;
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
|
import org.libreccm.l10n.GlobalizationHelper;
|
||||||
|
import org.libreccm.l10n.GlobalizedMessagesUtil;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.ContentSectionManager;
|
||||||
|
|
||||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
import org.librecms.dispatcher.ItemResolver;
|
import org.librecms.dispatcher.ItemResolver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.TooManyListenersException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows the user to select an index item to display when the front end user is
|
* Allows the user to select an index item to display when the front end user is
|
||||||
* browsing by Category
|
* browsing by Category
|
||||||
*
|
*
|
||||||
* @author Randy Graebner (randyg@alum.mit.edu)
|
* @author Randy Graebner (randyg@alum.mit.edu)
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a> +
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class IndexItemSelectionForm extends CMSForm {
|
public class IndexItemSelectionForm extends CMSForm {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
IndexItemSelectionForm.class);
|
IndexItemSelectionForm.class);
|
||||||
|
|
||||||
private final CategoryRequestLocal m_category;
|
|
||||||
private RadioGroup m_options;
|
|
||||||
private static final String NULL_OPTION_VALUE = "";
|
private static final String NULL_OPTION_VALUE = "";
|
||||||
private static final String NONE_OPTION_VALUE = "None";
|
private static final String NONE_OPTION_VALUE = "None";
|
||||||
|
|
||||||
private SaveCancelSection m_saveCancelSection;
|
private final CategoryRequestLocal selectedCategory;
|
||||||
|
private RadioGroup optionsGroup;
|
||||||
|
private final SaveCancelSection saveCancelSection;
|
||||||
|
|
||||||
|
public IndexItemSelectionForm(final CategoryRequestLocal selectedCategory) {
|
||||||
|
|
||||||
public IndexItemSelectionForm(CategoryRequestLocal m) {
|
|
||||||
super("EditCategory");
|
super("EditCategory");
|
||||||
|
super.setMethod(Form.POST);
|
||||||
|
|
||||||
|
this.selectedCategory = selectedCategory;
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final ContentSectionManager sectionManager = cdiUtil.findBean(
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
ContentSectionManager.class);
|
.findBean(GlobalizationHelper.class);
|
||||||
final CategoryManager categoryManager = cdiUtil.findBean(
|
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
|
||||||
CategoryManager.class);
|
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final ContentItemManager contentItemManager = cdiUtil.findBean(
|
|
||||||
ContentItemManager.class);
|
|
||||||
final ContentItemRepository contentItemRepository = cdiUtil.findBean(
|
|
||||||
ContentItemRepository.class);
|
|
||||||
|
|
||||||
setMethod(Form.POST);
|
|
||||||
|
|
||||||
m_category = m;
|
|
||||||
|
|
||||||
// Form header
|
// Form header
|
||||||
Label header = new Label(GlobalizationUtil.globalize(
|
final Label header = new Label(messagesUtil
|
||||||
"cms.ui.category.select_index_item"));
|
.getGlobalizedMessage("cms.ui.category.select_index_item"));
|
||||||
header.setFontWeight(Label.BOLD);
|
header.setFontWeight(Label.BOLD);
|
||||||
add(header, ColumnPanel.FULL_WIDTH);
|
super.add(header, ColumnPanel.FULL_WIDTH);
|
||||||
|
|
||||||
// Form errors
|
// Form errors
|
||||||
FormErrorDisplay m_errors = new FormErrorDisplay(this);
|
final FormErrorDisplay errorsDisplay = new FormErrorDisplay(this);
|
||||||
add(m_errors, ColumnPanel.FULL_WIDTH);
|
super.add(errorsDisplay, ColumnPanel.FULL_WIDTH);
|
||||||
|
|
||||||
// Option Group
|
// Option Group
|
||||||
m_options = new RadioGroup(new StringParameter("items"));
|
optionsGroup = new RadioGroup(new StringParameter("items"));
|
||||||
try {
|
try {
|
||||||
m_options.addPrintListener(event -> {
|
optionsGroup.addPrintListener(this::printOptionsGroup);
|
||||||
RadioGroup group = (RadioGroup) event.getTarget();
|
} catch (TooManyListenersException ex) {
|
||||||
PageState state = event.getPageState();
|
LOGGER.error("Error adding init listener to Radio Group", ex);
|
||||||
Category category = getCategory(event.getPageState());
|
throw new UnexpectedErrorException(ex);
|
||||||
java.util.List<Categorization> children = category.getObjects();
|
|
||||||
|
|
||||||
group.clearOptions();
|
|
||||||
|
|
||||||
// option for NO index Object
|
|
||||||
group.addOption(new Option(NONE_OPTION_VALUE,
|
|
||||||
new Label(GlobalizationUtil
|
|
||||||
.globalize(
|
|
||||||
"cms.ui.category.non_option"))));
|
|
||||||
|
|
||||||
// option for inheriting from the parent category
|
|
||||||
if (category.getParentCategory() != null) {
|
|
||||||
group.addOption(new Option(NULL_OPTION_VALUE,
|
|
||||||
new Label(GlobalizationUtil
|
|
||||||
.globalize(
|
|
||||||
"cms.ui.category.inherit_parent"))));
|
|
||||||
}
|
|
||||||
|
|
||||||
final ContentSection section = CMS.getContext()
|
|
||||||
.getContentSection();
|
|
||||||
final ItemResolver itemResolver = sectionManager
|
|
||||||
.getItemResolver(
|
|
||||||
section);
|
|
||||||
for (Categorization child : children) {
|
|
||||||
ContentItem item = (ContentItem) child
|
|
||||||
.getCategorizedObject();
|
|
||||||
Link link = new Link(
|
|
||||||
new Text(item.getDisplayName()),
|
|
||||||
itemResolver.generateItemURL(
|
|
||||||
state,
|
|
||||||
item.getObjectId(),
|
|
||||||
item.getDisplayName(),
|
|
||||||
section,
|
|
||||||
item.getVersion().name()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Component linkComponent = link;
|
|
||||||
//add the option with the link
|
|
||||||
group.addOption(new Option(item.getItemUuid(),
|
|
||||||
linkComponent));
|
|
||||||
}
|
|
||||||
|
|
||||||
// get currently selected item
|
|
||||||
Optional<CcmObject> optionalIndexObject = categoryManager
|
|
||||||
.getIndexObject(category)
|
|
||||||
.stream()
|
|
||||||
.findFirst();
|
|
||||||
if (optionalIndexObject.isPresent()) {
|
|
||||||
ContentItem indexItem = (ContentItem) optionalIndexObject
|
|
||||||
.get();
|
|
||||||
group.setValue(
|
|
||||||
state,
|
|
||||||
contentItemManager.getDraftVersion(indexItem,
|
|
||||||
ContentItem.class)
|
|
||||||
.getItemUuid()
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
String value = category.getParentCategory() != null
|
|
||||||
? NULL_OPTION_VALUE
|
|
||||||
: NONE_OPTION_VALUE;
|
|
||||||
group.setValue(state, value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (java.util.TooManyListenersException e) {
|
|
||||||
LOGGER.error("Error adding init listener to Radio Group", e);
|
|
||||||
throw new UncheckedWrapperException(e);
|
|
||||||
}
|
}
|
||||||
m_options.setLayout(RadioGroup.VERTICAL);
|
optionsGroup.setLayout(RadioGroup.VERTICAL);
|
||||||
add(m_options);
|
super.add(optionsGroup);
|
||||||
|
|
||||||
// Save and cancel buttons
|
// Save and cancel buttons
|
||||||
m_saveCancelSection = new SaveCancelSection();
|
saveCancelSection = new SaveCancelSection();
|
||||||
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||||
|
|
||||||
addSubmissionListener(new FormSecurityListener(
|
super.addSubmissionListener(new FormSecurityListener(
|
||||||
AdminPrivileges.ADMINISTER_CATEGORIES));
|
AdminPrivileges.ADMINISTER_CATEGORIES));
|
||||||
|
|
||||||
// Process listener
|
// Process listener
|
||||||
addProcessListener(event -> {
|
super.addProcessListener(this::process);
|
||||||
PageState state = event.getPageState();
|
}
|
||||||
FormData data = event.getFormData();
|
|
||||||
ParameterData param = data.getParameter(m_options
|
|
||||||
.getParameterModel().getName());
|
|
||||||
String selectedValue = (String) param.getValue();
|
|
||||||
|
|
||||||
Category category
|
private void printOptionsGroup(final PrintEvent event) {
|
||||||
= getCategory(event.getPageState());
|
|
||||||
|
|
||||||
if (selectedValue != null) {
|
final RadioGroup group = (RadioGroup) event.getTarget();
|
||||||
Optional<ContentItem> optionalItem = contentItemRepository
|
final PageState state = event.getPageState();
|
||||||
.findById(Long.parseLong(selectedValue));
|
final Category category = getCategory(event.getPageState());
|
||||||
if (optionalItem.isPresent()) {
|
|
||||||
ContentItem item = contentItemManager.getDraftVersion(
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
optionalItem.get(), ContentItem.class);
|
final CategoryAdminController controller = cdiUtil
|
||||||
try {
|
.findBean(CategoryAdminController.class);
|
||||||
categoryManager.setIndexObject(category, item);
|
final ContentItemManager itemManager = cdiUtil
|
||||||
categoryRepository.save(category);
|
.findBean(ContentItemManager.class);
|
||||||
} catch (ObjectNotAssignedToCategoryException e) {
|
final CategoryManager categoryManager = cdiUtil
|
||||||
throw new FormProcessException(e);
|
.findBean(CategoryManager.class);
|
||||||
}
|
final ContentSectionManager sectionManager = cdiUtil
|
||||||
|
.findBean(ContentSectionManager.class);
|
||||||
|
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||||
|
.findBean(GlobalizationHelper.class);
|
||||||
|
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
|
||||||
|
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
|
||||||
|
|
||||||
|
group.clearOptions();
|
||||||
|
|
||||||
|
// option for NO index Object
|
||||||
|
group.addOption(
|
||||||
|
new Option(NONE_OPTION_VALUE,
|
||||||
|
new Label(messagesUtil
|
||||||
|
.getGlobalizedMessage("cms.ui.category.non_option"))));
|
||||||
|
|
||||||
|
// option for inheriting from the parent category
|
||||||
|
if (category.getParentCategory() != null) {
|
||||||
|
group.addOption(
|
||||||
|
new Option(NULL_OPTION_VALUE,
|
||||||
|
new Label(messagesUtil
|
||||||
|
.getGlobalizedMessage(
|
||||||
|
"cms.ui.category.inherit_parent"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
final ContentSection section = CMS.getContext()
|
||||||
|
.getContentSection();
|
||||||
|
final ItemResolver itemResolver = sectionManager
|
||||||
|
.getItemResolver(section);
|
||||||
|
|
||||||
|
final List<ContentItem> assignedItems = controller
|
||||||
|
.retrieveAssignedContentItems(category);
|
||||||
|
for (final ContentItem item : assignedItems) {
|
||||||
|
|
||||||
|
final Link link = new Link(
|
||||||
|
new Text(item.getDisplayName()),
|
||||||
|
itemResolver.generateItemURL(
|
||||||
|
state,
|
||||||
|
item.getObjectId(),
|
||||||
|
item.getDisplayName(),
|
||||||
|
section,
|
||||||
|
item.getVersion().name()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
//add the option with the link
|
||||||
|
group.addOption(new Option(Long.toString(item.getObjectId()), link));
|
||||||
|
}
|
||||||
|
|
||||||
|
// get currently selected item
|
||||||
|
final Optional<CcmObject> optionalIndexObject = categoryManager
|
||||||
|
.getIndexObject(category)
|
||||||
|
.stream()
|
||||||
|
.findFirst();
|
||||||
|
if (optionalIndexObject.isPresent()) {
|
||||||
|
final ContentItem indexItem
|
||||||
|
= (ContentItem) optionalIndexObject
|
||||||
|
.get();
|
||||||
|
final ContentItem liveItem = itemManager
|
||||||
|
.getLiveVersion(indexItem, ContentItem.class)
|
||||||
|
.get();
|
||||||
|
group.setValue(
|
||||||
|
state,
|
||||||
|
Long.toString(liveItem.getObjectId()));
|
||||||
|
} else {
|
||||||
|
final String value;
|
||||||
|
if (category.getParentCategory() == null) {
|
||||||
|
value = NULL_OPTION_VALUE;
|
||||||
|
} else {
|
||||||
|
value = NONE_OPTION_VALUE;
|
||||||
|
}
|
||||||
|
group.setValue(state, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final ParameterData param = data
|
||||||
|
.getParameter(optionsGroup.getParameterModel().getName());
|
||||||
|
final String selectedValue = (String) param.getValue();
|
||||||
|
|
||||||
|
final Category category = getCategory(event.getPageState());
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CategoryManager categoryManager = cdiUtil
|
||||||
|
.findBean(CategoryManager.class);
|
||||||
|
final CategoryRepository categoryRepository = cdiUtil
|
||||||
|
.findBean(CategoryRepository.class);
|
||||||
|
final ContentItemManager contentItemManager = cdiUtil
|
||||||
|
.findBean(ContentItemManager.class);
|
||||||
|
final ContentItemRepository contentItemRepository = cdiUtil
|
||||||
|
.findBean(ContentItemRepository.class);
|
||||||
|
|
||||||
|
if (selectedValue != null) {
|
||||||
|
final Optional<ContentItem> optionalItem = contentItemRepository
|
||||||
|
.findById(Long.parseLong(selectedValue));
|
||||||
|
if (optionalItem.isPresent()) {
|
||||||
|
final ContentItem item = contentItemManager
|
||||||
|
.getLiveVersion(optionalItem.get(),
|
||||||
|
ContentItem.class)
|
||||||
|
.get();
|
||||||
|
try {
|
||||||
|
categoryManager.setIndexObject(category, item);
|
||||||
|
categoryRepository.save(category);
|
||||||
|
} catch (ObjectNotAssignedToCategoryException ex) {
|
||||||
|
throw new FormProcessException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -212,7 +261,7 @@ public class IndexItemSelectionForm extends CMSForm {
|
||||||
* @return The cancel button
|
* @return The cancel button
|
||||||
*/
|
*/
|
||||||
protected Submit getCancelButton() {
|
protected Submit getCancelButton() {
|
||||||
return m_saveCancelSection.getCancelButton();
|
return saveCancelSection.getCancelButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,9 +273,8 @@ public class IndexItemSelectionForm extends CMSForm {
|
||||||
*
|
*
|
||||||
* @pre ( state != null )
|
* @pre ( state != null )
|
||||||
*/
|
*/
|
||||||
protected Category getCategory(PageState state) {
|
protected Category getCategory(final PageState state) {
|
||||||
Category category = m_category.getCategory(state);
|
return selectedCategory.getCategory(state);
|
||||||
return category;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,66 +23,113 @@ import com.arsdigita.bebop.List;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
import com.arsdigita.bebop.event.ActionEvent;
|
import com.arsdigita.bebop.event.ActionEvent;
|
||||||
import com.arsdigita.bebop.event.ActionListener;
|
|
||||||
import com.arsdigita.bebop.list.ListModel;
|
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.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.categorization.CategoryManager;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A List of all subcategories of the current category.
|
* A List of all subcategories of the current category.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
*
|
||||||
* @author Stanislav Freidin (stas@arsdigita.com)
|
* @author Stanislav Freidin (stas@arsdigita.com)
|
||||||
* @author Michael Pih (pihman@arsdigita.com)
|
* @author Michael Pih (pihman@arsdigita.com)
|
||||||
* @version $Revision: #15 $ $DateTime: 2004/08/17 23:15:09 $
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class SubcategoryList extends SortableCategoryList {
|
public class SubcategoryList extends SortableCategoryList {
|
||||||
private final CategoryRequestLocal m_parent;
|
|
||||||
private final SingleSelectionModel m_model;
|
|
||||||
|
|
||||||
public SubcategoryList(final CategoryRequestLocal parent,
|
private final CategoryRequestLocal parentCategory;
|
||||||
final SingleSelectionModel model) {
|
private final SingleSelectionModel<String> selectedCategoryId;
|
||||||
super(parent);
|
|
||||||
|
|
||||||
m_parent = parent;
|
public SubcategoryList(
|
||||||
m_model = model;
|
final CategoryRequestLocal parentCategory,
|
||||||
|
final SingleSelectionModel<String> selectedCategoryId) {
|
||||||
|
|
||||||
setIdAttr("subcategories_list");
|
super(parentCategory);
|
||||||
|
|
||||||
|
this.parentCategory = parentCategory;
|
||||||
|
this.selectedCategoryId = selectedCategoryId;
|
||||||
|
|
||||||
|
super.setIdAttr("subcategories_list");
|
||||||
|
|
||||||
setModelBuilder(new SubcategoryModelBuilder());
|
setModelBuilder(new SubcategoryModelBuilder());
|
||||||
|
|
||||||
// Select the category in the main tree when the
|
// Select the category in the main tree when the
|
||||||
// user selects it here
|
// user selects it here
|
||||||
addActionListener(new ActionListener() {
|
super.addActionListener(this::actionPerformed);
|
||||||
public void actionPerformed(ActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
final String id = (String) getSelectedKey(state);
|
|
||||||
|
|
||||||
if (id != null) {
|
Label label = new Label(GlobalizationUtil.globalize(
|
||||||
m_model.setSelectedKey(state, id);
|
"cms.ui.category.subcategory.none"));
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Label label = new Label(GlobalizationUtil.globalize
|
|
||||||
("cms.ui.category.subcategory.none"));
|
|
||||||
label.setFontWeight(Label.ITALIC);
|
label.setFontWeight(Label.ITALIC);
|
||||||
setEmptyView(label);
|
setEmptyView(label);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SubcategoryModelBuilder extends LockableImpl
|
/**
|
||||||
implements ListModelBuilder {
|
* Select the category in the main tree when the user selects it here
|
||||||
public ListModel makeModel(List list, PageState state) {
|
*
|
||||||
final Category category = m_parent.getCategory(state);
|
* @param event
|
||||||
|
*/
|
||||||
|
private void actionPerformed(final ActionEvent event) {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final String categoryId = (String) getSelectedKey(state);
|
||||||
|
|
||||||
|
if (categoryId != null) {
|
||||||
|
selectedCategoryId.setSelectedKey(state, categoryId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ListModel makeMake(final List list, final PageState state) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CategoryManager categoryManager = cdiUtil
|
||||||
|
.findBean(CategoryManager.class);
|
||||||
|
final Category category = parentCategory.getCategory(state);
|
||||||
|
|
||||||
|
if (category != null
|
||||||
|
&& categoryManager.hasSubCategories(category)) {
|
||||||
|
|
||||||
|
final CategoryAdminController controller = cdiUtil.findBean(
|
||||||
|
CategoryAdminController.class);
|
||||||
|
final java.util.List<CategoryListItem> children = controller
|
||||||
|
.generateSubCategoryList(category);
|
||||||
|
|
||||||
|
return new CategoryListModel(children);
|
||||||
|
} else {
|
||||||
|
return List.EMPTY_MODEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SubcategoryModelBuilder extends LockableImpl
|
||||||
|
implements ListModelBuilder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListModel makeModel(final List list, final PageState state) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final CategoryManager categoryManager = cdiUtil
|
||||||
|
.findBean(CategoryManager.class);
|
||||||
|
final Category category = parentCategory.getCategory(state);
|
||||||
|
|
||||||
|
if (category != null
|
||||||
|
&& categoryManager.hasSubCategories(category)) {
|
||||||
|
|
||||||
|
final CategoryAdminController controller = cdiUtil.findBean(
|
||||||
|
CategoryAdminController.class);
|
||||||
|
final java.util.List<CategoryListItem> children = controller
|
||||||
|
.generateSubCategoryList(category);
|
||||||
|
|
||||||
if (category != null && !category.getSubCategories().isEmpty()) {
|
|
||||||
java.util.List<Category> children = category.getSubCategories();
|
|
||||||
return new CategoryListModel(children);
|
return new CategoryListModel(children);
|
||||||
} else {
|
} else {
|
||||||
return List.EMPTY_MODEL;
|
return List.EMPTY_MODEL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue