CCM NG/ccm-cms: ContentTypeAdminPane
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4433 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
91c510edd9
commit
874cc0ff83
|
|
@ -30,24 +30,34 @@ import com.arsdigita.bebop.event.ActionListener;
|
|||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
//ToDo import com.arsdigita.cms.SectionTemplateMapping;
|
||||
|
||||
import com.arsdigita.cms.ui.BaseAdminPane;
|
||||
import com.arsdigita.cms.ui.BaseDeleteForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
//ToDo insert later import com.arsdigita.cms.ui.ContentSectionPage;
|
||||
|
||||
import org.libreccm.core.CcmObject;
|
||||
|
||||
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.toolbox.ui.Cancellable;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.contentsection.ContentTypeManager;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* This class contains the split pane for the ContentType
|
||||
* administration interface.
|
||||
* This class contains the split pane for the ContentType administration
|
||||
* interface.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author Jack Chung
|
||||
|
|
@ -57,33 +67,33 @@ import java.math.BigDecimal;
|
|||
*/
|
||||
public final class ContentTypeAdminPane extends BaseAdminPane {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger(ContentTypeAdminPane.class);
|
||||
private static final Logger s_log = Logger.getLogger(
|
||||
ContentTypeAdminPane.class);
|
||||
private final ACSObjectSelectionModel m_model;
|
||||
private final ContentTypeRequestLocal m_type;
|
||||
|
||||
/**
|
||||
* Constructs an admin pane. It is containing
|
||||
* (a)
|
||||
* a list of available content types in a
|
||||
* given content section and adds a link to make additional content types
|
||||
* available (out of a list of installed, but available in a given content
|
||||
* section).
|
||||
* Constructs an admin pane. It is containing (a) a list of available
|
||||
* content types in a given content section and adds a link to make
|
||||
* additional content types available (out of a list of installed, but
|
||||
* available in a given content section).
|
||||
*/
|
||||
public ContentTypeAdminPane() {
|
||||
|
||||
//
|
||||
super(new Label(gz("cms.ui.types")),
|
||||
new ContentTypeListModelBuilder() ); //list with all Types avail.
|
||||
new ContentTypeListModelBuilder()); //list with all Types avail.
|
||||
|
||||
m_model = new ACSObjectSelectionModel(getSelectionModel());
|
||||
m_type = new SelectionRequestLocal();
|
||||
|
||||
ActionLink addTypeLink = new ActionLink(new Label(gz("cms.ui.type.add")));
|
||||
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));
|
||||
|
|
@ -154,75 +164,73 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
|||
//
|
||||
// }
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private class AddTypeContainer extends GridPanel implements ActionListener,
|
||||
FormProcessListener {
|
||||
|
||||
private Label m_noTypesAvailable =
|
||||
new Label(gz("cms.ui.type.select.none"));
|
||||
private SelectType m_selectType;
|
||||
private CreateType m_createType;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
AddTypeContainer() {
|
||||
super(1);
|
||||
Section selectSection = new Section();
|
||||
selectSection.setHeading(new Label(gz("cms.ui.type.select")));
|
||||
add(selectSection);
|
||||
|
||||
GridPanel container = new GridPanel(1);
|
||||
container.add(m_noTypesAvailable);
|
||||
m_selectType = new SelectType();
|
||||
m_selectType.addSubmissionListener(new CancelListener(m_selectType));
|
||||
m_selectType.addProcessListener(this);
|
||||
container.add(m_selectType);
|
||||
selectSection.setBody(container);
|
||||
|
||||
Section addSection = new Section() {
|
||||
|
||||
@Override
|
||||
public final boolean isVisible(final PageState state) {
|
||||
return super.isVisible(state)
|
||||
&& !ContentSection.getConfig().getHideUDCTUI();
|
||||
}
|
||||
};
|
||||
addSection.setHeading(new Label(gz("cms.ui.type.define")));
|
||||
m_createType = new CreateType(m_model);
|
||||
m_createType.addSubmissionListener(new CancelListener(m_createType));
|
||||
m_createType.addProcessListener(this);
|
||||
addSection.setBody(m_createType);
|
||||
add(addSection);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
PageState s = e.getPageState();
|
||||
ContentSection section = CMS.getContext().getContentSection();
|
||||
ContentTypeCollection contentTypes =
|
||||
section.getNotAssociatedContentTypes();
|
||||
boolean hasAvailableTypes = !contentTypes.isEmpty();
|
||||
m_selectType.setVisible(s, hasAvailableTypes);
|
||||
m_noTypesAvailable.setVisible(s, !hasAvailableTypes);
|
||||
}
|
||||
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
resetPane(state);
|
||||
}
|
||||
}
|
||||
|
||||
// ToDo (?) User Definied Content Types
|
||||
// private class AddTypeContainer extends GridPanel implements ActionListener,
|
||||
// FormProcessListener {
|
||||
//
|
||||
// private Label m_noTypesAvailable =
|
||||
// new Label(gz("cms.ui.type.select.none"));
|
||||
// private SelectType m_selectType;
|
||||
//// User Definied Content Types private CreateType m_createType;
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// */
|
||||
// AddTypeContainer() {
|
||||
// super(1);
|
||||
// Section selectSection = new Section();
|
||||
// selectSection.setHeading(new Label(gz("cms.ui.type.select")));
|
||||
// add(selectSection);
|
||||
//
|
||||
// GridPanel container = new GridPanel(1);
|
||||
// container.add(m_noTypesAvailable);
|
||||
// m_selectType = new SelectType();
|
||||
// m_selectType.addSubmissionListener(new CancelListener(m_selectType));
|
||||
// m_selectType.addProcessListener(this);
|
||||
// container.add(m_selectType);
|
||||
// selectSection.setBody(container);
|
||||
//
|
||||
// Section addSection = new Section() {
|
||||
//
|
||||
// @Override
|
||||
// public final boolean isVisible(final PageState state) {
|
||||
// return super.isVisible(state)
|
||||
// && !ContentSection.getConfig().getHideUDCTUI();
|
||||
// }
|
||||
// };
|
||||
// addSection.setHeading(new Label(gz("cms.ui.type.define")));
|
||||
// m_createType = new CreateType(m_model);
|
||||
// m_createType.addSubmissionListener(new CancelListener(m_createType));
|
||||
// m_createType.addProcessListener(this);
|
||||
// addSection.setBody(m_createType);
|
||||
// add(addSection);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * @param e
|
||||
// */
|
||||
// @Override
|
||||
// public void actionPerformed(ActionEvent e) {
|
||||
// PageState s = e.getPageState();
|
||||
// ContentSection section = CMS.getContext().getContentSection();
|
||||
// ContentTypeCollection contentTypes =
|
||||
// section.getNotAssociatedContentTypes();
|
||||
// boolean hasAvailableTypes = !contentTypes.isEmpty();
|
||||
// m_selectType.setVisible(s, hasAvailableTypes);
|
||||
// m_noTypesAvailable.setVisible(s, !hasAvailableTypes);
|
||||
// }
|
||||
//
|
||||
// public final void process(final FormSectionEvent e)
|
||||
// throws FormProcessException {
|
||||
// final PageState state = e.getPageState();
|
||||
// resetPane(state);
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* This class is essentially a copy of the CancelListener inside of
|
||||
* ModalPanel. We could not use the one in ModalPanel because it was
|
||||
|
|
@ -232,7 +240,7 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
|||
|
||||
Cancellable m_form;
|
||||
|
||||
CancelListener(Cancellable form) {
|
||||
CancelListener(final Cancellable form) {
|
||||
m_form = form;
|
||||
}
|
||||
|
||||
|
|
@ -242,13 +250,14 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
|||
PageState state = event.getPageState();
|
||||
if (m_form.isCancelled(state)) {
|
||||
getBody().pop(state);
|
||||
throw new FormProcessException(GlobalizationUtil.globalize(
|
||||
"cms.ui.type.cancelled"));
|
||||
throw new FormProcessException(new GlobalizedMessage(
|
||||
"cms.ui.type.cancelled", CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
}
|
||||
|
||||
} // end private class
|
||||
|
||||
private void resetPane(PageState state) {
|
||||
private void resetPane(final PageState state) {
|
||||
getBody().reset(state);
|
||||
if (getSelectionModel().isSelected(state)) {
|
||||
s_log.debug("The selection model is selected; displaying "
|
||||
|
|
@ -259,10 +268,13 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
|||
|
||||
private class SelectionRequestLocal extends ContentTypeRequestLocal {
|
||||
|
||||
@Override
|
||||
protected final Object initialValue(final PageState state) {
|
||||
ContentType contentType = (ContentType) m_model.getSelectedObject(state);
|
||||
ContentType contentType = (ContentType) m_model.getSelectedObject(
|
||||
state);
|
||||
return contentType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class DeleteForm extends BaseDeleteForm {
|
||||
|
|
@ -273,16 +285,28 @@ public final class ContentTypeAdminPane extends BaseAdminPane {
|
|||
addSubmissionListener(new TypeSecurityListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent e)
|
||||
throws FormProcessException {
|
||||
final PageState state = e.getPageState();
|
||||
final ContentSection section =
|
||||
CMS.getContext().getContentSection();
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
section.removeContentType(m_type.getContentType(state));
|
||||
section.save();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentSectionManager sectionManager = cdiUtil.findBean(
|
||||
ContentSectionManager.class);
|
||||
final ContentTypeManager typeManager = cdiUtil.findBean(
|
||||
ContentTypeManager.class);
|
||||
|
||||
m_type.getContentType(state).getContentItemClass();
|
||||
|
||||
sectionManager.removeContentTypeFromSection(
|
||||
typeManager.classNameToClass(m_type.getContentType(state)
|
||||
.getContentItemClass()),
|
||||
section);
|
||||
|
||||
getSelectionModel().clearSelection(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
|
||||
*
|
||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.type;
|
||||
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SimpleContainer;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
|
||||
import com.arsdigita.cms.ui.CMSForm;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.contentsection.ContentTypeManager;
|
||||
import org.librecms.contenttypes.ContentTypeInfo;
|
||||
import org.librecms.contenttypes.ContentTypesManager;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* This class contains a form component to that allows adding already-existing
|
||||
* content type to a content section.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author Jack Chung
|
||||
* @author Michael Pih
|
||||
*/
|
||||
public class SelectType extends CMSForm implements PrintListener,
|
||||
FormSubmissionListener,
|
||||
FormProcessListener {
|
||||
|
||||
private final static String TYPES = "types";
|
||||
private CheckboxGroup m_typesCheckbox;
|
||||
private Submit m_submit;
|
||||
private Submit m_cancel;
|
||||
|
||||
public SelectType() {
|
||||
super("ContentTypeSelect");
|
||||
|
||||
m_typesCheckbox = new CheckboxGroup(TYPES);
|
||||
try {
|
||||
m_typesCheckbox.addPrintListener(this);
|
||||
} catch (TooManyListenersException e) {
|
||||
throw new UncheckedWrapperException("TooManyListeners: " + e
|
||||
.getMessage());
|
||||
}
|
||||
|
||||
add(new Label(new GlobalizedMessage("cms.ui.type.available_types",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
add(m_typesCheckbox);
|
||||
|
||||
SimpleContainer s = new SimpleContainer();
|
||||
m_submit = new Submit("submit");
|
||||
m_submit.setButtonLabel("Add Selected Content Types");
|
||||
s.add(m_submit);
|
||||
m_cancel = new Submit("cancel");
|
||||
m_cancel.setButtonLabel("Cancel");
|
||||
s.add(m_cancel);
|
||||
add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
|
||||
|
||||
addProcessListener(this);
|
||||
addSubmissionListener(new TypeSecurityListener());
|
||||
addSubmissionListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a checkbox list of all content type not associated with the
|
||||
* current content section
|
||||
*/
|
||||
@Override
|
||||
public void prepare(final PrintEvent event) {
|
||||
|
||||
final CheckboxGroup target = (CheckboxGroup) event.getTarget();
|
||||
|
||||
// Get the current content section
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentTypesManager typesManager = cdiUtil.findBean(
|
||||
ContentTypesManager.class);
|
||||
|
||||
final List<ContentTypeInfo> availableTypes = typesManager
|
||||
.getAvailableContentTypes();
|
||||
final List<String> assignedTypes = section.getContentTypes()
|
||||
.stream()
|
||||
.map(contentType -> contentType.getContentItemClass())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<ContentTypeInfo> notAssignedTypes = availableTypes.stream()
|
||||
.filter(type -> assignedTypes.contains(type.getContentItemClass()
|
||||
.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (final ContentTypeInfo typeInfo : notAssignedTypes) {
|
||||
addOption(target, typeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void addOption(final CheckboxGroup target,
|
||||
final ContentTypeInfo typeInfo) {
|
||||
final Label label = new Label(new GlobalizedMessage(typeInfo
|
||||
.getLabelKey(), typeInfo.getLabelBundle()));
|
||||
target.addOption(new Option(typeInfo.getContentItemClass().getName(),
|
||||
label));
|
||||
}
|
||||
|
||||
/**
|
||||
* Form submission listener. If the cancel button was pressed, do not
|
||||
* process the form.
|
||||
*
|
||||
* @param event The submit event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void submitted(final FormSectionEvent event) throws
|
||||
FormProcessException {
|
||||
PageState state = event.getPageState();
|
||||
if (isCancelled(state)) {
|
||||
throw new FormProcessException(GlobalizationUtil.globalize(
|
||||
"cms.ui.cancelled"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this form was cancelled.
|
||||
*
|
||||
* @return true if the form was cancelled, false otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled(final PageState state) {
|
||||
return m_cancel.isSelected(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes form listener which updates a life cycle
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final ContentSection section = CMS.getContext().getContentSection();
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
final String[] types = (String[]) data.get(TYPES);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentTypeManager typeManager = cdiUtil.findBean(
|
||||
ContentTypeManager.class);
|
||||
final ContentSectionManager sectionManager = cdiUtil.findBean(
|
||||
ContentSectionManager.class);
|
||||
|
||||
if (types != null) {
|
||||
for (String type : types) {
|
||||
sectionManager.addContentTypeToSection(
|
||||
typeManager.classNameToClass(type),
|
||||
section,
|
||||
section.getLifecycleDefinitions().get(0),
|
||||
section.getWorkflowTemplates().get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,6 +24,9 @@ import org.libreccm.workflow.WorkflowTemplate;
|
|||
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||
import org.librecms.lifecycle.LifecycleDefinition;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
|
@ -39,6 +42,25 @@ public class ContentTypeManager {
|
|||
@Inject
|
||||
private ContentTypeRepository typeRepo;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Class<? extends ContentItem> classNameToClass(final String className) {
|
||||
final Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"No class with the name \"%s\" exists.", className),
|
||||
ex);
|
||||
}
|
||||
|
||||
if (clazz.isAssignableFrom(ContentItem.class)) {
|
||||
return (Class<? extends ContentItem>) clazz;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Class \"%s\" is not a content type.", className));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
@AuthorizationRequired
|
||||
public void setDefaultLifecycle(
|
||||
|
|
|
|||
Loading…
Reference in New Issue