diff --git a/ccm-cms-types-project/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Project.xml b/ccm-cms-types-project/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Project.xml index 591cc43f3..32ea788fc 100644 --- a/ccm-cms-types-project/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Project.xml +++ b/ccm-cms-types-project/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Project.xml @@ -6,8 +6,8 @@ diff --git a/ccm-cms-types-project/src/com/arsdigita/cms/contenttypes/ui/ProjectChildrenPropertiesStep.java b/ccm-cms-types-project/src/com/arsdigita/cms/contenttypes/ui/ProjectChildrenPropertiesStep.java index 51bc4bea3..89bd30930 100644 --- a/ccm-cms-types-project/src/com/arsdigita/cms/contenttypes/ui/ProjectChildrenPropertiesStep.java +++ b/ccm-cms-types-project/src/com/arsdigita/cms/contenttypes/ui/ProjectChildrenPropertiesStep.java @@ -9,7 +9,7 @@ import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; 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.authoring.WorkflowLockedComponentAccess; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import org.apache.log4j.Logger; /** diff --git a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganization.pdl b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganization.pdl deleted file mode 100644 index 19f50e8e1..000000000 --- a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganization.pdl +++ /dev/null @@ -1,67 +0,0 @@ -// -// Copyright (C) 2010 Sören Bernstein, for the Center of Social Politics of the University of Bremen -// -// 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 -// -// - -model com.arsdigita.cms.contenttypes; - -//import com.arsdigita.cms.ContentPage; - -//object GenericOrganization extends ContentPage { -// String[0..1] addendum = cms_organization.nameaddendum VARCHAR(512); - -// reference key (cms_organization.organization_id); -//} - -//object OrganizationRole extends XXX { -// String[1..1] roleName = cms_organizationrole.name VARCHAR(256); -// -//} - -//association { - -// GenericOrganization[0..n] children = join cms_organization.organization_id -// to cms_organization_organization_map.children_id, -// join cms_organization_organization_map.parent_id -// to cms_organization.organization_id; - -// GenericOrganization[0..1] parent = join cms_organization.organization_id -// to cms_organization_organization_map.parent_id, -// join cms_organization_organization_map.children_id -// to cms_organization.organization_id; - -// Integer[0..1] order = cms_organization_organization_map.order INTERGER; - -//} - -//association { - -// GenericOrganization[0..1] organization = join cms_contacts.contact_id -// to cms_organization_contact_map.contact_id, -// join cms_organization_contact_map.organization_id -// to cms_organizations.organization_id; - -// GenericContact[0..n] contacts = join cms_organizations.organization_id -// to cms_organization_contact_map.organization_id, -// join cms_organization_contact_map.contact_id -// to cms_contacts.contact_id; - - // Link Attribute -// String contact_type = cms_organization_contact_map.contact_type VARCHAR(100); -// BigDecimal contact_order = cms_organization_contact_map.contact_order INTEGER; - -//} diff --git a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl index 4a1719cf4..211d9d714 100644 --- a/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-types/GenericOrganizationalUnit.pdl @@ -24,45 +24,64 @@ import com.arsdigita.cms.ContentPage; //PDL definition for a commons base type for orgnizations, departments, projects etc. object type GenericOrganizationalUnit extends ContentPage { - //String[0..1] orgaunit_name = cms_organizationalunit.name VARCHAR(256); + //String[0..1] orgaunit_name = cms_organizationalunits.name VARCHAR(256); - String[0..1] addendum = cms_organizationalunit.addendum VARCHAR(512); + String[0..1] addendum = cms_organizationalunits.addendum VARCHAR(512); - reference key (cms_organizationalunit.organizationalunit_id); + reference key (cms_organizationalunits.organizationalunit_id); } //Parent <-> child relation organizationalunits to build department structures etc. association { - GenericOrganizationalUnit[0..1] orgaunit_parent = join cms_organizationalunit.organizationalunit_id - to cms_organizationalunit_organizationalunit_map.orgaunit_children_id, - join cms_organizationalunit_organizationalunit_map.orgaunit_parent_id - to cms_organizationalunit.organizationalunit_id; + GenericOrganizationalUnit[0..1] orgaunit_parent = join cms_organizationalunits.organizationalunit_id + to cms_organizationalunits_organizationalunit_map.orgaunit_children_id, + join cms_organizationalunits_organizationalunit_map.orgaunit_parent_id + to cms_organizationalunits.organizationalunit_id; - GenericOrganizationalUnit[0..n] orgaunit_children = join cms_organizationalunit.organizationalunit_id - to cms_organizationalunit_organizationalunit_map.orgaunit_parent_id, - join cms_organizationalunit_organizationalunit_map.orgaunit_children_id - to cms_organizationalunit.organizationalunit_id; + GenericOrganizationalUnit[0..n] orgaunit_children = join cms_organizationalunits.organizationalunit_id + to cms_organizationalunits_organizationalunit_map.orgaunit_parent_id, + join cms_organizationalunits_organizationalunit_map.orgaunit_children_id + to cms_organizationalunits.organizationalunit_id; //Link attribute, allows it to customize the order which the childs will be shown. - BigDecimal[0..1] orgaunit_children_order = cms_organizationalunit_organizationalunit_map.map_order INTEGER; + BigDecimal[0..1] orgaunit_children_order = cms_organizationalunits_organizationalunit_map.map_order INTEGER; } //Link for contact points. association { GenericOrganizationalUnit[0..1] organizationalunit = join cms_contacts.contact_id - to cms_organizationalunit_contact_map.contact_id, - join cms_organizationalunit_contact_map.organizationalunit_id - to cms_organizationalunit.organizationalunit_id; + to cms_organizationalunits_contact_map.contact_id, + join cms_organizationalunits_contact_map.organizationalunit_id + to cms_organizationalunits.organizationalunit_id; - GenericContact[0..n] contacts = join cms_organizationalunit.organizationalunit_id - to cms_organizationalunit_contact_map.organizationalunit_id, - join cms_organizationalunit_contact_map.contact_id + GenericContact[0..n] contacts = join cms_organizationalunits.organizationalunit_id + to cms_organizationalunits_contact_map.organizationalunit_id, + join cms_organizationalunits_contact_map.contact_id to cms_contacts.contact_id; //Some link attributes. - String contact_type = cms_organizationalunit_contact_map.contact_type VARCHAR(100); - BigDecimal contact_order = cms_organizationalunit_contact_map.map_order INTEGER; + String contact_type = cms_organizationalunits_contact_map.contact_type VARCHAR(100); + BigDecimal contact_order = cms_organizationalunits_contact_map.map_order INTEGER; + +} + +//Links a organization with persons. +association { + + GenericOrganizationalUnit[0..1] organizationalunit = join cms_persons.person_id + to cms_organizationalunits_person_map.person_id, + join cms_organizationalunits_person_map.organizationalunit_id + to cms_organizationalunits.organizationalunit_id; + + GenericPerson[0..n] persons = join cms_organizationalunits.organizationalunit_id + to cms_organizationalunits_person_map.organizationalunit_id, + join cms_organizationalunits_person_map.person_id + to cms_persons.person_id; + + //Additional attributes for the association + String role_name = cms_organizationalunits_person_map.role_name VARCHAR(100); + BigDecimal person_order = cms_organizationalunits_person_map.map_order INTEGER; } diff --git a/ccm-cms/src/WEB-INF/content-types/GenericOrganizationalUnit.xml b/ccm-cms/src/WEB-INF/content-types/GenericOrganizationalUnit.xml index 54665f91b..217439a8a 100644 --- a/ccm-cms/src/WEB-INF/content-types/GenericOrganizationalUnit.xml +++ b/ccm-cms/src/WEB-INF/content-types/GenericOrganizationalUnit.xml @@ -41,6 +41,15 @@ ordering="3" /> + + diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java index ac485d50b..c4ce5b695 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnit.java @@ -27,8 +27,11 @@ import com.arsdigita.util.Assert; import java.math.BigDecimal; /** + * This class provides a base type for building content types which represent organizations, + * departments, projects etc. * * @author Jens Pelzetter + * @version $Id$ */ public class GenericOrganizationalUnit extends ContentPage { @@ -39,6 +42,9 @@ public class GenericOrganizationalUnit extends ContentPage { public final static String CONTACT_ORDER = "contact_order"; public final static String ORGAUNIT_CHILDREN = "orgaunit_children"; public final static String ORGAUNIT_CHILDREN_ORDER = "orgaunit_children_order"; + public final static String PERSONS = "persons"; + public final static String ROLE = "role_name"; + public final static String PERSON_ORDER = "person_order"; public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericOrganizationalUnit"; public GenericOrganizationalUnit() { @@ -126,5 +132,25 @@ public class GenericOrganizationalUnit extends ContentPage { public boolean hasOrgaUnitChildren() { return !this.getOrgaUnitChildren().isEmpty(); } - + + public GenericOrganizationalUnitPersonCollection getPersons() { + return new GenericOrganizationalUnitPersonCollection((DataCollection) get(PERSONS)); + } + + public void addPerson(GenericPerson person) { + Assert.exists(person, GenericPerson.class); + + DataObject link = add(PERSONS, person); + + link.set(PERSON_ORDER, BigDecimal.valueOf(getPersons().size())); + } + + public void removePerson(GenericPerson person) { + Assert.exists(person, GenericPerson.class); + remove(PERSONS, person); + } + + public boolean hasPersons() { + return !this.getPersons().isEmpty(); + } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitContactCollection.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitContactCollection.java index fafce6b94..01d337d64 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitContactCollection.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitContactCollection.java @@ -18,23 +18,24 @@ public class GenericOrganizationalUnitContactCollection extends DomainCollection public static final String CONTACT_TYPE = "link.contact_type"; public static final String CONTACT_ORDER = "link.contact_order"; - - public GenericOrganizationalUnitContactCollection(DataCollection dataCollection) { + public GenericOrganizationalUnitContactCollection( + DataCollection dataCollection) { super(dataCollection); m_dataCollection.addOrder(ORDER); } - // Get the contact type of the link + // Get the contact type of the link public String getContactType() { return (String) m_dataCollection.get(CONTACT_TYPE); } // Get the contact order of the link public String getContactOrder() { - String retVal = ((BigDecimal) m_dataCollection.get(CONTACT_ORDER)).toString(); + String retVal = ((BigDecimal) m_dataCollection.get(CONTACT_ORDER)). + toString(); - if(retVal == null || retVal.isEmpty()) { + if (retVal == null || retVal.isEmpty()) { retVal = String.valueOf(this.getPosition()); } @@ -44,5 +45,4 @@ public class GenericOrganizationalUnitContactCollection extends DomainCollection public GenericContact getContact() { return new GenericContact(m_dataCollection.getDataObject()); } - } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitPersonCollection.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitPersonCollection.java new file mode 100644 index 000000000..764f2be12 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericOrganizationalUnitPersonCollection.java @@ -0,0 +1,43 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.persistence.DataCollection; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class GenericOrganizationalUnitPersonCollection extends DomainCollection { + + public static final String ORDER = "link.person_order asc"; + public static final String PERSON_ROLE = "link.role_name"; + public static final String PERSON_ORDER = "link.person_order"; + + public GenericOrganizationalUnitPersonCollection( + DataCollection dataCollection) { + super(dataCollection); + } + + /** + * Gets the name of the role of this orgaunit-person link + */ + public String getRoleName() { + return (String) m_dataCollection.get(PERSON_ROLE); + } + + public String getPersonOrder() { + String retVal = ((BigDecimal) m_dataCollection.get(PERSON_ORDER)). + toString(); + + if (retVal == null || retVal.isEmpty()) { + retVal = String.valueOf(this.getPosition()); + } + + return retVal; + } + + public GenericPerson getPerson() { + return new GenericPerson(m_dataCollection.getDataObject()); + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddChildForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddChildForm.java index bd399be2b..897fceb5c 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddChildForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddChildForm.java @@ -1,7 +1,3 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.FormData; @@ -26,7 +22,7 @@ public class GenericOrganizationalUnitAddChildForm extends BasicItemForm { private static final Logger s_log = Logger.getLogger( GenericOrganizationalUnitAddChildForm.class); - private GenericOrganizationalUnitPropertiesStep m_step; + private GenericOrganizationalUnitChildrenPropertiesStep m_step; private ItemSearchWidget m_itemSearch; private SaveCancelSection m_saveCancelSection; private final String ITEM_SEARCH = "orgaunitChild"; diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddPersonForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddPersonForm.java new file mode 100644 index 000000000..39e7c18b4 --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitAddPersonForm.java @@ -0,0 +1,70 @@ +/* + * To change this template, choose Tools | Templates + * 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.FormSectionEvent; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.cms.ui.authoring.BasicItemForm; +import org.apache.log4j.Logger; + +/** + * + * @author jensp + */ +public class GenericOrganizationalUnitAddPersonForm extends BasicItemForm { + + private static final Logger s_log = Logger.getLogger( + GenericOrganizationalUnitAddPersonForm.class); + private GenericOrganizationalUnitPersonPropertiesStep m_step; + private ItemSearchWidget m_itemSearch; + private SaveCancelSection m_saveCancelSection; + private final String ITEM_SEARCH = "orgaunitPerson"; + private ItemSelectionModel m_itemModel; + + public GenericOrganizationalUnitAddPersonForm(ItemSelectionModel itemModel) { + super("PersonAddForm", itemModel); + } + + @Override + protected void addWidgets() { + add(new Label((String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.genericorgaunit.select_person").localize())); + this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType. + findByAssociatedObjectType(GenericPerson.BASE_DATA_OBJECT_TYPE)); + add(this.m_itemSearch); + } + + @Override + public void init(FormSectionEvent fse) { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + + setVisible(state, true); + } + + @Override + public void process(FormSectionEvent fse) throws FormProcessException { + FormData data = fse.getFormData(); + PageState state = fse.getPageState(); + GenericOrganizationalUnit orga = (GenericOrganizationalUnit) getItemSelectionModel(). + getSelectedObject(state); + + if (!(this.getSaveCancelSection().getCancelButton().isSelected(state))) { + orga.addPerson((GenericPerson) data.get(ITEM_SEARCH)); + } + + init(fse); + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java index befa7ddb0..1a8466143 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildTable.java @@ -27,7 +27,7 @@ import java.math.BigDecimal; /** * - * @author jensp + * @author Jens Pelzetter */ public class GenericOrganizationalUnitChildTable extends Table implements TableActionListener { @@ -199,6 +199,7 @@ public class GenericOrganizationalUnitChildTable extends Table implements } } + @Override public void cellSelected(TableActionEvent event) { PageState state = event.getPageState(); @@ -218,6 +219,7 @@ public class GenericOrganizationalUnitChildTable extends Table implements } } + @Override public void headSelected(TableActionEvent event) { throw new UnsupportedOperationException("Not supported yet."); } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java index c54b94a86..53f550d9d 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitChildrenPropertiesStep.java @@ -1,11 +1,6 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; import com.arsdigita.cms.ui.authoring.BasicItemForm; @@ -41,7 +36,7 @@ public class GenericOrganizationalUnitChildrenPropertiesStep extends SimpleEditS addChildSheet.getSaveCancelSection().getCancelButton()); GenericOrganizationalUnitChildTable childrenTable = new GenericOrganizationalUnitChildTable( - (itemModel)); + itemModel); setDisplayComponent(childrenTable); } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonPropertiesStep.java new file mode 100644 index 000000000..ccf9a1bdb --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonPropertiesStep.java @@ -0,0 +1,41 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +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; + +/** + * + * @author Jens Pelzetter + */ +public class GenericOrganizationalUnitPersonPropertiesStep extends SimpleEditStep { + + private static final String ADD_PERSON_SHEET_NAME = "addPerson"; + + public GenericOrganizationalUnitPersonPropertiesStep( + ItemSelectionModel itemModel, + AuthoringKitWizard parent) { + this(itemModel, parent, null); + } + + public GenericOrganizationalUnitPersonPropertiesStep( + ItemSelectionModel itemModel, + AuthoringKitWizard parent, + String prefix) { + super(itemModel, parent, prefix); + + BasicItemForm addPersonSheet = new GenericOrganizationalUnitAddPersonForm(itemModel); + add(ADD_PERSON_SHEET_NAME, + (String) ContenttypesGlobalizationUtil.globalize( + "cms.contenttypes.ui.genericorgaunit.add_person").localize(), + new WorkflowLockedComponentAccess(addPersonSheet, itemModel), + addPersonSheet.getSaveCancelSection().getCancelButton()); + + GenericOrganizationalUnitPersonsTable personsTable = new GenericOrganizationalUnitPersonsTable(itemModel); + setDisplayComponent(personsTable); + } + +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonsTable.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonsTable.java new file mode 100644 index 000000000..6b387734f --- /dev/null +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationalUnitPersonsTable.java @@ -0,0 +1,223 @@ +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.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit; +import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitPersonCollection; +import com.arsdigita.cms.contenttypes.GenericPerson; +import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class GenericOrganizationalUnitPersonsTable 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; + + public GenericOrganizationalUnitPersonsTable(final ItemSelectionModel itemModel) { + super(); + m_itemModel = itemModel; + + setEmptyView(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.genericorgaunit.persons.none"))); + TableColumnModel tabModel = getColumnModel(); + + tabModel.add(new TableColumn( + 0, + ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.genericorgaunit.persons.order").localize(), + TABLE_COL_EDIT + )); + tabModel.add(new TableColumn( + 1, + ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.genericorgaunit.persons.name").localize() + )); + tabModel.add(new TableColumn( + 2, + ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.genericorgaunit.persons.role").localize() + )); + tabModel.add(new TableColumn( + 3, + ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.genericorgaunit.persons.delete").localize() + )); + + setModelBuilder(new GenericOrganizationalUnitTableModelBuilder(itemModel)); + + tabModel.get(0).setCellRenderer(new EditCellRenderer()); + tabModel.get(3).setCellRenderer(new DeleteCellRenderer()); + } + + private class GenericOrganizationalUnitTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + private ItemSelectionModel m_itemModel; + + public GenericOrganizationalUnitTableModelBuilder( + ItemSelectionModel itemModel) { + m_itemModel = itemModel; + } + + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + GenericOrganizationalUnit orgaunit = + (GenericOrganizationalUnit) m_itemModel.getSelectedObject(state); + return new GenericOrganizationalUnitTableModel(table, state, orgaunit); + } + } + + private class GenericOrganizationalUnitTableModel implements TableModel { + private final int MAX_DESC_LENGTH = 25; + private Table m_table; + private GenericOrganizationalUnitPersonCollection m_personsCollection; + private GenericPerson m_person; + + private GenericOrganizationalUnitTableModel( + Table table, + PageState state, + GenericOrganizationalUnit orgaunit + ) { + m_table = table; + m_personsCollection = orgaunit.getPersons(); + } + + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + public boolean nextRow() { + boolean ret; + + if ((m_personsCollection != null) + && m_personsCollection.next()) { + m_person = m_personsCollection.getPerson(); + ret = true; + } else { + ret = false; + } + + return ret; + } + + public Object getElementAt(int columnIndex) { + switch(columnIndex) { + case 0: + return m_personsCollection.getPersonOrder(); + case 1: + return String.format("%s %s %s %s", + m_person.getTitlePre(), + m_person.getGivenName(), + m_person.getSurname(), + m_person.getTitlePost()); + case 2: + return m_personsCollection.getRoleName(); + case 3: + return GlobalizationUtil.globalize("cms.ui.delete").localize(); + default: + return null; + } + } + + public Object getKeyAt(int columnIndex) { + return m_person.getID(); + } + } + + private class EditCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + com.arsdigita.cms.SecurityManager securityManager = Utilities. + getSecurityManager(state); + GenericPerson person = (GenericPerson) m_itemModel.getSelectedObject( + state); + + boolean canEdit = securityManager.canAccess(state.getRequest(), + com.arsdigita.cms.SecurityManager.EDIT_ITEM, + person); + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + return link; + } else { + return new Label(value.toString()); + } + } + } + + private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent( + Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int col) { + com.arsdigita.cms.SecurityManager securityManager = Utilities. + getSecurityManager(state); + GenericPerson person = (GenericPerson) m_itemModel.getSelectedObject( + state); + + boolean canEdit = securityManager.canAccess(state.getRequest(), + com.arsdigita.cms.SecurityManager.DELETE_ITEM, + person); + if (canEdit) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation((String) ContenttypesGlobalizationUtil. + globalize( + "cms.contenttypes.ui.genericorgaunit.persons.confirm_delete"). + localize()); + return link; + } else { + return new Label(value.toString()); + } + } + } + + @Override + public void cellSelected(TableActionEvent event) { + PageState state = event.getPageState(); + + GenericPerson person = new GenericPerson(new BigDecimal(event.getRowKey().toString())); + + GenericOrganizationalUnit orga = (GenericOrganizationalUnit) m_itemModel.getSelectedObject(state); + + TableColumn col = getColumnModel().get(event.getColumn().intValue()); + + if (col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { + } + + if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) { + orga.removePerson(person); + } + } + + + @Override + public void headSelected(TableActionEvent event) { + throw new UnsupportedOperationException("Not supported yet."); + } +}