CCM NG: Category Tab in Content Center now basically works (#2731).

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5213 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2018-01-23 11:12:39 +00:00
parent 28a80b751a
commit 4bcee8e0b0
16 changed files with 732 additions and 313 deletions

View File

@ -18,6 +18,7 @@
*/ */
package com.arsdigita.cms.ui.category; package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
@ -48,19 +49,10 @@ import java.util.Collection;
* @author Stanislav Freidin <sfreidin@redhat.com> * @author Stanislav Freidin <sfreidin@redhat.com>
* @author Justin Ross <jross@redhat.com> * @author Justin Ross <jross@redhat.com>
* @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>
*/ */
class BaseCategoryForm extends BaseForm { class BaseCategoryForm extends BaseForm {
final CategoryRequestLocal m_parent;
final TextField m_name;
final TextArea m_description;
final RadioGroup m_isAbstract;
final RadioGroup m_isVisible;
final RadioGroup m_isEnabled;
private Label m_script = new Label(new GlobalizedMessage(String.format(
"<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\"></script>",
Web.getWebappContextPath())),
false);
private final static String NAME = "name"; private final static String NAME = "name";
private final static String DESCRIPTION = "description"; private final static String DESCRIPTION = "description";
private final static String URL = "url"; private final static String URL = "url";
@ -68,64 +60,116 @@ class BaseCategoryForm extends BaseForm {
private final static String IS_VISIBLE = "isVisible"; private final static String IS_VISIBLE = "isVisible";
private final static String IS_ENABLED = "isEnabled"; private final static String IS_ENABLED = "isEnabled";
private final CategoryRequestLocal categoryRequestLocal;
private final TextField nameField;
private final TextArea descriptionArea;
private final RadioGroup isAbstractRadioGroup;
private final RadioGroup isVisibleRadioGroup;
private final RadioGroup isEnabledRadioGroup;
private Label script = new Label(new GlobalizedMessage(String
.format("<script src=\"%s/javascript/manipulate-input.js\"></script>",
Web.getWebappContextPath())),
false);
/** /**
* Constructor. * Constructor.
*/ */
BaseCategoryForm(final String key, protected BaseCategoryForm(final String key,
final GlobalizedMessage heading, final GlobalizedMessage heading,
final CategoryRequestLocal parent) { final CategoryRequestLocal parent) {
super(key, heading); super(key, heading);
m_parent = parent; categoryRequestLocal = parent;
m_name = new TextField(new TrimmedStringParameter(NAME)); nameField = new TextField(new TrimmedStringParameter(NAME));
addField(gz("cms.ui.name"), m_name); addField(gz("cms.ui.name"), nameField);
m_name.setSize(30); nameField.setSize(30);
m_name.setMaxLength(200); nameField.setMaxLength(200);
m_name.addValidationListener(new NotNullValidationListener()); nameField.addValidationListener(new NotNullValidationListener());
m_name.setOnFocus("if (this.form." + URL + ".value == '') { " nameField.setOnFocus(String.format(
+ " defaulting = true; this.form." + URL ""
+ ".value = urlize(this.value); }"); + "if (this.form.%1$s.value == '') {"
m_name.setOnKeyUp("if (defaulting) { this.form." + URL + " defaulting = true;"
+ ".value = urlize(this.value) }"); + " this.form.%1$s.value = urlize(this.value);"
+ "}",
URL));
nameField.setOnFocus(String.format(
""
+ "if (defaulting) {"
+ " this.form.%1$s.value = urlize(this.value)"
+ "}",
URL
));
// is abstract? // is abstract?
m_isAbstract = new RadioGroup(IS_ABSTRACT); isAbstractRadioGroup = new RadioGroup(IS_ABSTRACT);
m_isAbstract.addOption(new Option("no", new Label(gz("cms.ui.no")))); isAbstractRadioGroup.addOption(new Option("no", new Label(
m_isAbstract.addOption(new Option("yes", new Label(gz("cms.ui.yes")))); gz("cms.ui.no"))));
addField(gz("cms.ui.category.is_not_abstract"), m_isAbstract); isAbstractRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_not_abstract"), isAbstractRadioGroup);
// is visible // is visible
m_isVisible = new RadioGroup(IS_VISIBLE); isVisibleRadioGroup = new RadioGroup(IS_VISIBLE);
m_isVisible.addOption(new Option("no", new Label(gz("cms.ui.no")))); isVisibleRadioGroup.addOption(new Option("no",
m_isVisible.addOption(new Option("yes", new Label(gz("cms.ui.yes")))); new Label(gz("cms.ui.no"))));
addField(gz("cms.ui.category.is_visible"), m_isVisible); isVisibleRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_visible"), isVisibleRadioGroup);
// is enabled? // is enabled?
m_isEnabled = new RadioGroup(IS_ENABLED); isEnabledRadioGroup = new RadioGroup(IS_ENABLED);
m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no")))); isEnabledRadioGroup.addOption(new Option("no",
m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes")))); new Label(gz("cms.ui.no"))));
addField(gz("cms.ui.category.is_enabled"), m_isEnabled); isEnabledRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_enabled"), isEnabledRadioGroup);
m_description = new TextArea(new TrimmedStringParameter(DESCRIPTION)); descriptionArea = new TextArea(new TrimmedStringParameter(DESCRIPTION));
addField(gz("cms.ui.description"), m_description); addField(gz("cms.ui.description"), descriptionArea);
m_description.setWrap(TextArea.SOFT); descriptionArea.setWrap(TextArea.SOFT);
m_description.setRows(5); descriptionArea.setRows(5);
m_description.setCols(40); descriptionArea.setCols(40);
addAction(new Finish()); addAction(new Finish());
addAction(new Cancel()); addAction(new Cancel());
} }
protected CategoryRequestLocal getCategoryRequestLocal() {
return categoryRequestLocal;
}
protected TextField getNameField() {
return nameField;
}
protected TextArea getDescriptionArea() {
return descriptionArea;
}
protected RadioGroup getIsAbstractRadioGroup() {
return isAbstractRadioGroup;
}
protected RadioGroup getIsVisibleRadioGroup() {
return isVisibleRadioGroup;
}
protected RadioGroup getIsEnabledRadioGroup() {
return isEnabledRadioGroup;
}
@Override @Override
public void generateXML(PageState ps, Element parent) { public void generateXML(PageState ps, Element parent) {
m_script.generateXML(ps, parent); script.generateXML(ps, parent);
super.generateXML(ps, parent); super.generateXML(ps, parent);
} }
class NameUniqueListener implements ParameterListener { private class NameUniqueListener implements ParameterListener {
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
private final Widget m_widget; private final Widget m_widget;
@ -133,7 +177,7 @@ class BaseCategoryForm extends BaseForm {
final static int NAME_FIELD = 1; final static int NAME_FIELD = 1;
NameUniqueListener(final CategoryRequestLocal category) { NameUniqueListener(final CategoryRequestLocal category) {
this(category, m_name, NAME_FIELD); this(category, nameField, NAME_FIELD);
} }
NameUniqueListener(final CategoryRequestLocal category, NameUniqueListener(final CategoryRequestLocal category,
@ -149,7 +193,7 @@ class BaseCategoryForm extends BaseForm {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
final String title = (String) m_widget.getValue(state); final String title = (String) m_widget.getValue(state);
final Category parent = m_parent.getCategory(state); final Category parent = categoryRequestLocal.getCategory(state);
final Collection<Category> children = parent.getSubCategories(); final Collection<Category> children = parent.getSubCategories();

View File

@ -24,97 +24,94 @@ import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.dispatcher.AccessDeniedException; import com.arsdigita.dispatcher.AccessDeniedException;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
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.Category; import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AdminPrivileges;
/** /**
* TODO Needs a description. * TODO Needs a description.
* *
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross &lt;jross@redhat.com&gt;
* @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>
*/ */
final class CategoryAddForm extends BaseCategoryForm { final class CategoryAddForm extends BaseCategoryForm {
private static final Logger LOGGER = LogManager.getLogger private static final Logger LOGGER = LogManager.getLogger(
(CategoryAddForm.class); CategoryAddForm.class);
private final SingleSelectionModel m_model; private final SingleSelectionModel<String> categorySelectionModel;
/** /**
* Constructor. * Constructor.
*/ */
public CategoryAddForm(final CategoryRequestLocal parent, public CategoryAddForm(final CategoryRequestLocal parent,
final SingleSelectionModel model) { final SingleSelectionModel<String> model) {
super("AddSubcategories", gz("cms.ui.category.add"), parent); super("AddSubcategories", gz("cms.ui.category.add"), parent);
m_model = model; categorySelectionModel = model;
addProcessListener(new ProcessListener()); addProcessListener(new ProcessListener());
} }
private final class ProcessListener implements FormProcessListener { private final class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e) @Override
public final void process(final FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
LOGGER.debug("Adding a category"); LOGGER.debug("Adding a category");
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class); final PermissionChecker permissionChecker = cdiUtil
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class); .findBean(PermissionChecker.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); final CategoryController controller = cdiUtil
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class); .findBean(CategoryController.class);
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
final PageState state = e.getPageState(); final PageState state = event.getPageState();
final Category parent = m_parent.getCategory(state); final Category parent = getCategoryRequestLocal()
final String name = (String) m_name.getValue(state); .getCategory(state);
final String description = (String) m_description.getValue(state); final String name = (String) getNameField().getValue(state);
final String isAbstract = (String) m_isAbstract.getValue(state); final String description = (String) getDescriptionArea()
.getValue(state);
// this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the
// category is not abstract
final boolean isAbstract = !"yes"
.equals(getIsAbstractRadioGroup().getValue(state));
Assert.exists(parent, "Category parent"); Assert.exists(parent, "Category parent");
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using parent category " + parent + " to " + LOGGER.debug("Using parent category " + parent + " to "
"create new category"); + "create new category");
} }
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) { if (permissionChecker
final Category category = new Category(); .isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) {
category.setName(name);
final LocalizedString localizedDescription = new LocalizedString();
localizedDescription.addValue(config.getDefaultLocale(), description);
category.setDescription(localizedDescription);
// this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the
// category is not abstract
if ("yes".equals(isAbstract)) {
category.setAbstractCategory(false);
} else if ("no".equals(isAbstract)) {
category.setAbstractCategory(true);
}
categoryRepository.save(category); final Category category = controller.createCategory(parent,
name,
description,
isAbstract);
categoryManager.addSubCategoryToCategory(category, parent); categorySelectionModel.setSelectedKey(state,
category.getUniqueId());
m_model.setSelectedKey(state, category.getUniqueId());
} else { } else {
// XXX user a better exception here. // XXX user a better exception here.
// PermissionException doesn't work for this case. // PermissionException doesn't work for this case.
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
} }
} }
} }

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2018 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 com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import java.util.Objects;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
* Service methods for the Category Admin Tab in the Content Center.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoryController {
@Inject
private CategoryManager categoryManager;
@Inject
private CategoryRepository categoryRepo;
@Inject
private ConfigurationManager confManager;
/**
* Creates a new category.
*
* @param parentCategory The parent category of the new category.
* @param name The name of the new category (URL fragment).
* @param description A description of the new category-
* @param isAbstract Is the new category abstract?
* @return The new category.
*/
@Transactional(Transactional.TxType.REQUIRED)
protected Category createCategory(final Category parentCategory,
final String name,
final String description,
final boolean isAbstract) {
Objects.requireNonNull(parentCategory);
Objects.requireNonNull(name);
if (name.isEmpty() || name.matches("\\s*")) {
throw new IllegalArgumentException(
"The name of a category can't be empty.");
}
final KernelConfig kernelConfig = confManager
.findConfiguration(KernelConfig.class);
final Category category = new Category();
category.setName(name);
final LocalizedString localizedDescription = new LocalizedString();
localizedDescription.addValue(kernelConfig.getDefaultLocale(),
description);
category.setDescription(localizedDescription);
category.setAbstractCategory(isAbstract);
categoryRepo.save(category);
categoryManager.addSubCategoryToCategory(category, parentCategory);
return category;
}
@Transactional(Transactional.TxType.REQUIRED)
protected Optional<Category> getParentCategory(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 database.",
forCategory.getObjectId())));
if (category.getParentCategory() == null) {
return Optional.empty();
} else {
return categoryRepo
.findById(category.getParentCategory().getObjectId());
}
}
}

