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 @@
+
+]>
+
+|
+ |
+ ||
+
|
+