From d44f00ff43a21510e3feaf9c1f99f48c7e02b853 Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 11 Jun 2009 15:51:06 +0000 Subject: [PATCH] =?UTF-8?q?Aktueller=20Stand=20GenericOrganization=20mit?= =?UTF-8?q?=20Verk=C3=BCpfung=20zu=20Person.=20Funktioniert=20noch=20nicht?= =?UTF-8?q?=20100%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@192 8810af33-2d31-482b-a856-94f89814c4df --- .../application.xml | 2 + .../content-types/OrganizationRole.pdl | 73 ++++++ .../cms/contenttypes/GenericOrganization.xml | 6 +- .../ccm-cms-types-genericorganization.config | 2 - .../ccm-cms-types-genericorganization.load | 3 +- .../cms/contenttypes/GenericOrganization.java | 43 +-- .../cms/contenttypes/OrganizationRole.java | 246 ++++++++++++++++++ .../ui/GenericOrganizationPropertiesStep.java | 33 ++- .../ui/GenericOrganizationPropertyForm.java | 117 +++++++++ .../ui/OrganizationRolePropertiesStep.java | 70 +++++ .../ui/OrganizationRolePropertyForm.java | 198 ++++++++++++++ .../ui/OrganizationRoleSelectionModel.java | 25 ++ .../ui/OrganizationRoleTable.java | 203 +++++++++++++++ .../ui/OrganizationRoleTableModelBuilder.java | 86 ++++++ .../ui/OrganizationPropertyForm.java | 2 +- .../application.xml | 23 -- .../content-types/OrganizationRole.pdl | 26 -- .../postgres-create.sql | 3 - .../cms/contenttypes/OrganizationRole.xml | 28 -- .../src/ccm-cms-types-organizationrole.config | 3 - .../src/ccm-cms-types-organizationrole.load | 15 -- .../cms/contenttypes/OrganizationRole.java | 52 ---- .../OrganizationRoleCollection.java | 46 ---- .../OrganizationRoleInitializer.java | 27 -- .../contenttypes/OrganizationRoleLoader.java | 20 -- .../ui/OrganizationRolePropertyForm.java | 83 ------ .../cms/contenttypes/OrganizationRole.xsl | 29 --- .../arsdigita/cms/ui/ItemSearchWidget.java | 2 + .../util/UncheckedWrapperException.java | 5 + 29 files changed, 1057 insertions(+), 414 deletions(-) create mode 100644 ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRole.java rename ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java => ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertiesStep.java (59%) create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertyForm.java create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleSelectionModel.java create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTable.java create mode 100644 ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTableModelBuilder.java delete mode 100644 ccm-cms-types-organizationrole/application.xml delete mode 100644 ccm-cms-types-organizationrole/pdl/com/arsdigita/content-types/OrganizationRole.pdl delete mode 100644 ccm-cms-types-organizationrole/sql/ccm-cms-types-organizationrole/postgres-create.sql delete mode 100644 ccm-cms-types-organizationrole/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xml delete mode 100644 ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.config delete mode 100644 ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.load delete mode 100644 ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRole.java delete mode 100644 ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java delete mode 100644 ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleInitializer.java delete mode 100644 ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleLoader.java delete mode 100644 ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java delete mode 100644 ccm-cms-types-organizationrole/web/static/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xsl diff --git a/ccm-cms-types-genericorganization/application.xml b/ccm-cms-types-genericorganization/application.xml index fd1507eb2..a88c90f8f 100644 --- a/ccm-cms-types-genericorganization/application.xml +++ b/ccm-cms-types-genericorganization/application.xml @@ -8,6 +8,8 @@ + + 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 new file mode 100644 index 000000000..13deb6563 --- /dev/null +++ b/ccm-cms-types-genericorganization/pdl/com/arsdigita/content-types/OrganizationRole.pdl @@ -0,0 +1,73 @@ +// +// 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 OrganizationRole extends ACSObject { + String[1..1] roleName = ct_organizationroles.rolename VARCHAR(150); + Person[0..1] targetItem = join ct_organizationroles.target_item_id to ct_persons.person_id; + + Integer[0..1] roleOrder = ct_organizationroles.role_order INTEGER; + + reference key(ct_organizationroles.role_id); + aggressive load (roleOwner.id); +} + +association { + composite GenericOrganization[0..1] roleOwner = join ct_organizationroles.owner_id to ct_genericorganizations.organization_id; + composite OrganizationRole[0..n] roles = join ct_genericorganizations.organization_id to ct_organizationroles.owner_id; +} + +query getRefferingRoles { + BigDecimal id; + + do { + select r.role_id from organizationroles r where r.target_item_id = :itemID + } map { + id = r.role_id; + } +} + +data operation swapOrganizationRoleWithNextInGroup { + do { + update organizationroles + set role_order = CASE WHEN (role_order = :roleOrder) THEN + (:nextRoleOrder) + ELSE + (:roleOrder) + END + where (role_order = :roleOrder or role_order = :nextRoleOrder) + and (select owner_id from ct_organizationroles where organizationrole_id=role_id) = :roleID + and 2 = (select count(*) from ct_organizationroles r where r.role_id=r.organizationrole_id + and (role_order = :roleOrder or role_order = :nextRoleOrder) + and owner_id = :ownerID) + } +} + +query allRoleOrderForOrganization { + Integer linkOrder; + + do { + select r.role_order from ct_organizationroles r where r.owner_id = :ownerID + } + map { + linkOrder = r.linkOrder; + } +} diff --git a/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xml b/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xml index b7ac6b1d0..9c8abfeea 100644 --- a/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xml +++ b/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xml @@ -21,13 +21,13 @@ component="com.arsdigita.cms.contenttypes.ui.GenericOrganizationPropertiesStep" ordering="1"/> - + component="com.arsdigita.cms.contenttypes.ui.OrganizationRolePropertiesStep" + ordering="2"/> diff --git a/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.config b/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.config index 63fabae52..b6865e594 100644 --- a/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.config +++ b/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.config @@ -1,5 +1,3 @@ - \ No newline at end of file diff --git a/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load b/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load index 25a595380..54eec215a 100644 --- a/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load +++ b/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load @@ -4,12 +4,11 @@
-
- + diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganization.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganization.java index b5c22e1fe..32d6f2983 100644 --- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganization.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganization.java @@ -22,10 +22,7 @@ import com.arsdigita.cms.ContentPage; import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.OID; -import com.arsdigita.util.Assert; import java.math.BigDecimal; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.domain.DomainObjectFactory; import org.apache.log4j.Logger; @@ -70,24 +67,24 @@ public class GenericOrganization extends ContentPage { * Type of this class (used for internal purposed). */ public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericOrganization"; - private static final GenericOrganizationConfig s_config = new GenericOrganizationConfig(); + //private static final GenericOrganizationConfig s_config = new GenericOrganizationConfig(); private static final Logger s_log = Logger.getLogger(GenericOrganization.class); /** * Called when the class is loaded by the Java class loader. */ - static { + /*static { s_config.load(); - } + }*/ /** * Returns a possibly existing configuration object for the class. * * @return config object */ - public static final GenericOrganizationConfig getConfig() { + /*public static final GenericOrganizationConfig getConfig() { return s_config; - } + }*/ /** * Default constructor. This creates a new (empty) organization @@ -187,33 +184,5 @@ public class GenericOrganization extends ContentPage { */ public void setOrganizationDescription(String description) { set(DESCRIPTION, description); - } - - /** - * - * @return All roles associated with this organization. - */ - public OrganizationRoleCollection getOrganizationRoles() { - return new OrganizationRoleCollection((DataCollection) get(ROLES)); - } - - /** - * Adds a role to a organization. - * - * @param organizationRole The role to add. - */ - public void addOrganizationRole(OrganizationRole organizationRole) { - Assert.exists(organizationRole, OrganizationRole.class); - add(ROLES, organizationRole); - } - - /** - * Removes a role from a organization. - * - * @param organizationRole The role to remove. - */ - public void removeOrganizationRole(OrganizationRole organizationRole) { - Assert.exists(organizationRole, OrganizationRole.class); - remove(ROLES, organizationRole); - } + } } \ No newline at end of file diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRole.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRole.java new file mode 100644 index 000000000..ebf564820 --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRole.java @@ -0,0 +1,246 @@ +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.DataObjectNotFoundException; +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 OrganizationRole extends ACSObject { + + private static final Logger logger = Logger.getLogger(OrganizationRole.class); + public static final String ROLENAME = "roleName"; + public static final String TARGETITEM = "targetItem"; + public static final String ROLEOWNER = "roleOwner"; + public static final String ORDER = "roleOrder"; + public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrganizationRole"; + + public OrganizationRole() { + this(BASE_DATA_OBJECT_TYPE); + } + + public OrganizationRole(BigDecimal id) throws DataObjectNotFoundException { + this(new OID(BASE_DATA_OBJECT_TYPE, id)); + } + + public OrganizationRole(OID id) throws DataObjectNotFoundException { + super(id); + } + + public OrganizationRole(DataObject obj) { + super(obj); + } + + public OrganizationRole(String type) { + super(type); + } + + public String getRolename() { + return (String) get(ROLENAME); + } + + public void setRolename(String rolename) { + set(ROLENAME, rolename); + } + + public GenericOrganization getRoleOwner() { + DataObject obj = (DataObject) get(ROLEOWNER); + if (obj == null) { + return null; + } else { + return (GenericOrganization) DomainObjectFactory.newInstance(obj); + } + } + + public void setRoleOwner(GenericOrganization orga) { + Assert.exists(orga, GenericOrganization.class); + logger.debug(String.format("Setting role owner to %s", orga.getOrganizationName())); + setAssociation(ROLEOWNER, orga); + } + + public Person getTargetItem() { + DataObject object = (DataObject) get(TARGETITEM); + return (Person) DomainObjectFactory.newInstance(object); + } + + public void setTargetItem(Person item) { + setAssociation(TARGETITEM, item); + } + + public Integer getOrder() { + return (Integer) get(ORDER); + } + + public void setOrder(Integer order) { + Assert.exists(order); + set(ORDER, order); + } + + public String getURI(PageState s) { + Person item = getTargetItem(); + + if (item == null) { + logger.error(getOID() + " is a link between an organization and a person, but the associated person is null"); + return ""; + } + + ContentSection section = item.getContentSection(); + ItemResolver resolver = section.getItemResolver(); + String url = resolver.generateItemURL(s, item, section, item.getVersion()); + + return URL.there(s.getRequest(), url).toString(); + } + + public static DataCollection getReferingRoles(Person person) { + Session session = SessionManager.getSession(); + DataCollection roles = session.retrieve(BASE_DATA_OBJECT_TYPE); + Filter filter = roles.addInSubqueryFilter("id", "com.arsdigita.cms.contenttypes.getRefferingRoles"); + filter.set("itemID", person.getID()); + + return roles; + } + + public static DataCollection getRoles(GenericOrganization orga) { + logger.debug("Getting roles for an organization..."); + Session session = SessionManager.getSession(); + DataCollection roles = session.retrieve(BASE_DATA_OBJECT_TYPE); + roles.addEqualsFilter(ROLEOWNER + ".id", orga.getID()); + roles.addOrder(ORDER); + return roles; + } + + public void swapWithNext() throws UnsupportedOperationException { + swapWithNext("com.arsdigita.cms.contenttypes.allRoleOrderForOrganization", "com.arsdigita.cms.contenttypes.swapOrganizationRoleWithNextInGroup"); + } + + public void swapWithPrevious() throws UnsupportedOperationException { + swapWithNext("com.arsdigita.cms.contenttypes.allRoleOrderForOrganization", "com.arsdigita.cms.contenttypes.swapOrganizationRoleWithNextInGroup"); + } + + 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", getRoleOwner().getID()); + return query; + } + + protected DataOperation getSwapOperation(String operationName) { + DataOperation operation = SessionManager.getSession().retrieveDataOperation(operationName); + operation.setParameter("ownerID", getRoleOwner().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(ORDER); + + 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 = key; + + if (swapNext) { + otherKey = key + 1; + query.addOrder("roleOrder ASC"); + query.addFilter(query.getFilterFactory().greaterThan("roleOrder", currentKey, true)); + } else { + otherKey = key - 1; + query.addOrder("roleOrder DESC"); + query.addFilter(query.getFilterFactory().lessThan("roleOrder", currentKey, true)); + } + + if (query.next()) { + otherKey = ((Integer) query.get("roleOrder")).intValue(); + query.close(); + } + + DataOperation operation = getSwapOperation(operationName); + operation.setParameter("linkOrder", new Integer(key)); + operation.setParameter("nextLinkOrder", new Integer(otherKey)); + operation.execute(); + } + + protected void alphabetize() { + Session session = SessionManager.getSession(); + DataCollection roles = session.retrieve(BASE_DATA_OBJECT_TYPE); + roles.addEqualsFilter(ROLEOWNER + ".id", getRoleOwner().getID()); + roles.addOrder(ROLENAME); + int sortkey = 0; + while (roles.next()) { + sortkey++; + OrganizationRole role = new OrganizationRole(roles.getDataObject()); + role.setOrder(sortkey); + role.save(); + } + } + + public int maxOrder() { + GenericOrganization roleOwner = getRoleOwner(); + if (roleOwner == null) { + return 0; + } + int returnOrder = 0; + DataQuery query = SessionManager.getSession().retrieveQuery("com.arsdigita.cms.contenttypes.allRoleOrderForItem"); + query.setParameter("ownerID", getRoleOwner().getID()); + query.addOrder("linkOrder DESC"); + if (query.next()) { + Integer roleOrder = ((Integer) query.get("roleOrder")); + query.close(); + if (roleOrder != null) { + returnOrder = roleOrder.intValue(); + } + } + + return returnOrder; + } + + @Override + public void beforeSave() { + super.beforeSave(); + if (getOrder() == null) { + setOrder(maxOrder() + 1); + } + } +} diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertiesStep.java similarity index 59% rename from ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java rename to ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertiesStep.java index 1421b6199..f9fff3b13 100644 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertiesStep.java @@ -1,51 +1,56 @@ package com.arsdigita.cms.contenttypes.ui; -import com.arsdigita.bebop.Component; import com.arsdigita.bebop.PageState; import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.OrganizationRole; -import com.arsdigita.domain.DomainObject; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; +import com.arsdigita.cms.contenttypes.GenericOrganization; import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.SimpleEditStep; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.ui.util.GlobalizationUtil; +import com.arsdigita.domain.DomainObject; +import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.bebop.Component; import java.text.DateFormat; - +import org.apache.log4j.Logger; /** * * @author Jens Pelzetter */ -public class OrganizationRolePropertiesStep extends SimpleEditStep { +public class GenericOrganizationPropertiesStep extends SimpleEditStep { + + private static final Logger logger = Logger.getLogger(GenericOrganizationPropertiesStep.class); public static final String EDIT_SHEET_NAME = "edit"; - public OrganizationRolePropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + public GenericOrganizationPropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { super(itemModel, parent); setDefaultEditKey(EDIT_SHEET_NAME); BasicPageForm editSheet; - editSheet = new OrganizationRolePropertyForm(itemModel, this); + editSheet = new GenericOrganizationPropertyForm(itemModel, this); add(EDIT_SHEET_NAME, "Edit", new WorkflowLockedComponentAccess(editSheet, itemModel), editSheet.getSaveCancelSection().getCancelButton()); - setDisplayComponent(getOrganizationRolePropertySheet(itemModel)); + setDisplayComponent(getGenericOrganizationPropertySheet(itemModel)); } - public static Component getOrganizationRolePropertySheet(ItemSelectionModel itemModel) { + public static Component getGenericOrganizationPropertySheet(ItemSelectionModel itemModel) { DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); - sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.organizationrole.rolename"), OrganizationRole.ROLENAME); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.organizationname"), GenericOrganization.ORGANIZATIONNAME); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.organizationnameaddendum"), GenericOrganization.ORGANIZATIONNAMEADDENDUM); + sheet.add(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.description"), GenericOrganization.DESCRIPTION); if(!ContentSection.getConfig().getHideLaunchDate()) { sheet.add(GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date"), ContentPage.LAUNCH_DATE, new DomainObjectPropertySheet.AttributeFormatter() { - public String format(DomainObject item, String attribute, PageState state) { - ContentPage page = (ContentPage)item; + + public String format(DomainObject obj, String attribute, PageState state) { + ContentPage page = (ContentPage)obj; if(page.getLaunchDate() != null) { return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate()); } diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertyForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertyForm.java new file mode 100644 index 000000000..e12765e8d --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/GenericOrganizationPropertyForm.java @@ -0,0 +1,117 @@ +package com.arsdigita.cms.contenttypes.ui; + +import com.arsdigita.bebop.FormProcessException; +import com.arsdigita.cms.ui.authoring.BasicPageForm; +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.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.GenericOrganization; +import com.arsdigita.bebop.Label; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.form.TextArea; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.parameters.ParameterModel; +import com.arsdigita.bebop.parameters.StringParameter; + +import org.apache.log4j.Logger; + +/** + * + * @author Jens Pelzetter + */ +public class GenericOrganizationPropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener { + + private static final Logger logger = Logger.getLogger(GenericOrganizationPropertyForm.class); + + private GenericOrganizationPropertiesStep m_step; + + /** + * Organizationname. + */ + public static final String ORGANIZATIONAME = GenericOrganization.ORGANIZATIONNAME; + /** + * Addedum + */ + public static final String ORGANIZATIONNAMEADDENDUM = GenericOrganization.ORGANIZATIONNAMEADDENDUM; + /** + * Description + */ + public static final String DESCRIPTION = GenericOrganization.DESCRIPTION; + + public static final String ID = "GenericOrganization_edit"; + + public GenericOrganizationPropertyForm(ItemSelectionModel itemModel) { + this(itemModel, null); + } + + public GenericOrganizationPropertyForm(ItemSelectionModel itemModel, GenericOrganizationPropertiesStep step) { + super(ID, itemModel); + m_step = step; + addSubmissionListener(this); + } + + @Override + public void addWidgets() { + super.addWidgets(); + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.genericorganization.ui.organizationname"))); + ParameterModel organizationNameParam = new StringParameter(ORGANIZATIONAME); + TextField organizationName = new TextField(organizationNameParam); + organizationName.addValidationListener(new NotNullValidationListener()); + add(organizationName); + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.genericorganization.ui.organizationnameaddendum"))); + TextField organizationNameAddendum = new TextField(ORGANIZATIONNAMEADDENDUM); + add(organizationNameAddendum); + + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.genericorganzation.ui.description"))); + TextArea description = new TextArea(DESCRIPTION); + description.setRows(5); + description.setCols(30); + add(description); + } + + @Override + public void init(FormSectionEvent e) throws FormProcessException { + FormData data = e.getFormData(); + GenericOrganization orga = (GenericOrganization)super.initBasicWidgets(e); + + data.put(ORGANIZATIONAME, orga.getOrganizationName()); + data.put(ORGANIZATIONNAMEADDENDUM, orga.getOrganizationNameAddendum()); + data.put(DESCRIPTION, orga.getDescription()); + } + + @Override + public void process(FormSectionEvent e) throws FormProcessException { + logger.error("proccessing..."); + FormData data = e.getFormData(); + + GenericOrganization orga = (GenericOrganization)super.processBasicWidgets(e); + + if((orga != null) + && (getSaveCancelSection().getSaveButton().isSelected(e.getPageState()))) { + orga.setOrganizationName((String)data.get(ORGANIZATIONAME)); + orga.setOrganizationNameAddendum((String)data.get(ORGANIZATIONNAMEADDENDUM)); + orga.setDescription((String)data.get(DESCRIPTION)); + + logger.error("Saving new values of orga"); + orga.save(); + } + + if(m_step != null) { + m_step.maybeForwardToNextStep(e.getPageState()); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + logger.error("submitted"); + if((m_step != null) && + (getSaveCancelSection().getCancelButton().isSelected(e.getPageState()))) { + m_step.cancelStreamlinedCreation(e.getPageState()); + } + } +} \ No newline at end of file diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.java new file mode 100644 index 000000000..0b3ffc586 --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertiesStep.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; + +/** + * + * @author Jens Pelzetter + */ +public class OrganizationRolePropertiesStep extends ResettableContainer { + + private AuthoringKitWizard m_parent; + + private ItemSelectionModel m_itemModel; + private BigDecimalParameter m_roleParam = new BigDecimalParameter("organizationrole"); + private OrganizationRoleSelectionModel m_roleModel = new OrganizationRoleSelectionModel(m_roleParam); + + public OrganizationRolePropertiesStep(ItemSelectionModel itemModel, AuthoringKitWizard parent) { + this.m_itemModel = itemModel; + this.m_parent = parent; + setOrganizationRoleSelectionModel(); + add(getDisplayComponent()); + + Form form = new Form("organizationRoleEditForm"); + form.add(getEditSheet()); + + WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel); + edit.add(form); + add(edit); + } + + protected void setOrganizationRoleSelectionModel() { + setOrganizationRoleSelectionModel(new OrganizationRoleSelectionModel(m_roleParam)); + } + + protected void setOrganizationRoleSelectionModel(OrganizationRoleSelectionModel model) { + m_roleModel = model; + } + + protected OrganizationRoleSelectionModel getOrganizationRoleSelectionModel() { + return m_roleModel; + } + + protected BigDecimalParameter getRoleParam() { + return this.m_roleParam; + } + + public Component getDisplayComponent() { + SimpleContainer container = new SimpleContainer(); + container.add(new OrganizationRoleTable(m_itemModel, m_roleModel)); + return container; + } + + protected FormSection getEditSheet() { + return new OrganizationRolePropertyForm(this.m_itemModel, this.m_roleModel); + } + + @Override + public void register(Page p) { + super.register(p); + p.addComponentStateParam(this, m_roleParam); + } +} diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java new file mode 100644 index 000000000..359047cd2 --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java @@ -0,0 +1,198 @@ +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.bebop.form.TextField; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.util.GlobalizationUtil; +import com.arsdigita.cms.ContentType; +import com.arsdigita.cms.ItemSelectionModel; +import com.arsdigita.cms.contenttypes.Article; +import com.arsdigita.cms.contenttypes.GenericOrganization; +import com.arsdigita.cms.contenttypes.OrganizationRole; +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 OrganizationRolePropertyForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { + + public final static Logger logger = Logger.getLogger(OrganizationRolePropertyForm.class); + public final static String ID = "organizationrole_edit"; + //public final static String SSL_PROTOCOL = "https://"; + //public final static String HTTP_PROTOCOL = "http://"; + private ItemSelectionModel m_itemModel; + private OrganizationRoleSelectionModel m_roleModel; + private TextField m_rolename; + private ItemSearchWidget m_itemSearch; + private SaveCancelSection m_saveCancelSection; + private final String ITEM_SEARCH = "organizationRole"; + + public OrganizationRolePropertyForm(ItemSelectionModel itemModel, OrganizationRoleSelectionModel roleModel) { + super(new ColumnPanel(2)); + this.m_itemModel = itemModel; + this.m_roleModel = roleModel; + + addWidgets(); + addSaveCancelSection(); + + addInitListener(this); + addValidationListener(this); + addProcessListener(this); + addSubmissionListener(this); + } + + protected void addWidgets() { + this.m_rolename = new TextField("rolename"); + this.m_rolename.addValidationListener(new NotNullValidationListener()); + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.rolename"))); + add(this.m_rolename); + + add(new Label("Person")); + //logger.error(String.format("Person.CONTENT_TYPE = %s", Person.CONTENT_TYPE)); + //logger.error(String.format("Article.CONTENT_TYPE = %s", Article.CONTENT_TYPE)); + this.m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, ContentType.findByAssociatedObjectType("com.arsdigita.cms.contenttypes.Person")); + add(this.m_itemSearch); + } + + public 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_roleModel.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_roleModel.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); + } + + public SaveCancelSection getSaveCancelSection() { + return this.m_saveCancelSection; + } + + protected OrganizationRoleSelectionModel getRoleSelectionModel() { + return this.m_roleModel; + } + + /*protected Person getPerson(PageState s) { + return (Person) m_itemModel.getSelectedObject(s); + }*/ + + protected GenericOrganization getOrganization(PageState s) { + return (GenericOrganization)m_itemModel.getSelectedObject(s); + } + + protected OrganizationRole createOrganizationRole(PageState s) { + //Person person = this.getPerson(s); + //Assert.exists(person); + GenericOrganization orga = this.getOrganization(s); + Assert.exists(orga); + OrganizationRole role = new OrganizationRole(); + return role; + } + + protected void setOrganizationRoleProperties(OrganizationRole role, FormSectionEvent e) { + PageState state = e.getPageState(); + FormData data = e.getFormData(); + + role.setRolename((String)m_rolename.getValue(state)); + role.setTargetItem((Person)data.get(ITEM_SEARCH)); + + role.save(); + } + + public void init(FormSectionEvent e) throws FormProcessException { + FormData data = e.getFormData(); + PageState state = e.getPageState(); + + setVisible(state, true); + + OrganizationRole role; + if (m_roleModel.isSelected(state)) { + role = m_roleModel.getSelectedRole(state); + try { + m_rolename.setValue(state, role.getRolename()); + data.put(ITEM_SEARCH, role.getTargetItem()); + } catch (IllegalStateException ex) { + logger.error(ex.getMessage()); + throw ex; + } + } else { + m_rolename.setValue(state, null); + data.put(ITEM_SEARCH, null); + } + } + + public void process(FormSectionEvent e) throws FormProcessException { + PageState state = e.getPageState(); + OrganizationRole role; + + if (this.getSaveCancelSection().getCancelButton().isSelected(state)) { + m_roleModel.clearSelection(state); + } else { + if (m_roleModel.isSelected(state)) { + role = m_roleModel.getSelectedRole(state); + } else { + role = createOrganizationRole(state); + } + setOrganizationRoleProperties(role, e); + } + + m_roleModel.clearSelection(state); + init(e); + } + + public void validate(FormSectionEvent e) throws FormProcessException { + if (e.getFormData().get(ITEM_SEARCH) == null) { + throw new FormProcessException("Person selection is required."); + } + } + + public void submitted(FormSectionEvent e) throws FormProcessException { + if (this.m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) { + logger.debug("Cancel in submission listener"); + m_roleModel.clearSelection(e.getPageState()); + init(e); + throw new FormProcessException("cancelled"); + } + } +} \ No newline at end of file diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleSelectionModel.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleSelectionModel.java new file mode 100644 index 000000000..cba4f3f2e --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleSelectionModel.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.kernel.ui.ACSObjectSelectionModel; +import com.arsdigita.cms.contenttypes.OrganizationRole; + +/** + * + * @author Jens Pelzetter + */ +public class OrganizationRoleSelectionModel extends ACSObjectSelectionModel { + + public OrganizationRoleSelectionModel(BigDecimalParameter param) { + super(OrganizationRole.class.getName(), OrganizationRole.BASE_DATA_OBJECT_TYPE, param); + } + + public OrganizationRoleSelectionModel(String itemClass, String objectType, BigDecimalParameter parameter) { + super(itemClass, objectType, parameter); + } + + public OrganizationRole getSelectedRole(PageState state) { + return (OrganizationRole) getSelectedObject(state); + } +} \ No newline at end of file diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTable.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTable.java new file mode 100644 index 000000000..6c1f72e29 --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTable.java @@ -0,0 +1,203 @@ +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.Link; +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.OrganizationRole; +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 OrganizationRoleTable extends Table { + + private final static Logger logger = Logger.getLogger(OrganizationRoleTable.class); + private OrganizationRoleSelectionModel m_roleModel; + private ItemSelectionModel m_itemModel; + private TableColumn m_roleNameCol; + private TableColumn m_moveUpCol; + private TableColumn m_moveDownCol; + 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"; + protected final static String UP_EVENT = "up"; + protected final static String DOWN_EVENT = "down"; + + public OrganizationRoleTable(ItemSelectionModel itemModel, OrganizationRoleSelectionModel roleModel) { + super(); + this.m_itemModel = itemModel; + this.m_roleModel = roleModel; + 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 roles for this organization."); + setEmptyView(empty); + addTableActionListener(new OrganizationRoleTableActionListener()); + setRowSelectionModel(m_roleModel); + setDefaultCellRenderer(new OrganizationRoleTableRenderer()); + } + + protected void addColumns() { + TableColumnModel model = getColumnModel(); + int i = 0; + m_roleNameCol = new TableColumn(i, "Role"); + m_editCol = new TableColumn(++i, "Edit"); + m_delCol = new TableColumn(++i, "Delete"); + m_moveUpCol = new TableColumn(++i, ""); + m_moveDownCol = new TableColumn(++i, ""); + + model.add(m_roleNameCol); + model.add(m_editCol); + model.add(m_delCol); + model.add(m_moveUpCol); + model.add(m_moveDownCol); + setColumnModel(model); + } + + private class OrganizationRoleTableRenderer implements TableCellRenderer { + + public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) { + OrganizationRole role = (OrganizationRole) value; + boolean isFirst = (row == 0); + if (m_size.get(state) == null) { + m_size.set(state, new Long(((OrganizationRoleTableModelBuilder.OrganizationRoleTableModel) table.getTableModel(state)).size())); + } + boolean isLast = (row == ((Long) m_size.get(state)).intValue() - 1); + + String url = role.getURI(state); + if (column == m_roleNameCol.getModelIndex()) { + ExternalLink extLink = new ExternalLink(role.getRolename(), 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)) && !isLast) { + Label downLabel = new Label(DOWN_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 OrganizationRoleTableActionListener implements TableActionListener { + + private OrganizationRole getOrganizationRole(TableActionEvent e) { + Object o = e.getRowKey(); + BigDecimal id; + if(o instanceof String) { + logger.debug("row key is a string: " + o); + id = new BigDecimal((String)o); + } else { + id = (BigDecimal)e.getRowKey(); + } + + Assert.exists(id); + OrganizationRole role; + try { + role = (OrganizationRole)DomainObjectFactory.newInstance(new OID(OrganizationRole.BASE_DATA_OBJECT_TYPE, id)); + } catch(DataObjectNotFoundException ex) { + throw new UncheckedWrapperException(e); + } + return role; + } + + public void cellSelected(TableActionEvent e) { + int col = e.getColumn().intValue(); + PageState state = e.getPageState(); + OrganizationRole role = getOrganizationRole(e); + Assert.exists(role); + + if (col == m_roleNameCol.getModelIndex()) { + //Nothing to do... + } else if (col == m_editCol.getModelIndex()) { + if(Boolean.TRUE.equals(m_editor.get(state))) { + logger.debug("setting organizationRoleModel to: " + role.getRolename()); + m_roleModel.setSelectedObject(state, role); + } + } else if(col == m_delCol.getModelIndex()) { + if(Boolean.TRUE.equals(m_editor.get(state))) { + try { + logger.debug("About to delete"); + m_roleModel.clearSelection(state); + role.delete();; + } catch(Exception ex) { + throw new UncheckedWrapperException(ex); + } + } + } else if(col == m_moveUpCol.getModelIndex()) { + m_roleModel.clearSelection(state); + role.swapWithPrevious(); + } else if(col == m_moveDownCol.getModelIndex()) { + m_roleModel.clearSelection(state); + role.swapWithNext(); + } + } + + public void headSelected(TableActionEvent e) { + //Nothing + } + + } +} diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTableModelBuilder.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTableModelBuilder.java new file mode 100644 index 000000000..4da936afa --- /dev/null +++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/OrganizationRoleTableModelBuilder.java @@ -0,0 +1,86 @@ +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.GenericOrganization; +import com.arsdigita.cms.contenttypes.OrganizationRole; +import com.arsdigita.cms.contenttypes.Person; +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 OrganizationRoleTableModelBuilder extends LockableImpl implements TableModelBuilder { + + private static final Logger logger = Logger.getLogger(OrganizationRoleTableModelBuilder.class); + + private ItemSelectionModel m_itemModel; + + public OrganizationRoleTableModelBuilder(ItemSelectionModel itemModel) { + this.m_itemModel = itemModel; + } + + public TableModel makeModel(Table t, PageState s) { + logger.debug("OrganizationRoleTableModelBuilder.makemodel()"); + + DataCollection roles = getRoles(s); + + if(roles.isEmpty()) { + return Table.EMPTY_MODEL; + } else { + return new OrganizationRoleTableModel(roles); + } + } + + public DataCollection getRoles(PageState s) { + Assert.isTrue(this.m_itemModel.isSelected(s), "item selected"); + GenericOrganization orga = (GenericOrganization) m_itemModel.getSelectedItem(s); + return OrganizationRole.getRoles(orga); + } + + public static class OrganizationRoleTableModel implements TableModel { + + OrganizationRole m_role; + DataCollection m_roles; + + public OrganizationRoleTableModel(DataCollection roles) { + m_roles = roles; + m_role = null; + } + + public int getColumnCount() { + return (int)m_roles.size(); + } + + public boolean nextRow() { + if (m_roles.next()) { + DataObject obj = m_roles.getDataObject(); + m_role = (OrganizationRole)DomainObjectFactory.newInstance(obj); + return true; + } else { + return false; + } + } + + public Object getElementAt(int columnIndex) { + return m_role; + } + + public Object getKeyAt(int columnIndex) { + return m_role.getID(); + } + + public long size() { + return m_roles.size(); + } + } +} diff --git a/ccm-cms-types-organization/src/com/arsdigita/cms/contenttypes/ui/OrganizationPropertyForm.java b/ccm-cms-types-organization/src/com/arsdigita/cms/contenttypes/ui/OrganizationPropertyForm.java index 571a79e3a..fa05f73f5 100755 --- a/ccm-cms-types-organization/src/com/arsdigita/cms/contenttypes/ui/OrganizationPropertyForm.java +++ b/ccm-cms-types-organization/src/com/arsdigita/cms/contenttypes/ui/OrganizationPropertyForm.java @@ -72,7 +72,7 @@ public class OrganizationPropertyForm super( ID, itemModel ); m_step = step; addSubmissionListener(this); - } + } /** * Adds widgets to the form. diff --git a/ccm-cms-types-organizationrole/application.xml b/ccm-cms-types-organizationrole/application.xml deleted file mode 100644 index 63e3e08ea..000000000 --- a/ccm-cms-types-organizationrole/application.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - - - - - - - Content type representing a role in a organization (eg CEO). For use with the GenericOrganization type. - - \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/pdl/com/arsdigita/content-types/OrganizationRole.pdl b/ccm-cms-types-organizationrole/pdl/com/arsdigita/content-types/OrganizationRole.pdl deleted file mode 100644 index e20b02755..000000000 --- a/ccm-cms-types-organizationrole/pdl/com/arsdigita/content-types/OrganizationRole.pdl +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright (C) 2009 Jens Pelzetter/Center for Social Poltics, University of Bremen. All Rights Reserved. -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License -// as published by the Free Software Foundation; either version 2.1 of -// the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -model com.arsdigita.cms.contenttypes; - -import com.arsdigita.cms.ContentPage; - -object type OrganizationRole extends ContentPage { - String[0..1] rolename = ct_organizationroles.rolename VARCHAR(512); - - reference key (ct_organizationroles.role_id); -} \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/sql/ccm-cms-types-organizationrole/postgres-create.sql b/ccm-cms-types-organizationrole/sql/ccm-cms-types-organizationrole/postgres-create.sql deleted file mode 100644 index a733590e2..000000000 --- a/ccm-cms-types-organizationrole/sql/ccm-cms-types-organizationrole/postgres-create.sql +++ /dev/null @@ -1,3 +0,0 @@ -begin; -\i ddl/postgres/create.sql -end; \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xml b/ccm-cms-types-organizationrole/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xml deleted file mode 100644 index eebb8b209..000000000 --- a/ccm-cms-types-organizationrole/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.config b/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.config deleted file mode 100644 index bcf00468e..000000000 --- a/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.config +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.load b/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.load deleted file mode 100644 index 00f521900..000000000 --- a/ccm-cms-types-organizationrole/src/ccm-cms-types-organizationrole.load +++ /dev/null @@ -1,15 +0,0 @@ - - -
-
-
- - -
- - - - - - - \ No newline at end of file diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRole.java b/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRole.java deleted file mode 100644 index 8a7fc2102..000000000 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRole.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.arsdigita.cms.contenttypes; - -import com.arsdigita.cms.ContentPage; - -import java.math.BigDecimal; -import org.apache.log4j.Logger; -import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.DataObject; - -/** - * - * @author Jens Pelzetter - */ -public class OrganizationRole extends ContentPage { - - public static final String ROLENAME = "rolename"; - - public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrganizationRole"; - - public static final Logger logger = Logger.getLogger(OrganizationRole.class); - - public OrganizationRole() { - super(BASE_DATA_OBJECT_TYPE); - } - - public OrganizationRole(BigDecimal id) throws DataObjectNotFoundException { - super(id); - } - - public OrganizationRole(OID oid) { - super(oid); - } - - public OrganizationRole(DataObject obj) { - super(obj); - } - - public OrganizationRole(String type) { - super(type); - } - - public String getRoleName() { - return (String) get(ROLENAME); - } - - public void setRoleName(String rolename) { - logger.error(String.format("Setting rolename to %s", rolename)); - set(ROLENAME, rolename); - } - -} diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java b/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java deleted file mode 100644 index 74438688b..000000000 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.arsdigita.cms.contenttypes; - -import com.arsdigita.domain.DomainCollection; -import com.arsdigita.domain.DomainObject; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.Filter; -import com.arsdigita.persistence.PersistenceException; -/** - * - * @author Jens Pelzetter - */ -public class OrganizationRoleCollection extends DomainCollection { - - public OrganizationRoleCollection(DataCollection dataCollection) { - super(dataCollection); - } - - @Override - public void addOrder(String order) { - m_dataCollection.addOrder(order); - } - - @Override - public DomainObject getDomainObject() { - return new OrganizationRole(m_dataCollection.getDataObject()); - } - - public OrganizationRole getOrganizationRole() { - return (OrganizationRole) getDomainObject(); - } - - @Override - public Filter addFilter(String conditions) { - return m_dataCollection.addFilter(conditions); - } - - @Override - public void clearFilter() { - m_dataCollection.clearFilter(); - } - - @Override - public void clearOrder() throws PersistenceException { - m_dataCollection.clearOrder(); - } -} diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleInitializer.java b/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleInitializer.java deleted file mode 100644 index b718af491..000000000 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleInitializer.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.arsdigita.cms.contenttypes; - -import com.arsdigita.runtime.DomainInitEvent; -import org.apache.log4j.Logger; - -/** - * - * @author Jens Pelzetter - */ -public class OrganizationRoleInitializer extends ContentTypeInitializer { - - private final static Logger logger = Logger.getLogger(OrganizationRoleInitializer.class); - - public OrganizationRoleInitializer() { - super("ccm-cms-types-organizationrole.pdl.mf", OrganizationRole.BASE_DATA_OBJECT_TYPE); - } - - @Override - public void init(DomainInitEvent evt) { - super.init(evt); - } - - @Override - public String[] getStylesheets() { - return new String[]{"/static/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xsl"}; - } -} diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleLoader.java b/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleLoader.java deleted file mode 100644 index 3fc531d73..000000000 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/OrganizationRoleLoader.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.arsdigita.cms.contenttypes; - -import org.apache.log4j.Logger; - -/** - * - * @author Jens Pelzetter - */ -public class OrganizationRoleLoader extends AbstractContentTypeLoader { - private static final Logger logger = Logger.getLogger(OrganizationRoleLoader.class); - - private static final String TYPES[] = { "/WEB-INF/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xml" }; - - @Override - protected String[] getTypes() { - return TYPES; - } - - -} diff --git a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java b/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java deleted file mode 100644 index 074c7eb3d..000000000 --- a/ccm-cms-types-organizationrole/src/com/arsdigita/cms/contenttypes/ui/OrganizationRolePropertyForm.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.arsdigita.cms.contenttypes.ui; - -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.contenttypes.OrganizationRole; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.FormData; - -import org.apache.log4j.Logger; - -/** - * - * @author Jens Pelzetter - */ -public class OrganizationRolePropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener { - - private static final Logger logger = Logger.getLogger(OrganizationRolePropertyForm.class); - private OrganizationRolePropertiesStep m_step; - public static final String ROLENAME = OrganizationRole.ROLENAME; - public static final String ID = "OrganizationRole_edit"; - - public OrganizationRolePropertyForm(ItemSelectionModel itemModel) { - this(itemModel, null); - } - - public OrganizationRolePropertyForm(ItemSelectionModel itemModel, OrganizationRolePropertiesStep step) { - super(ID, itemModel); - m_step = step; - addSubmissionListener(this); - } - - @Override - protected void addWidgets() { - super.addWidgets(); - - add(new Label((String)GlobalizationUtil.globalize("cms.contenttypes.ui.organizationrole.rolename").localize())); - //ParameterModel rolenameParameter = new StringParameter(ROLENAME); - //TextField rolename = new TextField(rolenameParameter); - TextField rolename = new TextField(ROLENAME); - add(rolename); - } - - public void init(FormSectionEvent fse) { - FormData data = fse.getFormData(); - OrganizationRole role = (OrganizationRole)super.initBasicWidgets(fse); - - data.put(ROLENAME, role.getRoleName()); - } - - public void submitted(FormSectionEvent fse) { - logger.error("submitted"); - if((m_step != null) && - (getSaveCancelSection().getCancelButton().isSelected(fse.getPageState()))) { - m_step.cancelStreamlinedCreation(fse.getPageState()); - } - } - - public void process(FormSectionEvent fse) { - FormData data = fse.getFormData(); - - OrganizationRole role = (OrganizationRole)super.processBasicWidgets(fse); - - if((role != null) && - (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState()))) { - logger.error(String.format("Setting rolename to %s", data.get(ROLENAME))); - role.setRoleName((String)data.get(ROLENAME)); - - role.save(); - } - - if(m_step != null) { - m_step.maybeForwardToNextStep(fse.getPageState()); - } - } -} diff --git a/ccm-cms-types-organizationrole/web/static/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xsl b/ccm-cms-types-organizationrole/web/static/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xsl deleted file mode 100644 index e250af404..000000000 --- a/ccm-cms-types-organizationrole/web/static/content-types/com/arsdigita/cms/contenttypes/OrganizationRole.xsl +++ /dev/null @@ -1,29 +0,0 @@ - -]> - - - - -

- -

-
-
- - - -

- -

-
-
- -
\ No newline at end of file diff --git a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java index 382091028..ca092dc30 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/ItemSearchWidget.java @@ -137,6 +137,7 @@ public class ItemSearchWidget extends FormSection this.parent = parent; } + @Override public boolean isVisible(PageState ps) { return ((m_search.isSelected(ps) || hasQuery(ps)) && @@ -151,6 +152,7 @@ public class ItemSearchWidget extends FormSection super("
", false); } + @Override public boolean isVisible(PageState ps) { return ((m_search.isSelected(ps) || m_searchComponent.hasQuery(ps)) && diff --git a/ccm-core/src/com/arsdigita/util/UncheckedWrapperException.java b/ccm-core/src/com/arsdigita/util/UncheckedWrapperException.java index 246678240..0c1cb8207 100755 --- a/ccm-core/src/com/arsdigita/util/UncheckedWrapperException.java +++ b/ccm-core/src/com/arsdigita/util/UncheckedWrapperException.java @@ -18,6 +18,7 @@ */ package com.arsdigita.util; +import com.arsdigita.bebop.event.TableActionEvent; import org.apache.log4j.Logger; /** @@ -67,6 +68,10 @@ public class UncheckedWrapperException extends RuntimeException { this(msg, null); } + public UncheckedWrapperException(TableActionEvent e) { + throw new UnsupportedOperationException("Not yet implemented"); + } + /** * Constructor which takes a root cause * that this exception will be wrapping.