View File

@ -32,6 +32,7 @@ import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository; import org.libreccm.categorization.CategoryRepository;
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.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AdminPrivileges;
@ -49,52 +50,57 @@ final class CategoryEditForm extends BaseCategoryForm {
private static final String NO = "no"; private static final String NO = "no";
private static final String YES = "yes"; private static final String YES = "yes";
private final CategoryRequestLocal m_category;
private final CategoryRequestLocal selectedCategory;
public CategoryEditForm(final CategoryRequestLocal parent, public CategoryEditForm(final CategoryRequestLocal parent,
final CategoryRequestLocal category) { final CategoryRequestLocal selectedCategory) {
super("EditCategory", gz("cms.ui.category.edit"), parent); super("EditCategory", gz("cms.ui.category.edit"), parent);
m_category = category; this.selectedCategory = selectedCategory;
addInitListener(new InitListener()); super.addInitListener(new InitListener());
addProcessListener(new ProcessListener()); super.addProcessListener(new ProcessListener());
} }
private class InitListener implements FormInitListener { private class InitListener implements FormInitListener {
@Override @Override
public final void init(final FormSectionEvent e) public final void init(final FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
// Quasimodo: final PageState state = event.getPageState();
// Modified to ensure that the value is read from Category (and not the final Category category = selectedCategory.getCategory(state);
// localized version). This is necessary because we are in the admin GUI,
// a localized version would be confusing. final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
m_name.setValue(state, category.getName()); final GlobalizationHelper globalizationHelper = cdiUtil
m_description.setValue(state, category.getDescription()); .findBean(GlobalizationHelper.class);
//m_url.setValue(state, category.getURL(""));
getNameField().setValue(state, category.getName());
final LocalizedString description = category.getDescription();
getDescriptionArea()
.setValue(state,
globalizationHelper
.getValueFromLocalizedString(description));
// this seems anti-intuitive but the question is "can you place // this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the // items in this category. If the user says "yes" then the
// category is not abstract // category is not abstract
if (category.isAbstractCategory()) { if (category.isAbstractCategory()) {
m_isAbstract.setValue(state, NO); getIsAbstractRadioGroup().setValue(state, NO);
} else { } else {
m_isAbstract.setValue(state, YES); getIsAbstractRadioGroup().setValue(state, YES);
} }
if (category.isVisible()) { if (category.isVisible()) {
m_isVisible.setValue(state, YES); getIsVisibleRadioGroup().setValue(state, YES);
} else { } else {
m_isVisible.setValue(state, NO); getIsVisibleRadioGroup().setValue(state, NO);
} }
if (category.isEnabled()) { if (category.isEnabled()) {
m_isEnabled.setValue(state, YES); getIsEnabledRadioGroup().setValue(state, YES);
} else { } else {
m_isEnabled.setValue(state, NO); getIsEnabledRadioGroup().setValue(state, NO);
} }
} }
@ -103,8 +109,9 @@ final class CategoryEditForm extends BaseCategoryForm {
private class ProcessListener implements FormProcessListener { private class ProcessListener implements FormProcessListener {
@Override @Override
public final void process(final FormSectionEvent e) public final void process(final FormSectionEvent event)
throws FormProcessException { throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean( final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class); PermissionChecker.class);
@ -115,20 +122,21 @@ final class CategoryEditForm extends BaseCategoryForm {
final CategoryRepository categoryRepository = cdiUtil.findBean( final CategoryRepository categoryRepository = cdiUtil.findBean(
CategoryRepository.class); CategoryRepository.class);
final PageState state = e.getPageState(); final PageState state = event.getPageState();
final Category category = m_category.getCategory(state); final Category category = selectedCategory.getCategory(state);
if (permissionChecker.isPermitted( if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, category)) { AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
category.setName((String) m_name.getValue(state)); category.setName((String) getNameField().getValue(state));
final LocalizedString localizedDescription final LocalizedString localizedDescription
= new LocalizedString(); = new LocalizedString();
localizedDescription.addValue(config.getDefaultLocale(), localizedDescription
(String) m_description.getValue( .addValue(config.getDefaultLocale(),
state)); (String) getDescriptionArea().getValue(state));
category.setDescription(localizedDescription); category.setDescription(localizedDescription);
final String isAbstract = (String) m_isAbstract.getValue(state); final String isAbstract = (String) getIsAbstractRadioGroup()
.getValue(state);
// this seems anti-intuitive but the question is "can you place // this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the // items in this category. If the user says "yes" then the
// category is not abstract // category is not abstract
@ -138,14 +146,16 @@ final class CategoryEditForm extends BaseCategoryForm {
category.setAbstractCategory(true); category.setAbstractCategory(true);
} }
final String isVisible = (String) m_isVisible.getValue(state); final String isVisible = (String) getIsVisibleRadioGroup()
.getValue(state);
if (YES.equals(isVisible)) { if (YES.equals(isVisible)) {
category.setVisible(true); category.setVisible(true);
} else { } else {
category.setVisible(false); category.setVisible(false);
} }
final String isEnabled = (String) m_isEnabled.getValue(state); final String isEnabled = (String) getIsEnabledRadioGroup()
.getValue(state);
if (YES.equals(isEnabled)) { if (YES.equals(isEnabled)) {
category.setEnabled(true); category.setEnabled(true);
} else if (NO.equals(isEnabled)) { } else if (NO.equals(isEnabled)) {
@ -153,6 +163,7 @@ final class CategoryEditForm extends BaseCategoryForm {
} }
categoryRepository.save(category); categoryRepository.save(category);
} else { } else {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }

View File

@ -315,10 +315,12 @@ class CategoryItemPane extends BaseItemPane {
final String itemTitle; final String itemTitle;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
if (category == null) { if (category == null) {
itemTitle = "None"; itemTitle = "None";
} else { } else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class); .findBean(CategoryManager.class);
final List<CcmObject> indexObjects = categoryManager final List<CcmObject> indexObjects = categoryManager
@ -331,8 +333,6 @@ class CategoryItemPane extends BaseItemPane {
.findFirst(); .findFirst();
if (indexItem.isPresent()) { if (indexItem.isPresent()) {
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final ContentItem item = indexItem.get(); final ContentItem item = indexItem.get();
itemTitle = globalizationHelper itemTitle = globalizationHelper
@ -349,8 +349,10 @@ class CategoryItemPane extends BaseItemPane {
properties.add(new Property(gz("cms.ui.name"), properties.add(new Property(gz("cms.ui.name"),
category.getName())); category.getName()));
properties.add(new Property(gz("cms.ui.description"), properties.add(new Property(
category.getDescription().getValue())); gz("cms.ui.description"),
globalizationHelper
.getValueFromLocalizedString(category.getDescription())));
properties.add(new Property( properties.add(new Property(
gz("cms.ui.category.is_not_abstract"), gz("cms.ui.category.is_not_abstract"),
category.isAbstractCategory() category.isAbstractCategory()
@ -443,10 +445,15 @@ class CategoryItemPane extends BaseItemPane {
public final boolean isVisible(final PageState state) { public final boolean isVisible(final PageState state) {
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
if (category.getParentCategory() == null) { final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
return false; final CategoryController controller = cdiUtil
.findBean(CategoryController.class);
final Optional<Category> parentCategory = controller
.getParentCategory(category);
if (parentCategory.isPresent()) {
return parentCategory.get().isVisible();
} else { } else {
return category.getParentCategory().isVisible(); return false;
} }
} }

View File

@ -29,11 +29,13 @@ import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder; 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.globalization.GlobalizedMessage;
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.GlobalizationHelper;
import org.librecms.CmsConstants;
import java.util.ArrayList; import java.util.ArrayList;
@ -45,6 +47,7 @@ import java.util.ArrayList;
* @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 CategoryLinks extends List { public class CategoryLinks extends List {
public final static String SUB_CATEGORY = "sc"; public final static String SUB_CATEGORY = "sc";
private final CategoryRequestLocal m_parent; private final CategoryRequestLocal m_parent;
@ -52,8 +55,8 @@ public class CategoryLinks extends List {
public CategoryLinks(final CategoryRequestLocal parent, public CategoryLinks(final CategoryRequestLocal parent,
final SingleSelectionModel model) { final SingleSelectionModel model) {
super(new ParameterSingleSelectionModel super(new ParameterSingleSelectionModel(new BigDecimalParameter(
(new BigDecimalParameter(SUB_CATEGORY))); SUB_CATEGORY)));
setIdAttr("category_links_list"); setIdAttr("category_links_list");
m_parent = parent; m_parent = parent;
@ -64,6 +67,7 @@ public class CategoryLinks extends List {
// 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() { addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
final String id = (String) getSelectedKey(state); final String id = (String) getSelectedKey(state);
@ -72,10 +76,12 @@ public class CategoryLinks extends List {
m_model.setSelectedKey(state, id); m_model.setSelectedKey(state, id);
} }
} }
}); });
final Label label = new Label final Label label = new Label(new GlobalizedMessage(
(GlobalizationUtil.globalize("cms.ui.category.linked_none")); "cms.ui.category.linked_none",
CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC); label.setFontWeight(Label.ITALIC);
setEmptyView(label); setEmptyView(label);
} }
@ -91,9 +97,12 @@ public class CategoryLinks extends List {
if (category != null && category.getParentCategory() != null) { if (category != null && category.getParentCategory() != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryController controller = cdiUtil
.findBean(CategoryController.class);
final GlobalizationHelper globalizationHelper = cdiUtil final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class); .findBean(GlobalizationHelper.class);
final Category parent = category.getParentCategory(); final Category parent = controller
.getParentCategory(category).get();
java.util.List<CategoryListItem> categories = new ArrayList<>(); java.util.List<CategoryListItem> categories = new ArrayList<>();
final CategoryListItem parentItem = new CategoryListItem(); final CategoryListItem parentItem = new CategoryListItem();
@ -105,13 +114,21 @@ public class CategoryLinks extends List {
categories.add(parentItem); categories.add(parentItem);
return new CategoryListModel return new CategoryListModel(
(categories, categories,
category.getParentCategory() == null ? null : Long.parseLong(category.getParentCategory().getUniqueId())); parent.getObjectId());
// return new CategoryListModel(categories,
// category.getParentCategory()
// == null ? null : Long
// .parseLong(
// parent
// .getUniqueId()));
} else { } else {
return List.EMPTY_MODEL; return List.EMPTY_MODEL;
} }
} }
} }
} }

View File

@ -18,14 +18,19 @@
*/ */
package com.arsdigita.cms.ui.category; package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.*; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.util.GlobalizationUtil; import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.dispatcher.AccessDeniedException; import com.arsdigita.dispatcher.AccessDeniedException;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.KernelConfig;
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.Category; import org.libreccm.categorization.Category;
@ -33,6 +38,7 @@ import org.libreccm.categorization.CategoryRepository;
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.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.util.Collection; import java.util.Collection;
@ -41,8 +47,8 @@ import java.util.Locale;
/** /**
* Generates a form for creating new localisations for the given category. * Generates a form for creating new localisations for the given category.
* *
* This class is part of the admin GUI of CCM and extends the standard form * This class is part of the admin GUI of CCM and extends the standard form in
* in order to present forms for managing the multi-language categories. * order to present forms for managing the multi-language categories.
* *
* @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>
@ -52,14 +58,16 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
private static final Logger LOGGER = LogManager.getLogger( private static final Logger LOGGER = LogManager.getLogger(
CategoryLocalizationAddForm.class); CategoryLocalizationAddForm.class);
/** Creates a new instance of CategoryLocalizationAddForm */ /**
* Creates a new instance of CategoryLocalizationAddForm
*/
public CategoryLocalizationAddForm(final CategoryRequestLocal category) { public CategoryLocalizationAddForm(final CategoryRequestLocal category) {
super("AddCategoryLocalization", super("AddCategoryLocalization",
gz("cms.ui.category.localization_add"), category); gz("cms.ui.category.localization_add"), category);
addInitListener(new InitListener()); super.addInitListener(new InitListener());
addProcessListener(new ProcessListener()); super.addProcessListener(new ProcessListener());
} }
@ -83,27 +91,35 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
// Select one entry // Select one entry
m_locale.addOption(new Option("", m_locale.addOption(new Option("",
new Label(GlobalizationUtil.globalize( new Label(new GlobalizedMessage(
"cms.ui.select_one"))), state); "cms.ui.select_one",
CmsConstants.CMS_BUNDLE))),
state);
final Collection<String> locales = config.getSupportedLanguages(); final Collection<String> locales = config.getSupportedLanguages();
if (locales != null) { if (locales != null) {
for (String locale : locales) { for (String locale : locales) {
m_locale.addOption(new Option(locale, m_locale.addOption(new Option(locale,
new Text(new Locale(locale).getDisplayLanguage())), state); new Text(new Locale(locale)
.getDisplayLanguage())),
state);
} }
} }
} }
} }
private final class ProcessListener implements FormProcessListener { private final class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e) public final void process(final FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
LOGGER.debug("Adding a categoryLocalization to category " + m_category); LOGGER.debug("Adding a categoryLocalization to category "
+ m_category);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class); final PermissionChecker permissionChecker = cdiUtil.findBean(
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class); PermissionChecker.class);
final CategoryRepository categoryRepository = cdiUtil.findBean(
CategoryRepository.class);
final PageState state = e.getPageState(); final PageState state = e.getPageState();
@ -111,18 +127,19 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
final Locale locale = new Locale((String) m_locale.getValue(state)); final Locale locale = new Locale((String) m_locale.getValue(state));
final String title = (String) m_title.getValue(state); final String title = (String) m_title.getValue(state);
final String description = (String) m_description.getValue(state); final String description = (String) m_description.getValue(state);
final String url = (String) m_url.getValue(state); // final String url = (String) m_url.getValue(state);
final String isEnabled = (String) m_isEnabled.getValue(state); // final String isEnabled = (String) m_isEnabled.getValue(state);
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Adding localization for locale " + locale LOGGER.debug("Adding localization for locale " + locale
+ " to category " + category); + " to category " + category);
} }
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) { if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
category.getTitle().addValue(locale, title); category.getTitle().addValue(locale, title);
category.getDescription().addValue(locale, description); category.getDescription().addValue(locale, description);
category.setEnabled(isEnabled.equals("yes")); // category.setEnabled(isEnabled.equals("yes"));
categoryRepository.save(category); categoryRepository.save(category);
} else { } else {
@ -131,5 +148,7 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
throw new AccessDeniedException(); throw new AccessDeniedException();
} }
} }
} }
} }

