diff --git a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/Membership.pdl b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/Membership.pdl index 28bb05d24..147fd1691 100644 --- a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/Membership.pdl +++ b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/Membership.pdl @@ -22,8 +22,8 @@ import com.arsdigita.kernel.ACSObject; object type Membership extends ACSObject { MembershipStatus[1..1] status = join ct_memberships.status_id to ct_membershipstatus.status_id; - Date[1..1] memberFrom = ct_memberships.member_from DATE; - Date[1..1] memberTo = ct_memberships.member_to DATE; + Date[0..1] memberFrom = ct_memberships.member_from DATE; + Date[0..1] memberTo = ct_memberships.member_to DATE; Person[0..1] targetItem = join ct_memberships.target_item_id to ct_persons.person_id; reference key(ct_memberships.membership_id); @@ -32,7 +32,7 @@ object type Membership extends ACSObject { association { composite OrganizationalUnit[0..1] membershipOwner = join ct_memberships.owner_id to ct_organizationalunits.organizationalunit_id; - composite Membership[0..n] members = join ct_organizationalunits.organizationalunit_id to ct_memberships.ownerId; + composite Membership[0..n] members = join ct_organizationalunits.organizationalunit_id to ct_memberships.owner_id; } query getMembershipsReferingToUnits { diff --git a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrganizationalUnit.pdl b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrganizationalUnit.pdl index 361f3ec43..5247452ba 100644 --- a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrganizationalUnit.pdl +++ b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrganizationalUnit.pdl @@ -28,4 +28,17 @@ object type OrganizationalUnit extends ContentPage { String[0..1] organizationalunitDescription = ct_organizationalunits.organizationalunit_description VARCHAR(2048); reference key (ct_organizationalunits.organizationalunit_id); -} \ No newline at end of file + //aggressive load (direction.id); + //aggressive load (assistentDirection.id); +} + +association { + Person[0..1] direction = join ct_organizationalunits.direction_id to ct_persons.person_id; + OrganizationalUnit[0..n] directedUnit = join ct_persons.person_id to ct_organizationalunits.direction_id; +} + +association { + Person[0..1] assistentDirection = join ct_organizationalunits.assistantDirection_id to ct_persons.person_id; + OrganizationalUnit[0..n] assistenedDirectedUnit = join ct_persons.person_id to ct_organizationalunits.assistantDirection_id; +} + diff --git a/ccm-cms-types-organizationalunit/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationalUnit.xml b/ccm-cms-types-organizationalunit/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationalUnit.xml index 1e59c2710..44ba098fb 100644 --- a/ccm-cms-types-organizationalunit/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationalUnit.xml +++ b/ccm-cms-types-organizationalunit/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationalUnit.xml @@ -18,26 +18,40 @@ component="com.arsdigita.cms.contenttypes.ui.organizationalunit.OrganizationalUnitPropertiesStep" ordering="1"/> + + + + + ordering="4"/> + ordering="5"/> + ordering="6"/> diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/Membership.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/Membership.java index a06fc4b7a..6b23d119d 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/Membership.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/Membership.java @@ -116,6 +116,7 @@ public class Membership extends ACSObject { public void setMembershipOwner(OrganizationalUnit ou) { Assert.exists(ou, OrganizationalUnit.class); + logger.debug("Setting membership owner to " + ou.getOrganizationalUnitName()); setAssociation(MEMBERSHIP_OWNER, ou); } diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrganizationalUnit.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrganizationalUnit.java index 053fc2127..1a9b850a9 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrganizationalUnit.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrganizationalUnit.java @@ -20,9 +20,12 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.cms.ContentPage; import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; import java.math.BigDecimal; +import org.apache.log4j.Logger; /** * @@ -30,9 +33,14 @@ import java.math.BigDecimal; */ public class OrganizationalUnit extends ContentPage { + private final static Logger logger = Logger.getLogger(OrganizationalUnit.class); + public final static String ORGANIZATIONALUNIT_NAME = "organizationalunitName"; public final static String ORGANIZATIONALUNIT_DESCRIPTION = "organizationalunitDescription"; + public final static String DIRECTION = "direction"; + public final static String ASSISTANT_DIRECTION = "assistentDirection"; + public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrganizationalUnit"; public OrganizationalUnit() { @@ -71,4 +79,39 @@ public class OrganizationalUnit extends ContentPage { public void setOrganizationalUnitDescription(String description) { set(ORGANIZATIONALUNIT_DESCRIPTION, description); } + + public Person getDirection() { + DataObject dobj = (DataObject) get(DIRECTION); + if (dobj != null) { + return (Person) DomainObjectFactory.newInstance(dobj); + } else { + return null; + } + } + + public void setDirection(Person person) { + logger.debug("Setting direction..."); + Assert.exists(person, Person.class); + setAssociation(DIRECTION, person); + } + + public Person getAssistentDirection() { + DataObject dobj = (DataObject) get(ASSISTANT_DIRECTION); + if (dobj != null) { + return (Person) DomainObjectFactory.newInstance(dobj); + } else { + return null; + } + } + + + public void setAssistentDirection(Person person) { + Assert.exists(person, Person.class); + setAssociation(ASSISTANT_DIRECTION, person); + } + + @Override + public String getBaseDataObjectType() { + return BASE_DATA_OBJECT_TYPE; + } } diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/ChangeableSingleSelect.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/ChangeableSingleSelect.java index 06dd23484..b1b97babc 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/ChangeableSingleSelect.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/ChangeableSingleSelect.java @@ -17,6 +17,7 @@ import java.util.Iterator; public class ChangeableSingleSelect extends SingleSelect { private ArrayList m_options; + private ArrayList m_selected; private RequestLocal m_requestOptions = new RequestLocal() { @Override @@ -25,12 +26,17 @@ public class ChangeableSingleSelect extends SingleSelect { } }; + private final static String TOO_MANY_OPTIONS_SELECTED = + "Only one option may be selected by default on this option group."; + public ChangeableSingleSelect(String name) { super(new StringParameter(name)); + this.m_selected = new ArrayList(); } public ChangeableSingleSelect(ParameterModel model) { super(model); + this.m_selected = new ArrayList(); } @Override @@ -109,4 +115,25 @@ public class ChangeableSingleSelect extends SingleSelect { } } } + + @Override + @SuppressWarnings("deprecation") + public void setOptionSelected(String value) { + Assert.assertNotLocked(this); + if (!isMultiple()) { + // only one option may be selected + // to this selected list better be empty + Assert.assertTrue(m_selected.size() == 0, TOO_MANY_OPTIONS_SELECTED); + m_selected.add(value); + getParameterModel().setDefaultValue(value); + } else { + m_selected.add(value); + getParameterModel().setDefaultValue(m_selected.toArray()); + } + } + + public void setOptionSelected(Option option) { + setOptionSelected(option.getValue()); + } + } diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertyForm.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertyForm.java index 67273d83b..277fec1ab 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertyForm.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertyForm.java @@ -35,6 +35,8 @@ import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.SessionManager; import com.arsdigita.util.Assert; import com.arsdigita.util.UncheckedWrapperException; +import java.math.BigDecimal; +import java.util.Date; import java.util.Iterator; import org.apache.log4j.Logger; @@ -155,9 +157,11 @@ public class MembershipPropertyForm extends FormSection implements FormInitListe protected Membership createMembership(PageState state) { OrganizationalUnit ou = this.getOrganizationalUnit(state); + logger.debug("Owning ou: " + ou.getOrganizationalUnitName()); Assert.exists(ou); Membership membership = new Membership(); membership.setMembershipOwner(ou); + logger.debug("set ou to: " + membership.getMembershipOwner().getOrganizationalUnitName()); return membership; } @@ -167,6 +171,13 @@ public class MembershipPropertyForm extends FormSection implements FormInitListe membership.setTargetItem((Person) data.get(PERSON_SEARCH)); + MembershipStatus status = new MembershipStatus(new BigDecimal((String) this.m_status.getValue(state))); + logger.debug("this.m_status.getValues() = " + this.m_status.getValue(state)); + membership.setStatus(status); + + membership.setFrom((Date) this.m_from.getValue(state)); + membership.setTo((Date) this.m_to.getValue(state)); + membership.save(); } @@ -200,7 +211,7 @@ public class MembershipPropertyForm extends FormSection implements FormInitListe } } else { data.put(PERSON_SEARCH, null); - } + } } public void process(FormSectionEvent e) throws FormProcessException { diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTable.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTable.java index 027b60dbf..d118dc72e 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTable.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTable.java @@ -96,7 +96,26 @@ public class MembershipTable extends Table { String url = membership.getURI(state); if (column == m_personCol.getModelIndex()) { Person person = membership.getTargetItem(); - String fullName = String.format("%s %s %s, %s", person.getTitlePre(), person.getGivenName(), person.getSurname(), person.getTitlePost()); + StringBuilder fullNameBuilder = new StringBuilder(); + + if(person.getTitlePre() != null) { + fullNameBuilder.append(person.getTitlePre()); + fullNameBuilder.append(" "); + } + if(person.getGivenName() != null) { + fullNameBuilder.append(person.getGivenName()); + fullNameBuilder.append(" "); + } + if(person.getSurname() != null) { + fullNameBuilder.append(person.getSurname()); + fullNameBuilder.append(" "); + } + if(person.getTitlePost() != null) { + fullNameBuilder.append(person.getTitlePost()); + } + + //String fullName = String.format("%s %s %s, %s", person.getTitlePre(), person.getGivenName(), person.getSurname(), person.getTitlePost()); + String fullName = fullNameBuilder.toString(); ExternalLink extLink = new ExternalLink(fullName, url); return extLink; } else if(column == m_statusCol.getModelIndex()) { diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorStep.java new file mode 100644 index 000000000..230f13775 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorStep.java @@ -0,0 +1,39 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.authoring.WorkflowLockedComponentAccess; +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; + +/** + * + * @author Jens Pelzetter + */ +public class OrganizationalUnitChooseAssistentDirectorStep extends SimpleEditStep { + + private static String EDIT_SHEET_NAME = "edit"; + + public OrganizationalUnitChooseAssistentDirectorStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + super(itemModel, parent); + + OrganizationalUnitChooseAssistentDirectorTable table = new OrganizationalUnitChooseAssistentDirectorTable(itemModel, this); + + addComponent(EDIT_SHEET_NAME, "Select assistent director", new WorkflowLockedComponentAccess(table, itemModel)); + + setDisplayComponent(getOrganizationalUnitPropertiesSheet(itemModel)); + } + + private Component getOrganizationalUnitPropertiesSheet(ItemSelectionModel itemModel) { + DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); + + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_title_pre"), "assistentDirection.titlepre"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_givenname"), "assistentDirection.givenname"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_surname"), "assistentDirection.surname"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_title_post"), "assistentDirection.titlepost"); + + return sheet; + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorTable.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorTable.java new file mode 100644 index 000000000..113d5dfa8 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseAssistentDirectorTable.java @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2009 Jens Pelzetter, for the Center for Social Policy Research 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 + * + */ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +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.ContentItem; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.OrganizationalUnit; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; + +/** + * Table used to select the assistent director of + * an organizational unit. + * + * @author Jens Pelzetter + */ +public class OrganizationalUnitChooseAssistentDirectorTable extends Table implements TableActionListener { + + private static final String COL_PERSON = "Person"; + private static final String COL_CHOOSE_PERSON = "Select"; + private ItemSelectionModel m_selOrgaUnit; + private OrganizationalUnitChooseAssistentDirectorStep m_parent; + + public OrganizationalUnitChooseAssistentDirectorTable(ItemSelectionModel selOrgaUnit, OrganizationalUnitChooseAssistentDirectorStep parent) { + + super(); + + this.m_parent = parent; + this.m_selOrgaUnit = selOrgaUnit; + + TableColumnModel model = getColumnModel(); + model.add(new TableColumn(0, COL_PERSON)); + model.add(new TableColumn(1, COL_CHOOSE_PERSON)); + + setEmptyView(new Label("New Persons available.")); + setModelBuilder(new OrganizationalUnitChooseAssistentDirectorTableModelBuilder()); + + model.get(1).setCellRenderer(new SelectCellRenderer()); + + addTableActionListener(this); + } + + private class OrganizationalUnitChooseAssistentDirectorTableModelBuilder extends LockableImpl implements TableModelBuilder { + + public TableModel makeModel(Table t, PageState s) { + t.getRowSelectionModel().clearSelection(s); + DataCollection m_persons = SessionManager.getSession().retrieve(Person.BASE_DATA_OBJECT_TYPE); + m_persons.addEqualsFilter(ContentItem.VERSION, ContentItem.DRAFT); + return new OrganizationalUnitChooseAssistentDirectorTableModel(t, m_persons); + } + } + + private class OrganizationalUnitChooseAssistentDirectorTableModel implements TableModel { + + private Table m_table; + private DataCollection m_persons; + private Person m_person; + + private OrganizationalUnitChooseAssistentDirectorTableModel(Table t, DataCollection persons) { + m_table = t; + m_persons = persons; + } + + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + public boolean nextRow() { + if (m_persons.next()) { + m_person = (Person) DomainObjectFactory.newInstance(m_persons.getDataObject()); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + StringBuilder personNameBuilder = new StringBuilder(); + if ((m_person.getTitlePre() != null) && + m_person.getTitlePre().length() > 0) { + personNameBuilder.append(m_person.getTitlePre()); + personNameBuilder.append(" "); + } + if ((m_person.getGivenName() != null) && + m_person.getGivenName().length() > 0) { + personNameBuilder.append(m_person.getGivenName()); + personNameBuilder.append(" "); + } + if ((m_person.getSurname() != null) && + m_person.getSurname().length() > 0) { + personNameBuilder.append(m_person.getSurname()); + personNameBuilder.append(" "); + } + if ((m_person.getTitlePost() != null) && + m_person.getTitlePost().length() > 0) { + personNameBuilder.append(m_person.getTitlePost()); + } + return personNameBuilder.toString(); + case 1: + return COL_CHOOSE_PERSON; + default: + return null; + } + } + + public Object getKeyAt(int columnIndex) { + return m_person.getID(); + } + } + + private class SelectCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation("Select this person?"); + return link; + } + + } + + public void cellSelected(TableActionEvent e) { + PageState state = e.getPageState(); + TableColumn col = getColumnModel().get(e.getColumn().intValue()); + String colName = (String) col.getHeaderValue(); + + if (COL_CHOOSE_PERSON.equals(colName)) { + m_parent.showDisplayPane(state); + BigDecimal personID = new BigDecimal (e.getRowKey().toString()); + OrganizationalUnit orgaunit = (OrganizationalUnit) this.m_selOrgaUnit.getSelectedObject(state); + Person person = (Person) DomainObjectFactory.newInstance(new OID(Person.BASE_DATA_OBJECT_TYPE, personID)); + orgaunit.setAssistentDirection(person); + } + } + + public void headSelected(TableActionEvent e) { + throw new UnsupportedOperationException("Not supported yet."); + } +} \ No newline at end of file diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorStep.java new file mode 100644 index 000000000..5f89f5dc1 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorStep.java @@ -0,0 +1,39 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.authoring.SimpleEditStep; +import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; + +/** + * + * @author Jens Pelzetter + */ +public class OrganizationalUnitChooseDirectorStep extends SimpleEditStep { + + private static String EDIT_SHEET_NAME = "edit"; + + public OrganizationalUnitChooseDirectorStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + super(itemModel, parent); + + OrganizationalUnitChooseDirectorTable table = new OrganizationalUnitChooseDirectorTable(itemModel, this); + + addComponent(EDIT_SHEET_NAME, "Select Director", new WorkflowLockedComponentAccess(table, itemModel)); + + setDisplayComponent(getOrganizationalUnitPropertiesSheet(itemModel)); + } + + private Component getOrganizationalUnitPropertiesSheet(ItemSelectionModel itemModel) { + DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); + + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_title_pre"), "direction.titlepre"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_givenname"), "direction.givenname"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_surname"), "direction.surname"); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.director_title_post"), "direction.titlepost"); + + return sheet; + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorTable.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorTable.java new file mode 100644 index 000000000..bdcb7462d --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitChooseDirectorTable.java @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2009 Jens Pelzetter, for the Center for Social Policy Research 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 + * + */ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +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.ContentItem; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.OrganizationalUnit; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; +import org.apache.log4j.Logger; + +/** + * Table used to select the Director of + * an organizational unit. + * + * @author Jens Pelzetter + */ +public class OrganizationalUnitChooseDirectorTable extends Table implements TableActionListener { + + private final static Logger logger = Logger.getLogger(OrganizationalUnitChooseDirectorTable.class); + private static final String COL_PERSON = "Person"; + private static final String COL_CHOOSE_PERSON = "Select"; + private ItemSelectionModel m_selOrgaUnit; + private OrganizationalUnitChooseDirectorStep m_parent; + + public OrganizationalUnitChooseDirectorTable(ItemSelectionModel selOrgaUnit, OrganizationalUnitChooseDirectorStep parent) { + + super(); + + this.m_parent = parent; + this.m_selOrgaUnit = selOrgaUnit; + + TableColumnModel model = getColumnModel(); + model.add(new TableColumn(0, COL_PERSON)); + model.add(new TableColumn(1, COL_CHOOSE_PERSON)); + + setEmptyView(new Label("New Persons available.")); + setModelBuilder(new OrganizationalUnitChooseDirectorTableModelBuilder()); + + model.get(1).setCellRenderer(new SelectCellRenderer()); + + addTableActionListener(this); + } + + private class OrganizationalUnitChooseDirectorTableModelBuilder extends LockableImpl implements TableModelBuilder { + + public TableModel makeModel(Table t, PageState s) { + t.getRowSelectionModel().clearSelection(s); + DataCollection m_persons = SessionManager.getSession().retrieve(Person.BASE_DATA_OBJECT_TYPE); + m_persons.addEqualsFilter(ContentItem.VERSION, ContentItem.DRAFT); + return new OrganizationalUnitChooseDirectorTableModel(t, m_persons); + } + } + + private class OrganizationalUnitChooseDirectorTableModel implements TableModel { + + private Table m_table; + private DataCollection m_persons; + private Person m_person; + + private OrganizationalUnitChooseDirectorTableModel(Table t, DataCollection persons) { + m_table = t; + m_persons = persons; + } + + public int getColumnCount() { + return m_table.getColumnModel().size(); + } + + public boolean nextRow() { + if (m_persons.next()) { + m_person = (Person) DomainObjectFactory.newInstance(m_persons.getDataObject()); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + StringBuilder personNameBuilder = new StringBuilder(); + if ((m_person.getTitlePre() != null) && + m_person.getTitlePre().length() > 0) { + personNameBuilder.append(m_person.getTitlePre()); + personNameBuilder.append(" "); + } + if ((m_person.getGivenName() != null) && + m_person.getGivenName().length() > 0) { + personNameBuilder.append(m_person.getGivenName()); + personNameBuilder.append(" "); + } + if ((m_person.getSurname() != null) && + m_person.getSurname().length() > 0) { + personNameBuilder.append(m_person.getSurname()); + personNameBuilder.append(" "); + } + if ((m_person.getTitlePost() != null) && + m_person.getTitlePost().length() > 0) { + personNameBuilder.append(m_person.getTitlePost()); + } + return personNameBuilder.toString(); + case 1: + return COL_CHOOSE_PERSON; + default: + return null; + } + } + + public Object getKeyAt(int columnIndex) { + return m_person.getID(); + } + } + + private class SelectCellRenderer extends LockableImpl implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + ControlLink link = new ControlLink(value.toString()); + link.setConfirmation("Select this person?"); + return link; + } + + } + + public void cellSelected(TableActionEvent e) { + PageState state = e.getPageState(); + TableColumn col = getColumnModel().get(e.getColumn().intValue()); + String colName = (String) col.getHeaderValue(); + + logger.debug("Cell selected invoked..."); + + if (COL_CHOOSE_PERSON.equals(colName)) { + logger.debug ("Col is choose person col..."); + m_parent.showDisplayPane(state); + BigDecimal personID = new BigDecimal (e.getRowKey().toString()); + OrganizationalUnit orgaunit = (OrganizationalUnit) this.m_selOrgaUnit.getSelectedObject(state); + Person person = (Person) DomainObjectFactory.newInstance(new OID(Person.BASE_DATA_OBJECT_TYPE, personID)); + orgaunit.setDirection(person); + } + } + + public void headSelected(TableActionEvent e) { + throw new UnsupportedOperationException("Not supported yet."); + } +}