diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java index b23656336..c4ea56cfd 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java @@ -20,12 +20,14 @@ package com.arsdigita.cms.ui.type; import com.arsdigita.bebop.ActionLink; import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.GridPanel; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Page; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; +import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.cms.CMS; @@ -41,6 +43,7 @@ import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.ui.ACSObjectSelectionModel; import com.arsdigita.toolbox.ui.ActionGroup; import com.arsdigita.toolbox.ui.Cancellable; +import com.arsdigita.toolbox.ui.Section; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -48,6 +51,9 @@ import org.libreccm.cdi.utils.CdiUtil; import org.librecms.CmsConstants; import org.librecms.contentsection.ContentSectionManager; import org.librecms.contentsection.ContentTypeManager; +import org.librecms.contenttypes.ContentTypeInfo; + +import java.util.List; /** * This class contains the split pane for the ContentType administration @@ -59,11 +65,11 @@ import org.librecms.contentsection.ContentTypeManager; * @author Justin Ross <jross@redhat.com> * @author Jens Pelzetter */ -public final class ContentTypeAdminPane extends BaseAdminPane { +public final class ContentTypeAdminPane extends BaseAdminPane { private static final Logger LOGGER = LogManager.getLogger( ContentTypeAdminPane.class); - + private final ACSObjectSelectionModel m_model; private final ContentTypeRequestLocal m_type; @@ -85,10 +91,11 @@ public final class ContentTypeAdminPane extends BaseAdminPane { ActionLink addTypeLink = new ActionLink(new Label(gz("cms.ui.type.add"))); -// AddTypeContainer addTypeContainer = new AddTypeContainer(); -// getBody().add(addTypeContainer); -// getBody().connect(addTypeLink, addTypeContainer); -// addTypeLink.addActionListener(addTypeContainer); + AddTypeContainer addTypeContainer = new AddTypeContainer(); + getBody().add(addTypeContainer); + getBody().connect(addTypeLink, addTypeContainer); + addTypeLink.addActionListener(addTypeContainer); + setEdit(new ActionLink(new Label(gz("cms.ui.type.edit"))), new EditType(m_model)); @@ -303,4 +310,53 @@ public final class ContentTypeAdminPane extends BaseAdminPane { } + private class AddTypeContainer + extends GridPanel + implements ActionListener, FormProcessListener { + + private final Label noTypesAvailableLabel + = new Label(gz("cms.ui.type.select.none")); + private final SelectType selectType; + + public AddTypeContainer() { + super(1); + + final Section selectSection = new Section(); + selectSection.setHeading(new Label(gz("cms.ui.type.select"))); + add(selectSection); + + final GridPanel container = new GridPanel(1); + container.add(noTypesAvailableLabel); + selectType = new SelectType(); + selectType.addSubmissionListener(new CancelListener(selectType)); + selectType.addProcessListener(this); + container.add(selectType); + selectSection.setBody(container); + } + + @Override + public void actionPerformed(final ActionEvent event) { + + final PageState state = event.getPageState(); + final ContentSection section = CMS.getContext().getContentSection(); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); + final List contentTypes = controller + .getNotAssociatedContentTypes(section); + final boolean hasAvailableTypes = !contentTypes.isEmpty(); + selectType.setVisible(state, hasAvailableTypes); + noTypesAvailableLabel.setVisible(state, !hasAvailableTypes); + } + + @Override + public void process(final FormSectionEvent event) + throws FormProcessException { + + final PageState state = event.getPageState(); + resetPane(state); + } + + } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java index dcb989f8e..3aa403a9f 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java @@ -18,15 +18,21 @@ */ package com.arsdigita.cms.ui.type; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.l10n.GlobalizationHelper; +import org.libreccm.workflow.WorkflowTemplate; import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentTypeRepository; +import org.librecms.contenttypes.ContentTypeInfo; +import org.librecms.contenttypes.ContentTypesManager; +import org.librecms.lifecycle.LifecycleDefinition; +import java.nio.charset.IllegalCharsetNameException; +import java.util.ArrayList; import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.ResourceBundle; import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; @@ -42,16 +48,16 @@ import javax.transaction.Transactional; * @author Jens Pelzetter */ @RequestScoped -public class ContentTypeAdminPaneController { +class ContentTypeAdminPaneController { @Inject private ContentTypeRepository typeRepo; @Inject - private GlobalizationHelper globalizationHelper; + private ContentTypesManager typesManager; @Inject - private ConfigurationManager confManager; + private ContentSectionRepository sectionRepo; @Transactional(Transactional.TxType.REQUIRED) public List getTypeList(final ContentSection section) { @@ -65,19 +71,116 @@ public class ContentTypeAdminPaneController { private String[] generateListEntry(final ContentType type) { final String[] entry = new String[2]; - final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); + entry[0] = Long.toString(type.getObjectId()); + + final ContentTypeInfo typeInfo = typesManager + .getContentTypeInfo(type.getContentItemClass()); + final ResourceBundle labelBundle = ResourceBundle + .getBundle(typeInfo.getLabelBundle()); + final String labelKey = typeInfo.getLabelKey(); + + entry[1] = labelBundle.getString(labelKey); - entry[0] = type.getUuid(); - // Enable if admin UI has fields for editing localised labels... -// if (type.getLabel().hasValue(globalizationHelper.getNegotiatedLocale())) { -// entry[1] = type.getLabel().getValue(globalizationHelper -// .getNegotiatedLocale()); -// } else { - entry[1] = type.getLabel().getValue(kernelConfig.getDefaultLocale()); -// } - return entry; } + @Transactional(Transactional.TxType.REQUIRED) + public List getNotAssociatedContentTypes( + final ContentSection section) { + + final List availableTypes = typesManager + .getAvailableContentTypes(); + final List associatedTypes = typeRepo + .findByContentSection(section) + .stream() + .map(type -> typesManager.getContentTypeInfo(type)) + .collect(Collectors.toList()); + + return availableTypes + .stream() + .filter(typeInfo -> !associatedTypes.contains(typeInfo)) + .collect(Collectors.toList()); + } + + @Transactional(Transactional.TxType.REQUIRED) + public LifecycleDefinition getLifecycleDefinition(final ContentType type) { + + final ContentType contentType = typeRepo + .findById(type.getObjectId()) + .orElseThrow(() -> new IllegalCharsetNameException(String.format( + "No ContentType with Id %d in the database. " + + "Where did that ID come from?", + type.getObjectId()))); + + return contentType.getDefaultLifecycle(); + } + + @Transactional(Transactional.TxType.REQUIRED) + public Optional getLifecycleDefinitionLabel(final ContentType type, + final Locale locale) { + + final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition( + type); + + if (lifecycleDefinition == null) { + return Optional.empty(); + } else { + return Optional.of(lifecycleDefinition.getLabel().getValue(locale)); + } + } + + @Transactional(Transactional.TxType.REQUIRED) + public WorkflowTemplate getWorkflowTemplate(final ContentType type) { + + final ContentType contentType = typeRepo + .findById(type.getObjectId()) + .orElseThrow(() -> new IllegalCharsetNameException(String.format( + "No ContentType with Id %d in the database. " + + "Where did that ID come from?", + type.getObjectId()))); + + return contentType.getDefaultWorkflow(); + } + + @Transactional(Transactional.TxType.REQUIRED) + public Optional getWorkflowTemplateName(final ContentType type, + final Locale locale) { + + final WorkflowTemplate workflowTemplate = getWorkflowTemplate(type); + + if (workflowTemplate == null) { + return Optional.empty(); + } else { + return Optional.of(workflowTemplate.getName().getValue(locale)); + } + } + + @Transactional(Transactional.TxType.REQUIRED) + public List getLifecycleDefinitions( + final ContentSection section) { + + final ContentSection contentSection = sectionRepo + .findById(section.getObjectId()) + .orElseThrow(() -> new IllegalArgumentException(String.format( + "No ContentSection with ID %d in the database. " + + "Where did that ID come from?", + section.getObjectId()))); + + return new ArrayList<>(contentSection.getLifecycleDefinitions()); + } + + @Transactional(Transactional.TxType.REQUIRED) + public List getWorkflowTemplates( + final ContentSection section) { + + final ContentSection contentSection = sectionRepo + .findById(section.getObjectId()) + .orElseThrow(() -> new IllegalArgumentException(String.format( + "No ContentSection with ID %d in the database. " + + "Where did that ID come from?", + section.getObjectId()))); + + return new ArrayList<>(contentSection.getWorkflowTemplates()); + } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java index 7b1c06550..539d4d414 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java @@ -30,19 +30,23 @@ import com.arsdigita.kernel.KernelConfig; import com.arsdigita.toolbox.ui.Property; import com.arsdigita.toolbox.ui.PropertyList; +import org.libreccm.cdi.utils.CdiUtil; + import java.util.Locale; import org.libreccm.workflow.WorkflowTemplate; import org.librecms.CmsConstants; +import org.librecms.contenttypes.ContentTypeInfo; +import org.librecms.contenttypes.ContentTypesManager; import java.util.List; +import java.util.Optional; +import java.util.ResourceBundle; /** - * This component displays basic attributes of a content type - * including: + * This component displays basic attributes of a content type including: * - * label, description, default lifecycle definition, default workflow - * template + * label, description, default lifecycle definition, default workflow template * * @author Michael Pih * @author Justin Ross @@ -60,16 +64,26 @@ class ContentTypePropertyList extends PropertyList { protected final List properties(final PageState state) { final List props = super.properties(state); final ContentType type = m_type.getContentType(state); - final ContentSection section = - CMS.getContext().getContentSection(); + final ContentSection section = CMS.getContext().getContentSection(); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypesManager typesManager = cdiUtil + .findBean(ContentTypesManager.class); + final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(type); final KernelConfig kernelConfig = KernelConfig.getConfig(); final Locale defaultLocale = kernelConfig.getDefaultLocale(); - + + final ResourceBundle labelBundle = ResourceBundle + .getBundle(typeInfo.getLabelBundle()); + final ResourceBundle descBundle = ResourceBundle + .getBundle(typeInfo.getDescriptionBundle()); + props.add(new Property(gz("cms.ui.name"), - type.getLabel().getValue(defaultLocale))); + labelBundle.getString(typeInfo.getLabelKey()))); props.add(new Property(gz("cms.ui.description"), - type.getDescription().getValue(defaultLocale))); + descBundle + .getString(typeInfo.getDescriptionKey()))); // props.add(new Property(gz("cms.ui.type.parent"), // type.getParent().orElse(null))); props.add(new Property(gz("cms.ui.type.lifecycle"), @@ -84,27 +98,37 @@ class ContentTypePropertyList extends PropertyList { final ContentType type) { final KernelConfig kernelConfig = KernelConfig.getConfig(); final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final LifecycleDefinition cycle = type.getDefaultLifecycle(); - if (cycle == null) { - return lz("cms.ui.type.lifecycle.none"); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); + + final Optional label = controller + .getLifecycleDefinitionLabel(type, defaultLocale); + + if (label.isPresent()) { + return label.get(); } else { - return cycle.getLabel().getValue(defaultLocale); + return lz("cms.ui.type.lifecycle.none"); } } private String getWorkflow(final ContentSection section, final ContentType type) { - final KernelConfig kernelConfig = KernelConfig.getConfig(); + final KernelConfig kernelConfig = KernelConfig.getConfig(); final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final WorkflowTemplate template = type.getDefaultWorkflow(); - if (template == null) { - return lz("cms.ui.type.workflow.none"); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); + + final Optional name = controller + .getWorkflowTemplateName(type, defaultLocale); + + if (name.isPresent()) { + return name.get(); } else { - return template.getName().getValue(defaultLocale); + return lz("cms.ui.type.workflow.none"); } } @@ -115,4 +139,5 @@ class ContentTypePropertyList extends PropertyList { private static String lz(final String key) { return (String) gz(key).localize(); } + } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java index faa459ae6..0e891577b 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java @@ -25,6 +25,7 @@ import com.arsdigita.bebop.Label; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SingleSelectionModel; +import com.arsdigita.bebop.Text; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; @@ -34,12 +35,8 @@ import com.arsdigita.bebop.form.Hidden; import com.arsdigita.bebop.form.Option; import com.arsdigita.bebop.form.SingleSelect; import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.StringLengthValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.CMS; import org.librecms.contentsection.ContentSection; @@ -48,6 +45,7 @@ import org.librecms.lifecycle.LifecycleDefinition; import org.libreccm.workflow.WorkflowTemplate; import com.arsdigita.cms.ui.CMSForm; +import com.arsdigita.cms.ui.GlobalNavigation; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.util.UncheckedWrapperException; @@ -66,8 +64,6 @@ import java.util.Locale; import java.util.Optional; import java.util.TooManyListenersException; -import javax.persistence.NoResultException; - /** * This class contains a form component to edit a content type * @@ -80,12 +76,12 @@ public class EditType extends CMSForm private static final Logger LOGGER = LogManager.getLogger(EditType.class); - private final SingleSelectionModel m_types; + private final SingleSelectionModel m_types; // Form widgets private Hidden m_id; - private TextField m_label; - private TextArea m_description; +// private TextField m_label; +// private TextArea m_description; private SingleSelect m_lcSelect; private SingleSelect m_wfSelect; private Submit m_submit; @@ -95,36 +91,35 @@ public class EditType extends CMSForm * @param model The content type selection model. This tells the form which * content type is selected. */ - public EditType(final SingleSelectionModel model) { + public EditType(final SingleSelectionModel model) { super("EditContentType"); m_types = model; - m_id = new Hidden(new BigDecimalParameter("id")); + m_id = new Hidden(new LongParameter("id")); m_id.addValidationListener(new NotNullValidationListener()); add(m_id); - add(new Label(new GlobalizedMessage("cms.ui.type.label", - CmsConstants.CMS_BUNDLE))); - m_label = new TextField(new StringParameter("label")); - m_label.addValidationListener(new NotNullValidationListener()); - m_label.setSize(40); - m_label.setMaxLength(1000); - add(m_label); - - add(new Label(new GlobalizedMessage("cms.ui.description", - CmsConstants.CMS_BUNDLE))); - m_description = new TextArea(new StringParameter("description")); - m_description.addValidationListener( - new StringLengthValidationListener(4000)); - m_description.setCols(40); - m_description.setRows(5); - m_description.setWrap(TextArea.SOFT); - add(m_description); - +// add(new Label(new GlobalizedMessage("cms.ui.type.label", +// CmsConstants.CMS_BUNDLE))); +// m_label = new TextField(new StringParameter("label")); +// m_label.addValidationListener(new NotNullValidationListener()); +// m_label.setSize(40); +// m_label.setMaxLength(1000); +// add(m_label); +// +// add(new Label(new GlobalizedMessage("cms.ui.description", +// CmsConstants.CMS_BUNDLE))); +// m_description = new TextArea(new StringParameter("description")); +// m_description.addValidationListener( +// new StringLengthValidationListener(4000)); +// m_description.setCols(40); +// m_description.setRows(5); +// m_description.setWrap(TextArea.SOFT); +// add(m_description); add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle", CmsConstants.CMS_BUNDLE))); - m_lcSelect = new SingleSelect(new BigDecimalParameter("lifecycle")); + m_lcSelect = new SingleSelect(new LongParameter("lifecycle")); try { m_lcSelect.addPrintListener(new SelectLifecyclePrintListener()); } catch (TooManyListenersException e) { @@ -135,7 +130,7 @@ public class EditType extends CMSForm add(new Label(new GlobalizedMessage("cms.ui.type.workflow", CmsConstants.CMS_BUNDLE))); - m_wfSelect = new SingleSelect(new BigDecimalParameter("workflow")); + m_wfSelect = new SingleSelect(new LongParameter("workflow")); try { m_wfSelect.addPrintListener(new SelectWorkflowPrintListener()); } catch (TooManyListenersException e) { @@ -195,14 +190,14 @@ public class EditType extends CMSForm final ContentType type = getContentType(state); final long typeId = type.getObjectId(); - final String label = type.getLabel().getValue(kernelConfig - .getDefaultLocale()); - final String description = type.getDescription().getValue(kernelConfig - .getDefaultLocale()); +// final String label = type.getLabel().getValue(kernelConfig +// .getDefaultLocale()); +// final String description = type.getDescription().getValue(kernelConfig +// .getDefaultLocale()); data.put(m_id.getName(), typeId); - data.put(m_label.getName(), label); - data.put(m_description.getName(), description); +// data.put(m_label.getName(), label); +// data.put(m_description.getName(), description); final LifecycleDefinition cycle = type.getDefaultLifecycle(); if (cycle != null) { @@ -220,7 +215,7 @@ public class EditType extends CMSForm * model. */ private ContentType getContentType(final PageState state) { - final String key = m_types.getSelectedKey(state).toString(); + final String key = (String) m_types.getSelectedKey(state); final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final ContentTypeRepository typeRepo = cdiUtil.findBean( @@ -231,10 +226,10 @@ public class EditType extends CMSForm result = typeRepo.findById(Long.parseLong(key)); } catch (NumberFormatException ex) { throw new UncheckedWrapperException(String.format( - "The provided key \"%s\" is not a long.", key), - ex); + "The provided key \"%d\" is not a long.", key), + ex); } - + if (result.isPresent()) { return result.get(); } else { @@ -260,8 +255,8 @@ public class EditType extends CMSForm // Read form variables. final Long key = (Long) data.get(m_id.getName()); - final String label = (String) data.get(m_label.getName()); - final String description = (String) data.get(m_description.getName()); +// final String label = (String) data.get(m_label.getName()); +// final String description = (String) data.get(m_description.getName()); final Long lifecycleId = (Long) data.get(m_lcSelect.getName()); final Long workflowId = (Long) data.get(m_wfSelect.getName()); @@ -284,19 +279,26 @@ public class EditType extends CMSForm new Object[]{key})); } - final KernelConfig kernelConfig = KernelConfig.getConfig(); - - type.get().getLabel().addValue(kernelConfig.getDefaultLocale(), label); - type.get().getDescription().addValue(kernelConfig.getDefaultLocale(), - description); - +// final KernelConfig kernelConfig = KernelConfig.getConfig(); +// type.get().getLabel().addValue(kernelConfig.getDefaultLocale(), label); +// type.get().getDescription().addValue(kernelConfig.getDefaultLocale(), +// description); typeRepo.save(type.get()); // Handle default lifecycle and workflow. - final LifecycleDefinition defaultLifecycle = lifecycleDefRepo.findById( - lifecycleId).get(); - final WorkflowTemplate defaultWorkflow = workflowTemplateRepo.findById( - workflowId).get(); + final LifecycleDefinition defaultLifecycle; + if (lifecycleId == 0) { + defaultLifecycle = null; + } else { + defaultLifecycle = lifecycleDefRepo.findById(lifecycleId).get(); + } + final WorkflowTemplate defaultWorkflow; + if (workflowId == 0) { + defaultWorkflow = null; + } else { + defaultWorkflow = workflowTemplateRepo.findById(workflowId).get(); + } + typeManager.setDefaultLifecycle(type.get(), defaultLifecycle); typeManager.setDefaultWorkflow(type.get(), defaultWorkflow); @@ -316,19 +318,26 @@ public class EditType extends CMSForm .getTarget(); lifecycleSelect.clearOptions(); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); + // Get the current content section ContentSection section = CMS.getContext().getContentSection(); - lifecycleSelect.addOption(new Option("", "-- select --")); + lifecycleSelect.addOption(new Option( + "0", + new Label(new GlobalizedMessage("cms.ui.type.lifecycle.select", + CmsConstants.CMS_BUNDLE)))); - final List cycles = section - .getLifecycleDefinitions(); + final List cycles = controller + .getLifecycleDefinitions(section); final Locale defaultLocale = KernelConfig.getConfig() .getDefaultLocale(); cycles.forEach(cycle -> { lifecycleSelect.addOption( new Option(Long.toString(cycle.getDefinitionId()), - cycle.getLabel().getValue(defaultLocale))); + new Text(cycle.getLabel().getValue(defaultLocale)))); }); } @@ -349,10 +358,17 @@ public class EditType extends CMSForm // Get the current content section ContentSection section = CMS.getContext().getContentSection(); - workflowSelect.addOption(new Option("", "-- select --")); + workflowSelect.addOption(new Option( + "0", + new Label(new GlobalizedMessage("cms.ui.type.workflow.select", + CmsConstants.CMS_BUNDLE)))); - final List templates = section - .getWorkflowTemplates(); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeAdminPaneController controller = cdiUtil + .findBean(ContentTypeAdminPaneController.class); + + final List templates = controller + .getWorkflowTemplates(section); final Locale defaultLocale = KernelConfig.getConfig() .getDefaultLocale(); templates.forEach(template -> { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java index 55f1a4e4f..9e9984aff 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java @@ -26,6 +26,7 @@ import org.libreccm.security.PermissionChecker; import org.libreccm.security.PermissionManager; import org.libreccm.security.Role; import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentTypeRepository; @@ -49,6 +50,9 @@ public class TypePermissionsTableController { @Inject private PermissionManager permissionManager; + @Inject + private ContentSectionRepository sectionRepo; + @Inject private ContentTypeRepository typeRepo; @@ -63,9 +67,16 @@ public class TypePermissionsTableController { @Transactional(Transactional.TxType.REQUIRED) public List> retrieveTypePermissions( final long typeId, final ContentSection section) { - final ContentType type = typeRepo.findById(typeId).get(); - final List roles = section.getRoles(); + final ContentType type = typeRepo.findById(typeId).get(); + final ContentSection contentSection = sectionRepo + .findById(section.getObjectId()) + .orElseThrow(() -> new IllegalArgumentException(String.format( + "No ContentSection with ID %d in the database. " + + "Where did that Id come from?", + section.getObjectId()))); + + final List roles = contentSection.getRoles(); return roles.stream() .map(role -> retrievePermissionsForRole(type, role)) @@ -88,7 +99,7 @@ public class TypePermissionsTableController { } public void toggleTypeUsePermission(final ContentType type, - final Role role) { + final Role role) { if (permissionChecker.isPermitted(TypePrivileges.USE_TYPE, type, role)) { permissionManager.revokePrivilege(TypePrivileges.USE_TYPE, role, diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionSetup.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionSetup.java index 159cf40ed..d8b6fb571 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionSetup.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionSetup.java @@ -42,6 +42,7 @@ import org.librecms.dispatcher.MultilingualItemResolver; import java.util.Arrays; import org.librecms.contentsection.privileges.TypePrivileges; +import org.librecms.contenttypes.ContentTypeDescription; import java.util.Locale; @@ -348,6 +349,7 @@ public class ContentSectionSetup extends AbstractCcmApplicationSetup { final ContentType type = new ContentType(); type.setContentSection(section); type.setUuid(UUID.randomUUID().toString()); + type.setDisplayName(clazz.getSimpleName()); type.setContentItemClass(clazz.getName()); getEntityManager().persist(type); section.addContentType(type); diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java index 8ebfed155..5b5d99ac6 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java @@ -18,9 +18,6 @@ */ package org.librecms.contentsection; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.l10n.GlobalizationHelper; import org.librecms.contentsection.privileges.TypePrivileges; import org.libreccm.security.AuthorizationRequired; @@ -29,12 +26,8 @@ import org.libreccm.security.RequiresPrivilege; import org.libreccm.security.Role; import org.libreccm.workflow.WorkflowTemplate; import org.librecms.contentsection.privileges.AdminPrivileges; -import org.librecms.contenttypes.Article; import org.librecms.lifecycle.LifecycleDefinition; -import java.util.Objects; -import java.util.ResourceBundle; - import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; diff --git a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties index 9d30b13d6..efc36318a 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources.properties @@ -221,3 +221,26 @@ cms.ui.lifecycle.phase.edit_submit=Save cms.ui.lifecycle.phase.edit_cancel=Cancel cms.ui.lifecycle.phase.delete_submit=Delete cms.ui.lifecycle.phase.delete_cancel=Cancel +cms.ui.type.intro=Select a content type or create a new one +cms.ui.type.add=Add content type +cms.ui.types=Content types +cms.ui.type.details=Content Type Details +cms.ui.name=Name +cms.ui.description=Description +cms.ui.type.lifecycle=Default lifecycle +cms.ui.type.workflow=Standard workflow +cms.ui.type.lifecycle.none=No default lifecycle +cms.ui.type.workflow.none=No default workflow +cms.ui.type.templates=Templates +cms.ui.type.template.add=Add template +cms.ui.type.edit=Edit +cms.ui.type.delete=Delete +cms.ui.type.permissions=Permissions +cms.ui.type.permissions.role=Role +cms.ui.type.permissions_can_use=Can use +cms.ui.type.permission.action=Revoke permission +cms.ui.type.permissions.actions.revoke=Revoke permission +cms.ui.type.lifecycle.select=Select the default lifecycle +cms.ui.type.workflow.select=Select default workflow +cms.ui.type.select=Select Content Type +cms.ui.type.select.none=There are no available content types to select 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 8854ccd0d..1aa9dd2c6 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_de.properties @@ -220,3 +220,26 @@ cms.ui.lifecycle.phase.edit_submit=Speichern cms.ui.lifecycle.phase.edit_cancel=Abbrechen cms.ui.lifecycle.phase.delete_submit=L\u00f6schen cms.ui.lifecycle.phase.delete_cancel=Abbrechen +cms.ui.type.intro=W\u00e4hlen Sie einen Dokumenttyp oder erstellen Sie einen neuen +cms.ui.type.add=Dokumenttyp hinzuf\u00fcgen +cms.ui.types=Dokumenttypen +cms.ui.type.details=Dokumententyp Details +cms.ui.name=Name +cms.ui.description=Beschreibung +cms.ui.type.lifecycle=Voreingestellter Ver\u00f6ffentlichungszyklus +cms.ui.type.workflow=Voreingestellter Arbeitsablauf +cms.ui.type.lifecycle.none=Kein voreingestellter Ver\u00f6ffentlichungszyklus +cms.ui.type.workflow.none=Kein voreingestellter Arbeitsablauf +cms.ui.type.templates=Vorlagen +cms.ui.type.template.add=Vorlage hinzuf\u00fcgen +cms.ui.type.edit=Bearbeiten +cms.ui.type.delete=L\u00f6schen +cms.ui.type.permissions=Berechtigungen +cms.ui.type.permissions.role=Rolle +cms.ui.type.permissions_can_use=Darf Dokumenttype verwenden? +cms.ui.type.permission.action=Berechtigung entziehen +cms.ui.type.permissions.actions.revoke=Berechtigung entziehen +cms.ui.type.lifecycle.select=Voreingestellten Ver\u00f6ffentlichungszyklus ausw\u00e4hlen +cms.ui.type.workflow.select=Voreingestellten Arbeitsablauf ausw\u00e4hlen +cms.ui.type.select=Dolkumententype ausw\u00e4hlen +cms.ui.type.select.none=Keine verf\u00fcgbaren Dokumententypen 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 b5d264211..2afc0f694 100644 --- a/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties +++ b/ccm-cms/src/main/resources/org/librecms/CmsResources_fr.properties @@ -179,3 +179,26 @@ cms.ui.lifecycle.phase.edit_submit=Save cms.ui.lifecycle.phase.edit_cancel=Cancel cms.ui.lifecycle.phase.delete_submit=Delete cms.ui.lifecycle.phase.delete_cancel=Cancel +cms.ui.type.intro=Select a content type or create a new one +cms.ui.type.add=Add content type +cms.ui.types=Content types +cms.ui.type.details=Content Type Details +cms.ui.name=Name +cms.ui.description=Description +cms.ui.type.lifecycle=Default lifecycle +cms.ui.type.workflow=Standard workflow +cms.ui.type.lifecycle.none=No default lifecycle +cms.ui.type.workflow.none=No default workflow +cms.ui.type.templates=Templates +cms.ui.type.template.add=Add template +cms.ui.type.edit=Edit +cms.ui.type.delete=Delete +cms.ui.type.permissions=Permissions +cms.ui.type.permissions.role=Role +cms.ui.type.permissions_can_use=Can use content type? +cms.ui.type.permission.action=Revoke permission +cms.ui.type.permissions.actions.revoke=Revoke permission +cms.ui.type.lifecycle.select=Select the default lifecycle +cms.ui.type.workflow.select=Select default workflow +cms.ui.type.select=Select Content Type +cms.ui.type.select.none=There are no available content types to select diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/list/DefaultListCellRenderer.java b/ccm-core/src/main/java/com/arsdigita/bebop/list/DefaultListCellRenderer.java index a21e6b4ab..e9d9b210a 100755 --- a/ccm-core/src/main/java/com/arsdigita/bebop/list/DefaultListCellRenderer.java +++ b/ccm-core/src/main/java/com/arsdigita/bebop/list/DefaultListCellRenderer.java @@ -30,7 +30,7 @@ import com.arsdigita.bebop.PageState; * explicitly. * * @author David Lutterkort - * @version $Id$ */ + */ public class DefaultListCellRenderer implements ListCellRenderer { /** @@ -40,15 +40,21 @@ public class DefaultListCellRenderer implements ListCellRenderer { * isSelected is not true, returns a * ControlLink labelled with * value.toString(). When the user clicks on the link, that - * item becomes selected. */ - public Component getComponent(List list, PageState state, Object value, - String key, int index, boolean isSelected) + * item becomes selected. + */ + @Override + public Component getComponent(final List list, + final PageState state, + final Object value, + final String key, + final int index, + final boolean isSelected) { - Label l = new Label(value.toString()); + final Label label = new Label(value.toString()); if (isSelected) { - l.setFontWeight(Label.BOLD); - return l; + label.setFontWeight(Label.BOLD); + return label; } - return new ControlLink(l); + return new ControlLink(label); } } diff --git a/ccm-core/src/main/java/com/arsdigita/bebop/table/RowData.java b/ccm-core/src/main/java/com/arsdigita/bebop/table/RowData.java index eb5fc67bd..68f56abbc 100644 --- a/ccm-core/src/main/java/com/arsdigita/bebop/table/RowData.java +++ b/ccm-core/src/main/java/com/arsdigita/bebop/table/RowData.java @@ -37,10 +37,10 @@ public class RowData { private K rowKey; - private final List cols; + private final String[] cols; public RowData(final int numCols) { - cols = new ArrayList<>(numCols); + cols = new String[numCols]; } public K getRowKey() { @@ -52,11 +52,11 @@ public class RowData { } public String getColData(final int colIndex) { - return cols.get(colIndex); + return cols[colIndex]; } public void setColData(final int colIndex, final String data) { - cols.set(colIndex, data); + cols[colIndex] = data; } }