View File

@ -89,13 +89,13 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
m_title.setValue(state, category.getTitle().getValue(locale)); m_title.setValue(state, category.getTitle().getValue(locale));
m_description.setValue(state, category.getDescription().getValue(locale)); m_description.setValue(state, category.getDescription().getValue(locale));
m_url.setValue(state, category.getName()); // m_url.setValue(state, category.getName());
if (category.isEnabled()) { // if (category.isEnabled()) {
m_isEnabled.setValue(state, "yes"); // m_isEnabled.setValue(state, "yes");
} else { // } else {
m_isEnabled.setValue(state, "no"); // m_isEnabled.setValue(state, "no");
} // }
} }
} }
@ -122,8 +122,8 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
final Locale locale = new Locale((String) m_locale.getValue(state)); final Locale locale = new Locale((String) m_locale.getValue(state));
category.getTitle().addValue(locale, (String) m_title.getValue(state)); category.getTitle().addValue(locale, (String) m_title.getValue(state));
category.getDescription().addValue(locale, (String) m_description.getValue(state)); category.getDescription().addValue(locale, (String) m_description.getValue(state));
category.setName((String) m_url.getValue(state)); // category.setName((String) m_url.getValue(state));
category.setEnabled("yes".equals(m_isEnabled.getValue(state))); // category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
categoryRepository.save(category); categoryRepository.save(category);
} else { } else {
throw new AccessDeniedException(); throw new AccessDeniedException();

View File

@ -69,12 +69,12 @@ public class CategoryLocalizationForm extends BaseForm {
final TextField m_title; final TextField m_title;
final TextArea m_description; final TextArea m_description;
//final TextField m_url; //final TextField m_url;
final Hidden m_url; // final Hidden m_url;
final RadioGroup m_isEnabled; // final RadioGroup m_isEnabled;
private Embedded m_script = new Embedded(String.format( // private Embedded m_script = new Embedded(String.format(
"<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\">" + "</script>", // "<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\">" + "</script>",
Web.getWebappContextPath()), // Web.getWebappContextPath()),
false); // false);
private final static String LOCALE = "locale"; private final static String LOCALE = "locale";
private final static String TITLE = "title"; private final static String TITLE = "title";
@ -117,7 +117,7 @@ public class CategoryLocalizationForm extends BaseForm {
addField(gz("cms.ui.category.localization_locale"), m_locale); addField(gz("cms.ui.category.localization_locale"), m_locale);
m_title = new TextField(new TrimmedStringParameter(TITLE)); m_title = new TextField(new TrimmedStringParameter(TITLE));
addField(gz("cms.ui.name"), m_title); addField(gz("cms.ui.title"), m_title);
m_title.setSize(30); m_title.setSize(30);
m_title.setMaxLength(200); m_title.setMaxLength(200);
@ -128,10 +128,10 @@ public class CategoryLocalizationForm extends BaseForm {
m_title.setOnKeyUp("if (defaulting) { this.form." + URL + ".value = urlize(this.value) }"); m_title.setOnKeyUp("if (defaulting) { this.form." + URL + ".value = urlize(this.value) }");
// is enabled? // is enabled?
m_isEnabled = new RadioGroup(IS_ENABLED); // m_isEnabled = new RadioGroup(IS_ENABLED);
m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no")))); // m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no"))));
m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes")))); // m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes"))));
addField(gz("cms.ui.category.is_enabled"), m_isEnabled); // addField(gz("cms.ui.category.is_enabled"), m_isEnabled);
m_description = new TextArea(new TrimmedStringParameter(DESCRIPTION)); m_description = new TextArea(new TrimmedStringParameter(DESCRIPTION));
addField(gz("cms.ui.description"), m_description); addField(gz("cms.ui.description"), m_description);
@ -165,25 +165,25 @@ public class CategoryLocalizationForm extends BaseForm {
//the URLs. Also, a category is the same resource for every language variant therefore //the URLs. Also, a category is the same resource for every language variant therefore
//the URL should be the same. //the URL should be the same.
//Changed field to Hidden, initalised with URL of category itself. //Changed field to Hidden, initalised with URL of category itself.
m_url = new Hidden(new TrimmedStringParameter(URL)); // m_url = new Hidden(new TrimmedStringParameter(URL));
try { // try {
m_url.addPrintListener(new PrintListener() { // m_url.addPrintListener(new PrintListener() {
//
@Override // @Override
public void prepare(final PrintEvent event) { // public void prepare(final PrintEvent event) {
final Hidden target = (Hidden) event.getTarget(); // final Hidden target = (Hidden) event.getTarget();
final PageState state = event.getPageState(); // final PageState state = event.getPageState();
//
final Category cat = m_category.getCategory(state); // final Category cat = m_category.getCategory(state);
//
target.setValue(state, cat.getName()); // target.setValue(state, cat.getName());
} // }
//
}); // });
} catch (TooManyListenersException | IllegalArgumentException ex) { // } catch (TooManyListenersException | IllegalArgumentException ex) {
LOGGER.fatal(ex); // LOGGER.fatal(ex);
} // }
addField(gz("cms.ui.category.url"), m_url); // addField(gz("cms.ui.category.url"), m_url);
addAction(new Finish()); addAction(new Finish());
addAction(new Cancel()); addAction(new Cancel());
@ -192,7 +192,7 @@ public class CategoryLocalizationForm extends BaseForm {
@Override @Override
public void generateXML(PageState ps, Element parent) { public void generateXML(PageState ps, Element parent) {
m_script.generateXML(ps, parent); // m_script.generateXML(ps, parent);
super.generateXML(ps, parent); super.generateXML(ps, parent);
} }

View File

@ -32,22 +32,19 @@ import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel; 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.globalization.GlobalizedMessage;
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.GlobalizationHelper;
import org.libreccm.l10n.GlobalizedMessagesUtil; import org.libreccm.l10n.GlobalizedMessagesUtil;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges; import org.librecms.contentsection.privileges.AdminPrivileges;
import java.math.BigDecimal; import java.util.Iterator;
import java.util.ArrayList; import java.util.List;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
/** /**
* Lists all existing localizations for a selected category. * Lists all existing localizations for a selected category.
@ -64,6 +61,12 @@ public class CategoryLocalizationTable extends Table implements
private static final String TABLE_COL_LANG = "table_col_lang"; private static final String TABLE_COL_LANG = "table_col_lang";
private static final String TABLE_COL_DEL = "table_col_del"; private static final String TABLE_COL_DEL = "table_col_del";
private static final int COL_LOCALE = 0;
private static final int COL_TITLE = 1;
private static final int COL_DESCRIPTION = 2;
private static final int COL_EDIT = 3;
private static final int COL_DEL = 4;
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
private final SingleSelectionModel m_catLocale; private final SingleSelectionModel m_catLocale;
@ -94,31 +97,26 @@ public class CategoryLocalizationTable extends Table implements
// define columns // define columns
columnModel.add(new TableColumn( columnModel.add(new TableColumn(
0, COL_LOCALE,
messagesUtil.getGlobalizedMessage( messagesUtil.getGlobalizedMessage(
"cms.ui.category.localization.locale") "cms.ui.category.localization.locale"),
.localize(),
TABLE_COL_LANG)); TABLE_COL_LANG));
columnModel.add(new TableColumn( columnModel.add(new TableColumn(
1, COL_TITLE,
messagesUtil messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_name") .getGlobalizedMessage("cms.ui.category.localization_title")));
.localize()));
columnModel.add(new TableColumn( columnModel.add(new TableColumn(
2, COL_DESCRIPTION,
messagesUtil.getGlobalizedMessage( messagesUtil.getGlobalizedMessage(
"cms.ui.category.localization_description") "cms.ui.category.localization_description")));
.localize()));
columnModel.add(new TableColumn( columnModel.add(new TableColumn(
3, COL_EDIT,
messagesUtil messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_url") .getGlobalizedMessage("cms.ui.category.localization_edit")));
.localize()));
columnModel.add(new TableColumn( columnModel.add(new TableColumn(
4, COL_DEL,
messagesUtil messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_action") .getGlobalizedMessage("cms.ui.category.localization_action"),
.localize(),
TABLE_COL_DEL)); TABLE_COL_DEL));
super.setModelBuilder(new CategoryLocalizationTableModelBuilder()); super.setModelBuilder(new CategoryLocalizationTableModelBuilder());
@ -130,101 +128,87 @@ public class CategoryLocalizationTable extends Table implements
} }
/**
* XXXX
*
*/
private class CategoryLocalizationTableModelBuilder extends LockableImpl private class CategoryLocalizationTableModelBuilder extends LockableImpl
implements TableModelBuilder { implements TableModelBuilder {
public TableModel makeModel(Table table, PageState state) { @Override
public TableModel makeModel(final Table table, final PageState state) {
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
if (category != null) { if (category == null) {
return new CategoryLocalizationTableModel(table, state, category);
} else {
return Table.EMPTY_MODEL; return Table.EMPTY_MODEL;
} else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryLocalizationTableController controller = cdiUtil
.findBean(CategoryLocalizationTableController.class);
final List<CategoryLocalizationTableRow> rows = controller
.getCategoryLocalizations(category);
return new CategoryLocalizationTableModel(table, rows);
} }
} }
} }
/**
* XXX
*
*/
private class CategoryLocalizationTableModel implements TableModel { private class CategoryLocalizationTableModel implements TableModel {
private Table m_table; private final Table table;
private ArrayList<LocalizedString> localizedStringCollection; private final Iterator<CategoryLocalizationTableRow> iterator;
private LocalizedString m_categoryLocalization; private CategoryLocalizationTableRow currentRow;
private CategoryLocalizationTableModel(Table t, PageState ps, private CategoryLocalizationTableModel(
Category category) { final Table table,
m_table = t; final List<CategoryLocalizationTableRow> rows) {
localizedStringCollection = new ArrayList<>();
localizedStringCollection.add(category.getTitle()); this.table = table;
localizedStringCollection.add(category.getDescription()); iterator = rows.iterator();
} }
@Override
public int getColumnCount() { public int getColumnCount() {
return m_table.getColumnModel().size(); return table.getColumnModel().size();
} }
/** @Override
* Check collection for the existence of another row.
*
* If exists, fetch the value of current CategoryLocalization object
* into m_categoryLocalization class variable.
*/
public boolean nextRow() { public boolean nextRow() {
if (iterator.hasNext()) {
currentRow = iterator.next();
return true;
} else {
return false; return false;
// if (m_categoryLocalizations != null && m_categoryLocalizations.next()) { }
// m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization();
// return true;
//
// } else {
//
// return false;
//
// }
} }
/** @Override
* Return the public Object getElementAt(final int columnIndex) {
*
* @see com.arsdigita.bebop.table.TableModel#getElementAt(int) switch (columnIndex) {
*/ case COL_LOCALE:
public Object getElementAt(int columnIndex) { return currentRow.getLocale();
return null; case COL_TITLE:
// switch (columnIndex) { return currentRow.getTitle();
// case 0: case COL_DESCRIPTION:
// Locale clLocale = new Locale(m_categoryLocalization.getLocale()); return currentRow.getDescription();
// return clLocale.getDisplayLanguage(/*Locale*/); case COL_EDIT:
// case 1: return new GlobalizedMessage("cms.ui.edit",
// return m_categoryLocalization.getName(); CmsConstants.CMS_BUNDLE);
// case 2: case COL_DEL:
// String desc = m_categoryLocalization.getDescription(); return new GlobalizedMessage("cms.ui.delete",
// if (desc != null && desc.length() > MAX_DESC_LENGTH) { CmsConstants.CMS_BUNDLE);
// desc = desc.substring(MAX_DESC_LENGTH - 3).concat("..."); default:
// } throw new IllegalArgumentException("Illegal Column Index");
// return desc; }
// case 3:
// return m_categoryLocalization.getURL();
// case 4:
// return GlobalizationUtil.globalize("cms.ui.delete").localize();
// default:
// return null;
// }
} }
/** /**
* *
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int) * @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
*/ */
public Object getKeyAt(int columnIndex) { @Override
return null; public Object getKeyAt(final int columnIndex) {
// return m_categoryLocalization.getID(); return currentRow.getLocale();
} }
} }
@ -232,9 +216,15 @@ public class CategoryLocalizationTable extends Table implements
private class EditCellRenderer extends LockableImpl implements private class EditCellRenderer extends LockableImpl implements
TableCellRenderer { TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, @Override
boolean isSelected, final Object key, public Component getComponent(final Table table,
int row, int column) { final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean( final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class); PermissionChecker.class);
@ -253,9 +243,15 @@ public class CategoryLocalizationTable extends Table implements
private class DeleteCellRenderer extends LockableImpl implements private class DeleteCellRenderer extends LockableImpl implements
TableCellRenderer { TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, @Override
boolean isSelected, Object key, public Component getComponent(final Table table,
int row, int column) { final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean( final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class); PermissionChecker.class);
@ -279,9 +275,10 @@ public class CategoryLocalizationTable extends Table implements
* into picture when a link on the table is clicked. Handles edit and delete * into picture when a link on the table is clicked. Handles edit and delete
* event. * event.
*/ */
public void cellSelected(TableActionEvent evt) { @Override
public void cellSelected(final TableActionEvent event) {
PageState state = evt.getPageState(); PageState state = event.getPageState();
// // Get selected CategoryLocalization // // Get selected CategoryLocalization
// CategoryLocalization categoryLocalization = // CategoryLocalization categoryLocalization =
@ -308,8 +305,9 @@ public class CategoryLocalizationTable extends Table implements
* provide Implementation to TableActionListener method. Does nothing in our * provide Implementation to TableActionListener method. Does nothing in our
* case. * case.
*/ */
public void headSelected(TableActionEvent e) { @Override
throw new UnsupportedOperationException("Not Implemented"); public void headSelected(final TableActionEvent event) {
//Nothing
} }
} }

View File

@ -0,0 +1,77 @@
/*
* Copyright (C) 2018 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 org.libreccm.categorization.Category;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoryLocalizationTableController {
@Transactional(Transactional.TxType.REQUIRED)
protected List<CategoryLocalizationTableRow> getCategoryLocalizations(
final Category forCategory) {
final Map<Locale, CategoryLocalizationTableRow> localizations
= new HashMap<>();
final Set<Locale> locales = new HashSet<>();
locales.addAll(forCategory.getTitle().getAvailableLocales());
locales.addAll(forCategory.getDescription().getAvailableLocales());
return locales
.stream()
.map(locale -> generateRow(locale, forCategory))
.sorted()
.collect(Collectors.toList());
}
private CategoryLocalizationTableRow generateRow(final Locale locale,
final Category category) {
final CategoryLocalizationTableRow row
= new CategoryLocalizationTableRow(
locale);
if (category.getTitle().hasValue(locale)) {
row.setTitle(category.getTitle().getValue(locale));
}
if (category.getDescription().hasValue(locale)) {
row.setDescription(category.getDescription().getValue(locale));
}
return row;
}
}

View File

@ -0,0 +1,120 @@
/*
* Copyright (C) 2018 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.Locale;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CategoryLocalizationTableRow
implements Comparable<CategoryLocalizationTableRow> {
private final Locale locale;
private String title;
private String description;
public CategoryLocalizationTableRow(final Locale locale) {
this.locale = locale;
}
public Locale getLocale() {
return locale;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
@Override
public int compareTo(final CategoryLocalizationTableRow other) {
return locale.toString().compareTo(other.getLocale().toString());
}
@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + Objects.hashCode(locale);
hash = 53 * hash + Objects.hashCode(title);
hash = 53 * hash + Objects.hashCode(description);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CategoryLocalizationTableRow)) {
return false;
}
final CategoryLocalizationTableRow other
= (CategoryLocalizationTableRow) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(title, other.getTitle())) {
return false;
}
if (!Objects.equals(description, other.getDescription())) {
return false;
}
return Objects.equals(locale, other.getLocale());
}
public boolean canEqual(final Object obj) {
return obj instanceof CategoryLocalizationTableRow;
}
@Override
public String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "locale = \"%s\", "
+ "title = \"%s\", "
+ "description = \"%s\"%s"
+ " }",
super.toString(),
Objects.toString(locale),
title,
description,
data);
}
}

View File

@ -26,11 +26,13 @@ import com.arsdigita.bebop.event.ActionEvent;
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.globalization.GlobalizedMessage;
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.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
/** /**
* A List of all subcategories of the current category. * A List of all subcategories of the current category.
@ -63,8 +65,9 @@ public class SubcategoryList extends SortableCategoryList {
// user selects it here // user selects it here
super.addActionListener(this::actionPerformed); super.addActionListener(this::actionPerformed);
Label label = new Label(GlobalizationUtil.globalize( Label label = new Label(new GlobalizedMessage(
"cms.ui.category.subcategory.none")); "cms.ui.category.subcategory.none",
CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC); label.setFontWeight(Label.ITALIC);
setEmptyView(label); setEmptyView(label);
} }

View File

@ -506,3 +506,7 @@ cms.ui.pages.pagemodels.cancel=Cancel
cms.ui.cateogry.is_visible=Is visible? cms.ui.cateogry.is_visible=Is visible?
cms.ui.category.cantmoved=This category can't be moved. cms.ui.category.cantmoved=This category can't be moved.
cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instance cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instance
cms.ui.category.is_visible=Visible?
cms.ui.category.move=Move category
cms.ui.title=Title
cms.ui.select_one=Choose one

View File

@ -503,3 +503,7 @@ cms.ui.pages.pagemodels.cancel=Abbrechen
cms.ui.cateogry.is_visible=Sichtbar? cms.ui.cateogry.is_visible=Sichtbar?
cms.ui.category.cantmoved=Diese Kategorie kann nicht verschoben werden. cms.ui.category.cantmoved=Diese Kategorie kann nicht verschoben werden.
cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instanz cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instanz
cms.ui.category.is_visible=Sichtbar?
cms.ui.category.move=Kategorie verschieben
cms.ui.title=Titel
cms.ui.select_one=Bitte ausw\u00e4hlen

View File

@ -463,3 +463,9 @@ cms.ui.cateogry.is_visible=Is visible?
cms.ui.category.cantmoved=This category can't be moved. cms.ui.category.cantmoved=This category can't be moved.
cms.ui.category.localization_none=No localization available cms.ui.category.localization_none=No localization available
cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instance cms.ui.contentcenter.pagestable.columns.pages_instance.header=Pages Instance
cms.ui.category.is_visible=Visible?
cms.ui.category.subcategory.none=
cms.ui.category.linked_none=No linked categories
cms.ui.category.move=Move category
cms.ui.title=Title
cms.ui.select_one=Choose one