+ * + * If the creation component wishes to cancel the creation process, it should + * call + * + *+ * // The member variable m_parent points to the CreationSelector + * SomeContentItem item = somehowCreateTheItem(state); + * item.setParent(m_parent.getFolder(state)); + * m_parent.editItem(state, item); + *
+ * + * The component may also call + * + *m_parent.redirectBack(state);
+ * + * in order to get the current content section. + * + * @author unknown + * @author Jens Pelzetter + */ +public class CreationSelector extends MetaForm { + + private static final Logger LOGGER = LogManager.getLogger( + CreationSelector.class); + + private final FolderSelectionModel folderSelectionModel; + private final SingleSelectionModelm_parent.getContentSection(state);
CreationSelector. Load all the possible
+ * creation components from the database and stick them in the Map.
+ *
+ * @param typeSelectionModel the {@link SingleSelectionModel} which will
+ * supply a BigDecimal ID of the content type to
+ * instantiate
+ *
+ * @param folderSelectionModel the {@link FolderSelectionModel} containing
+ * the folder in which new items are to be
+ * created
+ */
+ public CreationSelector(final SingleSelectionModel- * - * If the creation component wishes to cancel the creation process, - * it should call - * - *- * // The member variable m_parent points to the CreationSelector - * SomeContentItem item = somehowCreateTheItem(state); - * item.setParent(m_parent.getFolder(state)); - * m_parent.editItem(state, item); - *
- * - * The component may also call - * - *m_parent.redirectBack(state);
- * - * in order to get the current content section. - * - * @version $Id: CreationSelector.java 2185 2011-06-20 21:16:02Z pboy $ - */ -public class CreationSelector extends MetaForm { - - private static Logger s_log = Logger.getLogger(CreationSelector.class); - - private final FolderSelectionModel m_folderSel; - private final SingleSelectionModel m_typeSel; - - private static Class[] s_args = new Class[] { - ItemSelectionModel.class, - CreationSelector.class - }; - - private Object[] m_vals; - - private ItemSelectionModel m_itemSel; - private BigDecimalParameter m_itemId; - - private ItemSelectionModel m_bundleSel; - private BigDecimalParameter m_bundleId; - - public static final String ITEM_ID = "iid"; - public static final String BUNDLE_ID = "bid"; - - /** - * Constructs a newm_parent.getContentSection(state);
CreationSelector. Load all the
- * possible creation components from the database and stick them
- * in the Map.
- *
- * @param typeModel the {@link SingleSelectionModel} which will
- * supply a BigDecimal ID of the content type to instantiate
- *
- * @param folderModel the {@link FolderSelectionModel} containing
- * the folder in which new items are to be created
- */
- public CreationSelector(final SingleSelectionModel typeModel,
- final FolderSelectionModel folderModel) {
- super("pageCreate");
-
- m_typeSel = typeModel;
-
- m_folderSel = folderModel;
- m_itemId = new BigDecimalParameter(ITEM_ID);
- m_bundleId = new BigDecimalParameter(BUNDLE_ID);
- m_bundleSel = new ItemSelectionModel(ContentBundle.class.getName(),
- ContentBundle.BASE_DATA_OBJECT_TYPE, m_bundleId);
- }
-
-
- /**
- *
- * @param state
- * @return
- */
- @Override
- public Form buildForm(PageState state) {
- BigDecimal typeID = (BigDecimal)m_typeSel.getSelectedKey(state);
- Component c = null;
- Form returnForm = new Form("pageCreate");
- FormErrorDisplay fed = new FormErrorDisplay(this);
- fed.setStateParamsAreRegistered(false);
- returnForm.add(fed , ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
- if (typeID != null) {
- try {
- ContentType type = new ContentType(typeID);
- AuthoringKit kit = type.getAuthoringKit();
- if(kit != null) {
- c = instantiateKitComponent(kit, type);
- if(c != null) {
- returnForm.add(c);
- returnForm.setMethod(Form.POST);
- returnForm.setEncType("multipart/form-data");
- }
- }
- } catch (DataObjectNotFoundException e) {
- // content type not found
- }
- }
- return returnForm;
- }
-
- /**
- * Add the item_id parameter.
- *
- * @param p
- */
- @Override
- public void register(Page p) {
- super.register(p);
- p.addComponentStateParam(this, m_itemId);
- p.addComponentStateParam(this, m_bundleId);
- }
-
- /**
- * Get the creation component.
- *
- * @param kit
- * @param type
- * @return
- */
- protected Component instantiateKitComponent
- (final AuthoringKit kit, final ContentType type) {
- String creatorName = kit.getCreateComponent();
- Object[] vals;
-
- if(creatorName == null) {
- return null;
- }
-
- try {
- Class createClass = Class.forName(creatorName);
- ItemSelectionModel itemModel = new ItemSelectionModel(type, m_itemId);
- vals = new Object[]{itemModel, this};
- Constructor constr = createClass.getConstructor(s_args);
- Component c = (Component)constr.newInstance(vals);
- return c;
- } catch (Exception e) {
- s_log.error("Instantiation failure", e);
- throw new UncheckedWrapperException (
- "Failed to instantiate creation component " +
- kit.getCreateComponent() + ": " + e.getMessage(),
- e);
- }
- }
-
- /**
- * Return the currently selected folder. Creation components will place
- * new items in this folder.
- *
- * @param s represents the current request
- * @return the currently selected folder, in which new items should be
- * placed.
- */
- public final Folder getFolder(PageState s) {
- return (Folder) m_folderSel.getSelectedObject(s);
- }
-
- /**
- * Return the currently selected content section. New items created by
- * creation components will belong to this section. This is the content
- * section to which the folder returned by {@link #getFolder getFolder}
- * belongs.
- *
- * @param s represents the current request
- * @return the currently selected content section.
- */
- public final ContentSection getContentSection(PageState s) {
- final ContentSection section = (ContentSection)
- getFolder(s).getContentSection();
-
- return section;
- }
-
- /**
- * Forward to the item editing UI. The creation component of an authoring
- * kit may call this method to indicate that the creation process is
- * complete.
- *
- * @param s the page state
- * @param item the newly created item
- */
- public void editItem(PageState s, ContentItem item) {
- ContentSection sec = getContentSection(s);
-
- String nodeURL = URL.getDispatcherPath() + sec.getPath() + "/";
- String target = ContentItemPage.getItemURL
- (nodeURL, item.getID(), ContentItemPage.AUTHORING_TAB,true);
-
- throw new RedirectSignal(target, true);
- }
-
- /**
- * Cancel item editing and go back to where the user came from
- *
- * @param s the page state
- */
- public void redirectBack(PageState state) {
- m_typeSel.clearSelection(state);
- }
-
-}
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/NewItemForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/NewItemForm.java
new file mode 100755
index 000000000..070985b57
--- /dev/null
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/NewItemForm.java
@@ -0,0 +1,201 @@
+/*
+ * 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.authoring;
+
+import com.arsdigita.bebop.BoxPanel;
+import com.arsdigita.bebop.Form;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.event.PrintEvent;
+import com.arsdigita.bebop.event.PrintListener;
+import com.arsdigita.bebop.form.OptionGroup;
+import com.arsdigita.bebop.form.SingleSelect;
+import com.arsdigita.bebop.form.Submit;
+import com.arsdigita.bebop.parameters.BigDecimalParameter;
+import com.arsdigita.bebop.parameters.LongParameter;
+import com.arsdigita.cms.ui.ItemSearch;
+import com.arsdigita.globalization.GlobalizedMessage;
+import com.arsdigita.util.UncheckedWrapperException;
+import com.arsdigita.xml.Element;
+
+import java.math.BigDecimal;
+
+import org.libreccm.cdi.utils.CdiUtil;
+import org.libreccm.security.PermissionChecker;
+import org.librecms.CmsConstants;
+import org.librecms.contentsection.ContentSection;
+import org.librecms.contentsection.ContentType;
+import org.librecms.contentsection.ContentTypeRepository;
+import org.librecms.contentsection.privileges.TypePrivileges;
+
+import java.util.List;
+import java.util.TooManyListenersException;
+import java.util.stream.Collectors;
+
+/**
+ * A form element which displays a select box of all content types available
+ * under the given content section, and forwards to the item creation UI when
+ * the user selects a content type to instantiate.
+ *
+ * @author Stanislav Freidin (sfreidin@arsdigtia.com)
+ * @author Jens Pelzetter
+ */
+public abstract class NewItemForm extends Form {
+
+ public static final String TYPE_ID = "tid";
+
+ private final SingleSelect typeSelect;
+ private final Submit submit;
+ private final Label emptyLabel;
+ private final Label createLabel;
+
+ public NewItemForm(final String name) {
+ this(name, BoxPanel.HORIZONTAL);
+ }
+
+ /**
+ * Construct a new NewItemForm. It sets a vertical BoxPanel as the component
+ * container.
+ *
+ * @param name the name attribute of the form.
+ * @param orientation
+ */
+ public NewItemForm(final String name, final int orientation) {
+
+ super(name, new BoxPanel(BoxPanel.VERTICAL));
+ setIdAttr("new_item_form");
+
+ final BoxPanel panel = new BoxPanel(orientation);
+ panel.setWidth("2%");
+ panel.setBorder(0);
+
+ // create and add an "empty" component
+ emptyLabel = new Label(
+ new GlobalizedMessage("cms.ui.authoring.no_types_registered",
+ CmsConstants.CMS_BUNDLE),
+ false);
+ emptyLabel.setIdAttr("empty_label");
+ panel.add(emptyLabel);
+
+ createLabel = new Label(
+ new GlobalizedMessage("cms.ui.authoring.create_new",
+ CmsConstants.CMS_BUNDLE),
+ false);
+ createLabel.setIdAttr("create_label");
+ panel.add(createLabel);
+
+ typeSelect = new SingleSelect(new BigDecimalParameter(TYPE_ID),
+ OptionGroup.SortMode.ALPHABETICAL_ASCENDING);
+ try {
+ typeSelect.addPrintListener(new PrintListener() {
+
+ // Read the content section's content types and add them as options
+ @Override
+ public void prepare(final PrintEvent event) {
+ final OptionGroup optionGroup = (OptionGroup) event
+ .getTarget();
+ optionGroup.clearOptions();
+ final PageState state = event.getPageState();
+
+ // gather the content types of this section into a list
+ final ContentSection section = getContentSection(state);
+ final ContentType parentType;
+ final List
+ * This component is a form for adding object administrators
+ *
+ * @author Michael Pih (pihman@arsdigita.com)
+ * @author Uday Mathur (umathur@arsdigita.com)
+ * @author Jens Pelzetter
+ */
+public class ObjectAddAdmin extends SimpleContainer
+ implements FormProcessListener {
+
+ private final static String SEARCH_QUERY = "searchQuery";
+ private final static String USERS = "roles";
+ private final static String SUBMIT = "addSubmit";
+ private final static String CANCEL = "addCancel";
+
+ private Widget searchWidget;
+ private final RequestLocal queryRequestLocal;
+ private String labelText;
+ private String m_submitText;
+
+ private final CMSContainer noMatchesContainer;
+ private final CMSContainer matchesContainer;
+
+ private final Form form;
+ private Hidden searchQuery;
+ private CheckboxGroup rolesCheckboxGroup;
+ private Submit submit;
+ private Submit cancel;
+
+ private final CcmObjectSelectionModel
+ * This panel allows a staff administrator to search for users and add them to a
+ * staff role for the content section. Subclasses only need to override {@link #buildForm buildForm} to
+ * return the request-specific form. The meta form takes care of
+ * interfacing that form with the normal control flow of serving a Bebop
+ * Listeners can be added directly to the meta form and are run
+ * whenever the corresponding listeners would be run on an ordinary
+ * form. The source of the Page. The meta form will fool the request-specific forms
+ * into thinking that they are part of a static Bebop Page.
+ * The properties of the meta form should be used to initialize the
+ * correspoding properties of the request-specific form whenever
+ * possible. These properties include name,
+ * method, and encType.
+ *
+ * FormSectionEvent will be the meta
+ * form.
+ *
+ * @author Stas Freidin
+ * @author David Lutterkort
+ */
+
+public abstract class MetaForm extends Form {
+
+ private RequestLocal m_dynamicForm;
+
+ /**
+ * Constructs a new meta form.
+ *
+ * @param name the name of the form
+ */
+ public MetaForm(String name) {
+ super(name);
+ m_dynamicForm = new RequestLocal() {
+ protected Object initialValue(PageState s) {
+ Form result = buildForm(s);
+ result.getModel().mergeModel(getModel());
+ // form isn't part of the page, so it is invisible
+ // on the page (vacuously). We should consider it
+ // visible iff the static container MetaForm is visible.
+ result.setProcessInvisible(
+ MetaForm.this.getProcessInvisible() ||
+ s.isVisibleOnPage(MetaForm.this));
+ result.traverse();
+ Traversal t = new Traversal() {
+ public void act(Component c) {
+ c.lock();
+ }
+ };
+ t.preorder(result);
+ return result;
+ }
+ };
+ }
+
+ /**
+ * Retrieves the form for the request represented by
+ * state. If the form hasn't been built
+ * yet, calls {@link #buildForm buildForm} to build the
+ * form.
+ *
+ * @param state describes the current request
+ * @return a custom-built form for this request.
+ * @pre state != null
+ * @post return != null
+ */
+ protected Form getDynamicForm(PageState state) {
+ return (Form) m_dynamicForm.get(state);
+ }
+
+ /**
+ * Builds the dynamic form. Subclasses should override this method to
+ * build the form based on the request represented by state.
+ *
+ * @param state describes the current request
+ * @return the form to be used for this request.
+ * @pre state != null
+ * @post return != null
+ */
+ public abstract Form buildForm(PageState state);
+
+ /**
+ * Force a rebuilding and updating of the dynamic form. Calls
+ * buildForm again and sets the dynamic form to the form
+ * returned by it.
+ *
+ * @param s describes the current request
+ */
+ public void rebuildForm(PageState s) {
+ m_dynamicForm.set(s, m_dynamicForm.initialValue(s));
+ }
+
+ /**
+ * Returns the form data constructed by {@link #process process} for the
+ * request described by state. If the form for this request
+ * hasn't been built yet, calls {@link #buildForm buildForm}.
+ *
+ * @param state describes the current request
+ * @return the values extracted from the HTTP request contained
+ * in state, or null if the form has not
+ * yet been processed.
+ * @pre state != null
+ */
+ public FormData getFormData(PageState state) {
+ return getDynamicForm(state).getFormData(state);
+ }
+
+ /**
+ * Generates the XML representing the form and its widgets, but not
+ * the state information, from s. The XML generation is
+ * delegated to the request-specific form by calling {@link
+ * #generateXMLSansState generateXMLSansState} on it.
+ *
+ * @param s represents the curent request
+ * @return the top-level element for the form.
+ */
+ protected Element generateXMLSansState(PageState s, Element parent) {
+ return getDynamicForm(s).generateXMLSansState(s, parent);
+ }
+
+ /**
+ * Processes the request-specific form for the request represented by
+ * state.
+ *
+ * @param state describes the current request
+ * @return the form data extracted from the current request.
+ * @pre state != null
+ * @post return != null
+ * @see Form#process Form.process(...)
+ * @see FormModel#process FormModel.process(...)
+ */
+ public FormData process(PageState state)
+ throws FormProcessException {
+
+ if (state.isVisibleOnPage(this))
+ return getDynamicForm(state).process(state);
+ return null; // XXX is this ok ?
+ }
+
+ /**
+ * Do nothing; the dynamic form will take care of the tag.
+ */
+ protected void addMagicTag() {
+ return;
+ }
+
+ /**
+ * Not implemented because meta forms currently don't support mixing static and
+ * dynamic widgets.
+ * @throws UnsupportedOperationException
+ */
+ public void add(Component pc, int constraints) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ /**
+ * Not implemented.
+ * @throws UnsupportedOperationException
+ */
+ public Container getPanel() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+}