diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/Orga2OrgaUnit.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/Orga2OrgaUnit.java index 0ec579408..2be999c1c 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/Orga2OrgaUnit.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/Orga2OrgaUnit.java @@ -20,6 +20,8 @@ import java.math.BigDecimal; import org.apache.log4j.Logger; /** + * This class represents all relationship between an organization and an + * organizational unit. * * @author Jens Pelzetter */ @@ -27,34 +29,72 @@ public class Orga2OrgaUnit extends ACSObject { private final static Logger logger = Logger.getLogger(Orga2OrgaUnit.class); + /** + * Id for the targetItem property. + */ public final static String TARGETITEM = "targetItem"; + /** + * Id for the unitOwner property. + */ public final static String UNITOWNER = "unitOwner"; + /** + * Id for the unitOrder property. + */ public final static String UNITORDER = "unitOrder"; + /** + * Object type + */ public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.Orga2OrgaUnit"; + /** + * Constrcutor without parameters for creating an new Orga2OrgaUnit relation. + */ public Orga2OrgaUnit() { super(BASE_DATA_OBJECT_TYPE); } + /** + * Tries to find the Orga2OrgaUnit relation with the given {@code id} in the database. + * + * @param id Of an existing organization to organizational unit relation. + */ public Orga2OrgaUnit(BigDecimal id) { this(new OID(BASE_DATA_OBJECT_TYPE, id)); } + /** + * Tries to find the Orga2OrgaUnit relation with the {@code id} in the database. + * + * @param id OID Of an existing organization to organizational unit relation. + */ public Orga2OrgaUnit(OID id) { super(id); } + /** + * Creates an new instance of this class from {@code obj} + * + * @param obj + */ public Orga2OrgaUnit(DataObject obj) { super(obj); } + /** + * + * @param type Type of the object to create. + */ public Orga2OrgaUnit(String type) { super(type); } + /** + * + * @return The GenericOrganization which is part of the relation. + */ public GenericOrganization getUnitOwner() { DataObject obj = (DataObject) get(UNITOWNER); if (obj == null) { @@ -64,30 +104,58 @@ public class Orga2OrgaUnit extends ACSObject { } } + /** + * Sets the owing organization. + * + * @param orga The owning organization. + */ public void setUnitOwner(GenericOrganization orga) { Assert.exists(orga, GenericOrganization.class); logger.debug(String.format("Setting unit owner to %s", orga.getOrganizationName())); setAssociation(UNITOWNER, orga); } + /** + * + * @return The OrganizationalUnit which is part of the relation. + */ public OrganizationalUnit getTargetItem() { DataObject object = (DataObject) get(TARGETITEM); return (OrganizationalUnit) DomainObjectFactory.newInstance(object); } + /** + * Sets the OrganizationalUnit + * + * @param unit + */ public void setTargetItem(OrganizationalUnit unit) { setAssociation(TARGETITEM, unit); } + /** + * + * @return The order of the the relations. + */ public Integer getOrder() { return (Integer) get(UNITORDER); } + /** + * Sets the order. + * + * @param order + */ public void setOrder(Integer order) { Assert.exists(order); set(UNITORDER, order); } + /** + * + * @param s Current PageState. + * @return The URI of the targetItem. + */ public String getURI(PageState s) { OrganizationalUnit unit = getTargetItem(); @@ -103,6 +171,11 @@ public class Orga2OrgaUnit extends ACSObject { return URL.there(s.getRequest(), url).toString(); } + /** + * + * @param unit + * @return All Orga2OrgaUnit relations for a specific OrganizationalUnit + */ public static DataCollection getReferingUnits(OrganizationalUnit unit) { Session session = SessionManager.getSession(); DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); @@ -112,6 +185,11 @@ public class Orga2OrgaUnit extends ACSObject { return units; } + /** + * + * @param orga + * @return All units associated with an GenericOrganization. + */ public static DataCollection getUnits(GenericOrganization orga) { Session session = SessionManager.getSession(); DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); @@ -120,34 +198,69 @@ public class Orga2OrgaUnit extends ACSObject { return units; } + /** + * Swaps an Orga2OrgaUnit relation with the next one in the list. + */ public void swapWithNext() { swapWithNext("com.arsdigita.cms.contenttypes.allUnitsOrderForOrganization", "com.arsdigita.cms.contenttypes.swapOrga2OrgaUnitWithNextInGroup"); } - public void swapWithPrevious() { + /** + * Swaps an Orga2OrgaUnit relation with the previous one in the list. + */ + public void swapWithPrevious() { swapWithPrevious("com.arsdigita.cms.contenttypes.allUnitsOrderForOrganization", "com.arsdigita.cms.contenttypes.swapOrga2OrgaUnitWithNextInGroup"); } + /** + * Swaps an Orga2OrgaUnit relation with the next one in the list. + * + * @param queryName Query to use. + * @param operationName Operation to use. + */ public void swapWithNext(String queryName, String operationName) { swapKeys(true, queryName, operationName); } + /** + * Swaps an Orga2OrgaUnit relation with the previous one in the list. + * + * @param queryName Query to use. + * @param operationName Operation to use. + */ public void swapWithPrevious(String queryName, String operationName) { swapKeys(false, queryName, operationName); } + /** + * + * @param queryName Name of the SwapQuery. + * @return The query named with @queryName + */ protected DataQuery getSwapQuery(String queryName) { DataQuery query = SessionManager.getSession().retrieveQuery(queryName); query.setParameter("ownerID", getUnitOwner().getID()); return query; } + /** + * + * @param operationName Name of the operation. + * @return Returns the DataOperation for swapping. + */ protected DataOperation getSwapOperation(String operationName) { DataOperation operation = SessionManager.getSession().retrieveDataOperation(operationName); operation.setParameter("ownerID", getUnitOwner().getID()); return operation; } + /** + * The method which does the real swapping. + * + * @param swapNext If true, swap with next, if false, swap with previous + * @param queryName Name of the DataQuery to use. + * @param operationName Name of the DataOperation to use. + */ protected void swapKeys(boolean swapNext, String queryName, String operationName) { String methodName = null; @@ -196,6 +309,9 @@ public class Orga2OrgaUnit extends ACSObject { operation.execute(); } + /** + * Don't kwow what this is for, but it is needed for the swapping + */ protected void alphabetize() { Session session = SessionManager.getSession(); DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); @@ -209,6 +325,10 @@ public class Orga2OrgaUnit extends ACSObject { } } + /** + * + * @return Maximum order index. + */ public int maxOrder() { GenericOrganization unitOwner = getUnitOwner(); if (unitOwner == null) { @@ -230,6 +350,9 @@ public class Orga2OrgaUnit extends ACSObject { return returnOrder; } + /** + * Invoked before saving to the database. + */ @Override public void beforeSave() { super.beforeSave(); diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertiesStep.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertiesStep.java index a2259223d..70fca8ace 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertiesStep.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertiesStep.java @@ -9,9 +9,9 @@ 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 java.math.BigDecimal; /** + * PropertiesStep for adding organizational units to an organization. * * @author Jens Pelzetter */ @@ -22,6 +22,12 @@ public class Orga2OrgaUnitPropertiesStep extends ResettableContainer { private BigDecimalParameter m_o2ouParam = new BigDecimalParameter(("orga2orgaunit")); private Orga2OrgaUnitSelectionModel m_o2ouModel = new Orga2OrgaUnitSelectionModel(m_o2ouParam); + /** + * Creates a new instance of the PropertiesStep. + * + * @param itemModel ItemSelectionModel to use + * @param parent Parent component. + */ public Orga2OrgaUnitPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { this.m_itemModel = itemModel; this.m_parent = parent; @@ -36,28 +42,54 @@ public class Orga2OrgaUnitPropertiesStep extends ResettableContainer { add(edit); } + /** + * Sets the custom SelectionModel to use. + */ protected void setOrga2OrgaUnitSelectionModel() { setOrga2OrgaUnitSelectionModel(new Orga2OrgaUnitSelectionModel(m_o2ouParam)); } + /** + * Sets the custom SelectionModel to use. + * + * @param model The {@see Orga2OrgaUnitSelectionModel} instance to use. + */ protected void setOrga2OrgaUnitSelectionModel(Orga2OrgaUnitSelectionModel model) { this.m_o2ouModel = model; } + /** + * Gets the {@see Orga2OrgaUnitSelectionModel} used. + * @return The Orga2OrgaUnitSelectionModel used. + */ protected Orga2OrgaUnitSelectionModel getOrga2OrgaUnitSelectionModel() { return this.m_o2ouModel; } + /** + * + * @return + */ protected BigDecimalParameter getO2OUParam() { return this.m_o2ouParam; } + /** + * Returns the displaying component. + * + * @return The displying Component. + */ public Component getDisplayComponent() { SimpleContainer container = new SimpleContainer(); container.add(new Orga2OrgaUnitTable(m_itemModel, m_o2ouModel)); return container; } + /** + * Returns the edit sheet used. + * + * @return The edit sheet used. + */ public FormSection getEditSheet() { return new Orga2OrgaUnitPropertyForm(this.m_itemModel, this.m_o2ouModel); } diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertyForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertyForm.java index 42a87631d..e8f09d36b 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertyForm.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitPropertyForm.java @@ -26,12 +26,17 @@ import com.arsdigita.util.UncheckedWrapperException; import org.apache.log4j.Logger; /** + * The form for adding, editing and removing associations between an organization + * and an organizational unit. * * @author Jens Pelzetter */ public class Orga2OrgaUnitPropertyForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { private final static Logger logger = Logger.getLogger(Orga2OrgaUnitPropertyForm.class); + /** + * ID String. + */ public final static String ID = "orga2orgaunit_edit"; private ItemSelectionModel m_itemModel; private Orga2OrgaUnitSelectionModel m_o2ouModel; @@ -39,6 +44,12 @@ public class Orga2OrgaUnitPropertyForm extends FormSection implements FormInitLi private SaveCancelSection m_saveCancelSection; private final String ITEM_SEARCH = "orga2OrgaUnit"; + /** + * Creates the new form using the ItemSelectionModel and Orga2OrgaUnitSelectionModel proviveded. + * + * @param itemModel + * @param o2ouModel + */ public Orga2OrgaUnitPropertyForm(ItemSelectionModel itemModel, Orga2OrgaUnitSelectionModel o2ouModel) { super(new ColumnPanel(2)); this.m_itemModel = itemModel; @@ -53,12 +64,18 @@ public class Orga2OrgaUnitPropertyForm extends FormSection implements FormInitLi addSubmissionListener(this); } - protected void addWidgets() { + /** + * Creates the widgets for the form. + */ + protected void addWidgets() { add(new Label("OrganizationalUnit")); this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.OrganizationalUnit")); add(this.m_itemSearch); } + /** + * Creates the section with the save and the cancel button. + */ public void addSaveCancelSection() { this.m_saveCancelSection = new SaveCancelSection(); try { @@ -91,18 +108,40 @@ public class Orga2OrgaUnitPropertyForm extends FormSection implements FormInitLi add(m_saveCancelSection, ColumnPanel.FULL_WIDTH); } + /** + * Returns the SavaCancelSection of the form. + * + * @return The SavaCancelSection of the form. + */ public SaveCancelSection getSaveCancelSection() { return this.m_saveCancelSection; } + /** + * Returns the Orga2OrgaUnitSelectionModel used. + * + * @return The Orga2OrgaUnitSelectionModel used. + */ protected Orga2OrgaUnitSelectionModel getO2OUSelectionModel() { return this.m_o2ouModel; } + /** + * Returns the Organization of the assocication displayed by the form. + * + * @param s + * @return The Organization of the assocication displayed by the form. + */ protected GenericOrganization getOrganization(PageState s) { return (GenericOrganization) m_itemModel.getSelectedItem(s); } + /** + * Creates a new Orga2OrgaUnit assoication form the values of the form. + * + * @param s + * @return + */ protected Orga2OrgaUnit createOrga2OrgaUnit(PageState s) { GenericOrganization orga = this.getOrganization(s); Assert.exists(orga); @@ -111,6 +150,12 @@ public class Orga2OrgaUnitPropertyForm extends FormSection implements FormInitLi return o2ou; } + /** + * Sets the properties of an Orga2OrgaUnit instance. + * + * @param o2ou + * @param e + */ protected void setOrga2OrgaUnitProperties(Orga2OrgaUnit o2ou, FormSectionEvent e) { PageState state = e.getPageState(); FormData data = e.getFormData(); diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitSelectionModel.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitSelectionModel.java index ddab79e21..459a1b793 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitSelectionModel.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitSelectionModel.java @@ -6,19 +6,37 @@ import com.arsdigita.cms.contenttypes.Orga2OrgaUnit; import com.arsdigita.kernel.ui.ACSObjectSelectionModel; /** + * The custom SelectionModel used by the {@see Orga2OrgaUnitPropertiesStep} and + * {@see Orga2OrgaUnitPropertyForm}. * * @author Jens Pelzetter */ public class Orga2OrgaUnitSelectionModel extends ACSObjectSelectionModel { + /** + * Creates an new instance. + * + * @param param The parameter to use. + */ public Orga2OrgaUnitSelectionModel(BigDecimalParameter param) { super(Orga2OrgaUnit.class.getName(), Orga2OrgaUnit.BASE_DATA_OBJECT_TYPE, param); } + /** + * + * @param itemClass + * @param objectType + * @param param + */ public Orga2OrgaUnitSelectionModel(String itemClass, String objectType, BigDecimalParameter param) { super(itemClass, objectType, param); } + /** + * + * @param s + * @return + */ public Orga2OrgaUnit getSelectedO2OU(PageState s) { return (Orga2OrgaUnit) getSelectedObject(s); } diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTable.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTable.java index 4dcb5fc58..3c1df89de 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTable.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTable.java @@ -26,6 +26,8 @@ import java.math.BigDecimal; import org.apache.log4j.Logger; /** + * The table used by {@see Orga2OrgaUnitPropertyForm} for displying the existing + * associations between an organization and an organizational unit. * * @author Jens Pelzetter */ @@ -41,11 +43,29 @@ public class Orga2OrgaUnitTable extends Table { private TableColumn m_delCol; private RequestLocal m_size; private RequestLocal m_editor; + /** + * ID String for the "edit" event. + */ protected final static String EDIT_EVENT = "Edit"; + /** + * ID for the "delete" event. + */ protected final static String DELETE_EVENT = "Delete"; + /** + * ID fpr the "up" event. + */ protected final static String UP_EVENT = "up"; + /** + * ID for the "down" event. + */ protected final static String DOWN_EVENT = "down"; + /** + * Creates an new table. + * + * @param itemModel + * @param o2ouModel + */ public Orga2OrgaUnitTable(ItemSelectionModel itemModel, Orga2OrgaUnitSelectionModel o2ouModel) { super(); this.m_itemModel = itemModel; @@ -72,6 +92,9 @@ public class Orga2OrgaUnitTable extends Table { setModelBuilder(new Orga2OrgaUnitTableModelBuilder(itemModel)); } + /** + * Adds the columns of the table. + */ public void addColumns() { TableColumnModel model = getColumnModel(); int i = 0; diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTableModelBuilder.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTableModelBuilder.java index 0fa8598ff..c241aee4b 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTableModelBuilder.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/Orga2OrgaUnitTableModelBuilder.java @@ -15,6 +15,7 @@ import com.arsdigita.util.LockableImpl; import org.apache.log4j.Logger; /** + * ModelBuilder for the TableModel of the {@see Orga2OrgaUnitTable}. * * @author Jens Pelzetter */ @@ -23,6 +24,11 @@ public class Orga2OrgaUnitTableModelBuilder extends LockableImpl implements Tabl private final static Logger logger = Logger.getLogger(Orga2OrgaUnitTableModelBuilder.class); private ItemSelectionModel m_itemModel; + /** + * Creates an new TableModelBuilder. + * + * @param itemModel + */ public Orga2OrgaUnitTableModelBuilder(ItemSelectionModel itemModel) { this.m_itemModel = itemModel; } @@ -37,17 +43,31 @@ public class Orga2OrgaUnitTableModelBuilder extends LockableImpl implements Tabl } } + /** + * Gets all organizational units associated with the selected organization. + * + * @param s + * @return All organizational units associated with the selected organization. + */ public DataCollection getUnits(PageState s) { Assert.isTrue(this.m_itemModel.isSelected(s), "item selected"); GenericOrganization orga = (GenericOrganization) this.m_itemModel.getSelectedItem(s); return Orga2OrgaUnit.getUnits(orga); } + /** + * The table model for the the {@see Orga2OrgaUnitTable}. + */ public static class Orga2OrgaUnitTableModel implements TableModel { Orga2OrgaUnit m_o2ou; DataCollection m_units; + /** + * Creates a new TableModel + * + * @param units The associations between an organization and some organizational units to display. + */ public Orga2OrgaUnitTableModel(DataCollection units) { m_units = units; m_o2ou = null; @@ -75,6 +95,11 @@ public class Orga2OrgaUnitTableModelBuilder extends LockableImpl implements Tabl return m_o2ou.getID(); } + /** + * Returns the number of associations displayed. + * + * @return The number of associations displayed. + */ public long size() { return m_units.size(); } diff --git a/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrgaUnit2OrgaUnit.pdl b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrgaUnit2OrgaUnit.pdl new file mode 100644 index 000000000..f3363751e --- /dev/null +++ b/ccm-cms-types-organizationalunit/pdl/com/arsdigita/content-types/OrgaUnit2OrgaUnit.pdl @@ -0,0 +1,69 @@ +// +// Copyright (C) 2009 Center of Socialpolitics, 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 OrgaUnit2OrgaUnit extends ACSObject { + OrganizationalUnit[0..1] targetItem = join ct_orgaunit2orgaunits.target_item_id to ct_organizationalunits.organizationalunit_id; + + Integer[0..1] unitOrder = ct_orgaunit2orgaunits.unit_order INTEGER; + + reference key(ct_orgaunit2orgaunits.orgaunit2orgaunit_id); + aggressive load (unitOwner.id); +} + +association { + composite OrganizationalUnit[0..1] unitOwner = join ct_orgaunit2orgaunits.owner_id to ct_organizationalunits.organizationalunit_id; + composite OrgaUnit2OrgaUnit[0..n] units = join ct_organizationalunits.organizationalunit_id to ct_orgaunit2orgaunits.owner_id; +} + +query getReferingOrgaUnits { + BigDecimal id; + + do { + select u.organizationalunit_id from orgaunit2orgaunits u where u.target_item_id = :itemID + } map { + id = u.orgaunit2orgaunit_id; + } +} + +data operation swapOrgaUnit2OrgaUnitWithNextInGroup { + do { + update ct_orgaunit2orgaunits + set unit_order = CASE WHEN (unit_order = :unitOrder) THEN + (:nextUnitOrder) + ELSE + (:unitOrder) + END + where (unit_order = :unitOrder or unit_order = :nextUnitOrder) + and owner_id = :ownerID + } +} + +query allUnitsOrderForUnit { + Integer unitOrder; + + do { + select u.unit_order from ct_orgaunit2orgaunits u where u.owner_id = :ownerID + } + map { + unitOrder = u.unitOrder; + } +} \ No newline at end of file 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 5696a7181..18662056b 100644 --- a/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load +++ b/ccm-cms-types-organizationalunit/src/ccm-cms-types-organizationalunit.load @@ -8,6 +8,7 @@ +
diff --git a/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrgaUnit2OrgaUnit.java b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrgaUnit2OrgaUnit.java new file mode 100644 index 000000000..53d3db79a --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/OrgaUnit2OrgaUnit.java @@ -0,0 +1,233 @@ +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.DataOperation; +import com.arsdigita.persistence.DataQuery; +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 org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class OrgaUnit2OrgaUnit extends ACSObject { + + private final static Logger logger = Logger.getLogger(OrgaUnit2OrgaUnit.class); + public final static String TARGETITEM = "targetItem"; + public final static String UNITOWNER = "unitOwner"; + public final static String UNITORDER = "unitOrder"; + public final static String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrgaUnit2OrgaUnit"; + + public OrgaUnit2OrgaUnit() { + super(BASE_DATA_OBJECT_TYPE); + } + + public OrgaUnit2OrgaUnit(DataObject obj) { + super(obj); + } + + public OrgaUnit2OrgaUnit(BigDecimal id) { + this(new OID(BASE_DATA_OBJECT_TYPE, id)); + } + + public OrgaUnit2OrgaUnit(OID id) { + super(id); + } + + public OrgaUnit2OrgaUnit(String type) { + super(type); + } + + public OrganizationalUnit getUnitOwner() { + DataObject obj = (DataObject) get(UNITOWNER); + if (obj == null) { + return null; + } else { + return (OrganizationalUnit) DomainObjectFactory.newInstance(obj); + } + } + + public void setUnitOwner(OrganizationalUnit ou) { + Assert.exists(ou, OrganizationalUnit.class); + setAssociation(UNITOWNER, ou); + } + + public OrganizationalUnit getTargetItem() { + DataObject obj = (DataObject) get(TARGETITEM); + return (OrganizationalUnit) DomainObjectFactory.newInstance(obj); + } + + public void setTargetItem(OrganizationalUnit ou) { + setAssociation(TARGETITEM, ou); + } + + public Integer getOrder() { + return (Integer) get(UNITORDER); + } + + public void setOrder(Integer order) { + Assert.exists(order); + set(UNITORDER, order); + } + + public String getURI(PageState state) { + OrganizationalUnit ou = this.getTargetItem(); + + if (ou == null) { + logger.error(getOID() + " is a link between two organizational units, but the associated organizational unit is null"); + return ""; + } + + ContentSection section = ou.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + String url = resolver.generateItemURL(state, ou, section, ou.getVersion()); + + return URL.there(state.getRequest(), url).toString(); + } + + public static DataCollection getReferingUnits(OrganizationalUnit unit) { + Session session = SessionManager.getSession(); + DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); + Filter filter = units.addInSubqueryFilter("id", "com.arsdigita.cms.contenttypes.getReferingOrgaUnits"); + filter.set("itemID", unit.getID()); + + return units; + } + + public static DataCollection getUnits(OrganizationalUnit ou) { + Session session = SessionManager.getSession(); + DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); + units.addEqualsFilter(UNITOWNER + ".id", ou.getID()); + units.addOrder(UNITORDER); + return units; + } + + public void swapWithNext() { + swapWithNext("com.arsdigita.cms.cotenttypes.addUnitsOrderForUnit", "com.arsdigita.cms.contenttypes.swapOrgaUnit2OrgaUnitWithNextInGroup"); + } + + public void swapWithPrevious() { + swapWithPrevious("com.arsdigita.cms.cotenttypes.addUnitsOrderForUnit", "com.arsdigita.cms.contenttypes.swapOrgaUnit2OrgaUnitWithNextInGroup"); + } + + public void swapWithNext(String queryName, String operationName) { + swapKeys(true, queryName, operationName); + } + + public void swapWithPrevious(String queryName, String operationName) { + swapKeys(false, queryName, operationName); + } + + protected DataQuery getSwapQuery(String queryName) { + DataQuery query = SessionManager.getSession().retrieveQuery(queryName); + query.setParameter("ownerID", getUnitOwner().getID()); + return query; + } + + protected DataOperation getSwapOperation(String operationName) { + DataOperation operation = SessionManager.getSession().retrieveDataOperation(operationName); + operation.setParameter("ownerID", getUnitOwner().getID()); + return operation; + } + + protected void swapKeys(boolean swapNext, String queryName, String operationName) { + String methodName = null; + if (swapNext) { + methodName = "swapWithNext"; + } else { + methodName = "swapWithPrevious"; + } + + Assert.isTrue(!isNew(), methodName + " cannot be called on an object that is new"); + + Integer currentKey = (Integer) get(UNITORDER); + + if (currentKey == null) { + alphabetize(); + return; + } + + Assert.isTrue(currentKey != null, methodName + " cannot be " + + "called on an object that is not currently in the " + + "list"); + + int key = currentKey.intValue(); + + DataQuery query = getSwapQuery(queryName); + + int otherKey; + if (swapNext) { + otherKey = key + 1; + query.addOrder("unitOrder ASC"); + query.addFilter(query.getFilterFactory().greaterThan("unitOrder", currentKey, true)); + } else { + otherKey = key - 1; + query.addOrder("unitOrder DESC"); + query.addFilter(query.getFilterFactory().lessThan("unitOrder", currentKey, true)); + } + + if (query.next()) { + otherKey = ((Integer) query.get("unitOrder")).intValue(); + query.close(); + } + + DataOperation operation = getSwapOperation(operationName); + operation.setParameter("unitOrder", new Integer(key)); + operation.setParameter("nextUnitOrder", new Integer(otherKey)); + operation.execute(); + } + + protected void alphabetize() { + Session session = SessionManager.getSession(); + DataCollection units = session.retrieve(BASE_DATA_OBJECT_TYPE); + units.addEqualsFilter(UNITOWNER + ".id", getUnitOwner().getID()); + int sortkey = 0; + while (units.next()) { + sortkey++; + OrgaUnit2OrgaUnit ou2ou = new OrgaUnit2OrgaUnit(units.getDataObject()); + ou2ou.setOrder(sortkey); + ou2ou.save(); + } + } + + public int maxOrder() { + OrganizationalUnit unitOwner = getUnitOwner(); + if (unitOwner == null) { + return 0; + } + + int returnOrder = 0; + DataQuery query = SessionManager.getSession().retrieveQuery("com.arsdigita.cms.contenttypes.allUnitsOrderForUnit"); + query.setParameter("ownerID", getUnitOwner().getID()); + query.addOrder("unitOrder DESC"); + if (query.next()) { + Integer unitOrder = ((Integer) query.get("unitOrder")); + query.close(); + if (unitOrder != null) { + returnOrder = unitOrder.intValue(); + } + } + + return returnOrder; + } + + @Override + public void beforeSave() { + super.beforeSave(); + if (getOrder() == null) { + setOrder(maxOrder() + 1); + } + } +} \ No newline at end of file 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/OrgaUnit2OrgaUnitPropertiesStep.java new file mode 100644 index 000000000..da5cae056 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertiesStep.java @@ -0,0 +1,70 @@ +package 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 java.math.BigDecimal; + +/** + * + * @author Jens Pelzetter + */ +public class OrgaUnit2OrgaUnitPropertiesStep extends ResettableContainer { + + private AuthoringKitWizard m_parent; + private ItemSelectionModel m_itemModel; + private BigDecimalParameter m_ou2ouParam = new BigDecimalParameter("orgaunit2orgaunit"); + private OrgaUnit2OrgaUnitSelectionModel m_ou2ouModel = new OrgaUnit2OrgaUnitSelectionModel(m_ou2ouParam); + + public OrgaUnit2OrgaUnitPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + this.m_itemModel = itemModel; + this.m_parent = parent; + setOrgaUnit2OrgaUnitSelectionModel(); + add(getDisplayComponent()); + + Form form = new Form("orgaUnit2OrgaUnitEditForm"); + form.add(getEditSheet()); + + WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel); + edit.add(form); + add(edit); + } + + protected void setOrgaUnit2OrgaUnitSelectionModel() { + setOrgaUnit2OrgaUnitSelectionModel(new OrgaUnit2OrgaUnitSelectionModel(this.m_ou2ouParam)); + } + + protected void setOrgaUnit2OrgaUnitSelectionModel(OrgaUnit2OrgaUnitSelectionModel model) { + this.m_ou2ouModel = model; + } + + protected OrgaUnit2OrgaUnitSelectionModel getOrgaUnit2OrgaUnitSelectionModel() { + return this.m_ou2ouModel; + } + + protected BigDecimalParameter getOU2OUParam() { + return this.m_ou2ouParam; + } + + public Component getDisplayComponent() { + SimpleContainer container = new SimpleContainer(); + container.add(new OrgaUnit2OrgaUnitTable(this.m_itemModel, this.m_ou2ouModel)); + return container; + } + + public FormSection getEditSheet() { + return new OrgaUnit2OrgaUnitPropertyForm(this.m_itemModel, this.m_ou2ouModel); + } + + @Override + public void register(Page page) { + super.register(page); + page.addComponentStateParam(this, m_ou2ouParam); + } +} 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/OrgaUnit2OrgaUnitPropertyForm.java new file mode 100644 index 000000000..2d91d0e73 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitPropertyForm.java @@ -0,0 +1,178 @@ +package com.arsdigita.cms.contenttypes.ui; + +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.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.OrgaUnit2OrgaUnit; +import com.arsdigita.cms.contenttypes.OrganizationalUnit; +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 OrgaUnit2OrgaUnitPropertyForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { + + private final static Logger logger = Logger.getLogger(OrgaUnit2OrgaUnitPropertyForm.class); + public final static String ID = "orgaUnit2OrgaUnit_edit"; + private ItemSelectionModel m_itemModel; + private OrgaUnit2OrgaUnitSelectionModel m_ou2ouModel; + private ItemSearchWidget m_itemSearch; + private SaveCancelSection m_saveCancelSection; + private final String ITEM_SEARCH = "orgaUnit2OrgaUnit"; + + public OrgaUnit2OrgaUnitPropertyForm(ItemSelectionModel itemModel, OrgaUnit2OrgaUnitSelectionModel ou2ouModel) { + super(new ColumnPanel(2)); + this.m_itemModel = itemModel; + this.m_ou2ouModel = ou2ouModel; + + + addWidgets(); + addSaveCancelSection(); + + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + addSubmissionListener(this); + } + + protected void addWidgets() { + add(new Label("OrganizationalUnit")); + this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.OrganizationalUnit")); + add(this.m_itemSearch); + } + + 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_ou2ouModel.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_ou2ouModel.isSelected(e.getPageState())) { + target.setButtonLabel("Save"); + } else { + target.setButtonLabel("Create"); + } + } + }); + } catch (Exception ex) { + throw new UncheckedWrapperException("this cannot happen", ex); + } + add(m_saveCancelSection, ColumnPanel.FULL_WIDTH); + } + + /** + * Returns the SavaCancelSection of the form. + * + * @return The SavaCancelSection of the form. + */ + public SaveCancelSection getSaveCancelSection() { + return this.m_saveCancelSection; + } + + protected OrgaUnit2OrgaUnitSelectionModel getOU2OUSelectionModel() { + return this.m_ou2ouModel; + } + + protected OrganizationalUnit getOrganizationalUnit(PageState state) { + return (OrganizationalUnit) this.m_itemModel.getSelectedItem(state); + } + + protected OrgaUnit2OrgaUnit createOrgaUnit2OrgaUnit(PageState state) { + OrganizationalUnit ou = this.getOrganizationalUnit(state); + Assert.exists(ou); + OrgaUnit2OrgaUnit ou2ou = new OrgaUnit2OrgaUnit(); + ou2ou.setUnitOwner(ou); + return ou2ou; + } + + protected void setOrgaUnit2OrgaUnitProperties(OrgaUnit2OrgaUnit ou2ou, FormSectionEvent event) { + FormData data = event.getFormData(); + + ou2ou.setTargetItem((OrganizationalUnit) data.get(ITEM_SEARCH)); + + ou2ou.save(); + } + + public void init(FormSectionEvent e) throws FormProcessException { + FormData data = e.getFormData(); + PageState state = e.getPageState(); + + setVisible(state, true); + + OrgaUnit2OrgaUnit ou2ou; + if (this.m_ou2ouModel.isSelected(state)) { + ou2ou = this.m_ou2ouModel.getSelectedOU2OU(state); + try { + data.put(ITEM_SEARCH, ou2ou.getTargetItem()); + } catch(IllegalStateException ex) { + throw ex; + } + } else { + data.put(ITEM_SEARCH, null); + } + } + + public void process(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + OrgaUnit2OrgaUnit ou2ou; + + if (this.m_saveCancelSection.getCancelButton().isSelected(state)) { + this.m_ou2ouModel.clearSelection(state); + } else { + if (this.m_ou2ouModel.isSelected(state)) { + ou2ou = m_ou2ouModel.getSelectedOU2OU(state); + } else { + ou2ou = createOrgaUnit2OrgaUnit(state); + } + setOrgaUnit2OrgaUnitProperties(ou2ou, e); + } + + this.m_ou2ouModel.clearSelection(state); + this.init(e); + } + + public void validate(FormSectionEvent e) throws FormProcessException { + if (e.getFormData().get(ITEM_SEARCH) == null) { + throw new FormProcessException("OrganizationalUnit selection is requiered"); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + if (this.m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) { + this.m_ou2ouModel.clearSelection(e.getPageState()); + this.init(e); + throw new FormProcessException("cancelled"); + } + } +} 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/OrgaUnit2OrgaUnitSelectionModel.java new file mode 100644 index 000000000..79a7f3dfb --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitSelectionModel.java @@ -0,0 +1,25 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.cms.contenttypes.OrgaUnit2OrgaUnit; +import com.arsdigita.kernel.ui.ACSObjectSelectionModel; + +/** + * + * @author Jens Pelzetter + */ +public class OrgaUnit2OrgaUnitSelectionModel extends ACSObjectSelectionModel { + + public OrgaUnit2OrgaUnitSelectionModel(BigDecimalParameter param) { + super(OrgaUnit2OrgaUnit.class.getName(), OrgaUnit2OrgaUnit.BASE_DATA_OBJECT_TYPE, param); + } + + public OrgaUnit2OrgaUnitSelectionModel(String itemClass, String objectType, BigDecimalParameter param) { + super(itemClass, objectType, param); + } + + public OrgaUnit2OrgaUnit getSelectedOU2OU(PageState state) { + return (OrgaUnit2OrgaUnit) getSelectedObject(state); + } +} 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/OrgaUnit2OrgaUnitTable.java new file mode 100644 index 000000000..4bd669121 --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTable.java @@ -0,0 +1,207 @@ +package com.arsdigita.cms.contenttypes.ui; + +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.ItemSelectionModel; +import com.arsdigita.cms.SecurityManager; +import com.arsdigita.cms.contenttypes.OrgaUnit2OrgaUnit; +import com.arsdigita.cms.dispatcher.Utilities; +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 OrgaUnit2OrgaUnitTable extends Table { + + private final static Logger logger = Logger.getLogger(OrgaUnit2OrgaUnitTable.class); + private OrgaUnit2OrgaUnitSelectionModel m_ou2ouModel; + private ItemSelectionModel m_itemModel; + private TableColumn m_orgaUnitCol; + private TableColumn m_moveUpCol; + private TableColumn m_moveDownCol; + private TableColumn m_editCol; + private TableColumn m_delCol; + private RequestLocal m_size; + private RequestLocal m_editor; + /** + * ID String for the "edit" event. + */ + protected final static String EDIT_EVENT = "Edit"; + /** + * ID for the "delete" event. + */ + protected final static String DELETE_EVENT = "Delete"; + /** + * ID fpr the "up" event. + */ + protected final static String UP_EVENT = "up"; + /** + * ID for the "down" event. + */ + protected final static String DOWN_EVENT = "down"; + + public OrgaUnit2OrgaUnitTable(ItemSelectionModel itemModel, OrgaUnit2OrgaUnitSelectionModel ou2ouModel) { + super(); + this.m_itemModel = itemModel; + this.m_ou2ouModel = ou2ouModel; + addColumns(); + + this.m_size = new RequestLocal(); + this.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 organizational units associated with this organizational unit."); + setEmptyView(empty); + addTableActionListener(new OrgaUnit2OrgaUnitTableActionListener()); + setRowSelectionModel(this.m_ou2ouModel); + setDefaultCellRenderer(new OrgaUnit2OrgaUnitTableRenderer()); + setModelBuilder(new OrgaUnit2OrgaUnitTableModelBuilder(itemModel)); + } + + public void addColumns() { + TableColumnModel model = getColumnModel(); + int i = 0; + this.m_orgaUnitCol = new TableColumn(i, "Organizational Unit"); + this.m_editCol = new TableColumn(++i, "Edit"); + this.m_delCol = new TableColumn(++i, "Delete"); + this.m_moveUpCol = new TableColumn(++i, ""); + this.m_moveDownCol = new TableColumn(++i, ""); + + model.add(this.m_orgaUnitCol); + model.add(this.m_editCol); + model.add(this.m_delCol); + model.add(this.m_moveUpCol); + model.add(this.m_moveDownCol); + setColumnModel(model); + } + + private class OrgaUnit2OrgaUnitTableRenderer implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + OrgaUnit2OrgaUnit ou2ou = (OrgaUnit2OrgaUnit) value; + boolean isFirst = (row == 0); + if (m_size.get(state) == null) { + m_size.set(state, new Long(((OrgaUnit2OrgaUnitTableModelBuilder.OrgaUnit2OrgaUnitTableModel) table.getTableModel(state)).size())); + } + boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1); + + String url = ou2ou.getURI(state); + if (column == m_orgaUnitCol.getModelIndex()) { + ExternalLink extLink = new ExternalLink(ou2ou.getTargetItem().getOrganizationalUnitName(), url); + return extLink; + } 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 if (column == m_moveUpCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state)) && !isFirst) { + Label downLabel = new Label(UP_EVENT); + downLabel.setClassAttr("linkSort"); + return new ControlLink(downLabel); + } else { + return new Label(""); + } + } else if (column == m_moveDownCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state)) && !isLast) { + Label downLabel = new Label(DOWN_EVENT); + downLabel.setClassAttr("linkSort"); + return new ControlLink(downLabel); + } else { + return new Label(""); + } + } else { + throw new UncheckedWrapperException("column out of bounds"); + } + } + } + + private class OrgaUnit2OrgaUnitTableActionListener implements TableActionListener { + + private OrgaUnit2OrgaUnit getOrgaUnit2OrgaUnit(TableActionEvent event) { + Object o = event.getRowKey(); + BigDecimal id; + if (o instanceof String) { + id = new BigDecimal((String) o); + } else { + id = (BigDecimal) event.getRowKey(); + } + + Assert.exists(id); + OrgaUnit2OrgaUnit ou2ou; + try { + ou2ou = (OrgaUnit2OrgaUnit) DomainObjectFactory.newInstance(new OID(OrgaUnit2OrgaUnit.BASE_DATA_OBJECT_TYPE, id)); + } catch (Exception ex) { + throw new UncheckedWrapperException(ex); + } + return ou2ou; + } + + public void cellSelected(TableActionEvent e) { + int col = e.getColumn().intValue(); + PageState state = e.getPageState(); + OrgaUnit2OrgaUnit ou2ou = getOrgaUnit2OrgaUnit(e); + Assert.exists(ou2ou); + + if (col == m_editCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + m_ou2ouModel.setSelectedObject(state, ou2ou); + } + } else if (col == m_delCol.getModelIndex()) { + if (Boolean.TRUE.equals(m_editor.get(state))) { + try { + m_ou2ouModel.clearSelection(state); + ou2ou.delete(); + } catch (Exception ex) { + throw new UncheckedWrapperException(ex); + } + } + } else if (col == m_moveUpCol.getModelIndex()) { + m_ou2ouModel.clearSelection(state); + ou2ou.swapWithPrevious(); + } else if (col == m_moveDownCol.getModelIndex()) { + m_ou2ouModel.clearSelection(state); + ou2ou.swapWithNext(); + } + } + + public void headSelected(TableActionEvent e) { + } + } +} 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/OrgaUnit2OrgaUnitTableModelBuilder.java new file mode 100644 index 000000000..459f3935c --- /dev/null +++ b/ccm-cms-types-organizationalunit/src/com/arsdigita/cms/contenttypes/ui/OrgaUnit2OrgaUnitTableModelBuilder.java @@ -0,0 +1,84 @@ +package com.arsdigita.cms.contenttypes.ui; + +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.OrgaUnit2OrgaUnit; +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 OrgaUnit2OrgaUnitTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private final static Logger logger = Logger.getLogger(OrgaUnit2OrgaUnitTableModelBuilder.class); + + private ItemSelectionModel m_itemModel; + + public OrgaUnit2OrgaUnitTableModelBuilder(ItemSelectionModel itemModel) { + this.m_itemModel = itemModel; + } + + public TableModel makeModel(Table t, PageState s) { + DataCollection units = getUnits(s); + + if(units.isEmpty()) { + return Table.EMPTY_MODEL; + } else { + return new OrgaUnit2OrgaUnitTableModel(units); + } + } + + public DataCollection getUnits(PageState state) { + Assert.isTrue(this.m_itemModel.isSelected(state), "item selected"); + OrganizationalUnit unit = (OrganizationalUnit) this.m_itemModel.getSelectedItem(state); + return OrgaUnit2OrgaUnit.getUnits(unit); + } + + public static class OrgaUnit2OrgaUnitTableModel implements TableModel { + + OrgaUnit2OrgaUnit m_ou2ou; + DataCollection m_units; + + public OrgaUnit2OrgaUnitTableModel(DataCollection units) { + this.m_units = units; + this.m_ou2ou = null; + } + + public int getColumnCount() { + return (int) this.m_units.size(); + } + + public boolean nextRow() { + if (this.m_units.next()) { + DataObject obj = this.m_units.getDataObject(); + this.m_ou2ou = (OrgaUnit2OrgaUnit) DomainObjectFactory.newInstance(obj); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + return this.m_ou2ou; + } + + public Object getKeyAt(int columnIndex) { + return this.m_ou2ou.getID(); + } + + public long size() { + return this.m_units.size(); + } + + } +}