Removed some already disabled classes from ccm-cms

pull/28/head
Jens Pelzetter 2022-03-16 19:37:56 +01:00
parent 7a62bc4ad2
commit ad387198be
9 changed files with 0 additions and 1145 deletions

View File

@ -1,142 +0,0 @@
/*
* Copyright (C) 2002-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.FormProcessException;
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.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ContentTypeCollection;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentHidden;
import com.arsdigita.formbuilder.PersistentSingleSelect;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.log4j.Logger;
import java.math.BigDecimal;
import java.util.TooManyListenersException;
/**
* This class contains the form component for adding a Content Item element to
* a content type
*
* @author Scott Seago (scott@arsdigita.com)
* @version $Revision: #15 $ $Date: 2004/08/17 $
*/
public class AddContentItemElement extends ElementAddForm {
private static final Logger s_log =
Logger.getLogger(AddContentItemElement.class);
private SingleSelect m_itemTypeSelect;
/**
* Constructor
*/
public AddContentItemElement(ACSObjectSelectionModel types) {
super("ContentTypeAddContentItemElement", "Add a ContentItem Element", types);
add(new Label(GlobalizationUtil.globalize("cms.ui.type.association_content_type")));
m_itemTypeSelect = new SingleSelect(new BigDecimalParameter("AddContentItemTypeSelect"));
try {
m_itemTypeSelect.addPrintListener(new ItemTypeSelectPrintListener());
} catch (TooManyListenersException ex) {
s_log.error("too many listeners", ex);
throw new UncheckedWrapperException(ex);
}
add(m_itemTypeSelect);
add(m_buttons, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
}
private ContentType getItemType(PageState state)
throws FormProcessException {
BigDecimal itemTypeID =
(BigDecimal) m_itemTypeSelect.getValue(state);
ContentType itemType = null;
Assert.exists(itemTypeID, "itemTypeID");
try {
itemType = new ContentType(itemTypeID);
} catch (DataObjectNotFoundException ex) {
throw new FormProcessException(GlobalizationUtil.globalize("cms.ui.type.invalid"));
}
return itemType;
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
ContentType itemType = getItemType(state);
dot.addOptionalAssociation(label,
MetadataRoot.getMetadataRoot().getObjectType(itemType.getAssociatedObjectType()));
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
ContentType itemType = getItemType(state);
PersistentHidden pContentTypeName = PersistentHidden.create(label + "Type");
pContentTypeName.setDefaultValue(itemType.getAssociatedObjectType());
pContentTypeName.save();
pForm.addComponent(pContentTypeName);
PersistentSingleSelect pSelect = PersistentSingleSelect.create(label);
pSelect.setParameterModel("com.arsdigita.bebop.parameters.BigDecimalParameter");
pSelect.save();
pForm.addComponent(pSelect);
}
/**
* Print listener: generates the SingleSelect options for itemType
*/
private class ItemTypeSelectPrintListener implements PrintListener {
public void prepare(PrintEvent event) {
SingleSelect t = (SingleSelect) event.getTarget();
t.clearOptions();
// Get the current content section
ContentSection section = CMS.getContext().getContentSection();
ContentTypeCollection contentTypes = section.getCreatableContentTypes(true);
contentTypes.addOrder(ContentType.LABEL);
while (contentTypes.next()) {
ContentType type = contentTypes.getContentType();
t.addOption(new Option(type.getID().toString(), type.getName()));
}
}
}
}

View File

@ -1,174 +0,0 @@
/*
* 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.BoxPanel;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.FormSection;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Date;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.IntegerParameter;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.formbuilder.PersistentDate;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding a date element to
* a content type
*
* @author Xixi D'Moon (xdmoon@arsdigita.com)
* @author Stanislav Freidin (sfreidin@arsdigita.com)
* @version $Revision: #14 $ $Date: 2004/08/17 $
*/
public class AddDateElement extends ElementAddForm {
private Date m_date;
private CheckboxGroup m_valReq; //whether a value is requred
private TextField m_fromYear, m_toYear;
/**
* Constructor
*/
public AddDateElement(ACSObjectSelectionModel types) {
super("ContentTypeAddDateElement", "Add a Date Element", types);
/*
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.element.value_required")));
m_valReq = new CheckboxGroup("AddDateElementValReq");
// XXX fix l18n wrt request
m_valReq.addOption(new Option(lz("cms.ui.no"), lz("cms.ui.yes")));
add(m_valReq);
*/
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.default_date")));
m_date = new Date("elementdate");
long cur = System.currentTimeMillis();
java.util.Date curtime = new java.util.Date(cur);
m_date.setDefaultValue(curtime);
m_date.setClassAttr("AddDateElementChooseDate");
add(m_date);
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.year_range")));
m_fromYear = new TextField(new IntegerParameter("fromYear"));
m_fromYear.setSize(6);
m_fromYear.setMaxLength(4);
m_toYear = new TextField(new IntegerParameter("toYear"));
m_toYear.setSize(6);
m_toYear.setMaxLength(4);
FormSection rangeSec = new FormSection
(new BoxPanel(BoxPanel.HORIZONTAL, false));
rangeSec.add(new Label(GlobalizationUtil.globalize("cms.ui.type.from")));
rangeSec.add(m_fromYear);
rangeSec.add(new Label(GlobalizationUtil.globalize("cms.ui.type.to")));
rangeSec.add(m_toYear);
add(rangeSec);
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
java.util.Date date = (java.util.Date) m_date.getValue(state);
// String[] valReq = (String[]) m_valReq.getValue(state);
// Quasimodo
// Disable the value requierd feature
String[] valReq = null;
if (valReq == null) {
dot.addOptionalAttribute(label, MetadataRoot.DATE);
} else {
dot.addRequiredAttribute(label, MetadataRoot.DATE, date);
}
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
PersistentDate pDate = PersistentDate.create(label);
pDate.setParameterModel("com.arsdigita.bebop.parameters.DateParameter");
pForm.addComponent(pDate);
}
/**
* Initializes date widget to current date.
*/
protected final void doInit(FormSectionEvent event) {
java.util.Date date = new java.util.Date(System.currentTimeMillis());
m_date.setValue(event.getPageState(), date);
}
protected final void doValidate(FormSectionEvent e)
throws FormProcessException {
PageState state = e.getPageState();
Integer fromYear = (Integer) m_fromYear.getValue(state);
Integer toYear = (Integer) m_toYear.getValue(state);
if (!(fromYear != null && toYear != null)) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.type.year_range_not_balanced"));
} else {
if ((fromYear.intValue() < 0) || (toYear.intValue() < 0)) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.type.year_is_negative"));
}
if (fromYear.intValue() > toYear.intValue()) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.type.year_range_wrong_order"));
}
if ((toYear.intValue() - fromYear.intValue()) > 200) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.type.year_range_too_great"));
}
if ((fromYear.intValue() < 1900 || fromYear.intValue() > 2100) &&
(toYear.intValue() < 1900 || toYear.intValue() > 2100)) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.type.year_too_anachronistic"));
}
}
}
private static String lz(final String key) {
return (String) GlobalizationUtil.globalize(key).localize();
}
}

