diff --git a/ccm-cms-types-baseContact/pdl/com/arsdigita/content-types/BaseContact.pdl b/ccm-cms-types-baseContact/pdl/com/arsdigita/content-types/BaseContact.pdl index d46cf9a6e..3ada5ae4e 100644 --- a/ccm-cms-types-baseContact/pdl/com/arsdigita/content-types/BaseContact.pdl +++ b/ccm-cms-types-baseContact/pdl/com/arsdigita/content-types/BaseContact.pdl @@ -20,10 +20,10 @@ object type BaseContact extends ContentPage { reference key ( ct_baseContacts.contact_id ); } -object type BaseContactEntry extends ACSObject { +object type BaseContactEntry extends ContentItem { String [1..1] key = ct_baseContactEntries.key VARCHAR(100); - String [1..1] description = ct_baseContactEntries.description VARCHAR(100); + String [0..1] description = ct_baseContactEntries.description VARCHAR(100); String [1..1] value = ct_baseContactEntries.value VARCHAR(100); reference key ( ct_baseContactEntries.contactentry_id ); diff --git a/ccm-cms-types-baseContact/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/BaseContact.xml b/ccm-cms-types-baseContact/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/BaseContact.xml new file mode 100644 index 000000000..6bcddcbfb --- /dev/null +++ b/ccm-cms-types-baseContact/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/BaseContact.xml @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ccm-cms-types-baseContact/src/ccm-cms-types-baseContact.config b/ccm-cms-types-baseContact/src/ccm-cms-types-baseContact.config index adfdba100..1e00b4304 100755 --- a/ccm-cms-types-baseContact/src/ccm-cms-types-baseContact.config +++ b/ccm-cms-types-baseContact/src/ccm-cms-types-baseContact.config @@ -1,4 +1,4 @@ - + diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContact.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContact.java index cc51f5655..75fd1e008 100755 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContact.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContact.java @@ -43,6 +43,9 @@ public class BaseContact extends ContentPage { public static final String ADDRESS = "address"; public static final String CONTACT_ENTRIES = "contactentries"; + // Config + private static BaseContactConfig s_config = new BaseContactConfig(); + /** Data object type for tihs domain object */ public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.BaseContact"; @@ -75,6 +78,13 @@ public class BaseContact extends ContentPage { Assert.exists(getContentType(), ContentType.class); } + /** + * Retrieves the current configuration + */ + public static BaseContactConfig getConfig() { + return s_config; + } + /////////////////////////////////////////////////////////////// // accessors diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntry.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntry.java index 0c0fcc7a4..e6fe7753b 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntry.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntry.java @@ -20,64 +20,64 @@ package com.arsdigita.cms.contenttypes; -import com.arsdigita.kernel.ACSObject; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.metadata.ObjectType; +import java.math.BigDecimal; import org.apache.log4j.Logger; /** * * @author quasi */ -public class BaseContactEntry extends ACSObject { +public class BaseContactEntry extends ContentItem { public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.BaseContactEntry"; private static final String BASE_DATA_OBJECT_PACKAGE = "com.arsdigita.cms.contenttypes"; - + private static final Logger s_log = Logger.getLogger(BaseContactEntry.class); /** PDL property names */ public static final String KEY = "key"; public static final String VALUE = "value"; public static final String DESCRIPTION = "description"; - + /** * Creates a new instance of BaseContactEntry */ - public BaseContactEntry(String typeName) { - super(typeName); - } - - public BaseContactEntry(ObjectType type) { - super(type); - } - - public BaseContactEntry(OID oid) { - super(oid); - } - - public BaseContactEntry(DataObject dataObject) { - super(dataObject); - } - public BaseContactEntry() { this(BASE_DATA_OBJECT_TYPE); } - public BaseContactEntry(String key, String value, String description) { - this(); - setKey(key); - setValue(value); - setDescription(description); + public BaseContactEntry(String typeName) { + super(typeName); } - public BaseContactEntry(OID oid, String key, String value, String description) { - this(oid); + public BaseContactEntry(OID oid) { + super(oid); + } + + public BaseContactEntry(DataObject object) { + super(object); + } + + /** + * Constructor. Retrieves an object instance with the given id. + * @param id the id of the object to retrieve + */ + public BaseContactEntry(BigDecimal id) throws DataObjectNotFoundException { + this(new OID(BASE_DATA_OBJECT_TYPE, id)); + } + + public BaseContactEntry(BaseContact contact, String key, String value, String description) { + this(); + setName(key + " for " + contact.getName() + "(" + contact.getID() + ")"); setKey(key); setValue(value); setDescription(description); + save(); } ///////////////////////////////////////////////// diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntryCollection.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntryCollection.java index 6a1460aca..d1dd71829 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntryCollection.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactEntryCollection.java @@ -8,15 +8,16 @@ package com.arsdigita.cms.contenttypes; -import com.arsdigita.kernel.ACSObjectCollection; +import com.arsdigita.domain.DomainCollection; import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; /** * * @author quasi */ -public class BaseContactEntryCollection extends ACSObjectCollection { +public class BaseContactEntryCollection extends DomainCollection { /** * Creates a new instance of BaseContactEntryCollection @@ -42,7 +43,7 @@ public class BaseContactEntryCollection extends ACSObjectCollection { } public BaseContactEntry getBaseContactEntry() { - return (BaseContactEntry) getDomainObject(); + return new BaseContactEntry(m_dataCollection.getDataObject()); } } diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactInitializer.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactInitializer.java index cfa34fa35..af5a1a983 100755 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactInitializer.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/BaseContactInitializer.java @@ -28,20 +28,24 @@ import org.apache.log4j.Logger; */ public class BaseContactInitializer extends ContentTypeInitializer { public final static String versionId = - "$Id: BaseContactInitializer.java $" + - "$Author: quasi $" + - "$DateTime: 2009/03/15 $"; + "$Id: BaseContactInitializer.java $" + + "$Author: quasi $" + + "$DateTime: 2009/03/15 $"; private static final Logger s_log = Logger.getLogger(BaseContactInitializer.class); - + public BaseContactInitializer() { super("ccm-cms-types-baseContact.pdl.mf", - BaseContact.BASE_DATA_OBJECT_TYPE); + BaseContact.BASE_DATA_OBJECT_TYPE); } - + public String[] getStylesheets() { return new String[] { "/static/content-types/com/arsdigita/cms/contenttypes/BaseContact.xsl" }; } - + + public String getTraversalXML() { + return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/BaseContact.xml"; + } + } diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAddressPropertiesStep.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAddressPropertiesStep.java index 34dd751c8..e983bcb45 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAddressPropertiesStep.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAddressPropertiesStep.java @@ -35,7 +35,6 @@ public class BaseContactAddressPropertiesStep extends SimpleEditStep { public static final String CHANGE_ADDRESS_SHEET_NAME = "changeAddress"; public static final String DELETE_ADDRESS_SHEET_NAME = "deleteAddress"; - /** Creates a new instance of BaseContactAddressPropertiesStep */ public BaseContactAddressPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { this(itemModel, parent, ""); @@ -77,26 +76,29 @@ public class BaseContactAddressPropertiesStep extends SimpleEditStep { DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.address").localize(), "address." + BaseAddress.ADDRESS); - sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.postal_code").localize(), "address." + BaseAddress.POSTAL_CODE); + if(!BaseContact.getConfig().getHideAddressPostalCode()) + sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.postal_code").localize(), "address." + BaseAddress.POSTAL_CODE); sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.city").localize(), "address." + BaseAddress.CITY); - sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.state").localize(), "address." + BaseAddress.STATE); + if(!BaseContact.getConfig().getHideAddressState()) + sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.state").localize(), "address." + BaseAddress.STATE); - sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.iso_country_code").localize(), - "address." + BaseAddress.ISO_COUNTRY_CODE, - new DomainObjectPropertySheet.AttributeFormatter() { - public String format(DomainObject item, - String attribute, - PageState state) { - BaseAddress baseAddress = ((BaseContact)item).getAddress(); - if(baseAddress != null && baseAddress.getIsoCountryCode() != null) { - return BaseAddress.getCountryNameFromIsoCode(baseAddress.getIsoCountryCode()); - } else { - return (String)BaseAddressGlobalizationUtil.globalize - ("cms.ui.unknown").localize(); + if(!BaseContact.getConfig().getHideAddressCountry()) { + sheet.add((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.iso_country_code").localize(), + "address." + BaseAddress.ISO_COUNTRY_CODE, + new DomainObjectPropertySheet.AttributeFormatter() { + public String format(DomainObject item, + String attribute, + PageState state) { + BaseAddress baseAddress = ((BaseContact)item).getAddress(); + if(baseAddress != null && baseAddress.getIsoCountryCode() != null) { + return BaseAddress.getCountryNameFromIsoCode(baseAddress.getIsoCountryCode()); + } else { + return (String)BaseAddressGlobalizationUtil.globalize + ("cms.ui.unknown").localize(); + } } - } + }); } - ); return sheet; diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEditAddressPropertyForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEditAddressPropertyForm.java index be654e868..ef2f8ad07 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEditAddressPropertyForm.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEditAddressPropertyForm.java @@ -91,23 +91,27 @@ public class BaseContactEditAddressPropertyForm extends BasicPageForm implements address.setCols(30); add(address); - add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.postal_code").localize())); - ParameterModel postalCodeParam = new StringParameter(POSTAL_CODE); - TextField postalCode = new TextField(postalCodeParam); - /* XXX NumberListener ?*/ - add(postalCode); + if(!BaseContact.getConfig().getHideAddressPostalCode()) { + add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.postal_code").localize())); + ParameterModel postalCodeParam = new StringParameter(POSTAL_CODE); + TextField postalCode = new TextField(postalCodeParam); + /* XXX NumberListener ?*/ + add(postalCode); + } add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.city").localize())); ParameterModel cityParam = new StringParameter(CITY); TextField city = new TextField(cityParam); add(city); - add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.state").localize())); - ParameterModel stateParam = new StringParameter(STATE); - TextField state = new TextField(stateParam); - add(state); + if(!BaseContact.getConfig().getHideAddressState()) { + add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.state").localize())); + ParameterModel stateParam = new StringParameter(STATE); + TextField state = new TextField(stateParam); + add(state); + } - if (!BaseAddress.getConfig().getHideCountryCodeSelection()) { + if (!BaseContact.getConfig().getHideAddressCountry()) { add(new Label((String)BaseAddressGlobalizationUtil.globalize("cms.contenttypes.ui.baseAddress.iso_country_code").localize())); ParameterModel countryParam = new StringParameter(ISO_COUNTRY_CODE); countryParam.addParameterListener(new StringInRangeValidationListener(0, 2)); diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesPropertiesStep.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesPropertiesStep.java new file mode 100644 index 000000000..fccd21274 --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesPropertiesStep.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 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.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; + +/** + * A UI step to manipulate Phones for the Contact object + * which is retrieved from the ItemSelectionModel. + * + * + * @author Shashin Shinde sshinde@redhat.com + * @version $Id: PhoBaseContactEntriesPropertiesStepva 287 2005-02-22 00:29:02Z sskracic $ + */ +public class BaseContactEntriesPropertiesStep extends SimpleEditStep { + + /** The name of the editing sheet added to this step */ + private static String ADD_CONTACT_ENTRY_SHEET_NAME = "addContactEntry"; + + public BaseContactEntriesPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public BaseContactEntriesPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent, String prefix) { + super(itemModel, parent, prefix); + +//XXX + BasicItemForm addContactEntrySheet = new BaseContactEntryAddForm(itemModel); + add(ADD_CONTACT_ENTRY_SHEET_NAME, "Add Contact Entry", new WorkflowLockedComponentAccess(addContactEntrySheet, itemModel), addContactEntrySheet.getSaveCancelSection().getCancelButton()); + + BaseContactEntriesTable contactEntriesTable = new BaseContactEntriesTable(itemModel); + setDisplayComponent(contactEntriesTable); + + } + +} \ No newline at end of file diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesTable.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesTable.java new file mode 100644 index 000000000..c2f1bd916 --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesTable.java @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2008 Sören Bernstein 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.contenttypes.ui; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.ControlLink; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.event.TableActionEvent; +import com.arsdigita.bebop.event.TableActionListener; +import com.arsdigita.bebop.table.TableCellRenderer; +import com.arsdigita.bebop.table.TableColumn; +import com.arsdigita.bebop.table.TableColumnModel; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.SecurityManager; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.contenttypes.BaseContactEntry; +import com.arsdigita.cms.contenttypes.BaseContactEntryCollection; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * Lists all existing contact entries for a selected contact. + * + * @author Sören Bernstein (quasimodo) quasi@barkhof.uni-bremen.de + */ +public class BaseContactEntriesTable extends Table implements TableActionListener{ + + + private final String TABLE_COL_EDIT = "table_col_edit"; + private final String TABLE_COL_DEL = "table_col_del"; + + private ItemSelectionModel m_itemModel; + + /** + * Creates a new instance of BaseContactEntriesTable + */ + public BaseContactEntriesTable(final ItemSelectionModel itemModel) { + + super(); + this.m_itemModel = itemModel; + + // if table is empty: + setEmptyView(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactentries.none"))); + TableColumnModel tab_model = getColumnModel(); + + // define columns + tab_model.add(new TableColumn(0, GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactentries.key").localize(), TABLE_COL_EDIT)); + tab_model.add(new TableColumn(1, GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactentries.value").localize())); + tab_model.add(new TableColumn(2, GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactentries.description").localize())); + tab_model.add(new TableColumn(3, GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactentries.delete").localize(), TABLE_COL_DEL)); + + setModelBuilder(new BaseContactTableModelBuilder(itemModel)); + + tab_model.get(0).setCellRenderer(new EditCellRenderer()); + tab_model.get(3).setCellRenderer(new DeleteCellRenderer()); + + addTableActionListener(this); + + } + + /** + * XXXX + * + */ + private class BaseContactTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public BaseContactTableModelBuilder(ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + public TableModel makeModel(Table table, PageState state) { + + table.getRowSelectionModel().clearSelection(state); + + BaseContact baseContact = (BaseContact) m_itemModel.getSelectedObject(state); + +// if (baseContact != null && baseContact.hasContactEntries()) { + return new BaseContactTableModel(table, state, baseContact); +// } else { +// return Table.EMPTY_MODEL; +// } + } + } + + /** + * XXX + * + */ + private class BaseContactTableModel implements TableModel { + + final private int MAX_DESC_LENGTH = 25; + + private Table m_table; + private BaseContactEntryCollection m_baseContactEntryCollection; + private BaseContactEntry m_baseContactEntry; + + private BaseContactTableModel(Table t, PageState ps, BaseContact baseContact) { + m_table = t; + m_baseContactEntryCollection = baseContact.getContactEntries(); + } + + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + /** + * Check collection for the existence of another row. + * + * If exists, fetch the value of current BaseContactEntryCollection object + * into m_baseContactEntry class variable. + */ + public boolean nextRow() { + + if(m_baseContactEntryCollection != null && m_baseContactEntryCollection.next()){ + m_baseContactEntry = m_baseContactEntryCollection.getBaseContactEntry(); + return true; + + } else { + + return false; + + } + } + + /** + * Return the + * @see com.arsdigita.bebop.table.TableModel#getElementAt(int) + */ + public Object getElementAt(int columnIndex) { + switch (columnIndex){ + case 0: + return m_baseContactEntry.getKey(); + case 1: + return m_baseContactEntry.getValue(); + case 2: + return (m_baseContactEntry.getDescription() != null && m_baseContactEntry.getDescription().length() > MAX_DESC_LENGTH) + ? m_baseContactEntry.getDescription().substring(0, MAX_DESC_LENGTH) + : m_baseContactEntry.getDescription(); + case 3: + return GlobalizationUtil.globalize("cms.ui.delete").localize(); + default: + return null; + } + } + + /** + * + * @see com.arsdigita.bebop.table.TableModel#getKeyAt(int) + */ + public Object getKeyAt(int columnIndex) { + return m_baseContactEntry.getID(); + } + + } + + /** + * Check for the permissions to edit item and put either a Label or + * a ControlLink accordingly. + */ + private class EditCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, + boolean isSelected, Object key, + int row, int column) { + + SecurityManager sm = Utilities.getSecurityManager(state); + BaseContact baseContact = (BaseContact) m_itemModel.getSelectedObject(state); + + boolean canEdit = sm.canAccess(state.getRequest(), + SecurityManager.EDIT_ITEM, + baseContact); + if(canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + return new Label(value.toString()); + } + } + } + + /** + * Check for the permissions to delete item and put either a Label or + * a ControlLink accordingly. + */ + private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, + boolean isSelected, Object key, + int row, int column) { + + SecurityManager sm = Utilities.getSecurityManager(state); + BaseContact baseContact = (BaseContact) m_itemModel.getSelectedObject(state); + + boolean canDelete = sm.canAccess(state.getRequest(), + SecurityManager.DELETE_ITEM, + baseContact); + if(canDelete) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) GlobalizationUtil.globalize( + "cms.contenttypes.ui.baseContact.confirm_delete").localize()); + return link; + } else { + return new Label(value.toString()); + } + } + } + + /** + * Provide implementation to TableActionListener method. + * Code that comes into picture when a link on the table is clicked. + * Handles edit and delete event. + */ + public void cellSelected(TableActionEvent evt) { + + PageState state = evt.getPageState(); + + // Get selected BaseContactEntry + BaseContactEntry baseContactEntry = + new BaseContactEntry(new BigDecimal(evt.getRowKey().toString())); + + // Get BaseContact + BaseContact baseContact = (BaseContact) m_itemModel.getSelectedObject(state); + + // Get selected column + TableColumn col = getColumnModel().get(evt.getColumn().intValue()); + + // Edit + if(col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + + } + + // Delete + if(col.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + baseContact.removeContactEntry(baseContactEntry); + } + + } + + /** + * provide Implementation to TableActionListener method. + * Does nothing in our case. + */ + public void headSelected(TableActionEvent e) { + throw new UnsupportedOperationException("Not Implemented"); + } + + +} diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryAddForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryAddForm.java new file mode 100644 index 000000000..555092dff --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryAddForm.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2008 Sören Bernstein 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.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +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.TextField; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.contenttypes.BaseContactEntry; +import com.arsdigita.cms.contenttypes.util.BaseAddressGlobalizationUtil; +import com.arsdigita.cms.contenttypes.util.BaseContactGlobalizationUtil; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import com.arsdigita.bebop.parameters.StringParameter; +import java.util.StringTokenizer; + +import org.apache.log4j.Logger; + +/** + * Generates a form for creating new localisations for the given category. + * + * This class is part of the admin GUI of CCM and extends the standard form + * in order to present forms for managing the multi-language categories. + * + * @author Sören Bernstein (quasimodo) quasi@zes.uni-bremen.de + */ +public class BaseContactEntryAddForm extends BasicItemForm { + private static final Logger s_log = Logger.getLogger(BaseContactEntryAddForm.class); + + private ItemSelectionModel m_itemModel; + + /** Creates a new instance of CategoryLocalizationAddForm */ + public BaseContactEntryAddForm(ItemSelectionModel itemModel) { + + super("BaseContactEntryAddForm",itemModel); + m_itemModel = itemModel; + + } + + protected void addWidgets() { + + // Key field + add(new Label(BaseContactGlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactEntry.key"))); + ParameterModel contactEntryKeyParam = new StringParameter(BaseContactEntry.KEY); + SingleSelect contactEntryKey = new SingleSelect(contactEntryKeyParam); + contactEntryKey.addValidationListener(new NotNullValidationListener()); + contactEntryKey.addOption(new Option("", new Label((String)BaseAddressGlobalizationUtil.globalize("cms.ui.select_one" ).localize()))); + + // Add the Options to the SingleSelect widget + StringTokenizer keyList = BaseContact.getConfig().getContactEntryKeys(); + while(keyList.hasMoreTokens()) { + String currentKey = keyList.nextToken(); + contactEntryKey.addOption(new Option(currentKey, ((String)BaseContactGlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactEntry.key." + currentKey).localize()))); + } + + add(contactEntryKey); + + // Value field + add(new Label(BaseContactGlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactEntry.value"))); + ParameterModel contactEntryValueParam = new StringParameter(BaseContactEntry.VALUE); + TextField contactEntryValue = new TextField(contactEntryValueParam); + contactEntryValue.addValidationListener(new NotNullValidationListener()); + add(contactEntryValue); + + // Description field, only for internal usage + add(new Label(BaseContactGlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.contactEntry.description"))); + ParameterModel contactEntryDescriptionParam = new StringParameter(BaseContactEntry.DESCRIPTION); + TextField contactEntryDescription = new TextField(contactEntryDescriptionParam); + add(contactEntryDescription); + + } + + public void init(FormSectionEvent fse) { + + } + + public void process(FormSectionEvent fse) { + FormData data = fse.getFormData(); + BaseContact baseContact = (BaseContact)m_itemModel.getSelectedObject(fse.getPageState()); + + // save only if save button was pressed + if (baseContact != null + && getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) { + + BaseContactEntry contactEntry = new BaseContactEntry(baseContact, + (String)data.get(BaseContactEntry.KEY), + (String)data.get(BaseContactEntry.VALUE), + (String)data.get(BaseContactEntry.DESCRIPTION)); + + baseContact.addContactEntry(contactEntry); + } + } +} diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPropertiesStep.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPropertiesStep.java index 0fb61fc89..7e5c99191 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPropertiesStep.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPropertiesStep.java @@ -14,6 +14,7 @@ import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.SegmentedPanel; +import com.arsdigita.cms.contenttypes.BaseContact; import java.text.DateFormat; import org.apache.log4j.Logger; @@ -24,7 +25,7 @@ import org.apache.log4j.Logger; public class BaseContactPropertiesStep extends SimpleEditStep { private static final Logger logger = Logger.getLogger(BaseContactPropertiesStep.class); - + /** * Name of the this edit sheet (Don't know if this this really needed. * It has the same value in almost all PropertiesStep classes) @@ -50,21 +51,31 @@ public class BaseContactPropertiesStep extends SimpleEditStep { /* A new SimpleEditStep */ SimpleEditStep basicProperties = new SimpleEditStep(itemModel, parent, EDIT_BASIC_SHEET_NAME); + /* Create the edit component for this SimpleEditStep and the corresponding link */ BasicPageForm editBasicSheet = new BaseContactPropertyForm(itemModel, this); basicProperties.add(EDIT_BASIC_SHEET_NAME, "Edit Basic", new WorkflowLockedComponentAccess(editBasicSheet, itemModel), editBasicSheet.getSaveCancelSection().getCancelButton()); + /* Set the displayComponent for this step */ basicProperties.setDisplayComponent(getBaseContactPropertySheet(itemModel)); - BaseContactPersonPropertiesStep personProperties = new BaseContactPersonPropertiesStep(itemModel, parent); - BaseContactAddressPropertiesStep addressProperties = new BaseContactAddressPropertiesStep(itemModel, parent); -// BaseContactEntriesTable baseContactEntries = new BaseContactEntriesTable(itemModel, parent); - /* Add the SimpleEditStep to the segmented panel */ segmentedPanel.addSegment(new Label("Basic"), basicProperties); - segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.person").localize()), personProperties); - segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.address").localize()), addressProperties); -// segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.baseContactEntries").localize()), baseContactEntries); + + // If not disabled via registry, add the ui for attaching a person + if(!BaseContact.getConfig().getHidePerson()) { + BaseContactPersonPropertiesStep personProperties = new BaseContactPersonPropertiesStep(itemModel, parent); + segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.person").localize()), personProperties); + } + + // If not disabled via registry, add the ui for attaching a baseAddress + if(!BaseContact.getConfig().getHideAddress()) { + BaseContactAddressPropertiesStep addressProperties = new BaseContactAddressPropertiesStep(itemModel, parent); + segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.address").localize()), addressProperties); + } + + BaseContactEntriesPropertiesStep baseContactEntries = new BaseContactEntriesPropertiesStep(itemModel, parent); + segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.baseContactEntries").localize()), baseContactEntries); /* Sets the composed segmentedPanel as display component */ setDisplayComponent(segmentedPanel); diff --git a/ccm-cms-types-baseContact/web/static/content-types/com/arsdigita/cms/contenttypes/BaseContact.xsl b/ccm-cms-types-baseContact/web/static/content-types/com/arsdigita/cms/contenttypes/BaseContact.xsl new file mode 100644 index 000000000..a039f12d5 --- /dev/null +++ b/ccm-cms-types-baseContact/web/static/content-types/com/arsdigita/cms/contenttypes/BaseContact.xsl @@ -0,0 +1,41 @@ + +]> + + + + + + + + + + + +
+ +
+ + + + + + + +
Address:
+
+
+ + +

+ + Address +
+
+
+ +
\ No newline at end of file