diff --git a/ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl b/ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl index de54872d7..d5d42e45d 100644 --- a/ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl +++ b/ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl @@ -1,5 +1,5 @@ // -// Copyright (C) 2009 Center of Socialpolitics, University of Bremen +// Copyright (C) 2009 Center for Social Policy Reseearch, 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 diff --git a/ccm-cms-types-organizationalunit/application.xml b/ccm-cms-types-organizationalunit/application.xml index 23226cabb..5795800c5 100644 --- a/ccm-cms-types-organizationalunit/application.xml +++ b/ccm-cms-types-organizationalunit/application.xml @@ -8,8 +8,7 @@ - - + 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 new file mode 100644 index 000000000..28bb05d24 --- /dev/null +++ b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/Membership.pdl @@ -0,0 +1,46 @@ +// +// Copyright (C) 2009 Center for Social Policy Reseearch, 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.ContentItem; +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; + Person[0..1] targetItem = join ct_memberships.target_item_id to ct_persons.person_id; + + reference key(ct_memberships.membership_id); + aggressive load (membershipOwner.id); +} + +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; +} + +query getMembershipsReferingToUnits { + BigDecimal id; + + do { + select m.membership_id from memberships m where m.target_item_id = :itemID; + } map { + id = m.membership_id; + } +} \ No newline at end of file diff --git a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/MembershipStatus.pdl b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/MembershipStatus.pdl new file mode 100644 index 000000000..64359b9fe --- /dev/null +++ b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/MembershipStatus.pdl @@ -0,0 +1,28 @@ +// +// Copyright (c) 2009 Center for Social Policy Research, 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.kernel.ACSObject; + +object type MembershipStatus extends ACSObject { + + String[1..1] membershipStatusName = ct_membershipstatus.status_name VARCHAR(250); + + reference key(ct_membershipstatus.status_id); +} \ No newline at end of file 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 8f9676c3a..1e59c2710 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 @@ -15,15 +15,30 @@ labelBundle="com.arsdigita.cms.contenttypes.OrganizationalUnitResources" descriptionKey="organizationalunit.authoring.basic_properties.description" descriptionBundle="com.arsdigita.cms.contenttypes.OrganizationalUnitResources" - component="com.arsdigita.cms.contenttypes.ui.OrganizationalUnitPropertiesStep" + component="com.arsdigita.cms.contenttypes.ui.organizationalunit.OrganizationalUnitPropertiesStep" ordering="1"/> + + + + + diff --git a/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load b/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load index 18662056b..86c656544 100644 --- a/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load +++ b/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load @@ -9,7 +9,8 @@
- +
+ 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 new file mode 100644 index 000000000..a06fc4b7a --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/Membership.java @@ -0,0 +1,162 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.dispatcher.ItemResolver; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.kernel.ACSObject; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.OID; +import com.arsdigita.persistence.Session; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.util.Assert; +import com.arsdigita.web.URL; +import java.math.BigDecimal; +import java.text.DateFormat; +import java.util.Date; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class Membership extends ACSObject { + + private final static Logger logger = Logger.getLogger(Membership.class); + public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Membership"; + public final static String STATUS = "status"; + public final static String FROM = "memberFrom"; + public final static String TO = "memberTo"; + public final static String MEMBERSHIP_OWNER = "membershipOwner"; + public final static String TARGET_ITEM = "targetItem"; + + public Membership() { + super(BASE_DATA_OBJECT_TYPE); + } + + public Membership(DataObject obj) { + super(obj); + } + + public Membership(BigDecimal id) { + this(new OID(BASE_DATA_OBJECT_TYPE, id)); + } + + public Membership(OID oid) { + super(oid); + } + + public Membership(String type) { + super(type); + } + + public MembershipStatus getStatus() { + DataObject obj = (DataObject) get(STATUS); + if (obj != null) { + return new MembershipStatus(obj); + } else { + return null; + } + } + + public void setStatus(MembershipStatus status) { + setAssociation(STATUS, status); + } + + public String getStatusName() { + String name = ""; + if (getStatus() != null) { + name = getStatus().getStatusName(); + } + return name; + } + + public String formatDate(Date date) { + if (date != null) { + return DateFormat.getDateInstance(DateFormat.LONG).format(date); + } else { + return null; + } + } + + public Date getFrom() { + return (Date) get(FROM); + } + + public String getDisplayFrom() { + return formatDate(getFrom()); + } + + public void setFrom(Date from) { + set(FROM, from); + } + + public Date getTo() { + return (Date) get(TO); + } + + public String getDisplayTo() { + return formatDate(getTo()); + } + + public void setTo(Date to) { + set(TO, to); + } + + public OrganizationalUnit getMembershipOwner() { + DataObject obj = (DataObject) get(MEMBERSHIP_OWNER); + if (obj == null) { + return null; + } else { + return (OrganizationalUnit) DomainObjectFactory.newInstance(obj); + } + } + + public void setMembershipOwner(OrganizationalUnit ou) { + Assert.exists(ou, OrganizationalUnit.class); + setAssociation(MEMBERSHIP_OWNER, ou); + } + + public Person getTargetItem() { + DataObject obj = (DataObject) get(TARGET_ITEM); + return (Person) DomainObjectFactory.newInstance(obj); + } + + public void setTargetItem(Person person) { + Assert.exists(person, Person.class); + setAssociation(TARGET_ITEM, person); + } + + public String getURI(PageState state) { + Person person = this.getTargetItem(); + + if (person == null) { + logger.error(getOID() + " is a link between a OrganizationalUnit and a Person, but the associated Person is null"); + return ""; + } + + ContentSection section = person.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + String url = resolver.generateItemURL(state, person, section, person.getVersion()); + + return URL.there(state.getRequest(), url).toString(); + } + + public static DataCollection getReferingPersons(Person person) { + Session session = SessionManager.getSession(); + DataCollection memberships = session.retrieve(BASE_DATA_OBJECT_TYPE); + Filter filter = memberships.addInSubqueryFilter("id", "com.arsdigita.cms.contenttypes.getReferingPersons"); + filter.set("itemID", person.getID()); + + return memberships; + } + + public static DataCollection getMemberships(OrganizationalUnit ou) { + Session session = SessionManager.getSession(); + DataCollection dc = session.retrieve(BASE_DATA_OBJECT_TYPE); + dc.addEqualsFilter(MEMBERSHIP_OWNER + ".id", ou.getID()); + return dc; + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatus.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatus.java new file mode 100644 index 000000000..ffb088258 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatus.java @@ -0,0 +1,54 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.kernel.ACSObject; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.persistence.OID; +import java.math.BigDecimal; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatus extends ACSObject { + + public static final Logger logger = Logger.getLogger(MembershipStatus.class); + + public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.MembershipStatus"; + + public static final String MEMBERSHIP_STATUS_NAME = "membershipStatusName"; + + public MembershipStatus() { + super(BASE_DATA_OBJECT_TYPE); + logger.debug("Paramless constructor..."); + } + + public MembershipStatus(BigDecimal id) throws DataObjectNotFoundException { + this(new OID(BASE_DATA_OBJECT_TYPE, id)); + logger.debug("id constructor..."); + } + + public MembershipStatus(OID id) throws DataObjectNotFoundException { + super(id); + logger.debug("oid constructor..."); + } + + public MembershipStatus(DataObject obj) { + super(obj); + logger.debug("obj constructor..."); + } + + public MembershipStatus(String type) { + super(type); + logger.debug("type constructor..."); + } + + public String getStatusName() { + return (String) get(MEMBERSHIP_STATUS_NAME); + } + + public void setStatusName(String typeName) { + set(MEMBERSHIP_STATUS_NAME, typeName); + } +} \ No newline at end of file diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatusCollection.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatusCollection.java new file mode 100644 index 000000000..fcdbe9c9a --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/MembershipStatusCollection.java @@ -0,0 +1,50 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.domain.DomainCollection; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.SessionManager; +import java.math.BigDecimal; +import org.apache.log4j.Logger; +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusCollection extends DomainCollection { + + private final static Logger logger = Logger.getLogger(MembershipStatusCollection.class); + + public static MembershipStatusCollection getMembershipStatusCollection() { + logger.debug("Getting MembershipStatusCollection..."); + SessionManager.getSession().retrieve(MembershipStatus.BASE_DATA_OBJECT_TYPE); + DataCollection statusCollection = SessionManager.getSession().retrieve(MembershipStatus.BASE_DATA_OBJECT_TYPE); + return new MembershipStatusCollection(statusCollection); + } + + private MembershipStatusCollection(DataCollection dataCollection) { + super(dataCollection); + logger.debug("MembershipStatusCollection constructor..."); + } + + @Override + public DomainObject getDomainObject() { + return new MembershipStatus(m_dataCollection.getDataObject()); + } + + public MembershipStatus getMembershipStatus() { + return (MembershipStatus) getDomainObject(); + } + + public String getMembershipStatusName() { + return getMembershipStatus().getStatusName(); + } + + public BigDecimal getMembershipStatusId() { + return getMembershipStatus().getID(); + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertiesStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertiesStep.java new file mode 100644 index 000000000..237761d7a --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertiesStep.java @@ -0,0 +1,71 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.FormSection; +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.ui.ResettableContainer; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipPropertiesStep extends ResettableContainer { + + private AuthoringKitWizard m_parent; + private ItemSelectionModel m_itemModel; + private BigDecimalParameter m_membershipParam = new BigDecimalParameter("membership"); + private MembershipSelectionModel m_membershipModel; // = new MembershipSelectionModel(m_membershipParam); + + public MembershipPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + this.m_itemModel = itemModel; + this.m_parent = parent; + setMembershipSelectionModel(); + add(getDisplayComponent()); + + Form form = new Form("membershipEditForm"); + form.add(getEditSheet()); + + WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel); + edit.add(form); + add(edit); + } + + protected void setMembershipSelectionModel() { + setMembershipSelectionModel(new MembershipSelectionModel(this.m_membershipParam)); + } + + protected void setMembershipSelectionModel(MembershipSelectionModel membershipModel) { + this.m_membershipModel = membershipModel; + } + + protected MembershipSelectionModel getMembershipSelectionModel() { + return this.m_membershipModel; + } + + protected BigDecimalParameter getMembershipParam() { + return this.m_membershipParam; + } + + public Component getDisplayComponent() { + SimpleContainer container = new SimpleContainer(); + container.add(new MembershipTable(m_itemModel, m_membershipModel)); + return container; + } + + public FormSection getEditSheet() { + return new MembershipPropertyForm(m_itemModel, m_membershipModel); + } + + @Override + public void register(Page p) { + super.register(p); + p.addComponentStateParam(this, m_membershipParam); + } + +} 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 new file mode 100644 index 000000000..d596855b5 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipPropertyForm.java @@ -0,0 +1,214 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.FormSection; +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.FormValidationListener; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Option; +import com.arsdigita.bebop.form.SingleSelect; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.parameters.DateParameter; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Membership; +import com.arsdigita.cms.contenttypes.MembershipStatusCollection; +import com.arsdigita.cms.contenttypes.OrganizationalUnit; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.cms.ui.ItemSearchWidget; +import com.arsdigita.util.Assert; +import com.arsdigita.util.UncheckedWrapperException; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipPropertyForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { + + private final static Logger logger = Logger.getLogger(MembershipPropertyForm.class); + + public final static String ID = "membership_edit"; + private ItemSelectionModel m_itemModel; + private MembershipSelectionModel m_membershipModel; + + private ItemSearchWidget m_personSearch; + private final static String PERSON_SEARCH = "membership"; + private SingleSelect m_status; + private com.arsdigita.bebop.form.Date m_from; + private com.arsdigita.bebop.form.Date m_to; + private SaveCancelSection m_saveCancelSection; + + public MembershipPropertyForm(ItemSelectionModel itemModel, MembershipSelectionModel membershipModel) { + super(new ColumnPanel(2)); + this.m_itemModel = itemModel; + this.m_membershipModel = membershipModel; + + addWidgets(); + addSaveCancelSection(); + + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + addSubmissionListener(this); + } + + protected void addWidgets() { + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.orgnizationalunit.membership.Person"))); + this.m_personSearch = new ItemSearchWidget(PERSON_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.Person")); + add(this.m_personSearch); + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.orgnizationalunit.membership.Status"))); + ParameterModel statusParam = new StringParameter((Membership.STATUS)); + this.m_status = new SingleSelect(statusParam); + add(this.m_status); + MembershipStatusCollection statusValues = MembershipStatusCollection.getMembershipStatusCollection(); + while(statusValues.next()) { + this.m_status.addOption(new Option(statusValues.getMembershipStatusId().toString(), statusValues.getMembershipStatusName())); + } + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.organizationalunit.membership.from"))); + ParameterModel fromParam = new DateParameter(Membership.FROM); + //fromParam.addParameterListener(new NotNullValidationListener()); + this.m_from = new com.arsdigita.bebop.form.Date(fromParam); + add(this.m_from); + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.organizationalunit.membership.to"))); + ParameterModel toParam = new DateParameter(Membership.TO); + this.m_to = new com.arsdigita.bebop.form.Date(toParam); + add(this.m_to); + } + + protected void addSaveCancelSection() { + this.m_saveCancelSection = new SaveCancelSection(); + try { + this.m_saveCancelSection.getCancelButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_membershipModel.isSelected(e.getPageState())) { + target.setButtonLabel("cancel"); + } else { + target.setButtonLabel("Reset"); + } + } + }); + + this.m_saveCancelSection.getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_membershipModel.isSelected(e.getPageState())) { + target.setButtonLabel("Save"); + } else { + target.setButtonLabel("Create"); + } + } + }); + } catch(Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + add(this.m_saveCancelSection, ColumnPanel.FULL_WIDTH); + } + + public SaveCancelSection getSaveCancelSection() { + return this.m_saveCancelSection; + } + + protected MembershipSelectionModel getMembershipSelectionModel() { + return this.m_membershipModel; + } + + protected OrganizationalUnit getOrganizationalUnit(PageState state) { + return (OrganizationalUnit) m_itemModel.getSelectedItem(state); + } + + protected Membership createMembership(PageState state) { + OrganizationalUnit ou = this.getOrganizationalUnit(state); + Assert.exists(ou); + Membership membership = new Membership(); + membership.setMembershipOwner(ou); + return membership; + } + + protected void setMembershipProperties(Membership membership, FormSectionEvent event) { + PageState state = event.getPageState(); + FormData data = event.getFormData(); + + membership.setTargetItem((Person) data.get(PERSON_SEARCH)); + + membership.save(); + } + + public void init(FormSectionEvent e) throws FormProcessException { + FormData data = e.getFormData(); + PageState state = e.getPageState(); + + setVisible(state, true); + + Membership membership; + if (m_membershipModel.isSelected(state)) { + membership = m_membershipModel.getSelectedMembership(state); + try { + data.put(PERSON_SEARCH, membership.getTargetItem()); + data.put(Membership.STATUS, membership.getStatus()); + data.put(Membership.FROM, membership.getFrom()); + data.put(Membership.TO, membership.getTo()); + } catch (IllegalStateException ex) { + throw ex; + } + } else { + data.put(PERSON_SEARCH, null); + } + } + + public void process(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + Membership membership; + + if (this.getSaveCancelSection().getCancelButton().isSelected(state)) { + this.m_membershipModel.clearSelection(state); + } else { + if (this.m_membershipModel.isSelected(state)) { + membership = m_membershipModel.getSelectedMembership(state); + } else { + membership = createMembership(state); + } + setMembershipProperties(membership, e); + } + + this.m_membershipModel.clearSelection(state); + init(e); + } + + public void validate(FormSectionEvent e) throws FormProcessException { + if (e.getFormData().get(PERSON_SEARCH) == null) { + throw new FormProcessException("Person selection is required"); + } + + if(e.getFormData().get(Membership.STATUS) == null) { + throw new FormProcessException("Status of membership is required"); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + if (this.m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) { + m_membershipModel.clearSelection(e.getPageState()); + init(e); + throw new FormProcessException("cancelled"); + } + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipSelectionModel.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipSelectionModel.java new file mode 100644 index 000000000..9853c65f7 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipSelectionModel.java @@ -0,0 +1,25 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.contenttypes.Membership; +import com.arsdigita.kernel.ui.ACSObjectSelectionModel; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipSelectionModel extends ACSObjectSelectionModel { + + public MembershipSelectionModel(BigDecimalParameter param) { + super(Membership.class.getName(), Membership.BASE_DATA_OBJECT_TYPE, param); + } + + public MembershipSelectionModel(String itemClass, String objectType, BigDecimalParameter param) { + super(itemClass, objectType, param); + } + + public Membership getSelectedMembership(PageState state) { + return (Membership) getSelectedObject(state); + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertiesStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertiesStep.java new file mode 100644 index 000000000..c578c2ef2 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertiesStep.java @@ -0,0 +1,78 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.cms.contenttypes.ui.*; +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.Form; +import com.arsdigita.bebop.FormSection; +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.SimpleContainer; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; +import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusPropertiesStep extends ResettableContainer { + + private Logger logger = Logger.getLogger(MembershipStatusPropertiesStep.class); + + private AuthoringKitWizard m_parent; + + private ItemSelectionModel m_itemModel; + private BigDecimalParameter m_statusParam = new BigDecimalParameter(("membershipstatus")); + private MembershipStatusSelectionModel m_statusModel = new MembershipStatusSelectionModel(m_statusParam); + + public MembershipStatusPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + logger.debug("Invoking MembershipStatusPropertiesStep(itemModel, parent)..."); + this.m_itemModel = itemModel; + this.m_parent = parent; + setMembershipStatusSelectionModel(); + add(getDisplayComponent()); + + Form form = form = new Form("membershipStatusEditForm"); + form.add(getEditSheet()); + + WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel); + edit.add(form); + add(edit); + logger.debug("finished."); + } + + protected void setMembershipStatusSelectionModel() { + setMembershipStatusSelectionModel(new MembershipStatusSelectionModel(m_statusParam)); + } + + protected void setMembershipStatusSelectionModel(MembershipStatusSelectionModel statusModel) { + this.m_statusModel = statusModel; + } + + protected MembershipStatusSelectionModel getMembershipStatusSelectionModel() { + return this.m_statusModel; + } + + protected BigDecimalParameter getStatusParam() { + return this.m_statusParam; + } + + protected Component getDisplayComponent() { + SimpleContainer container = new SimpleContainer(); + container.add(new MembershipStatusTable(this.m_itemModel, this.m_statusModel)); + return container; + } + + protected FormSection getEditSheet() { + return new MembershipStatusPropertyForm((this.m_itemModel), this.m_statusModel); + } + + @Override + public void register(Page p) { + this.logger.info("registering..."); + super.register(p); + p.addComponentStateParam(this, this.m_statusParam); + this.logger.info("finished..."); + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertyForm.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertyForm.java new file mode 100644 index 000000000..112e5f4d4 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusPropertyForm.java @@ -0,0 +1,181 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.ColumnPanel; +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.bebop.FormSection; +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.FormValidationListener; +import com.arsdigita.bebop.event.PrintEvent; +import com.arsdigita.bebop.event.PrintListener; +import com.arsdigita.bebop.form.Submit; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.MembershipStatus; +import com.arsdigita.util.UncheckedWrapperException; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusPropertyForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { + + private final static Logger logger = Logger.getLogger(MembershipStatusPropertyForm.class); + + public final static String ID = "membershipStatusEditForm_edit"; + private ItemSelectionModel m_itemModel; + private MembershipStatusSelectionModel m_statusModel; + private TextField m_statusName; + private SaveCancelSection m_saveCancelSection; + + public MembershipStatusPropertyForm(ItemSelectionModel itemModel, MembershipStatusSelectionModel statusModel) { + super(new ColumnPanel(2)); + logger.debug("Constructor..."); + this.m_itemModel = itemModel; + this.m_statusModel = statusModel; + + addWidgets(); + addSaveCancelSection(); + + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + addSubmissionListener(this); + logger.debug("Constructor finished..."); + } + + protected void addWidgets() { + logger.debug("Adding widgets..."); + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.membershipstatus.warning_changes_here_significant_for_all"))); + this.m_statusName = new TextField("statusName"); + this.m_statusName.addValidationListener(new NotNullValidationListener()); + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.membershipstatus.statusname"))); + add(this.m_statusName); + logger.debug("widgets added"); + } + + protected void addSaveCancelSection() { + logger.debug("adding savecancelsec..."); + this.m_saveCancelSection = new SaveCancelSection(); + try { + this.m_saveCancelSection.getCancelButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_statusModel.isSelected(e.getPageState())) { + target.setButtonLabel("Cancel"); + } else { + target.setButtonLabel("Reset"); + } + } + }); + + this.m_saveCancelSection.getSaveButton().addPrintListener(new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_statusModel.isSelected(e.getPageState())) { + target.setButtonLabel("Save"); + } else { + target.setButtonLabel("Create"); + } + } + }); + } catch(Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + add(this.m_saveCancelSection, ColumnPanel.FULL_WIDTH); + logger.debug("savecancelsec added."); + } + + public SaveCancelSection getSaveCancelSection() { + return this.m_saveCancelSection; + } + + protected MembershipStatusSelectionModel getMembershipStatusSelectionModel() { + return this.m_statusModel; + } + + protected MembershipStatus createMembershipStatus(PageState state) { + logger.debug("creating new membership status..."); + MembershipStatus status = new MembershipStatus(); + logger.debug("new membership status created."); + return status; + } + + protected void setMembershipStatusProperties(MembershipStatus status, FormSectionEvent e) { + logger.debug("setting properties..."); + PageState state = e.getPageState(); + //FormData data = e.getFormData(); + + status.setStatusName((String) m_statusName.getValue(state)); + + status.save(); + logger.debug("properties set"); + } + + public void init(FormSectionEvent e) throws FormProcessException { + logger.debug("init Listener invoked."); + PageState state = e.getPageState(); + //FormData data = e.getFormData(); + + setVisible(state, true); + + MembershipStatus status; + if (m_statusModel.isSelected(state)) { + status = m_statusModel.getSelectedMembershipStatus(state); + try { + m_statusName.setValue(state, status.getStatusName()); + } catch (IllegalStateException ex) { + throw ex; + } + } else { + m_statusName.setValue(state, null); + } + logger.debug("init Listener finished."); + } + + public void process(FormSectionEvent e) throws FormProcessException { + logger.debug("process Listener invoked."); + PageState state = e.getPageState(); + MembershipStatus status; + + if (this.getSaveCancelSection().getCancelButton().isSelected(state)) { + m_statusModel.clearSelection(state); + } else { + if (m_statusModel.isSelected(state)) { + status = m_statusModel.getSelectedMembershipStatus(state); + } else { + status = createMembershipStatus(state); + } + setMembershipStatusProperties(status, e); + } + + m_statusModel.clearSelection(state); + init(e); + logger.debug("process Listener finished."); + } + + public void validate(FormSectionEvent e) throws FormProcessException { + //Nothing yet + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + logger.debug("submit Listener invoked."); + if (this.m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) { + m_statusModel.clearSelection(e.getPageState()); + init(e); + throw new FormProcessException("cancelled"); + } + logger.debug("submit Listener finished."); + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusSelectionModel.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusSelectionModel.java new file mode 100644 index 000000000..644775c20 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusSelectionModel.java @@ -0,0 +1,25 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.contenttypes.MembershipStatus; +import com.arsdigita.kernel.ui.ACSObjectSelectionModel; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusSelectionModel extends ACSObjectSelectionModel { + + public MembershipStatusSelectionModel(BigDecimalParameter param) { + super(MembershipStatus.class.getName(), MembershipStatus.BASE_DATA_OBJECT_TYPE, param); + } + + public MembershipStatusSelectionModel(String itemClass, String objectType, BigDecimalParameter parameter) { + super(itemClass, objectType, parameter); + } + + public MembershipStatus getSelectedMembershipStatus(PageState state) { + return (MembershipStatus) getSelectedObject(state); + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTable.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTable.java new file mode 100644 index 000000000..45b527ab7 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTable.java @@ -0,0 +1,166 @@ +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.RequestLocal; +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.cms.ContentItem; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.SecurityManager; +import com.arsdigita.cms.contenttypes.MembershipStatus; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; +import com.arsdigita.util.UncheckedWrapperException; +import java.math.BigDecimal; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusTable extends Table { + + private final static Logger logger = Logger.getLogger(MembershipStatusTable.class); + private MembershipStatusSelectionModel m_statusModel; + private ItemSelectionModel m_itemModel; + private TableColumn m_statusNameCol; + private TableColumn m_editCol; + private TableColumn m_delCol; + private RequestLocal m_size; + private RequestLocal m_editor; + protected final static String EDIT_EVENT = "Edit"; + protected final static String DELETE_EVENT = "Delete"; + + public MembershipStatusTable(ItemSelectionModel itemModel, MembershipStatusSelectionModel statusModel) { + super(); + this.m_itemModel = itemModel; + this.m_statusModel = statusModel; + addColumns(); + + m_size = new RequestLocal(); + m_editor = new RequestLocal() { + + @Override + public Object initialValue(PageState state) { + SecurityManager sm = Utilities.getSecurityManager(state); + ContentItem item = m_itemModel.getSelectedItem(state); + Boolean val = new Boolean(sm.canAccess(state.getRequest(), SecurityManager.EDIT_ITEM, item)); + return val; + } + }; + + Label empty = new Label("There are no status."); + setEmptyView(empty); + addTableActionListener(new MembershipStatusTableActionListener()); + setRowSelectionModel(this.m_statusModel); + setDefaultCellRenderer(new MembershipStatusTableRenderer()); + setModelBuilder(new MembershipStatusTableModelBuilder(itemModel)); + } + + protected void addColumns() { + TableColumnModel model = getColumnModel(); + int i = 0; + this.m_statusNameCol = new TableColumn(i, "Status name"); + this.m_editCol = new TableColumn(++i, "Edit"); + this.m_delCol = new TableColumn(++i, "Delete"); + + model.add(this.m_statusNameCol); + model.add(this.m_editCol); + model.add(this.m_delCol); + setColumnModel(model); + } + + private class MembershipStatusTableRenderer implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + + MembershipStatus status = (MembershipStatus) value; + boolean isFirst = (row == 0); + if (m_size.get(state) == null) { + m_size.set(state, new Long(((MembershipStatusTableModelBuilder.MembershipStatusTableModel) table.getTableModel(state)).size())); + } + boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1); + + if (column == m_statusNameCol.getModelIndex()) { + Label statusNameLabel = new Label(status.getStatusName()); + return statusNameLabel; + } else if (column == m_editCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + if (isSelected) { + return new Label(EDIT_EVENT, Label.BOLD); + } else { + return new ControlLink(EDIT_EVENT); + } + } else { + return new Label(EDIT_EVENT); + } + } else if (column == m_delCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + return new ControlLink(DELETE_EVENT); + } else { + return new Label(DELETE_EVENT); + } + } else { + throw new UncheckedWrapperException("column index out of bounds"); + } + } + } + + private class MembershipStatusTableActionListener implements TableActionListener { + + private MembershipStatus getMembershipStatus(TableActionEvent e) { + Object o = e.getRowKey(); + BigDecimal id; + if (o instanceof String) { + id = new BigDecimal((String) o); + } else { + id = (BigDecimal) e.getRowKey(); + } + + Assert.exists(id); + MembershipStatus status; + try { + status = (MembershipStatus) DomainObjectFactory.newInstance(new OID(MembershipStatus.BASE_DATA_OBJECT_TYPE, id)); + } catch (DataObjectNotFoundException ex) { + throw new UncheckedWrapperException(ex); + } + return status; + } + + public void cellSelected(TableActionEvent e) { + int col = e.getColumn().intValue(); + PageState state = e.getPageState(); + MembershipStatus status = getMembershipStatus(e); + Assert.exists(status); + + if (col == m_editCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + m_statusModel.setSelectedObject(state, status); + } + } else if (col == m_delCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + try { + m_statusModel.clearSelection(state); + status.delete(); + } catch (Exception ex) { + throw new UncheckedWrapperException(ex); + } + } + } + } + + public void headSelected(TableActionEvent e) { + //Nothing + } + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTableModelBuilder.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTableModelBuilder.java new file mode 100644 index 000000000..45887219c --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipStatusTableModelBuilder.java @@ -0,0 +1,81 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.MembershipStatus; +import com.arsdigita.cms.contenttypes.MembershipStatusCollection; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.util.Assert; +import com.arsdigita.util.LockableImpl; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipStatusTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private final static Logger logger = Logger.getLogger(MembershipStatusTableModelBuilder.class); + private ItemSelectionModel m_itemModel; + + public MembershipStatusTableModelBuilder(ItemSelectionModel itemModel) { + this.m_itemModel = itemModel; + } + + public TableModel makeModel(Table t, PageState s) { + DataCollection statusValues = getStatus(s); + + if (statusValues.isEmpty()) { + return Table.EMPTY_MODEL; + } else { + return new MembershipStatusTableModel(statusValues); + } + } + + public DataCollection getStatus(PageState state) { + //Assert.isTrue(this.m_itemModel.isSelected(state), "item selected"); + return (DataCollection) MembershipStatusCollection.getMembershipStatusCollection().getDomainObject(); + } + + public static class MembershipStatusTableModel implements TableModel { + + MembershipStatus m_status; + DataCollection m_statusValues; + + public MembershipStatusTableModel(DataCollection statusValues) { + m_statusValues = statusValues; + m_status = null; + } + + public int getColumnCount() { + return (int) m_statusValues.size(); + } + + public boolean nextRow() { + if (m_statusValues.next()) { + DataObject obj = m_statusValues.getDataObject(); + m_status = (MembershipStatus) DomainObjectFactory.newInstance(obj); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + return m_status; + } + + public Object getKeyAt(int columnIndex) { + return m_status.getID(); + } + + public long size() { + return m_statusValues.size(); + } + } +} 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 new file mode 100644 index 000000000..027b60dbf --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTable.java @@ -0,0 +1,160 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.Component; +import com.arsdigita.bebop.ControlLink; +import com.arsdigita.bebop.ExternalLink; +import com.arsdigita.bebop.Label; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; +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.cms.ContentItem; +import com.arsdigita.cms.SecurityManager; +import org.apache.log4j.Logger; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Membership; +import com.arsdigita.cms.contenttypes.MembershipStatus; +import com.arsdigita.cms.contenttypes.Person; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.OID; +import com.arsdigita.util.Assert; +import com.arsdigita.util.UncheckedWrapperException; +import java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipTable extends Table { + + private final static Logger logger = Logger.getLogger(MembershipTable.class); + private MembershipSelectionModel m_membershipModel; + private ItemSelectionModel m_itemModel; + private TableColumn m_personCol; + private TableColumn m_statusCol; + private TableColumn m_editCol; + //private TableColumn m_delCol; + private RequestLocal m_size; + private RequestLocal m_editor; + + protected final static String EDIT_EVENT = "Edit"; + protected final static String DELETE_EVENT = "Delete"; + + public MembershipTable(ItemSelectionModel itemModel, MembershipSelectionModel membershipModel) { + super(); + this.m_itemModel = itemModel; + this.m_membershipModel = membershipModel; + addColumns(); + + m_size = new RequestLocal(); + m_editor = new RequestLocal() { + + @Override + public Object initialValue(PageState state) { + SecurityManager sm = Utilities.getSecurityManager(state); + ContentItem item = m_itemModel.getSelectedItem(state); + Boolean val = new Boolean(sm.canAccess(state.getRequest(), SecurityManager.EDIT_ITEM, item)); + return val; + } + }; + + Label empty = new Label("This organizational unit has no members."); + setEmptyView(empty); + addTableActionListener(new MembershipTableActionListener()); + setRowSelectionModel(m_membershipModel); + setDefaultCellRenderer(new MembershipTableRenderer()); + setModelBuilder(new MembershipTableModelBuilder(itemModel)); + } + + public void addColumns() { + TableColumnModel model = getColumnModel(); + int i = 0; + this.m_personCol = new TableColumn(i, "Person"); + this.m_statusCol = new TableColumn(++i, "Status"); + this.m_editCol = new TableColumn(++i, "Edit"); + + model.add(this.m_personCol); + model.add(this.m_statusCol); + model.add(this.m_editCol); + setColumnModel(model); + } + + private class MembershipTableRenderer implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + Membership membership = (Membership) value; + if (m_size.get(state) == null) { + m_size.set(state, new Long(((MembershipTableModelBuilder.MembershipTableModel) table.getTableModel(state)).size())); + } + + 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()); + ExternalLink extLink = new ExternalLink(fullName, url); + return extLink; + } else if(column == m_statusCol.getModelIndex()) { + MembershipStatus status = membership.getStatus(); + return new Label(status.getStatusName()); + } else if(column == m_editCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + if (isSelected) { + return new Label(EDIT_EVENT, Label.BOLD); + } else { + return new ControlLink(EDIT_EVENT); + } + } else { + return new Label(EDIT_EVENT); + } + } else { + throw new UncheckedWrapperException("column out of bounds"); + } + } + } + + private class MembershipTableActionListener implements TableActionListener { + + private Membership getMembership(TableActionEvent event) { + Object obj = event.getRowKey(); + BigDecimal id; + if (obj instanceof String) { + id = new BigDecimal((String) obj); + } else { + id = (BigDecimal) obj; + } + + Assert.exists(id); + Membership membership; + try { + membership = (Membership) DomainObjectFactory.newInstance(new OID(Membership.BASE_DATA_OBJECT_TYPE, id)); + } catch (DataObjectNotFoundException ex) { + throw new UncheckedWrapperException(ex); + } + return membership; + } + + public void cellSelected(TableActionEvent e) { + int col = e.getColumn().intValue(); + PageState state = e.getPageState(); + Membership membership = getMembership(e); + Assert.exists(membership); + + if (col == m_editCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + m_membershipModel.setSelectedObject(state, membership); + } + } + } + + public void headSelected(TableActionEvent e) { + } + + } + +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTableModelBuilder.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTableModelBuilder.java new file mode 100644 index 000000000..443ccb194 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/MembershipTableModelBuilder.java @@ -0,0 +1,84 @@ +package com.arsdigita.cms.contenttypes.ui.organizationalunit; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.Table; +import com.arsdigita.bebop.table.TableModel; +import com.arsdigita.bebop.table.TableModelBuilder; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Membership; +import com.arsdigita.cms.contenttypes.OrganizationalUnit; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.persistence.DataObject; +import com.arsdigita.util.Assert; +import com.arsdigita.util.LockableImpl; +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class MembershipTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private final static Logger logger = Logger.getLogger(MembershipTableModelBuilder.class); + + private ItemSelectionModel m_itemModel; + + public MembershipTableModelBuilder(ItemSelectionModel itemModel) { + this.m_itemModel = itemModel; + } + + public TableModel makeModel(Table t, PageState s) { + DataCollection members = getMembers(s); + + if(members.isEmpty()) { + return Table.EMPTY_MODEL; + } else { + return new MembershipTableModel(members); + } + } + + public DataCollection getMembers(PageState state) { + Assert.isTrue(this.m_itemModel.isSelected(state), "item selected"); + OrganizationalUnit unit = (OrganizationalUnit) this.m_itemModel.getSelectedItem(state); + return Membership.getMemberships(unit); + } + + public static class MembershipTableModel implements TableModel { + + Membership m_membership; + DataCollection m_memberships; + + public MembershipTableModel(DataCollection memberships) { + m_memberships = memberships; + m_membership = null; + } + + public int getColumnCount() { + return (int) m_memberships.size(); + } + + public boolean nextRow() { + if (m_memberships.next()) { + DataObject obj = m_memberships.getDataObject(); + m_membership = (Membership) DomainObjectFactory.newInstance(obj); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + return m_membership; + } + + public Object getKeyAt(int columnIndex) { + return m_membership.getID(); + } + + public long size() { + return m_memberships.size(); + } + + } +} diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertiesStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertiesStep.java similarity index 95% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertiesStep.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertiesStep.java index da5cae056..556e305fc 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertiesStep.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertiesStep.java @@ -1,5 +1,6 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; +import com.arsdigita.cms.contenttypes.ui.*; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Form; import com.arsdigita.bebop.FormSection; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertyForm.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertyForm.java similarity index 99% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertyForm.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertyForm.java index 2d91d0e73..8686d9dfd 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertyForm.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitPropertyForm.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.ColumnPanel; import com.arsdigita.bebop.FormData; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitSelectionModel.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitSelectionModel.java similarity index 92% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitSelectionModel.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitSelectionModel.java index 79a7f3dfb..566ee0d3d 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitSelectionModel.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitSelectionModel.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.parameters.BigDecimalParameter; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTable.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTable.java similarity index 99% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTable.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTable.java index 4bd669121..51fb2457c 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTable.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTable.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.ControlLink; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTableModelBuilder.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTableModelBuilder.java similarity index 97% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTableModelBuilder.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTableModelBuilder.java index 459f3935c..6c07fa78d 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTableModelBuilder.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrgaUnit2OrgaUnitTableModelBuilder.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.Table; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertiesStep.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertiesStep.java similarity index 97% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertiesStep.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertiesStep.java index 4e56d8208..e1e2decca 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertiesStep.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertiesStep.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.Component; import com.arsdigita.bebop.PageState; diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertyForm.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertyForm.java similarity index 98% rename from ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertyForm.java rename to ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertyForm.java index a8cc5f933..e4760da73 100644 --- a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrganizationalUnitPropertyForm.java +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/organizationalunit/OrganizationalUnitPropertyForm.java @@ -1,4 +1,4 @@ -package com.arsdigita.cms.contenttypes.ui; +package com.arsdigita.cms.contenttypes.ui.organizationalunit; import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormProcessException; diff --git a/ccm-cms/web/packages/content-section/www/admin/item.jsp b/ccm-cms/web/packages/content-section/www/admin/item.jsp index 91f864493..d69e17871 100755 --- a/ccm-cms/web/packages/content-section/www/admin/item.jsp +++ b/ccm-cms/web/packages/content-section/www/admin/item.jsp @@ -41,19 +41,23 @@ // in the section change synchronized(this) { if (Utilities.getLastSectionRefresh(section).after(timestamp)) { - s_log.error("refreshing itemPage"); + s_log.debug("refreshing itemPage"); + s_log.debug("Creating new ContentItemPage instance..."); itemPage = new ContentItemPage(); + s_log.debug("Calling init on new instance..."); itemPage.init(); + s_log.debug("Creating time stamp..."); timestamp = new Date(); } } + s_log.debug("Starting dispatch process..."); RequestContext context = DispatcherHelper.getRequestContext(request); if(itemPage == null) { - s_log.error("WARNING: itemPage is NULL"); + s_log.warn("WARNING: itemPage is NULL"); } else { - s_log.error("ALL OK: itemPage is not null"); + s_log.info("ALL OK: itemPage is not null"); } itemPage.dispatch(request, response, context); s_log.debug("exited item.jsp's service method"); diff --git a/ccm-core/src/com/arsdigita/bebop/Page.java b/ccm-core/src/com/arsdigita/bebop/Page.java index 067202792..adb277322 100755 --- a/ccm-core/src/com/arsdigita/bebop/Page.java +++ b/ccm-core/src/com/arsdigita/bebop/Page.java @@ -81,17 +81,15 @@ import org.apache.log4j.Logger; * @version $Id: Page.java 1270 2006-07-18 13:34:55Z cgyg9330 $ */ public class Page extends BlockStylable implements Container { + public static final String versionId = - "$Id: Page.java 1270 2006-07-18 13:34:55Z cgyg9330 $" + - "by $Author: cgyg9330 $, $DateTime: 2004/08/16 18:10:38 $"; - + "$Id: Page.java 1270 2006-07-18 13:34:55Z cgyg9330 $" + + "by $Author: cgyg9330 $, $DateTime: 2004/08/16 18:10:38 $"; private static final Logger s_log = Logger.getLogger(Page.class); - /** * The delimiter character for components naming */ private static final String DELIMITER = "."; - /** * The prefix that gets prepended to all state variables. Components must * not use variables starting with this prefix. This guarantees that the @@ -99,33 +97,28 @@ public class Page extends BlockStylable implements Container { * interfere with each other. */ private static final String COMPONENT_PREFIX = "bbp" + DELIMITER; - private static final String INTERNAL = COMPONENT_PREFIX; - /** * The name of the special parameter that indicates which component has * been selected. */ static final String SELECTED = INTERNAL + "s"; - static final String CONTROL_EVENT = INTERNAL + "e"; - static final String CONTROL_VALUE = INTERNAL + "v"; - static final Collection CONTROL_EVENT_KEYS; + + static { CONTROL_EVENT_KEYS = new ArrayList(3); CONTROL_EVENT_KEYS.add(SELECTED); CONTROL_EVENT_KEYS.add(CONTROL_EVENT); CONTROL_EVENT_KEYS.add(CONTROL_VALUE); } - /** * The name of the request parameter used for the visibility state of * components stored in m_invisible. */ static final String INVISIBLE = INTERNAL + "i"; - /** * Map of stateful components (id --> Component) * SortedMap used because component based hash for page is based on concatenation of @@ -134,48 +127,36 @@ public class Page extends BlockStylable implements Container { */ private SortedMap m_componentMap; private List m_components; - /** * Map of component -> owned parameter collection */ private Map m_componentParameterMap = new HashMap(); - private FormModel m_stateModel; - /** * Container that renders this Page. */ protected Container m_panel; - private List m_actionListeners; - private List m_requestListeners; - /** * The title of the page to be added in the head of HTML output. The * title is wrapped in a Label to allow developers to add * PrintListeners to dynamically change the value of the title. */ private Label m_title; - /** * Stores the actual title for the current request. The title may be * generated with a PrintListener of the m_title Label. */ private RequestLocal m_currentTitle; - /** * A list of all the client-side stylesheets. The elements of the list * are of type Page.Stylesheet, defined at the end of this file. */ private List m_clientStylesheets; - private StringParameter m_selected; - private StringParameter m_controlEvent; - private StringParameter m_controlValue; - /** * The default (initial) visibility of components. The encoding is * identical to that for PageState.m_invisible. @@ -184,18 +165,15 @@ public class Page extends BlockStylable implements Container { * PageState. */ protected BitSet m_invisible; - /** * The PageErrorDisplay component that will display page state validation * errors on this page */ private Component m_errorDisplay; - /** * Indicates whether finish() has been called on this Page. */ private boolean m_finished = false; - /** * indicates whether pageState.stateAsURL() should export the * entire state for this page, or whether it should only export @@ -273,10 +251,11 @@ public class Page extends BlockStylable implements Container { // Initialize the RequestLocal where the title for the current // request will be kept m_currentTitle = new RequestLocal() { - protected Object initialValue(PageState state) { - return m_title.firePrintEvent(state); - } - }; + + protected Object initialValue(PageState state) { + return m_title.firePrintEvent(state); + } + }; // Initialize the set of state parameters to hold // the ones necessary for keeping track of the selected component and @@ -285,15 +264,15 @@ public class Page extends BlockStylable implements Container { m_controlEvent = new StringParameter(CONTROL_EVENT); m_controlValue = new StringParameter(CONTROL_VALUE); - m_stateModel=new FormModel("stateModel", true); + m_stateModel = new FormModel("stateModel", true); m_stateModel.addFormParam(m_selected); m_stateModel.addFormParam(m_controlEvent); m_stateModel.addFormParam(m_controlValue); // Set up the visibility tracking parameters m_invisible = new BitSet(32); - BitSetParameter p = new BitSetParameter(INVISIBLE, - BitSetParameter.ENCODE_DGAP); + BitSetParameter p = new BitSetParameter(INVISIBLE, + BitSetParameter.ENCODE_DGAP); m_stateModel.addFormParam(p); } @@ -334,7 +313,7 @@ public class Page extends BlockStylable implements Container { */ public void add(Component c) { m_panel.add(c); - + } /** @@ -444,7 +423,7 @@ public class Page extends BlockStylable implements Container { * * @author Matthew Booth (mbooth@redhat.com) */ - public void setPanel( Container c ) { + public void setPanel(Container c) { m_panel = c; } @@ -466,7 +445,7 @@ public class Page extends BlockStylable implements Container { * @return the title of the page for the current request. */ public final Label getTitle(PageState state) { - return (Label)m_currentTitle.get(state); + return (Label) m_currentTitle.get(state); } /** @@ -620,7 +599,7 @@ public class Page extends BlockStylable implements Container { Element title = page.newChildElement("bebop:title", BEBOP_XML_NS); title.setText(getTitle(ps).getLabel(ps)); - for (Iterator i = m_clientStylesheets.iterator(); i.hasNext(); ) { + for (Iterator i = m_clientStylesheets.iterator(); i.hasNext();) { ((Stylesheet) i.next()).generateXML(page); } @@ -655,10 +634,10 @@ public class Page extends BlockStylable implements Container { } if (Kernel.getConfig().isDebugEnabled() && - debugStructure(state.getRequest()) ) { + debugStructure(state.getRequest())) { Element structure = - page.newChildElement("bebop:structure", BEBOP_XML_NS); + page.newChildElement("bebop:structure", BEBOP_XML_NS); showStructure(state, structure); } @@ -689,8 +668,8 @@ public class Page extends BlockStylable implements Container { * @pre response != null */ public PageState process(HttpServletRequest request, - HttpServletResponse response) - throws ServletException { + HttpServletResponse response) + throws ServletException { PageState result = new PageState(this, request, response); try { @@ -744,7 +723,7 @@ public class Page extends BlockStylable implements Container { * #process(HttpServletRequest,HttpServletResponse)} instead. */ protected PageState prepare(HttpServletRequest req, HttpServletResponse res) - throws ServletException { + throws ServletException { Assert.assertLocked(this); PageState state = process(req, res); @@ -763,8 +742,8 @@ public class Page extends BlockStylable implements Container { * @post res.isCommitted() == (return == null) */ public Document buildDocument(HttpServletRequest req, - HttpServletResponse res) - throws ServletException { + HttpServletResponse res) + throws ServletException { try { Document doc = new Document(); PageState state = process(req, res); @@ -801,11 +780,15 @@ public class Page extends BlockStylable implements Container { Assert.assertNotLocked(this); Traversal componentRegistrar = new Traversal() { - protected void act(Component c) { - addComponent(c); - c.register(Page.this); - } - }; + + protected void act(Component c) { + addComponent(c); + c.register(Page.this); + } + }; + if (m_panel == null) { + s_log.warn("m_panel is null"); + } componentRegistrar.preorder(m_panel); if (m_errorDisplay != null) { addComponent(m_errorDisplay); @@ -828,10 +811,11 @@ public class Page extends BlockStylable implements Container { } m_stateModel.lock(); Traversal componentLocker = new Traversal() { - protected void act(Component c) { - c.lock(); - } - }; + + protected void act(Component c) { + c.lock(); + } + }; componentLocker.preorder(m_panel); @@ -896,7 +880,7 @@ public class Page extends BlockStylable implements Container { protected void fireActionEvent(PageState state) { ActionEvent e = null; - for (Iterator i = m_actionListeners.iterator(); i.hasNext(); ) { + for (Iterator i = m_actionListeners.iterator(); i.hasNext();) { if (e == null) { e = new ActionEvent(this, state); } @@ -922,7 +906,7 @@ public class Page extends BlockStylable implements Container { protected void fireRequestEvent(PageState state) { RequestEvent e = null; - for (Iterator i = m_requestListeners.iterator(); i.hasNext(); ) { + for (Iterator i = m_requestListeners.iterator(); i.hasNext();) { if (e == null) { e = new RequestEvent(this, state); } @@ -939,6 +923,7 @@ public class Page extends BlockStylable implements Container { // Client-side stylesheet storage private class Stylesheet { + String m_URI; String m_type; @@ -964,20 +949,19 @@ public class Page extends BlockStylable implements Container { public void addComponent(Component c) { Assert.assertNotLocked(this); - if ( ! stateContains(c) ) { - if(c == null) { + if (!stateContains(c)) { + if (c == null) { s_log.error("c is null"); - } else { - //s_log.error("c: " + c.toString()); - } + } /*else { + s_log.error("c: " + c.toString()); + }*/ String key = c.getKey(); if (key == null) { key = Integer.toString(m_components.size()); } if (m_componentMap.get(key) != null) { - throw new IllegalArgumentException - ("Component key must not be duplicated. The key " + - key + " is shared by more than one component."); + throw new IllegalArgumentException("Component key must not be duplicated. The key " + + key + " is shared by more than one component."); } m_componentMap.put(key, c); m_components.add(c); @@ -1004,15 +988,14 @@ public class Page extends BlockStylable implements Container { public void addComponentStateParam(Component c, ParameterModel p) { Assert.assertNotLocked(this); - if ( ! stateContains(c)) { - throw new IllegalArgumentException - ("Component must be registered in Page"); + if (!stateContains(c)) { + throw new IllegalArgumentException("Component must be registered in Page"); } - if ( ! m_stateModel.containsFormParam(p) ) { + if (!m_stateModel.containsFormParam(p)) { p.setName(parameterName(c, p.getName())); m_stateModel.addFormParam(p); - Collection params = (Collection)m_componentParameterMap.get(c); + Collection params = (Collection) m_componentParameterMap.get(c); if (params == null) { params = new ArrayList(); m_componentParameterMap.put(c, params); @@ -1025,10 +1008,9 @@ public class Page extends BlockStylable implements Container { *

Get the parameters registered for a given component.

*/ public Collection getComponentParameters(Component c) { - return (Collection)m_componentParameterMap.get(c); + return (Collection) m_componentParameterMap.get(c); } - /** * Gets the state index of a component. This is the number assigned * to the component in the register traveral @@ -1113,7 +1095,7 @@ public class Page extends BlockStylable implements Container { public boolean isVisibleDefault(Component c) { Assert.assertTrue(stateContains(c)); - return ! m_invisible.get(stateIndex(c)); + return !m_invisible.get(stateIndex(c)); } /** @@ -1131,12 +1113,12 @@ public class Page extends BlockStylable implements Container { * @see Component#setVisible Component.setVisible * @see Component#register Component.register */ - public void setVisibleDefault(Component c, boolean v) { + public void setVisibleDefault(Component c, boolean v) { Assert.assertNotLocked(this); addComponent(c); int i = stateIndex(c); - if ( v ) { + if (v) { m_invisible.clear(i); } else { m_invisible.set(i); @@ -1148,7 +1130,7 @@ public class Page extends BlockStylable implements Container { * c. */ public String parameterName(Component c, String name) { - if ( c == null || ! stateContains(c) ) { + if (c == null || !stateContains(c)) { return name; } @@ -1164,40 +1146,37 @@ public class Page extends BlockStylable implements Container { void reset(final PageState ps, Component cmpnt) { Traversal resetter = new Traversal() { - protected void act(Component c) { - Collection cp = getComponentParameters(c); - if (cp != null) { - Iterator iter = cp.iterator(); - while ( iter.hasNext() ) { - ParameterModel p = (ParameterModel) iter.next(); - ps.setValue(p, null); - } + + protected void act(Component c) { + Collection cp = getComponentParameters(c); + if (cp != null) { + Iterator iter = cp.iterator(); + while (iter.hasNext()) { + ParameterModel p = (ParameterModel) iter.next(); + ps.setValue(p, null); } - c.setVisible(ps, isVisibleDefault(c)); } - }; + c.setVisible(ps, isVisibleDefault(c)); + } + }; resetter.preorder(cmpnt); } - /** * Return the prefix that is prepended to each component's state * parameters to keep them unique. */ private final String componentPrefix(Component c) { - if ( c==null ) { + if (c == null) { return COMPONENT_PREFIX + "g" + DELIMITER; } else { // WRS: preferentially use key if it exists String key = c.getKey(); if (key == null) { - if ( stateContains(c) ) { + if (stateContains(c)) { key = String.valueOf(stateIndex(c)); } else { - throw new IllegalArgumentException - ("Cannot generate prefix for component: key is null " - + "and component " + c.toString() + "/" + c.getKey() - + " did not register with page."); + throw new IllegalArgumentException("Cannot generate prefix for component: key is null " + "and component " + c.toString() + "/" + c.getKey() + " did not register with page."); } } return COMPONENT_PREFIX + key + DELIMITER; @@ -1211,19 +1190,18 @@ public class Page extends BlockStylable implements Container { * @return the unmangled name. */ private static final String unmangle(String name) { - if ( ! name.startsWith(COMPONENT_PREFIX) ) { + if (!name.startsWith(COMPONENT_PREFIX)) { return name; } // Find the second occurence of delimiter - int prefix = name.indexOf(DELIMITER, name.indexOf(DELIMITER)+1); - if ( prefix >= 0 && prefix < name.length() ) { - return name.substring(prefix+1); + int prefix = name.indexOf(DELIMITER, name.indexOf(DELIMITER) + 1); + if (prefix >= 0 && prefix < name.length()) { + return name.substring(prefix + 1); } return name; } // Procs for debugging output - private static String NAME = "name"; /** @@ -1241,22 +1219,22 @@ public class Page extends BlockStylable implements Container { // Control event Element eventName = - state.newChildElement("bebop:eventName", BEBOP_XML_NS); + state.newChildElement("bebop:eventName", BEBOP_XML_NS); eventName.addAttribute(NAME, m_controlEvent.getName()); eventName.setText(req.getParameter(m_controlEvent.getName())); Element eventValue = - state.newChildElement("bebop:eventValue", BEBOP_XML_NS); + state.newChildElement("bebop:eventValue", BEBOP_XML_NS); eventValue.addAttribute(NAME, m_controlValue.getName()); eventValue.setText(req.getParameter(m_controlValue.getName())); // Global parameters Element globalState = - root.newChildElement("bebop:params", BEBOP_XML_NS); - for (Iterator ii=getStateModel().getParameters(); ii.hasNext(); ) { + root.newChildElement("bebop:params", BEBOP_XML_NS); + for (Iterator ii = getStateModel().getParameters(); ii.hasNext();) { ParameterModel p = (ParameterModel) ii.next(); - if ( !p.getName().startsWith(COMPONENT_PREFIX) ) { + if (!p.getName().startsWith(COMPONENT_PREFIX)) { Element param = - globalState.newChildElement("bebop:param", BEBOP_XML_NS); + globalState.newChildElement("bebop:param", BEBOP_XML_NS); param.addAttribute(NAME, p.getName()); param.setText(String.valueOf(s.getValue(p))); } @@ -1277,32 +1255,36 @@ public class Page extends BlockStylable implements Container { cmp.addAttribute("isVisible", (s.isVisible(c) ? "yes" : "no")); cmp.addAttribute("class", c.getClass().getName()); - if ( c.getKey() != null ) { + if (c.getKey() != null) { String prefix = componentPrefix(c); - for (Iterator i = getStateModel().getParameters(); i.hasNext(); ) { + for (Iterator i = getStateModel().getParameters(); i.hasNext();) { ParameterModel p = (ParameterModel) i.next(); - if ( !p.getName().startsWith(prefix) ) { continue; } + if (!p.getName().startsWith(prefix)) { + continue; + } Element param = - parent.newChildElement("bebop:param", BEBOP_XML_NS); + parent.newChildElement("bebop:param", BEBOP_XML_NS); param.addAttribute(NAME, unmangle(p.getName())); param.addAttribute("defaultValue", - String.valueOf(req.getParameter(p.getName()))); + String.valueOf(req.getParameter(p.getName()))); param.addAttribute("currentValue", String.valueOf(s.getValue(p))); } } - for (Iterator i = c.children(); i.hasNext(); ) { + for (Iterator i = c.children(); i.hasNext();) { showVisibility(s, ((Component) i.next()), cmp); } } private static String getDebugLabel(Component c) { - if ( c.getKey() != null ) { return c.getKey(); } + if (c.getKey() != null) { + return c.getKey(); + } String klass = c.getClass().getName(); - return klass.substring(klass.lastIndexOf(".")+1, klass.length()); + return klass.substring(klass.lastIndexOf(".") + 1, klass.length()); } - + /** * return a string that represents an ordered list of component * ids used on the page. For situations where only the @@ -1310,25 +1292,25 @@ public class Page extends BlockStylable implements Container { * by implementations of hashCode & equals * @return */ - public String getComponentString () { - Iterator it = m_componentMap.keySet().iterator(); - /*int hash = 0; - while (it.hasNext()) { - String componentId = (String)it.next(); - s_log.debug("component id = " + componentId); - hash = hash | componentId.hashCode(); - s_log.debug("hash so far = " + hash); - }*/ - Date start = new Date(); - - StringBuffer hashString = new StringBuffer(); - while (it.hasNext()) { - String componentId = (String)it.next(); - hashString.append(componentId); - } - s_log.debug("Time to create hashCode for page: " + (new Date().getTime() - start.getTime())); - return hashString.toString(); - - + public String getComponentString() { + Iterator it = m_componentMap.keySet().iterator(); + /*int hash = 0; + while (it.hasNext()) { + String componentId = (String)it.next(); + s_log.debug("component id = " + componentId); + hash = hash | componentId.hashCode(); + s_log.debug("hash so far = " + hash); + }*/ + Date start = new Date(); + + StringBuffer hashString = new StringBuffer(); + while (it.hasNext()) { + String componentId = (String) it.next(); + hashString.append(componentId); + } + s_log.debug("Time to create hashCode for page: " + (new Date().getTime() - start.getTime())); + return hashString.toString(); + + } } diff --git a/ccm-core/src/com/arsdigita/bebop/util/Traversal.java b/ccm-core/src/com/arsdigita/bebop/util/Traversal.java index 8822436d7..c2190f919 100755 --- a/ccm-core/src/com/arsdigita/bebop/util/Traversal.java +++ b/ccm-core/src/com/arsdigita/bebop/util/Traversal.java @@ -92,6 +92,8 @@ public abstract class Traversal { ("Component " + c + " is part of a cycle"); } + //s_log.debug("preorder called for component " + c.toString()); + int flag = test(c); if (flag == PERFORM_ACTION) {