View File

@ -1,112 +0,0 @@
/*
* 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.BoxPanel;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.cms.util.GlobalizationUtil;
/**
* This class contains the form component for selecting which
* type of element to add to a content type
*
* @author Xixi D'Moon (xdmoon@arsdigita.com)
* @version $Revision: #11 $ $Date: 2004/08/17 $
*/
public class AddElement extends CMSForm {
private SingleSelect m_elementType;
private Submit m_submit;
public static final String TEXT_ELEMENT = "text";
public static final String NUMBER_ELEMENT = "number";
public static final String DATE_ELEMENT = "date";
public static final String TEXT_ASSET_ELEMENT = "textAsset";
public static final String IMAGE_ELEMENT = "image";
public static final String FILE_ELEMENT = "file";
public static final String CONTENT_ITEM_ELEMENT = "contentItem";
/**
* Constructor
*/
public AddElement() {
super("ContentTypeAddElement", new BoxPanel(BoxPanel.HORIZONTAL));
//possible types of elements that can be added to a user-defined
//content type
add(new Label(GlobalizationUtil.globalize("cms.ui.type.element.type")));
m_elementType = new SingleSelect("elementTypeSelect");
m_elementType.setClassAttr("AddElementSelectType");
m_elementType.addOption(new Option("text", "Text"));
m_elementType.addOption(new Option("number", "Number"));
m_elementType.addOption(new Option("date", "Date"));
m_elementType.addOption(new Option("textAsset", "Text Asset"));
m_elementType.addOption(new Option("image", "Image"));
m_elementType.addOption(new Option("contentItem", "Content Item"));
m_elementType.addOption(new Option("file", "File"));
//m_elementType.addOption(new Option("document", "Document"));
//m_elementType.addOption(new Option("multimedia", "Multimedia"));
add(m_elementType);
m_submit = new Submit("submit");
m_submit.setButtonLabel("Add Element");
add(m_submit, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
//add the listeners
//does not do anything other than ui logic in OneType.java
//addProcessListener(this);
}
protected SingleSelect getElementTypeSelect(){
return m_elementType;
}
protected Submit getSubmit(){
return m_submit;
}
/**
* Processes the form
*/
/* public void process(FormSectionEvent e) throws FormProcessException {
PageState state = e.getPageState();
FormData data = e.getFormData();
String type = (String) data.get(m_elementType.getName());
}*/
/**
* Retrieve the type of the element that the user wants to add
* during form processing
*/
public String getElementType(FormSectionEvent e) {
return (String)m_elementType.getValue(e.getPageState());
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (C) 2002-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.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.FileAsset;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentHidden;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding a File element to
* a content type
*
* @author Scott Seago (scott@arsdigita.com)
* @version $Revision: #13 $ $Date: 2004/08/17 $
*/
public class AddFileElement extends ElementAddForm {
public static final String ACTION_NONE = "none";
public static final String ACTION_UPLOAD = "upload";
public static final String ACTION_DELETE = "delete";
public static final String ACTION = "action";
/**
* Constructor
*/
public AddFileElement(ACSObjectSelectionModel types) {
super("ContentTypeAddFileElement", "Add a File Element", types);
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
dot.addOptionalAssociation(label,
MetadataRoot.getMetadataRoot().getObjectType
(FileAsset.BASE_DATA_OBJECT_TYPE));
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
PersistentHidden pFile = PersistentHidden.create(label);
pFile.setDefaultValue(label+".file");
pFile.save();
pForm.addComponent(pFile);
}
}

View File

@ -1,74 +0,0 @@
/*
* Copyright (C) 2002-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.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ImageAsset;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentHidden;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding a Image element to
* a content type
*
* @author Scott Seago (scott@arsdigita.com)
* @version $Revision: #13 $ $Date: 2004/08/17 $
*/
public class AddImageElement extends ElementAddForm {
public static final String ACTION_NONE = "none";
public static final String ACTION_UPLOAD = "upload";
public static final String ACTION_DELETE = "delete";
public static final String ACTION = "action";
/**
* Constructor
*/
public AddImageElement(ACSObjectSelectionModel types) {
super("ContentTypeAddImageElement", "Add a Image Element", types);
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
dot.addOptionalAssociation(label,
MetadataRoot.getMetadataRoot().getObjectType
(ImageAsset.BASE_DATA_OBJECT_TYPE));
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
PersistentHidden pImage = PersistentHidden.create(label);
pImage.setDefaultValue(label+".image");
pImage.save();
pForm.addComponent(pImage);
}
}

View File

@ -1,90 +0,0 @@
/*
* 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.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentTextField;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding a number element to
* a content type
*
* @author Xixi D'Moon (xdmoon@arsdigita.com)
* @author Stanislav Freidin (sfreidin@arsdigita.com)
* @version $Revision: #13 $ $Date: 2004/08/17 $
*/
public class AddNumberElement extends ElementAddForm {
private CheckboxGroup m_valReq; //whether a value is requred
/**
* Constructor
*/
public AddNumberElement(ACSObjectSelectionModel types) {
super("ContentTypeAddNumberElement", "Add a Number Element", types);
/*
add(new Label(GlobalizationUtil.globalize("cms.ui.type.element.value_required")));
m_valReq = new CheckboxGroup("AddNumberElementValReq");
m_valReq.addOption(new Option("yes", "Yes"));
add(m_valReq);
*/
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
// String[] valReq = (String[]) m_valReq.getValue(state);
// Quasimodo
// Disable the value requierd feature
String[] valReq = null;
if (valReq == null) {
dot.addOptionalAttribute(label, MetadataRoot.BIGDECIMAL);
} else {
dot.addRequiredAttribute(label, MetadataRoot.BIGDECIMAL, "0");
}
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
PersistentTextField pTextField = PersistentTextField.create(label);
pTextField.setParameterModel
("com.arsdigita.bebop.parameters.BigDecimalParameter");
pTextField.save();
pForm.addComponent(pTextField);
}
}

View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2002-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.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.TextAsset;
import com.arsdigita.formbuilder.PersistentDeditor;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding a TextAsset element to
* a content type
*
* @author Scott Seago (scott@arsdigita.com)
* @version $Revision: #13 $ $Date: 2004/08/17 $
*/
public class AddTextAssetElement extends ElementAddForm {
/**
* Constructor
*/
public AddTextAssetElement(ACSObjectSelectionModel types) {
super("ContentTypeAddTextAssetElement", "Add a TextAsset Element", types);
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
dot.addOptionalAssociation(label,
MetadataRoot.getMetadataRoot().getObjectType
(TextAsset.BASE_DATA_OBJECT_TYPE));
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
PersistentDeditor pTextArea = PersistentDeditor.create(label);
pTextArea.save();
pForm.addComponent(pTextArea);
}
}

View File

@ -1,143 +0,0 @@
/*
* 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.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.RadioGroup;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.IntegerParameter;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.formbuilder.PersistentForm;
import com.arsdigita.formbuilder.PersistentTextArea;
import com.arsdigita.formbuilder.PersistentTextField;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.MetadataRoot;
/**
* This class contains the form component for adding an text element to
* a content type
*
* @author Xixi D'Moon (xdmoon@arsdigita.com)
* @author Stanislav Freidin (sfreidin@arsdigita.com)
* @version $Revision: #14 $ $Date: 2004/08/17 $
*/
public class AddTextElement extends ElementAddForm {
private static final String INPUT_BOX = "inputBox";
private static final String TEXT_AREA = "textArea";
private TextField m_length; //can be a number or default 4000
private RadioGroup m_dataEntry; //data entry method
private CheckboxGroup m_valReq;
/**
* Constructor
*/
public AddTextElement(ACSObjectSelectionModel types) {
super("ContentTypeAddTextElement", "Add a Text Element", types);
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.maximum_length")));
m_length = new TextField(new IntegerParameter("length"));
m_length.setSize(15);
m_length.setMaxLength(10);
add(m_length);
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.data_entry_method")));
m_dataEntry = new RadioGroup("TextElementDataEntryMethodSelect");
m_dataEntry.setClassAttr("vertical");
m_dataEntry.addOption(new Option( INPUT_BOX, "Input box"));
m_dataEntry.addOption(new Option( TEXT_AREA, "Text Area"));
add(m_dataEntry);
/*
add(new Label(GlobalizationUtil.globalize
("cms.ui.type.element.value_required")));
m_valReq = new CheckboxGroup("AddTextElementValReq");
m_valReq.addOption(new Option("yes", "Yes"));
add(m_valReq);
*/
add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER);
}
protected final void addAttribute(DynamicObjectType dot, String label,
PageState state)
throws FormProcessException {
Integer length = (Integer) m_length.getValue(state);
// String[] valReq = (String[]) m_valReq.getValue(state);
// Quasimodo
// Disable the value requierd feature
String[] valReq = null;
if (length == null) {
length = new Integer(4000);
}
if (valReq == null) {
dot.addOptionalAttribute(label, MetadataRoot.STRING,
length.intValue());
} else {
dot.addRequiredAttribute(label, MetadataRoot.STRING,
length.intValue(), " ");
}
}
protected final void addFormComponent(PersistentForm pForm, String label,
PageState state)
throws FormProcessException {
String dataEntry = (String) m_dataEntry.getValue(state);
Integer length = (Integer) m_length.getValue(state);
if (dataEntry.equals(INPUT_BOX)) {
PersistentTextField pTextField = PersistentTextField.create(label);
if (length!=null) {
pTextField.setMaxLength(length.intValue());
}
pTextField.save();
pForm.addComponent(pTextField);
} else if (dataEntry.equals(TEXT_AREA)) {
PersistentTextArea pTextArea = PersistentTextArea.create(label);
pTextArea.save();
pForm.addComponent(pTextArea);
}
}
/**
* Sets default values for input fields.
*/
protected final void doInit(FormSectionEvent e) {
PageState state = e.getPageState();
m_dataEntry.setValue(state, INPUT_BOX);
}
}

View File

@ -1,267 +0,0 @@
/*
* 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.BoxPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionAdapter;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.metadata.DynamicObjectType;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.log4j.Logger;
import java.math.BigDecimal;
import java.util.Iterator;
/**
* This class contains the component to generate a table
* of elements for a particular content type
*/
public class TypeElements extends BoxPanel {
private static Logger s_log =
Logger.getLogger(TypeElements.class);
private SingleSelectionModel m_types;
private Table m_elementsTable;
private TableColumn m_removeColumn;
public TypeElements(SingleSelectionModel m) {
super();
m_types = m;
m_elementsTable = makeElementsTable();
m_removeColumn = m_elementsTable.getColumn(3);
m_removeColumn.setCellRenderer(new RemoveCellRenderer());
m_removeColumn.setAlign("center");
m_elementsTable.addTableActionListener(new ElementRemover());
add(m_elementsTable);
}
public void register(Page p) {
p.addComponent(this);
}
public Table getTable() {
return m_elementsTable;
}
/**
* creates and returns a content type
*/
private ContentType makeType(BigDecimal typeId) {
ContentType type = null;
try {
type = new ContentType(typeId);
} catch (DataObjectNotFoundException e) {
UncheckedWrapperException.throwLoggedException(getClass(), "Unable to make content type for id: "
+ typeId,
e);
}
return type;
}
/**
* Produce remove links.
*/
private static class RemoveCellRenderer implements TableCellRenderer {
private static final Logger logger = Logger.getLogger(RemoveCellRenderer.class);
private static Label s_noAction;
private static ControlLink s_link;
static {
logger.debug("Static initializer is starting...");
s_noAction = new Label("&nbsp;", false);
s_noAction.lock();
s_link = new ControlLink(new Label(GlobalizationUtil.globalize(
"cms.ui.type.element.delete")));
s_link.setConfirmation("Permanently remove this element?");
logger.debug("Static initalizer finished.");
}
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
if (((Boolean) value).booleanValue()) {
return s_link;
} else {
return s_noAction;
}
}
}
// Removes an element
private class ElementRemover extends TableActionAdapter {
public void cellSelected(TableActionEvent e) {
int col = e.getColumn().intValue();
if (m_removeColumn != m_elementsTable.getColumn(col)) {
return;
}
PageState s = e.getPageState();
DynamicObjectType dot = getDynamicObjectType(s);
String element = e.getRowKey().toString();
dot.removeAttribute(element);
dot.save();
}
}
private DynamicObjectType getDynamicObjectType(PageState s) {
BigDecimal typeId = new BigDecimal(m_types.getSelectedKey(s).toString());
ContentType type = makeType(typeId);
return new DynamicObjectType(type.getAssociatedObjectType());
}
/**
* creates and returns the list of elements of this udct
* by iterating through the declared properties of the associated
* dynamic object type
*
* return the table of elements of this type
*/
private Table makeElementsTable() {
final String[] headers = {"Name", "Element Type", "Multiplicity",
"Remove"};
TableModelBuilder b = new TableModelBuilder() {
private boolean m_locked;
public TableModel makeModel(final Table t, final PageState s) {
return new TableModel() {
DynamicObjectType dot = getDynamicObjectType(s);
//NOTE: this only gets the non-inherited properties of
// the object type
Iterator declaredProperties = dot.getObjectType().
getDeclaredProperties();
Property currentProperty = null;
public int getColumnCount() {
return headers.length;
}
public boolean nextRow() {
boolean next = declaredProperties.hasNext();
if (next) {
currentProperty =
(Property) declaredProperties.next();
}
return next;
}
public Object getElementAt(int columnIndex) {
if (currentProperty == null) {
throw new IllegalArgumentException();
}
switch (columnIndex) {
case 0:
return currentProperty.getName();
case 1:
String dataType = currentProperty.getType().
getName();
if (dataType.equals("String")) {
return "text";
} else if (dataType.equals("BigDecimal")) {
return "number";
} else if (dataType.equals("Date")) {
return "date";
} else {
return dataType;
}
case 2:
if (currentProperty.isNullable()) {
return "0 or 1";
} else if (currentProperty.isRequired()) {
return "1";
} else if (currentProperty.isCollection()) {
return "0 to n";
} else {
return new Integer(currentProperty.
getMultiplicity());
}
case 3:
return new Boolean(isRemovable());
default:
throw new IllegalArgumentException(
"columnIndex exceeds "
+ "number of columns available");
}
}
public Object getKeyAt(int columnIndex) {
if (currentProperty == null) {
throw new IllegalArgumentException();
} else {
//uses the element name as key, unique for each row
return currentProperty.getName();
}
}
private boolean isRemovable() {
return true;
}
};
}
public void lock() {
m_locked = true;
}
public boolean isLocked() {
return m_locked;
}
};
Table result = new Table(b, headers);
CMSContainer ifemptable = new CMSContainer();
ifemptable.setClassAttr("emptyTypeElementsTable");
result.setEmptyView(ifemptable);
//result.getColumn(0).setCellRenderer(new DefaultTableCellRenderer(true));
result.setClassAttr("ContentTypeElementsTable");
return result;
}
}