diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/BaseCategoryForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/BaseCategoryForm.java
index dc43374ce..a9d49e42e 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/BaseCategoryForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/BaseCategoryForm.java
@@ -18,6 +18,7 @@
*/
package com.arsdigita.cms.ui.category;
+import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
@@ -48,19 +49,10 @@ import java.util.Collection;
* @author Stanislav Freidin <sfreidin@redhat.com>
* @author Justin Ross <jross@redhat.com>
* @author Yannick Bülter
+ * @author Jens Pelzetter
*/
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(
- "",
- Web.getWebappContextPath())),
- false);
private final static String NAME = "name";
private final static String DESCRIPTION = "description";
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_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("",
+ Web.getWebappContextPath())),
+ false);
+
/**
* Constructor.
*/
- BaseCategoryForm(final String key,
- final GlobalizedMessage heading,
- final CategoryRequestLocal parent) {
+ protected BaseCategoryForm(final String key,
+ final GlobalizedMessage heading,
+ final CategoryRequestLocal parent) {
+
super(key, heading);
- m_parent = parent;
+ categoryRequestLocal = parent;
- m_name = new TextField(new TrimmedStringParameter(NAME));
- addField(gz("cms.ui.name"), m_name);
+ nameField = new TextField(new TrimmedStringParameter(NAME));
+ addField(gz("cms.ui.name"), nameField);
- m_name.setSize(30);
- m_name.setMaxLength(200);
- m_name.addValidationListener(new NotNullValidationListener());
- m_name.setOnFocus("if (this.form." + URL + ".value == '') { "
- + " defaulting = true; this.form." + URL
- + ".value = urlize(this.value); }");
- m_name.setOnKeyUp("if (defaulting) { this.form." + URL
- + ".value = urlize(this.value) }");
+ nameField.setSize(30);
+ nameField.setMaxLength(200);
+ nameField.addValidationListener(new NotNullValidationListener());
+ nameField.setOnFocus(String.format(
+ ""
+ + "if (this.form.%1$s.value == '') {"
+ + " defaulting = true;"
+ + " 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?
- m_isAbstract = new RadioGroup(IS_ABSTRACT);
- m_isAbstract.addOption(new Option("no", new Label(gz("cms.ui.no"))));
- m_isAbstract.addOption(new Option("yes", new Label(gz("cms.ui.yes"))));
- addField(gz("cms.ui.category.is_not_abstract"), m_isAbstract);
+ isAbstractRadioGroup = new RadioGroup(IS_ABSTRACT);
+ isAbstractRadioGroup.addOption(new Option("no", new Label(
+ gz("cms.ui.no"))));
+ isAbstractRadioGroup.addOption(new Option("yes", new Label(gz(
+ "cms.ui.yes"))));
+ addField(gz("cms.ui.category.is_not_abstract"), isAbstractRadioGroup);
// is visible
- m_isVisible = new RadioGroup(IS_VISIBLE);
- m_isVisible.addOption(new Option("no", new Label(gz("cms.ui.no"))));
- m_isVisible.addOption(new Option("yes", new Label(gz("cms.ui.yes"))));
- addField(gz("cms.ui.category.is_visible"), m_isVisible);
+ isVisibleRadioGroup = new RadioGroup(IS_VISIBLE);
+ isVisibleRadioGroup.addOption(new Option("no",
+ new Label(gz("cms.ui.no"))));
+ isVisibleRadioGroup.addOption(new Option("yes", new Label(gz(
+ "cms.ui.yes"))));
+ addField(gz("cms.ui.category.is_visible"), isVisibleRadioGroup);
// 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("yes", new Label(gz("cms.ui.yes"))));
- addField(gz("cms.ui.category.is_enabled"), m_isEnabled);
+ isEnabledRadioGroup = new RadioGroup(IS_ENABLED);
+ isEnabledRadioGroup.addOption(new Option("no",
+ new Label(gz("cms.ui.no"))));
+ 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));
- addField(gz("cms.ui.description"), m_description);
+ descriptionArea = new TextArea(new TrimmedStringParameter(DESCRIPTION));
+ addField(gz("cms.ui.description"), descriptionArea);
- m_description.setWrap(TextArea.SOFT);
- m_description.setRows(5);
- m_description.setCols(40);
+ descriptionArea.setWrap(TextArea.SOFT);
+ descriptionArea.setRows(5);
+ descriptionArea.setCols(40);
addAction(new Finish());
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
public void generateXML(PageState ps, Element parent) {
- m_script.generateXML(ps, parent);
+ script.generateXML(ps, parent);
super.generateXML(ps, parent);
}
- class NameUniqueListener implements ParameterListener {
+ private class NameUniqueListener implements ParameterListener {
private final CategoryRequestLocal m_category;
private final Widget m_widget;
@@ -133,7 +177,7 @@ class BaseCategoryForm extends BaseForm {
final static int NAME_FIELD = 1;
NameUniqueListener(final CategoryRequestLocal category) {
- this(category, m_name, NAME_FIELD);
+ this(category, nameField, NAME_FIELD);
}
NameUniqueListener(final CategoryRequestLocal category,
@@ -149,7 +193,7 @@ class BaseCategoryForm extends BaseForm {
final PageState state = e.getPageState();
final String title = (String) m_widget.getValue(state);
- final Category parent = m_parent.getCategory(state);
+ final Category parent = categoryRequestLocal.getCategory(state);
final Collection children = parent.getSubCategories();
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAddForm.java
index 82984ac4e..9d5f56d37 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAddForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryAddForm.java
@@ -24,97 +24,94 @@ import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.dispatcher.AccessDeniedException;
-import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.Assert;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
-import org.libreccm.categorization.CategoryManager;
-import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
-import org.libreccm.configuration.ConfigurationManager;
-import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
+
/**
* TODO Needs a description.
*
* @author Justin Ross <jross@redhat.com>
* @author Yannick Bülter
+ * @author Jens Pelzetter
*/
final class CategoryAddForm extends BaseCategoryForm {
- private static final Logger LOGGER = LogManager.getLogger
- (CategoryAddForm.class);
+ private static final Logger LOGGER = LogManager.getLogger(
+ CategoryAddForm.class);
- private final SingleSelectionModel m_model;
+ private final SingleSelectionModel categorySelectionModel;
/**
* Constructor.
*/
public CategoryAddForm(final CategoryRequestLocal parent,
- final SingleSelectionModel model) {
+ final SingleSelectionModel model) {
+
super("AddSubcategories", gz("cms.ui.category.add"), parent);
- m_model = model;
+ categorySelectionModel = model;
addProcessListener(new ProcessListener());
}
private final class ProcessListener implements FormProcessListener {
- public final void process(final FormSectionEvent e)
- throws FormProcessException {
+ @Override
+ public final void process(final FormSectionEvent event)
+ throws FormProcessException {
+
LOGGER.debug("Adding a category");
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
- final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
- final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
- final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
- final KernelConfig config = manager.findConfiguration(KernelConfig.class);
+ final PermissionChecker permissionChecker = cdiUtil
+ .findBean(PermissionChecker.class);
+ final CategoryController controller = cdiUtil
+ .findBean(CategoryController.class);
- final PageState state = e.getPageState();
+ final PageState state = event.getPageState();
- final Category parent = m_parent.getCategory(state);
- final String name = (String) m_name.getValue(state);
- final String description = (String) m_description.getValue(state);
- final String isAbstract = (String) m_isAbstract.getValue(state);
+ final Category parent = getCategoryRequestLocal()
+ .getCategory(state);
+ final String name = (String) getNameField().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");
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Using parent category " + parent + " to " +
- "create new category");
+ LOGGER.debug("Using parent category " + parent + " to "
+ + "create new category");
}
- if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) {
- final Category category = new Category();
- 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);
- }
+ if (permissionChecker
+ .isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) {
- categoryRepository.save(category);
+ final Category category = controller.createCategory(parent,
+ name,
+ description,
+ isAbstract);
- categoryManager.addSubCategoryToCategory(category, parent);
-
- m_model.setSelectedKey(state, category.getUniqueId());
+ categorySelectionModel.setSelectedKey(state,
+ category.getUniqueId());
} else {
// XXX user a better exception here.
// PermissionException doesn't work for this case.
throw new AccessDeniedException();
}
}
+
}
+
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryController.java
new file mode 100644
index 000000000..1d2f7b3bb
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryController.java
@@ -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 Jens Pelzetter
+ */
+@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 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());
+ }
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryEditForm.java
index 8e44f6e9b..a44579144 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryEditForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryEditForm.java
@@ -32,6 +32,7 @@ import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
+import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker;
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 YES = "yes";
- private final CategoryRequestLocal m_category;
+
+ private final CategoryRequestLocal selectedCategory;
public CategoryEditForm(final CategoryRequestLocal parent,
- final CategoryRequestLocal category) {
+ final CategoryRequestLocal selectedCategory) {
super("EditCategory", gz("cms.ui.category.edit"), parent);
- m_category = category;
+ this.selectedCategory = selectedCategory;
- addInitListener(new InitListener());
- addProcessListener(new ProcessListener());
+ super.addInitListener(new InitListener());
+ super.addProcessListener(new ProcessListener());
}
private class InitListener implements FormInitListener {
@Override
- public final void init(final FormSectionEvent e)
+ public final void init(final FormSectionEvent event)
throws FormProcessException {
- final PageState state = e.getPageState();
- final Category category = m_category.getCategory(state);
+
+ final PageState state = event.getPageState();
+ final Category category = selectedCategory.getCategory(state);
- // 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.
- m_name.setValue(state, category.getName());
- m_description.setValue(state, category.getDescription());
- //m_url.setValue(state, category.getURL(""));
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final GlobalizationHelper globalizationHelper = cdiUtil
+ .findBean(GlobalizationHelper.class);
+
+ 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
// items in this category. If the user says "yes" then the
// category is not abstract
if (category.isAbstractCategory()) {
- m_isAbstract.setValue(state, NO);
+ getIsAbstractRadioGroup().setValue(state, NO);
} else {
- m_isAbstract.setValue(state, YES);
+ getIsAbstractRadioGroup().setValue(state, YES);
}
if (category.isVisible()) {
- m_isVisible.setValue(state, YES);
+ getIsVisibleRadioGroup().setValue(state, YES);
} else {
- m_isVisible.setValue(state, NO);
+ getIsVisibleRadioGroup().setValue(state, NO);
}
if (category.isEnabled()) {
- m_isEnabled.setValue(state, YES);
+ getIsEnabledRadioGroup().setValue(state, YES);
} else {
- m_isEnabled.setValue(state, NO);
+ getIsEnabledRadioGroup().setValue(state, NO);
}
}
@@ -103,8 +109,9 @@ final class CategoryEditForm extends BaseCategoryForm {
private class ProcessListener implements FormProcessListener {
@Override
- public final void process(final FormSectionEvent e)
+ public final void process(final FormSectionEvent event)
throws FormProcessException {
+
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
@@ -115,20 +122,21 @@ final class CategoryEditForm extends BaseCategoryForm {
final CategoryRepository categoryRepository = cdiUtil.findBean(
CategoryRepository.class);
- final PageState state = e.getPageState();
- final Category category = m_category.getCategory(state);
+ final PageState state = event.getPageState();
+ final Category category = selectedCategory.getCategory(state);
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
- category.setName((String) m_name.getValue(state));
+ category.setName((String) getNameField().getValue(state));
final LocalizedString localizedDescription
- = new LocalizedString();
- localizedDescription.addValue(config.getDefaultLocale(),
- (String) m_description.getValue(
- state));
+ = new LocalizedString();
+ localizedDescription
+ .addValue(config.getDefaultLocale(),
+ (String) getDescriptionArea().getValue(state));
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
// items in this category. If the user says "yes" then the
// category is not abstract
@@ -138,14 +146,16 @@ final class CategoryEditForm extends BaseCategoryForm {
category.setAbstractCategory(true);
}
- final String isVisible = (String) m_isVisible.getValue(state);
+ final String isVisible = (String) getIsVisibleRadioGroup()
+ .getValue(state);
if (YES.equals(isVisible)) {
category.setVisible(true);
} else {
category.setVisible(false);
}
- final String isEnabled = (String) m_isEnabled.getValue(state);
+ final String isEnabled = (String) getIsEnabledRadioGroup()
+ .getValue(state);
if (YES.equals(isEnabled)) {
category.setEnabled(true);
} else if (NO.equals(isEnabled)) {
@@ -153,6 +163,7 @@ final class CategoryEditForm extends BaseCategoryForm {
}
categoryRepository.save(category);
+
} else {
throw new AccessDeniedException();
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java
index d4ad5b98b..afcc40d62 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java
@@ -315,10 +315,12 @@ class CategoryItemPane extends BaseItemPane {
final String itemTitle;
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final GlobalizationHelper globalizationHelper = cdiUtil
+ .findBean(GlobalizationHelper.class);
if (category == null) {
itemTitle = "None";
} else {
- final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final List indexObjects = categoryManager
@@ -331,15 +333,13 @@ class CategoryItemPane extends BaseItemPane {
.findFirst();
if (indexItem.isPresent()) {
- final GlobalizationHelper globalizationHelper = cdiUtil
- .findBean(GlobalizationHelper.class);
final ContentItem item = indexItem.get();
itemTitle = globalizationHelper
.getValueFromLocalizedString(item.getTitle(),
item::getDisplayName);
- } else if (indexObjects.isEmpty()){
+ } else if (indexObjects.isEmpty()) {
itemTitle = "None";
} else {
final CcmObject indexObj = indexObjects.get(0);
@@ -349,8 +349,10 @@ class CategoryItemPane extends BaseItemPane {
properties.add(new Property(gz("cms.ui.name"),
category.getName()));
- properties.add(new Property(gz("cms.ui.description"),
- category.getDescription().getValue()));
+ properties.add(new Property(
+ gz("cms.ui.description"),
+ globalizationHelper
+ .getValueFromLocalizedString(category.getDescription())));
properties.add(new Property(
gz("cms.ui.category.is_not_abstract"),
category.isAbstractCategory()
@@ -443,10 +445,15 @@ class CategoryItemPane extends BaseItemPane {
public final boolean isVisible(final PageState state) {
final Category category = m_category.getCategory(state);
- if (category.getParentCategory() == null) {
- return false;
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final CategoryController controller = cdiUtil
+ .findBean(CategoryController.class);
+ final Optional parentCategory = controller
+ .getParentCategory(category);
+ if (parentCategory.isPresent()) {
+ return parentCategory.get().isVisible();
} else {
- return category.getParentCategory().isVisible();
+ return false;
}
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLinks.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLinks.java
index 9f23d4811..e7a550231 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLinks.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLinks.java
@@ -29,11 +29,13 @@ import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
+import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
+import org.librecms.CmsConstants;
import java.util.ArrayList;
@@ -45,6 +47,7 @@ import java.util.ArrayList;
* @author Yannick Bülter
*/
public class CategoryLinks extends List {
+
public final static String SUB_CATEGORY = "sc";
private final CategoryRequestLocal m_parent;
@@ -52,8 +55,8 @@ public class CategoryLinks extends List {
public CategoryLinks(final CategoryRequestLocal parent,
final SingleSelectionModel model) {
- super(new ParameterSingleSelectionModel
- (new BigDecimalParameter(SUB_CATEGORY)));
+ super(new ParameterSingleSelectionModel(new BigDecimalParameter(
+ SUB_CATEGORY)));
setIdAttr("category_links_list");
m_parent = parent;
@@ -64,26 +67,29 @@ public class CategoryLinks extends List {
// Select the category in the main tree when the
// user selects it here
addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- final PageState state = e.getPageState();
- final String id = (String) getSelectedKey(state);
- if (id != null) {
- m_model.setSelectedKey(state, id);
- }
+ public void actionPerformed(ActionEvent e) {
+ final PageState state = e.getPageState();
+ final String id = (String) getSelectedKey(state);
+
+ if (id != null) {
+ m_model.setSelectedKey(state, id);
}
- });
+ }
- final Label label = new Label
- (GlobalizationUtil.globalize("cms.ui.category.linked_none"));
+ });
+
+ final Label label = new Label(new GlobalizedMessage(
+ "cms.ui.category.linked_none",
+ CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC);
setEmptyView(label);
}
// 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
- implements ListModelBuilder {
-
+ implements ListModelBuilder {
+
@Override
public ListModel makeModel(List list, PageState state) {
final Category category = m_parent.getCategory(state);
@@ -91,27 +97,38 @@ public class CategoryLinks extends List {
if (category != null && category.getParentCategory() != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final GlobalizationHelper globalizationHelper =cdiUtil
- .findBean(GlobalizationHelper.class);
- final Category parent = category.getParentCategory();
-
+ final CategoryController controller = cdiUtil
+ .findBean(CategoryController.class);
+ final GlobalizationHelper globalizationHelper = cdiUtil
+ .findBean(GlobalizationHelper.class);
+ final Category parent = controller
+ .getParentCategory(category).get();
+
java.util.List categories = new ArrayList<>();
final CategoryListItem parentItem = new CategoryListItem();
parentItem.setCategoryId(parent.getObjectId());
final String label = globalizationHelper
- .getValueFromLocalizedString(parent.getTitle(),
- parent::getName);
+ .getValueFromLocalizedString(parent.getTitle(),
+ parent::getName);
parentItem.setLabel(label);
-
+
categories.add(parentItem);
- return new CategoryListModel
- (categories,
- category.getParentCategory() == null ? null : Long.parseLong(category.getParentCategory().getUniqueId()));
+ return new CategoryListModel(
+ categories,
+ parent.getObjectId());
+
+// return new CategoryListModel(categories,
+// category.getParentCategory()
+// == null ? null : Long
+// .parseLong(
+// parent
+// .getUniqueId()));
} else {
return List.EMPTY_MODEL;
}
}
+
}
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationAddForm.java
index 869e99e9b..88ac54903 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationAddForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationAddForm.java
@@ -18,14 +18,19 @@
*/
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.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.dispatcher.AccessDeniedException;
+import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
@@ -33,6 +38,7 @@ import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.security.PermissionChecker;
+import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Collection;
@@ -41,8 +47,8 @@ import java.util.Locale;
/**
* 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
- * in order to present forms for managing the multi-language categories.
+ * This class is part of the admin GUI of CCM and extends the standard form in
+ * order to present forms for managing the multi-language categories.
*
* @author Sören Bernstein
* @author Yannick Bülter
@@ -50,16 +56,18 @@ import java.util.Locale;
public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
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) {
super("AddCategoryLocalization",
- gz("cms.ui.category.localization_add"), category);
+ gz("cms.ui.category.localization_add"), category);
- addInitListener(new InitListener());
- addProcessListener(new ProcessListener());
+ super.addInitListener(new InitListener());
+ super.addProcessListener(new ProcessListener());
}
@@ -70,40 +78,48 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
private class InitListener implements FormInitListener {
public final void init(final FormSectionEvent e)
- throws FormProcessException {
+ throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager manager = cdiUtil.findBean(
- ConfigurationManager.class);
+ ConfigurationManager.class);
final KernelConfig config = manager.findConfiguration(
- KernelConfig.class);
+ KernelConfig.class);
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
// Select one entry
m_locale.addOption(new Option("",
- new Label(GlobalizationUtil.globalize(
- "cms.ui.select_one"))), state);
+ new Label(new GlobalizedMessage(
+ "cms.ui.select_one",
+ CmsConstants.CMS_BUNDLE))),
+ state);
final Collection locales = config.getSupportedLanguages();
if (locales != null) {
for (String locale : locales) {
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 {
public final void process(final FormSectionEvent e)
- throws FormProcessException {
- LOGGER.debug("Adding a categoryLocalization to category " + m_category);
+ throws FormProcessException {
+ LOGGER.debug("Adding a categoryLocalization to category "
+ + m_category);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
- final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
- final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
+ final PermissionChecker permissionChecker = cdiUtil.findBean(
+ PermissionChecker.class);
+ final CategoryRepository categoryRepository = cdiUtil.findBean(
+ CategoryRepository.class);
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 String title = (String) m_title.getValue(state);
final String description = (String) m_description.getValue(state);
- final String url = (String) m_url.getValue(state);
- final String isEnabled = (String) m_isEnabled.getValue(state);
+// final String url = (String) m_url.getValue(state);
+// final String isEnabled = (String) m_isEnabled.getValue(state);
if (LOGGER.isDebugEnabled()) {
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.getDescription().addValue(locale, description);
- category.setEnabled(isEnabled.equals("yes"));
+// category.setEnabled(isEnabled.equals("yes"));
categoryRepository.save(category);
} else {
@@ -131,5 +148,7 @@ public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
throw new AccessDeniedException();
}
}
+
}
+
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationEditForm.java
index e05ce14d9..2a6c1f6c7 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationEditForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationEditForm.java
@@ -89,13 +89,13 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
m_title.setValue(state, category.getTitle().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()) {
- m_isEnabled.setValue(state, "yes");
- } else {
- m_isEnabled.setValue(state, "no");
- }
+// if (category.isEnabled()) {
+// m_isEnabled.setValue(state, "yes");
+// } else {
+// m_isEnabled.setValue(state, "no");
+// }
}
}
@@ -122,8 +122,8 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
final Locale locale = new Locale((String) m_locale.getValue(state));
category.getTitle().addValue(locale, (String) m_title.getValue(state));
category.getDescription().addValue(locale, (String) m_description.getValue(state));
- category.setName((String) m_url.getValue(state));
- category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
+// category.setName((String) m_url.getValue(state));
+// category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
categoryRepository.save(category);
} else {
throw new AccessDeniedException();
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationForm.java
index 3da5c2eaa..6e4d39c69 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationForm.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationForm.java
@@ -69,12 +69,12 @@ public class CategoryLocalizationForm extends BaseForm {
final TextField m_title;
final TextArea m_description;
//final TextField m_url;
- final Hidden m_url;
- final RadioGroup m_isEnabled;
- private Embedded m_script = new Embedded(String.format(
- "",
- Web.getWebappContextPath()),
- false);
+// final Hidden m_url;
+// final RadioGroup m_isEnabled;
+// private Embedded m_script = new Embedded(String.format(
+// "",
+// Web.getWebappContextPath()),
+// false);
private final static String LOCALE = "locale";
private final static String TITLE = "title";
@@ -117,7 +117,7 @@ public class CategoryLocalizationForm extends BaseForm {
addField(gz("cms.ui.category.localization_locale"), m_locale);
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.setMaxLength(200);
@@ -128,10 +128,10 @@ public class CategoryLocalizationForm extends BaseForm {
m_title.setOnKeyUp("if (defaulting) { this.form." + URL + ".value = urlize(this.value) }");
// 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("yes", new Label(gz("cms.ui.yes"))));
- addField(gz("cms.ui.category.is_enabled"), m_isEnabled);
+// m_isEnabled = new RadioGroup(IS_ENABLED);
+// m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no"))));
+// m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes"))));
+// addField(gz("cms.ui.category.is_enabled"), m_isEnabled);
m_description = new TextArea(new TrimmedStringParameter(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 URL should be the same.
//Changed field to Hidden, initalised with URL of category itself.
- m_url = new Hidden(new TrimmedStringParameter(URL));
- try {
- m_url.addPrintListener(new PrintListener() {
-
- @Override
- public void prepare(final PrintEvent event) {
- final Hidden target = (Hidden) event.getTarget();
- final PageState state = event.getPageState();
-
- final Category cat = m_category.getCategory(state);
-
- target.setValue(state, cat.getName());
- }
-
- });
- } catch (TooManyListenersException | IllegalArgumentException ex) {
- LOGGER.fatal(ex);
- }
- addField(gz("cms.ui.category.url"), m_url);
+// m_url = new Hidden(new TrimmedStringParameter(URL));
+// try {
+// m_url.addPrintListener(new PrintListener() {
+//
+// @Override
+// public void prepare(final PrintEvent event) {
+// final Hidden target = (Hidden) event.getTarget();
+// final PageState state = event.getPageState();
+//
+// final Category cat = m_category.getCategory(state);
+//
+// target.setValue(state, cat.getName());
+// }
+//
+// });
+// } catch (TooManyListenersException | IllegalArgumentException ex) {
+// LOGGER.fatal(ex);
+// }
+// addField(gz("cms.ui.category.url"), m_url);
addAction(new Finish());
addAction(new Cancel());
@@ -192,7 +192,7 @@ public class CategoryLocalizationForm extends BaseForm {
@Override
public void generateXML(PageState ps, Element parent) {
- m_script.generateXML(ps, parent);
+// m_script.generateXML(ps, parent);
super.generateXML(ps, parent);
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTable.java
index e94010284..600e01150 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTable.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTable.java
@@ -32,22 +32,19 @@ import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.bebop.util.GlobalizationUtil;
+import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.GlobalizedMessagesUtil;
-import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Locale;
+import java.util.Iterator;
+import java.util.List;
/**
* 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_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 SingleSelectionModel m_model;
private final SingleSelectionModel m_catLocale;
@@ -94,31 +97,26 @@ public class CategoryLocalizationTable extends Table implements
// define columns
columnModel.add(new TableColumn(
- 0,
+ COL_LOCALE,
messagesUtil.getGlobalizedMessage(
- "cms.ui.category.localization.locale")
- .localize(),
+ "cms.ui.category.localization.locale"),
TABLE_COL_LANG));
columnModel.add(new TableColumn(
- 1,
+ COL_TITLE,
messagesUtil
- .getGlobalizedMessage("cms.ui.category.localization_name")
- .localize()));
+ .getGlobalizedMessage("cms.ui.category.localization_title")));
columnModel.add(new TableColumn(
- 2,
+ COL_DESCRIPTION,
messagesUtil.getGlobalizedMessage(
- "cms.ui.category.localization_description")
- .localize()));
+ "cms.ui.category.localization_description")));
columnModel.add(new TableColumn(
- 3,
+ COL_EDIT,
messagesUtil
- .getGlobalizedMessage("cms.ui.category.localization_url")
- .localize()));
+ .getGlobalizedMessage("cms.ui.category.localization_edit")));
columnModel.add(new TableColumn(
- 4,
+ COL_DEL,
messagesUtil
- .getGlobalizedMessage("cms.ui.category.localization_action")
- .localize(),
+ .getGlobalizedMessage("cms.ui.category.localization_action"),
TABLE_COL_DEL));
super.setModelBuilder(new CategoryLocalizationTableModelBuilder());
@@ -130,101 +128,87 @@ public class CategoryLocalizationTable extends Table implements
}
- /**
- * XXXX
- *
- */
private class CategoryLocalizationTableModelBuilder extends LockableImpl
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);
- if (category != null) {
- return new CategoryLocalizationTableModel(table, state, category);
- } else {
+ if (category == null) {
return Table.EMPTY_MODEL;
+ } else {
+ final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
+ final CategoryLocalizationTableController controller = cdiUtil
+ .findBean(CategoryLocalizationTableController.class);
+
+ final List rows = controller
+ .getCategoryLocalizations(category);
+ return new CategoryLocalizationTableModel(table, rows);
}
}
}
- /**
- * XXX
- *
- */
private class CategoryLocalizationTableModel implements TableModel {
- private Table m_table;
- private ArrayList localizedStringCollection;
- private LocalizedString m_categoryLocalization;
+ private final Table table;
+ private final Iterator iterator;
+ private CategoryLocalizationTableRow currentRow;
- private CategoryLocalizationTableModel(Table t, PageState ps,
- Category category) {
- m_table = t;
- localizedStringCollection = new ArrayList<>();
- localizedStringCollection.add(category.getTitle());
- localizedStringCollection.add(category.getDescription());
+ private CategoryLocalizationTableModel(
+ final Table table,
+ final List rows) {
+
+ this.table = table;
+ iterator = rows.iterator();
}
+ @Override
public int getColumnCount() {
- return m_table.getColumnModel().size();
+ return table.getColumnModel().size();
}
- /**
- * Check collection for the existence of another row.
- *
- * If exists, fetch the value of current CategoryLocalization object
- * into m_categoryLocalization class variable.
- */
+ @Override
public boolean nextRow() {
- return false;
-// if (m_categoryLocalizations != null && m_categoryLocalizations.next()) {
-// m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization();
-// return true;
-//
-// } else {
-//
-// return false;
-//
-// }
+
+ if (iterator.hasNext()) {
+ currentRow = iterator.next();
+ return true;
+ } else {
+ return false;
+ }
}
- /**
- * Return the
- *
- * @see com.arsdigita.bebop.table.TableModel#getElementAt(int)
- */
- public Object getElementAt(int columnIndex) {
- return null;
-// switch (columnIndex) {
-// case 0:
-// Locale clLocale = new Locale(m_categoryLocalization.getLocale());
-// return clLocale.getDisplayLanguage(/*Locale*/);
-// case 1:
-// return m_categoryLocalization.getName();
-// case 2:
-// String desc = m_categoryLocalization.getDescription();
-// if (desc != null && desc.length() > MAX_DESC_LENGTH) {
-// desc = desc.substring(MAX_DESC_LENGTH - 3).concat("...");
-// }
-// return desc;
-// case 3:
-// return m_categoryLocalization.getURL();
-// case 4:
-// return GlobalizationUtil.globalize("cms.ui.delete").localize();
-// default:
-// return null;
-// }
+ @Override
+ public Object getElementAt(final int columnIndex) {
+
+ switch (columnIndex) {
+ case COL_LOCALE:
+ return currentRow.getLocale();
+ case COL_TITLE:
+ return currentRow.getTitle();
+ case COL_DESCRIPTION:
+ return currentRow.getDescription();
+ case COL_EDIT:
+ return new GlobalizedMessage("cms.ui.edit",
+ CmsConstants.CMS_BUNDLE);
+ case COL_DEL:
+ return new GlobalizedMessage("cms.ui.delete",
+ CmsConstants.CMS_BUNDLE);
+ default:
+ throw new IllegalArgumentException("Illegal Column Index");
+ }
}
/**
*
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
*/
- public Object getKeyAt(int columnIndex) {
- return null;
-// return m_categoryLocalization.getID();
+ @Override
+ public Object getKeyAt(final int columnIndex) {
+ return currentRow.getLocale();
}
}
@@ -232,9 +216,15 @@ public class CategoryLocalizationTable extends Table implements
private class EditCellRenderer extends LockableImpl implements
TableCellRenderer {
- public Component getComponent(Table table, PageState state, Object value,
- boolean isSelected, final Object key,
- int row, int column) {
+ @Override
+ public Component getComponent(final Table table,
+ final PageState state,
+ final Object value,
+ final boolean isSelected,
+ final Object key,
+ final int row,
+ final int column) {
+
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
@@ -253,9 +243,15 @@ public class CategoryLocalizationTable extends Table implements
private class DeleteCellRenderer extends LockableImpl implements
TableCellRenderer {
- public Component getComponent(Table table, PageState state, Object value,
- boolean isSelected, Object key,
- int row, int column) {
+ @Override
+ public Component getComponent(final Table table,
+ final PageState state,
+ final Object value,
+ final boolean isSelected,
+ final Object key,
+ final int row,
+ final int column) {
+
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
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
* event.
*/
- public void cellSelected(TableActionEvent evt) {
+ @Override
+ public void cellSelected(final TableActionEvent event) {
- PageState state = evt.getPageState();
+ PageState state = event.getPageState();
// // Get selected CategoryLocalization
// CategoryLocalization categoryLocalization =
@@ -308,8 +305,9 @@ public class CategoryLocalizationTable extends Table implements
* provide Implementation to TableActionListener method. Does nothing in our
* case.
*/
- public void headSelected(TableActionEvent e) {
- throw new UnsupportedOperationException("Not Implemented");
+ @Override
+ public void headSelected(final TableActionEvent event) {
+ //Nothing
}
}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableController.java
new file mode 100644
index 000000000..2700dfa43
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableController.java
@@ -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 Jens Pelzetter
+ */
+@RequestScoped
+class CategoryLocalizationTableController {
+
+ @Transactional(Transactional.TxType.REQUIRED)
+ protected List getCategoryLocalizations(
+ final Category forCategory) {
+
+ final Map localizations
+ = new HashMap<>();
+
+ final Set 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;
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableRow.java
new file mode 100644
index 000000000..7bf6bd3fd
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryLocalizationTableRow.java
@@ -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 Jens Pelzetter
+ */
+class CategoryLocalizationTableRow
+ implements Comparable {
+
+ 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);
+ }
+
+}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/SubcategoryList.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/SubcategoryList.java
index 8716d2bd8..561ed2111 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/SubcategoryList.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/SubcategoryList.java
@@ -26,11 +26,13 @@ import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.util.GlobalizationUtil;
+import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil;
+import org.librecms.CmsConstants;
/**
* A List of all subcategories of the current category.
@@ -63,8 +65,9 @@ public class SubcategoryList extends SortableCategoryList {
// user selects it here
super.addActionListener(this::actionPerformed);
- Label label = new Label(GlobalizationUtil.globalize(
- "cms.ui.category.subcategory.none"));
+ Label label = new Label(new GlobalizedMessage(
+ "cms.ui.category.subcategory.none",
+ CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC);
setEmptyView(label);
}
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
index b0e7d308a..2cddced84 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties
@@ -506,3 +506,7 @@ cms.ui.pages.pagemodels.cancel=Cancel
cms.ui.cateogry.is_visible=Is visible?
cms.ui.category.cantmoved=This category can't be moved.
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
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
index e58852542..d10d51e5b 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties
@@ -503,3 +503,7 @@ cms.ui.pages.pagemodels.cancel=Abbrechen
cms.ui.cateogry.is_visible=Sichtbar?
cms.ui.category.cantmoved=Diese Kategorie kann nicht verschoben werden.
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
diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
index d89bfc330..7e6b7926a 100644
--- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
+++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties
@@ -463,3 +463,9 @@ cms.ui.cateogry.is_visible=Is visible?
cms.ui.category.cantmoved=This category can't be moved.
cms.ui.category.localization_none=No localization available
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