CCM NG: Content Center Category Tab
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5161 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
85991a3151
commit
8ddfede706
|
|
@ -34,6 +34,7 @@ import com.arsdigita.bebop.event.ChangeListener;
|
|||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ui.BaseAdminPane;
|
||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
||||
import com.arsdigita.cms.ui.BaseTree;
|
||||
|
|
@ -47,13 +48,13 @@ import org.apache.logging.log4j.Logger;
|
|||
import org.libreccm.categorization.Categorization;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.categorization.DomainOwnership;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.libreccm.security.PermissionChecker;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A split pane for the Category Administration UI.
|
||||
*
|
||||
|
|
@ -78,8 +79,8 @@ public final class CategoryAdminPane extends BaseAdminPane {
|
|||
m_contextModel = new UseContextSelectionModel(new StringParameter(
|
||||
CONTEXT_SELECTED));
|
||||
|
||||
/* Left column */
|
||||
/* Use context section */
|
||||
// Left column
|
||||
// Use context section
|
||||
List list = new List(new CategoryUseContextModelBuilder());
|
||||
list.setSelectionModel(m_contextModel);
|
||||
list.addChangeListener(new ContextSelectionListener());
|
||||
|
|
@ -303,9 +304,12 @@ public final class CategoryAdminPane extends BaseAdminPane {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object getSelectedKey(PageState state) {
|
||||
public Object getSelectedKey(final PageState state) {
|
||||
|
||||
Object val = super.getSelectedKey(state);
|
||||
if (val == null || ((String) val).length() == 0) {
|
||||
if (val == null
|
||||
|| ((CharSequence) val).length() == 0) {
|
||||
|
||||
val = DEFAULT_USE_CONTEXT;
|
||||
state.setValue(getStateParameter(), val);
|
||||
fireStateChanged(state);
|
||||
|
|
@ -315,14 +319,22 @@ public final class CategoryAdminPane extends BaseAdminPane {
|
|||
|
||||
}
|
||||
|
||||
public String getUseContext(PageState state) {
|
||||
public String getUseContext(final PageState state) {
|
||||
|
||||
String selected = (String) m_contextModel.getSelectedKey(state);
|
||||
return (DEFAULT_USE_CONTEXT).equals(selected) ? (String) null : selected;
|
||||
if (DEFAULT_USE_CONTEXT.equals(selected)) {
|
||||
return null;
|
||||
} else {
|
||||
return selected;
|
||||
}
|
||||
// return (DEFAULT_USE_CONTEXT).equals(selected) ? (String) null : selected;
|
||||
}
|
||||
|
||||
public class ContextSelectionListener implements ChangeListener {
|
||||
private class ContextSelectionListener implements ChangeListener {
|
||||
|
||||
@Override
|
||||
public final void stateChanged(final ChangeEvent event) {
|
||||
|
||||
LOGGER.debug("Selection state changed; I may change "
|
||||
+ "the body's visible pane");
|
||||
|
||||
|
|
@ -337,12 +349,26 @@ public final class CategoryAdminPane extends BaseAdminPane {
|
|||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
final Category root = categoryRepo
|
||||
final Category root;
|
||||
if (DEFAULT_USE_CONTEXT.equals(rootCategoryId)) {
|
||||
final ContentSection section = CMS
|
||||
.getContext()
|
||||
.getContentSection();
|
||||
|
||||
final CategoryAdminController controller = CdiUtil
|
||||
.createCdiUtil()
|
||||
.findBean(CategoryAdminController.class);
|
||||
final java.util.List<DomainOwnership> ownerships
|
||||
= controller
|
||||
.retrieveDomains(section);
|
||||
root = ownerships.get(0).getDomain().getRoot();
|
||||
} else {
|
||||
root = categoryRepo
|
||||
.findById(Long.parseLong(rootCategoryId))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
rootCategoryId)));
|
||||
|
||||
}
|
||||
if (root != null) {
|
||||
m_model.setSelectedKey(state, root.getUniqueId());
|
||||
m_categoryTree.reset(state);
|
||||
|
|
|
|||
|
|
@ -23,9 +23,16 @@ import com.arsdigita.bebop.SingleSelectionModel;
|
|||
import com.arsdigita.bebop.Tree;
|
||||
import com.arsdigita.bebop.tree.TreeModel;
|
||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.categorization.CategoryRepository;
|
||||
import org.libreccm.categorization.CategoryTreeModelLite;
|
||||
import org.libreccm.categorization.DomainOwnership;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
|
||||
/**
|
||||
* Lists category tree.
|
||||
|
|
@ -49,22 +56,34 @@ class CategoryTreeModelBuilder extends LockableImpl
|
|||
m_contextModel = contextModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final TreeModel makeModel(final Tree tree, final PageState state) {
|
||||
final Category category = (Category) m_contextModel.getSelectedKey(state);
|
||||
|
||||
final CategoryTreeModelLite model = new CategoryTreeModelLite(category);
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final Category root;
|
||||
if (DEFAULT_USE_CONTEXT.equals(m_contextModel.getSelectedKey(state))) {
|
||||
final ContentSection section = CMS
|
||||
.getContext()
|
||||
.getContentSection();
|
||||
|
||||
return model;
|
||||
final CategoryAdminController controller = cdiUtil
|
||||
.findBean(CategoryAdminController.class);
|
||||
final java.util.List<DomainOwnership> ownerships
|
||||
= controller
|
||||
.retrieveDomains(section);
|
||||
root = ownerships.get(0).getDomain().getRoot();
|
||||
} else {
|
||||
final CategoryRepository categoryRepo = cdiUtil
|
||||
.findBean(CategoryRepository.class);
|
||||
root = categoryRepo
|
||||
.findById(Long.parseLong((String) m_contextModel
|
||||
.getSelectedKey(state)))
|
||||
.orElseThrow(() -> new UnexpectedErrorException(String
|
||||
.format("No Category with ID %s in the database.",
|
||||
m_contextModel.getSelectedKey(state))));
|
||||
}
|
||||
|
||||
private String getUseContext(PageState state) {
|
||||
String context = null;
|
||||
if (m_contextModel != null) {
|
||||
context = (String) m_contextModel.getSelectedKey(state);
|
||||
if ((DEFAULT_USE_CONTEXT).equals(context)) {
|
||||
context = null;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
return new CategoryTreeModelLite(root);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,49 +18,52 @@
|
|||
*/
|
||||
package org.libreccm.categorization;
|
||||
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.tree.TreeModel;
|
||||
import com.arsdigita.bebop.tree.TreeNode;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Implements the {@link com.arsdigita.bebop.tree.TreeModel} interface for
|
||||
* categories.
|
||||
*
|
||||
* @author Daniel Berrange
|
||||
* @version $Revision: #17 $ $DateTime: 2004/08/16 18:10:38 $
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter </a>
|
||||
*/
|
||||
public class CategoryTreeModelLite implements TreeModel {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CategoryTreeModelLite.class);
|
||||
// String m_order = null;
|
||||
final Category category;
|
||||
private final Category root;
|
||||
|
||||
/**
|
||||
* Initializes with the passed in the root Category.
|
||||
* Initialises with the passed in the root Category.
|
||||
*
|
||||
* @param root the root category for this TreeModel
|
||||
*/
|
||||
// public CategoryTreeModelLite(Category root) {
|
||||
// this(root, null);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Initializes with the passed in the root Category.
|
||||
*
|
||||
* @param root the root category for this TreeModel
|
||||
*/
|
||||
public CategoryTreeModelLite(Category root) {
|
||||
public CategoryTreeModelLite(final Category root) {
|
||||
// super(root.getUniqueId(),
|
||||
// "com.arsdigita.categorization.getRootCategory",
|
||||
// "com.arsdigita.categorization.getSubCategories");
|
||||
// m_order = order;
|
||||
category = root;
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
|
@ -68,20 +71,82 @@ public class CategoryTreeModelLite implements TreeModel {
|
|||
// String getSubCategories) {
|
||||
// return new CategoryTreeIterator(node, getSubCategories, m_order);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public TreeNode getRoot(PageState data) {
|
||||
return null;
|
||||
public TreeNode getRoot(final PageState data) {
|
||||
return new CategoryTreeNode(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(TreeNode n, PageState data) {
|
||||
return false;
|
||||
public boolean hasChildren(final TreeNode node,
|
||||
final PageState state) {
|
||||
|
||||
Objects.requireNonNull(node);
|
||||
if (node.getKey() == null
|
||||
|| !(node.getKey() instanceof Long)) {
|
||||
throw new IllegalArgumentException(
|
||||
"The key of the provided TreeNode is null or not a Long.");
|
||||
}
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryTreeModelLiteController controller = cdiUtil
|
||||
.findBean(CategoryTreeModelLiteController.class);
|
||||
|
||||
return controller.hasSubCategories((long) node.getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<TreeNode> getChildren(TreeNode n, PageState data) {
|
||||
return null;
|
||||
public Iterator<TreeNode> getChildren(final TreeNode node,
|
||||
final PageState state) {
|
||||
|
||||
Objects.requireNonNull(node);
|
||||
if (node.getKey() == null
|
||||
|| !(node.getKey() instanceof Long)) {
|
||||
throw new IllegalArgumentException(
|
||||
"The key of the provided TreeNode is null or not a Long.");
|
||||
}
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CategoryTreeModelLiteController controller = cdiUtil
|
||||
.findBean(CategoryTreeModelLiteController.class);
|
||||
|
||||
return controller
|
||||
.findSubCategories((long) node.getKey())
|
||||
.stream()
|
||||
.map(this::buildTreeNode)
|
||||
.iterator();
|
||||
}
|
||||
|
||||
private TreeNode buildTreeNode(final Category category) {
|
||||
return new CategoryTreeNode(category);
|
||||
}
|
||||
|
||||
private class CategoryTreeNode implements TreeNode {
|
||||
|
||||
private final Category category;
|
||||
|
||||
public CategoryTreeNode(final Category category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKey() {
|
||||
return category.getObjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElement() {
|
||||
|
||||
if (category.getTitle().getValues().isEmpty()) {
|
||||
return category.getName();
|
||||
} else {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
.findBean(GlobalizationHelper.class);
|
||||
return globalizationHelper
|
||||
.getValueFromLocalizedString(category.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// private static class CategoryTreeIterator extends DataQueryTreeIterator {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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 org.libreccm.categorization;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class CategoryTreeModelLiteController {
|
||||
|
||||
@Inject
|
||||
private CategoryManager categoryManager;
|
||||
|
||||
@Inject
|
||||
private CategoryRepository categoryRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected boolean hasSubCategories(final long categoryId) {
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(categoryId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Category with ID %d in the database.",
|
||||
categoryId)));
|
||||
|
||||
return categoryManager.hasSubCategories(category);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
protected List<Category> findSubCategories(final long categoryId) {
|
||||
|
||||
final Category category = categoryRepo
|
||||
.findById(categoryId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Category with ID %d in the database.",
|
||||
categoryId)));
|
||||
|
||||
return new ArrayList<>(category.getSubCategories());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue