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 c804999c7..d46cf9a6e 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 @@ -8,10 +8,10 @@ import com.arsdigita.cms.*; // Contact Object object type BaseContact extends ContentPage { - component Person [0..1] person = join ct_baseContacts.person_id + Person [0..1] person = join ct_baseContacts.person_id to ct_persons.person_id; - component BaseAddress [0..1] address = join ct_baseContacts.address_id + BaseAddress [0..1] address = join ct_baseContacts.address_id to ct_baseAddresses.address_id; component BaseContactEntry [0..n] contactentries = join ct_baseContacts.contact_id @@ -29,4 +29,3 @@ object type BaseContactEntry extends ACSObject { reference key ( ct_baseContactEntries.contactentry_id ); } - 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 f22a22124..cc51f5655 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 @@ -23,7 +23,11 @@ import com.arsdigita.persistence.DataObject; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ContentPage; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataOperation; +import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Assert; import java.math.BigDecimal; @@ -75,19 +79,24 @@ public class BaseContact extends ContentPage { /////////////////////////////////////////////////////////////// // accessors - // Set the person for this contact + // Get the person for this contact public Person getPerson() { - return (Person) get(PERSON); + return (Person) DomainObjectFactory.newInstance((DataObject)get(PERSON)); } - // Get the person for this contact + // Set the person for this contact public void setPerson(Person person) { set(PERSON, person); } + // Unset the address for this contact + public void unsetPerson() { + set(PERSON, null); + } + // Get the address for this contact public BaseAddress getAddress() { - return (BaseAddress) get(ADDRESS); + return (BaseAddress)DomainObjectFactory.newInstance((DataObject)get(ADDRESS)); } // Set the address for this contact @@ -95,6 +104,11 @@ public class BaseContact extends ContentPage { set(ADDRESS, address); } + // Unset the address for this contact + public void unsetAddress() { + set(ADDRESS, null); + } + // Get all contact entries for this contact, p. ex. phone number, type of contact etc. public BaseContactEntryCollection getContactEntries() { return new BaseContactEntryCollection ((DataCollection) get(CONTACT_ENTRIES)); @@ -115,5 +129,4 @@ public class BaseContact extends ContentPage { public boolean hasContactEntries() { return !this.getContactEntries().isEmpty(); } - } } 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 4e8fb95b9..34dd751c8 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 @@ -47,29 +47,28 @@ public class BaseContactAddressPropertiesStep extends SimpleEditStep { // BaseContact baseContact = (BaseContact)itemModel.getSelectedObject(state); //XXX - if(/*baseContact.getAddress() == null*/ true) { -// BasicPageForm addAddressSheet = new BaseContactAddAddressPropertyForm(itemModel, this); - BasicPageForm addAddressSheet = new BaseContactEditAddressPropertyForm(itemModel, this); - add(ADD_ADDRESS_SHEET_NAME, "Add Address", new WorkflowLockedComponentAccess(addAddressSheet, itemModel), addAddressSheet.getSaveCancelSection().getCancelButton()); +// if(/*baseContact.getAddress() == null*/ true) { + BasicPageForm attachAddressSheet = new BaseContactAttachAddressPropertyForm(itemModel, this); + add(ADD_ADDRESS_SHEET_NAME, "Attach Address", new WorkflowLockedComponentAccess(attachAddressSheet, itemModel), attachAddressSheet.getSaveCancelSection().getCancelButton()); /* Set the displayComponent for this step */ - setDisplayComponent(getEmptyBaseAddressPropertySheet(itemModel)); +// setDisplayComponent(getEmptyBaseAddressPropertySheet(itemModel)); - } else { +// } else { // editAddress BasicPageForm editAddressSheet = new BaseContactEditAddressPropertyForm(itemModel, this); add(EDIT_ADDRESS_SHEET_NAME, "Edit Address", new WorkflowLockedComponentAccess(editAddressSheet, itemModel), editAddressSheet.getSaveCancelSection().getCancelButton()); - BasicPageForm changeAddressSheet = new BaseContactEditAddressPropertyForm(itemModel, this); - add(CHANGE_ADDRESS_SHEET_NAME, "Change Address", new WorkflowLockedComponentAccess(changeAddressSheet, itemModel), changeAddressSheet.getSaveCancelSection().getCancelButton()); +// BasicPageForm attachAddressSheet = new BaseContactAttachAddressPropertyForm(itemModel, this); +// add(CHANGE_ADDRESS_SHEET_NAME, "Reattach Address", new WorkflowLockedComponentAccess(attachAddressSheet, itemModel), attachAddressSheet.getSaveCancelSection().getCancelButton()); -// BasicPageForm deleteAddressSheet = new BaseContactDeleteAddressPropertyForm(itemModel, this); -// add(DELETE_ADDRESS_SHEET_NAME, "Delete Address", new WorkflowLockedComponentAccess(deleteAddressSheet, itemModel), DeleteAddressSheet.getSaveCancelSection().getCancelButton()); + BasicPageForm deleteAddressSheet = new BaseContactDeleteAddressForm(itemModel, this); + add(DELETE_ADDRESS_SHEET_NAME, "Delete Address", new WorkflowLockedComponentAccess(deleteAddressSheet, itemModel), deleteAddressSheet.getSaveCancelSection().getCancelButton()); /* Set the displayComponent for this step */ setDisplayComponent(getBaseAddressPropertySheet(itemModel)); - } +// } } diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachAddressPropertyForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachAddressPropertyForm.java new file mode 100644 index 000000000..23f9a87ad --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachAddressPropertyForm.java @@ -0,0 +1,144 @@ +/* + * BaseContactEditAddressPropertyForm.java + * + * Created on 8. Juli 2009, 10:27 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SaveCancelSection; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.contenttypes.BaseAddress; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ContentType; +import com.arsdigita.util.UncheckedWrapperException; + +import org.apache.log4j.Logger; + +/** + * + * @author quasi + */ +public class BaseContactAttachAddressPropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener { + + private static final Logger logger = Logger.getLogger(BaseContactPropertyForm.class); + + private BaseContactAddressPropertiesStep m_step; + private ItemSearchWidget m_itemSearch; + private SaveCancelSection m_saveCancelSection; + private final String ITEM_SEARCH = "baseContactAddress"; + + /** + * ID of the form + */ + public static final String ID = "BaseContactAttachAddress"; + + /** + * Constrctor taking an ItemSelectionModel + * + * @param itemModel + */ + public BaseContactAttachAddressPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + /** + * Constrctor taking an ItemSelectionModel and an instance of BaseContactPropertiesStep. + * + * @param itemModel + * @param step + */ + public BaseContactAttachAddressPropertyForm(ItemSelectionModel itemModel, BaseContactAddressPropertiesStep step) { + super(ID, itemModel); + addSubmissionListener(this); + + addSaveCancelSection(); + + addInitListener(this); + addSubmissionListener(this); + + } + + @Override + public void addWidgets() { + add(new Label("BaseContact.address")); + this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.BaseAddress")); + add(this.m_itemSearch); + } + + public void init(FormSectionEvent fse) { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + setVisible(state, true); + + if (baseContact != null) { + data.put(ITEM_SEARCH, baseContact.getAddress()); + } + } + + public void process(FormSectionEvent fse) { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) { + baseContact.setAddress((BaseAddress)data.get(ITEM_SEARCH)); + } + init(fse); + } + + + /** + * Creates the section with the save and the cancel button. + */ + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(e.getPageState()); + Submit target = (Submit) e.getTarget(); + + if (baseContact.getAddress() != null) { + target.setButtonLabel("Change"); + } else { + target.setButtonLabel("Add"); + } + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } + + public void validate(FormSectionEvent e) throws FormProcessException { + if (e.getFormData().get(ITEM_SEARCH) == null) { + throw new FormProcessException("BaseAddress selection is required"); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + if (getSaveCancelSection().getCancelButton().isSelected(e.getPageState())) { + init(e); + throw new FormProcessException("cancelled"); + } + } +} \ No newline at end of file diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachPersonPropertyForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachPersonPropertyForm.java new file mode 100644 index 000000000..1736f47bd --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactAttachPersonPropertyForm.java @@ -0,0 +1,144 @@ +/* + * BaseContactEditPersonPropertyForm.java + * + * Created on 8. Juli 2009, 10:27 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.SaveCancelSection; +import com.arsdigita.bebop.event.FormInitListener; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.FormSubmissionListener; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ContentType; +import com.arsdigita.util.UncheckedWrapperException; + +import org.apache.log4j.Logger; + +/** + * + * @author quasi + */ +public class BaseContactAttachPersonPropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener { + + private static final Logger logger = Logger.getLogger(BaseContactPropertyForm.class); + + private BaseContactPersonPropertiesStep m_step; + private ItemSearchWidget m_itemSearch; + private SaveCancelSection m_saveCancelSection; + private final String ITEM_SEARCH = "baseContactPerson"; + + /** + * ID of the form + */ + public static final String ID = "BaseContactAttachPerson"; + + /** + * Constrctor taking an ItemSelectionModel + * + * @param itemModel + */ + public BaseContactAttachPersonPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + /** + * Constrctor taking an ItemSelectionModel and an instance of BaseContactPropertiesStep. + * + * @param itemModel + * @param step + */ + public BaseContactAttachPersonPropertyForm(ItemSelectionModel itemModel, BaseContactPersonPropertiesStep step) { + super(ID, itemModel); + addSubmissionListener(this); + + addSaveCancelSection(); + + addInitListener(this); + addSubmissionListener(this); + + } + + @Override + public void addWidgets() { + add(new Label("BaseContact.person")); + this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.Person")); + add(this.m_itemSearch); + } + + public void init(FormSectionEvent fse) { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + setVisible(state, true); + + if (baseContact != null) { + data.put(ITEM_SEARCH, baseContact.getPerson()); + } + } + + public void process(FormSectionEvent fse) { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) { + baseContact.setPerson((Person)data.get(ITEM_SEARCH)); + } + init(fse); + } + + + /** + * Creates the section with the save and the cancel button. + */ + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(e.getPageState()); + Submit target = (Submit) e.getTarget(); + + if (baseContact.getPerson() != null) { + target.setButtonLabel("Change"); + } else { + target.setButtonLabel("Add"); + } + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } + + public void validate(FormSectionEvent e) throws FormProcessException { + if (e.getFormData().get(ITEM_SEARCH) == null) { + throw new FormProcessException("BasePerson selection is required"); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + if (getSaveCancelSection().getCancelButton().isSelected(e.getPageState())) { + init(e); + throw new FormProcessException("cancelled"); + } + } +} \ No newline at end of file diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeleteAddressForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeleteAddressForm.java new file mode 100644 index 000000000..1ff4e62e4 --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeleteAddressForm.java @@ -0,0 +1,77 @@ +/* + * BaseContactDeleteAddressForm.java + * + * Created on 17. Juli 2009, 10:10 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.util.UncheckedWrapperException; + +/** + * + * @author quasi + */ +public class BaseContactDeleteAddressForm extends BasicPageForm implements FormProcessListener { + + /** + * ID of the form + */ + public static final String ID = "BaseContactDeleteAddress"; + + BaseContactDeleteAddressForm(ItemSelectionModel itemModel, BaseContactAddressPropertiesStep step) { + super(ID, itemModel); + addSaveCancelSection(); + } + + public void init(FormSectionEvent fse) { + + } + + public void addWidgets() { + add(new Label("BaseContact.address.delete")); + } + + /** + * Creates the section with the save and the cancel button. + */ + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(e.getPageState()); + Submit target = (Submit) e.getTarget(); + target.setButtonLabel("Delete"); + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } + + public final void process(final FormSectionEvent fse) throws FormProcessException { + + final PageState state = fse.getPageState(); + final BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + if (baseContact != null && baseContact.getAddress() != null) { + baseContact.unsetAddress(); + } + } + +} diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeletePersonForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeletePersonForm.java new file mode 100644 index 000000000..59b4f30a5 --- /dev/null +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactDeletePersonForm.java @@ -0,0 +1,77 @@ +/* + * BaseContactDeletePersonForm.java + * + * Created on 17. Juli 2009, 10:10 + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.event.FormProcessListener; +import com.arsdigita.bebop.event.FormSectionEvent; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.BaseContact; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +import com.arsdigita.util.UncheckedWrapperException; + +/** + * + * @author quasi + */ +public class BaseContactDeletePersonForm extends BasicPageForm implements FormProcessListener { + + /** + * ID of the form + */ + public static final String ID = "BaseContactDeletePerson"; + + BaseContactDeletePersonForm(ItemSelectionModel itemModel, BaseContactPersonPropertiesStep step) { + super(ID, itemModel); + addSaveCancelSection(); + } + + public void init(FormSectionEvent fse) { + + } + + public void addWidgets() { + add(new Label("BaseContact.person.delete")); + } + + /** + * Creates the section with the save and the cancel button. + */ + public void addSaveCancelSection() { + try { + getSaveCancelSection().getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(e.getPageState()); + Submit target = (Submit) e.getTarget(); + target.setButtonLabel("Delete"); + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + } + + public final void process(final FormSectionEvent fse) throws FormProcessException { + + final PageState state = fse.getPageState(); + final BaseContact baseContact = (BaseContact)getItemSelectionModel().getSelectedObject(state); + + if (baseContact != null && baseContact.getPerson() != null) { + baseContact.unsetPerson(); + } + } + +} 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 deleted file mode 100644 index e6756bc6c..000000000 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntriesTable.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * 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.ui.category; - -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.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 { - - - private final String TABLE_COL_EDIT = "table_col_lang"; - private final String TABLE_COL_DEL = "table_col_del"; - - /** - * Creates a new instance of BaseContactEntriesTable - */ - public BaseContactEntriesTable(final ItemSelectionModel itemModel, AuthoringKitWizard parent) { - - 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 - // XXX globalize - 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.delete").localize(), TABLE_COL_DEL)); - - setModelBuilder(new BaseContactTableModelBuilder()); - - tab_model.get(0).setCellRenderer(new EditCellRenderer()); - tab_model.get(2).setCellRenderer(new DeleteCellRenderer()); - - addTableActionListener(this); - - } - - /** - * XXXX - * - */ - private class BaseContactTableModelBuilder extends LockableImpl implements TableModelBuilder { - - public TableModel makeModel(Table table, PageState state) { -//XXX - final BaseContact baseContact = m_category.getCategory(state); - - if (baseContact != null && baseContact.hasContactEntries()) { - return new BaseContactTableModel(table, state, category); - } 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_baseContactEntryColletion = new BaseContactEntryCollection(baseContact); - } - - 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 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); -// CategoryLocalization cl = -// (CategoryLocalization) m_clSel.getSelectedObject(state); - -// boolean canEdit = sm.canAccess(state.getRequest(), -// SecurityManager.DELETE_ITEM, -// cl); -// if(canEdit) { - if(true) { - 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); -// CategoryLocalization categoryLocalization = -// new CategoryLocalization(new BigDecimal(evt.getRowKey().toString())); - -// boolean canDelete = sm.canAccess(state.getRequest(), -// SecurityManager.DELETE_ITEM, -// categoryLocalization); -// if(canDelete) { - if(true) { - 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 -// XXX - BaseContact baseContact = m_baseContact.getCategory(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.delContactEntry(baseContactEntry.getID()); - } - - } - - /** - * 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 deleted file mode 100644 index bb94a55c9..000000000 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryAddForm.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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.ui.category; - - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.categorization.CategorizationConfig; -import com.arsdigita.categorization.Category; -import com.arsdigita.dispatcher.AccessDeniedException; -import com.arsdigita.cms.util.GlobalizationUtil; -import java.util.Locale; -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 CategoryLocalizationAddForm extends CategoryLocalizationForm { - - public static final String versionId = - "$Id: CategoryLocalizationAddForm.java 287 2005-02-22 00:29:02Z sskracic $" + - "$Author: sskracic $" + - "$DateTime: 2004/08/17 23:15:09 $"; - - private static final Logger s_log = Logger.getLogger - (CategoryAddForm.class); - - /** Creates a new instance of CategoryLocalizationAddForm */ - public CategoryLocalizationAddForm(final CategoryRequestLocal category) { - - super("AddCategoryLocalization", - gz("cms.ui.category.localization.add"), category); - - addInitListener(new InitListener()); - addProcessListener(new ProcessListener()); - - } - - // Deaktivate this widget, if category is root -// public boolean isVisible(PageState state) { -// return !m_category.getCategory(state).isRoot(); -// } - - private class InitListener implements FormInitListener { - public final void init(final FormSectionEvent e) - throws FormProcessException { - - final PageState state = e.getPageState(); - final Category category = m_category.getCategory(state); - - // Select one entry - m_locale.addOption(new Option("", - new Label((String) GlobalizationUtil.globalize( - "cms.ui.select_one").localize())), state); - - // all supported languages (by registry entry) - CategorizationConfig catConfig = new CategorizationConfig(); - StringTokenizer strTok = catConfig.getSupportedLanguages(); - - while(strTok.hasMoreTokens()) { - - String code = strTok.nextToken(); - - // If lanuage exists, remove it from the selection list - if(!category.getCategoryLocalizationCollection(). - localizationExists(code)) { - m_locale.addOption(new Option(code, - new Locale(code).getDisplayLanguage()), state); - } - } - } - } - - - private final class ProcessListener implements FormProcessListener { - public final void process(final FormSectionEvent e) - throws FormProcessException { - s_log.debug("Adding a categoryLocalization to category " + m_category); - - final PageState state = e.getPageState(); - - final Category category = m_category.getCategory(state); - final String locale = (String) m_locale.getValue(state); - final String name = (String) m_name.getValue(state); - final String description = (String) m_description.getValue(state); - final String url = (String) m_url.getValue(state); - final String isEnabled = (String) m_isEnabled.getValue(state); - - // Was soll das?? - //Assert.assertNotNull(parent, "Category parent"); - - if (s_log.isDebugEnabled()) { - s_log.debug("Adding localization for locale " + locale + - " to category " + category); - } - - if (category.canEdit()) { - category.addLanguage(locale, name, description, url); - category.setEnabled("yes".equals(isEnabled), locale); - category.save(); - - } else { - // XXX user a better exception here. - // PermissionException doesn't work for this case. - throw new AccessDeniedException(); - } - } - } -} diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryForm.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryForm.java deleted file mode 100644 index 28c979602..000000000 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactEntryForm.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * 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.ui.category; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.ParameterEvent; -import com.arsdigita.bebop.event.ParameterListener; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.RadioGroup; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.form.Widget; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.ParameterData; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringInRangeValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.parameters.TrimmedStringParameter; -import com.arsdigita.categorization.Category; -import com.arsdigita.categorization.CategoryCollection; -import com.arsdigita.cms.ui.BaseForm; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.xml.Element; - -/** - * Base class for CategoryLocalizationAddForm and CategoryLocalizationEditForm. - * - * 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 CategoryLocalizationForm extends BaseForm { - - final CategoryRequestLocal m_category; - final SingleSelect m_locale; - final TextField m_name; - final TextArea m_description; - final TextField m_url; - final RadioGroup m_isEnabled; - private Label m_script = new Label( - "", false); - - private final static String LOCALE = "locale"; - private final static String NAME = "name"; - private final static String DESCRIPTION = "description"; - private final static String URL = "url"; - private final static String IS_ENABLED = "isEnabled"; - - /** - * Creates a new instance of CategoryLocalizationForm. - * - */ - public CategoryLocalizationForm(final String key, - final GlobalizedMessage heading, - final CategoryRequestLocal category) { - - super(key, heading); - - m_category = category; - - // Parameter-Model for SingleSelect - ParameterModel localeParam = new StringParameter(LOCALE); - localeParam.addParameterListener(new StringInRangeValidationListener(0, 2)); - - m_locale = new SingleSelect(localeParam); - m_locale.addValidationListener(new ParameterListener() { - - public void validate(ParameterEvent e) throws FormProcessException { - - // the --select one-- option is not allowed - ParameterData data = e.getParameterData(); - String code = (String) data.getValue() ; - if (code == null || code.length() == 0) { - data.addError( - (String)GlobalizationUtil.globalize( - "cms.ui.category.localization.error_locale").localize()); - } - } - }); - - addField(gz("cms.ui.category.localization.locale"), m_locale); - - m_name = new TextField(new TrimmedStringParameter(NAME)); - addField(gz("cms.ui.name"), m_name); - - m_name.setSize(30); - m_name.setMaxLength(200); - m_name.addValidationListener(new NotNullValidationListener()); - m_name.setOnFocus("if (this.form." + URL + ".value == '') { " + - " defaulting = true; this.form." + URL + - ".value = urlize(this.value); }"); - m_name.setOnKeyUp("if (defaulting) { this.form." + URL + - ".value = urlize(this.value) }"); - - // is enabled? - m_isEnabled = new RadioGroup(IS_ENABLED); - m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no")))); - m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes")))); - addField(gz("cms.ui.category.is_enabled"),m_isEnabled); - - m_description = new TextArea - (new TrimmedStringParameter(DESCRIPTION)); - addField(gz("cms.ui.description"), m_description); - - m_description.setWrap(TextArea.SOFT); - m_description.setRows(5); - m_description.setCols(40); - - // URL - // JavaScript auto-url generation is off by default. - // It is turned on under the following circumstances - // - // * If the url is null, upon starting edit of the title - // * If the url is null, upon finishing edit of name - // - // The rationale is that, auto-url generation is useful - // if the url is currently null, but once a name has been - // created you don't want to subsequently change it since - // it breaks URLs & potentially overwrites the user's - // customizations. - m_url = new TextField(new TrimmedStringParameter(URL)); - m_url.setSize(30); - m_url.setMaxLength(200); - m_url.addValidationListener(new NotNullValidationListener()); - m_url.setOnFocus("defaulting = false"); - m_url.setOnBlur("if (this.value == '') " + - "{ defaulting = true; this.value = urlize(this.form." + NAME + - ".value) }"); - addField(gz("cms.ui.category.url"),m_url); - - addAction(new Finish()); - addAction(new Cancel()); - - } - - public void generateXML(PageState ps, Element parent) { - m_script.generateXML(ps, parent); - super.generateXML(ps, parent); - } - - /** - * Purpose: - * - * XXXToDo: Should be extended with the function: - * Names have to be unambiguous in the selected language - */ - class NameUniqueListener implements ParameterListener { - private final CategoryRequestLocal m_category; - private final Widget m_widget; - private final int m_type; - public final static int NAME_FIELD = 1; - public final static int URL_FIELD = 2; - - NameUniqueListener(final CategoryRequestLocal category) { - this(category,m_name,NAME_FIELD); - } - NameUniqueListener(final CategoryRequestLocal category, - Widget widget, int type) { - m_category = category; - m_widget = widget; - m_type = type; - } - - - /** - * Purpose: - * - * XXX provisional, has to be adapted - * - * @param e - * @throws com.arsdigita.bebop.FormProcessException - */ - public final void validate(final ParameterEvent e) - throws FormProcessException { - final PageState state = e.getPageState(); - final String title = (String) m_widget.getValue(state); - - final Category category = m_category.getCategory(state); - - final CategoryCollection children = category.getChildren(); - - while (children.next()) { - final Category child = children.getCategory(); - String compField = - (m_type == URL_FIELD) ? child.getURL() : child.getName(); - if (compField.equalsIgnoreCase(title) - && (m_category == null - || !m_category.getCategory(state).equals(child))) { - throw new FormProcessException - (lz("cms.ui.category.name_not_unique")); - } - } - } - } -} diff --git a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPersonPropertiesStep.java b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPersonPropertiesStep.java index 6f258dac9..33d07cf24 100644 --- a/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPersonPropertiesStep.java +++ b/ccm-cms-types-baseContact/src/com/arsdigita/cms/contenttypes/ui/BaseContactPersonPropertiesStep.java @@ -43,29 +43,28 @@ public class BaseContactPersonPropertiesStep extends SimpleEditStep { super(itemModel, parent, prefix); //XXX - if(false/*EMPTY*/) { +// if(false/*EMPTY*/) { - BasicPageForm addPersonSheet = new BaseContactEditPersonPropertyForm(itemModel, this); -// BasicPageForm addPersonSheet = new BaseContactAddPersonPropertyForm(itemModel, this); - add(EDIT_PERSON_SHEET_NAME, "Add Person", new WorkflowLockedComponentAccess(addPersonSheet, itemModel), addPersonSheet.getSaveCancelSection().getCancelButton()); + BasicPageForm addPersonSheet = new BaseContactAttachPersonPropertyForm(itemModel, this); + add(ADD_PERSON_SHEET_NAME, "Attach Person", new WorkflowLockedComponentAccess(addPersonSheet, itemModel), addPersonSheet.getSaveCancelSection().getCancelButton()); /* Set the displayComponent for this step */ - setDisplayComponent(getEmptyPersonPropertySheet(itemModel)); +// setDisplayComponent(getEmptyPersonPropertySheet(itemModel)); - } else { +// } else { BasicPageForm editPersonSheet = new BaseContactEditPersonPropertyForm(itemModel, this); add(EDIT_PERSON_SHEET_NAME, "Edit Person", new WorkflowLockedComponentAccess(editPersonSheet, itemModel), editPersonSheet.getSaveCancelSection().getCancelButton()); - BasicPageForm changePersonSheet = new BaseContactEditPersonPropertyForm(itemModel, this); - add(CHANGE_PERSON_SHEET_NAME, "Change Person", new WorkflowLockedComponentAccess(changePersonSheet, itemModel), changePersonSheet.getSaveCancelSection().getCancelButton()); +// BasicPageForm changePersonSheet = new BaseContactEditPersonPropertyForm(itemModel, this); +// add(CHANGE_PERSON_SHEET_NAME, "Change Person", new WorkflowLockedComponentAccess(changePersonSheet, itemModel), changePersonSheet.getSaveCancelSection().getCancelButton()); -// BasicPageForm deletePersonSheet = new BaseContactDeletePersonPropertyForm(itemModel, this); -// add(DELETE_PERSON_SHEET_NAME, "Delete Person", new WorkflowLockedComponentAccess(deletePersonSheet, itemModel), deletePersonSheet.getSaveCancelSection().getCancelButton()); + BasicPageForm deletePersonSheet = new BaseContactDeletePersonForm(itemModel, this); + add(DELETE_PERSON_SHEET_NAME, "Delete Person", new WorkflowLockedComponentAccess(deletePersonSheet, itemModel), deletePersonSheet.getSaveCancelSection().getCancelButton()); /* Set the displayComponent for this step */ setDisplayComponent(getPersonPropertySheet(itemModel)); - } +// } } 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 73d15fa9e..0fb61fc89 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 @@ -58,13 +58,13 @@ public class BaseContactPropertiesStep extends SimpleEditStep { BaseContactPersonPropertiesStep personProperties = new BaseContactPersonPropertiesStep(itemModel, parent); BaseContactAddressPropertiesStep addressProperties = new BaseContactAddressPropertiesStep(itemModel, parent); - BaseContactEntriesTable baseContactEntries = new BaseContactEntriesTable(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); +// segmentedPanel.addSegment(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.baseContact.baseContactEntries").localize()), baseContactEntries); /* Sets the composed segmentedPanel as display component */ setDisplayComponent(segmentedPanel);