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 2106264d6..f10815ca7 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
@@ -18,15 +18,15 @@
labelBundle="com.arsdigita.cms.contenttypes.GenericOrganizationResources"
descriptionKey="genericorganization.authoring.basic_properties.description"
descriptionBundle="com.arsdigita.cms.contenttypes.GenericOrganizationResources"
- component="com.arsdigita.cms.contenttypes.ui.genericOrganization.GenericOrganizationPropertiesStep"
+ component="com.arsdigita.cms.contenttypes.ui.genericorganization.GenericOrganizationEdit"
ordering="1"/>
diff --git a/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/genericorganization-item.jsp b/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/genericorganization-item.jsp
new file mode 100644
index 000000000..5d1d82aa3
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/genericorganization-item.jsp
@@ -0,0 +1,9 @@
+
+
+
+
+
+
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 ef8c59987..c526d0d91 100644
--- a/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load
+++ b/ccm-cms-types-genericorganization/src/ccm-cms-types-genericorganization.load
@@ -8,7 +8,7 @@
-
+
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 ee83fb4ca..37c4831f7 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
@@ -47,23 +47,21 @@ public class GenericOrganization extends ContentPage {
public static final String ORGANIZATIONNAME = "organizationname";
public static final String ORGANIZATIONNAMEADDENDUM = "organizationnameaddendum";
public static final String DESCRIPTION = "description";
- public static final String FUNCTIONS = "functions";
+ public static final String ROLES = "roles";
public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.GenericOrganization";
- public static final String ITEMS = "associatedContentItemsForGenericOrganization";
-
private static final GenericOrganizationConfig s_config = new GenericOrganizationConfig();
private static final Logger s_log = Logger.getLogger(GenericOrganization.class);
-// static {
-// s_config.load();
-// }
+ static {
+ s_config.load();
+ }
-// public static final GenericOrganizationConfig getConfig () {
-// return s_config;
-// }
+ public static final GenericOrganizationConfig getConfig () {
+ return s_config;
+ }
/**
* Default constructor. This creates a new (empty) organization
@@ -88,71 +86,6 @@ public class GenericOrganization extends ContentPage {
super(type);
}
- public void beforeSave() {
- super.beforeSave();
-
- Assert.exists(getContentType(), ContentType.class);
- }
-
- //Functions for adding and removing associated ContentItems
-
- /**
- * Adds an association.
- *
- * @param item The item to associated with the organization.
- */
- public void addContentItem(ContentItem item) {
- s_log.debug("item is " + item);
- item.addToAssociation(getItemsForGenericOrganization());
- }
-
- /**
- * Removes an association
- *
- * @item The item which should longer be associated with this organization.
- */
- public void removeContentItem(ContentItem item) {
- s_log.debug("item is " + item);
- DataOperation operation = SessionManager.getSession().retrieveDataOperation("com.arsdigita.cms.contenttypes.removeGenericOrganizationFromContentItemAssociation");
- operation.setParameter("itemID", new Integer(item.getID().intValue()));
- operation.execute();
- }
-
- /**
- * Removes all mappings between this organization and any other content items
- */
- private void removeItemMappings() {
- DataOperation operation = SessionManager.getSession().retrieveDataOperation("com.arsdigita.cms.contenttypes.removeGenericOrganizationFromAllAssociations");
- operation.setParameter("organizationID", new Integer(this.getID().intValue()));
- }
-
- /**
- * Gets the DataAssociation object for this organization
- */
- public DataAssociation getItemsForGenericOrganization() {
- return (DataAssociation)get(ITEMS);
- }
-
- /**
- * Returns the organization for a given content item
- *
- * @param item
- * @return The Organization
- */
- public static GenericOrganization getGenericOrganizationForItem(ContentItem item) {
- s_log.debug("getting contact for item " + item);
- DataQuery query = SessionManager.getSession().retrieveQuery("com.arsdigita.cms.contenttypes.getGenericOrganizationForItem");
- query.setParameter("itemID", item.getID());
- BigDecimal orgaID;
- GenericOrganization orga = null;
- while(query.next()) {
- orgaID = (BigDecimal)query.get("organizationID");
- orga = new GenericOrganization(orgaID);
- }
- s_log.debug("returning GenericOrganization " + orga);
- return orga;
- }
-
/* accessors *************************************************/
public String getOrganizationName() {
@@ -179,23 +112,18 @@ public class GenericOrganization extends ContentPage {
set(DESCRIPTION, description);
}
- public OrganizationFunctionCollection getOrganizationFunctions() {
- return new OrganizationFunctionCollection((DataCollection) get(FUNCTIONS));
+ public OrganizationRoleCollection getOrganizationRoles() {
+ return new OrganizationRoleCollection((DataCollection) get(ROLES));
}
- public void addOrganizationFunction(OrganizationFunction organizationFunction) {
- Assert.exists(organizationFunction, OrganizationFunction.class);
- add(FUNCTIONS, organizationFunction);
+ public void addOrganizationRole(OrganizationRole organizationRole) {
+ Assert.exists(organizationRole, OrganizationRole.class);
+ add(ROLES, organizationRole);
}
- public void removeOrganizationFunction(OrganizationFunction organizationFunction) {
- Assert.exists(organizationFunction, OrganizationFunction.class);
- remove(FUNCTIONS, organizationFunction);
+ public void removeOrganizationRole(OrganizationRole organizationRole) {
+ Assert.exists(organizationRole, OrganizationRole.class);
+ remove(ROLES, organizationRole);
}
-
- private DataObject retrieveDataObject(String attr) {
- return (DataObject)get(attr);
- }
-
}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationInitializer.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationInitializer.java
index 6a00bada0..4120b3f96 100644
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationInitializer.java
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationInitializer.java
@@ -16,92 +16,48 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
-
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.contenttypes.ContentTypeInitializer;
-import com.arsdigita.domain.DomainObject;
-import com.arsdigita.domain.DomainObjectFactory;
-import com.arsdigita.domain.DomainObjectInstantiator;
-import com.arsdigita.persistence.DataObject;
-import com.arsdigita.runtime.DomainInitEvent;
-import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
-import com.arsdigita.cms.ContentPage;
import org.apache.log4j.Logger;
-import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
-import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
-import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.runtime.LegacyInitEvent;
-import com.arsdigita.cms.ContentSection;
-import com.arsdigita.cms.contenttypes.ui.genericOrganization.GenericOrganizationPropertiesStep;
/**
*
* @author Jens Pelzetter
*/
-
public class GenericOrganizationInitializer extends ContentTypeInitializer {
-
- public final static String versionId =
- "$Id: GenericOrganizationInitializer.java 1 2009-04-30 09:32:55Z jensp $" +
- "$Author: jensp $" +
- "$DateTime: 2009/04/30 11:33:39 $";
+ public final static String versionId =
+ "$Id: GenericOrganizationInitializer.java 1 2009-04-30 09:32:55Z jensp $" +
+ "$Author: jensp $" +
+ "$DateTime: 2009/04/30 11:33:39 $";
private static final Logger s_log = Logger.getLogger(GenericOrganizationInitializer.class);
public GenericOrganizationInitializer() {
- super("ccm-cms-types-genericorganization.pdl.mf",
- GenericOrganization.BASE_DATA_OBJECT_TYPE);
- }
-
-
- public void init(DomainInitEvent evt) {
- super.init(evt);
- }
- /*public void init(LegacyInitEvent evt) {
- super.init(evt);
-
- if(ContentSection.getConfig().getHasGenericOrganizationsAuthoringStep()) {
- AuthoringKitWizard.registerAssetStep(getBaseType(),
- getAuthoringStep(),
- getAuthoringStepLabel(),
- getAuthoringStepDescription(),
- getAuthoringStepSortKey());
-
- ContentItemTraversalAdapter associatedGenericOrganizationTraversalAdapters = new ContentItemTraversalAdapter();
- associatedGenericOrganizationTraversalAdapters.addAssociationProperty("/object/functions");
- }
- }*/
-
- private int getAuthoringStepSortKey() {
- return 1;
- }
-
- private GlobalizedMessage getAuthoringStepDescription() {
- return new GlobalizedMessage("com.arsdigita.cms.contenttypes.genericorganization_authoring_step_description",
- "com.arsdigita.cms.contenttypes.GenericOrganizationResources");
- }
-
- private GlobalizedMessage getAuthoringStepLabel() {
- return new GlobalizedMessage("com.arsdigita.cms.contenttypes.genericorganization_authoring_step_label",
- "com.arsdigita.cms.contenttypes.GenericOrganizationResources");
- }
-
- private Class getAuthoringStep() {
- //return AddGenericOrganizationPropertiesStep.class;
- return GenericOrganizationPropertiesStep.class;
- }
-
- public String[] getStylesheets() {
- return new String[] { "/static/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xsl" };
+ super("ccm-cms-types-genericorganization.pdl.mf",
+ GenericOrganization.BASE_DATA_OBJECT_TYPE);
}
+ @Override
public String getTraversalXML() {
- return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/GenericOrganization.xml";
+ return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/GenericOrganization.xml";
}
-
- private String getBaseType() {
- return ContentPage.BASE_DATA_OBJECT_TYPE;
+
+ public String getStylesheet() {
+ return "static/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xsl";
+ }
+
+ @Override
+ public void init(LegacyInitEvent evt) {
+ super.init(evt);
+
+ /* MetadataProviderRegistry.registerAdapter(OrganizationRole.BASE_DATA_OBJECT_TYPE,
+ new OrganizationRoleMetadataProvider());*/
+ /*URLService.registerFinder(OrganizationRole.BASE_DATA_OBJECT_TYPE,
+ new OrganizationRoleURLFinder());
+
+ ContentSection.registerExtraXMLGenerator(GenericOrganization.class.getName(),
+ new OrganizationRolesPanel());*/
}
-
}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationLoader.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationLoader.java
index 00e807fe2..37dbd4180 100644
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationLoader.java
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/GenericOrganizationLoader.java
@@ -20,6 +20,14 @@
package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.contenttypes.AbstractContentTypeLoader;
+import com.arsdigita.cms.ContentSection;
+import com.arsdigita.cms.ContentType;
+import com.arsdigita.cms.lifecycle.LifecycleDefinition;
+import com.arsdigita.util.parameter.Parameter;
+import com.arsdigita.util.parameter.ResourceParameter;
+import com.arsdigita.workflow.simple.WorkflowTemplate;
+
+import java.io.InputStream;
import org.apache.log4j.Logger;
@@ -29,7 +37,7 @@ import org.apache.log4j.Logger;
*/
public class GenericOrganizationLoader extends AbstractContentTypeLoader {
- public static final Logger s_log = Logger.getLogger(GenericOrganizationLoader.class);
+ private static final Logger s_log = Logger.getLogger(GenericOrganizationLoader.class);
private static final String[] TYPES = {
"/WEB-INF/content-types/com/arsdigita/cms/contenttypes/GenericOrganization.xml"
};
@@ -37,5 +45,31 @@ public class GenericOrganizationLoader extends AbstractContentTypeLoader {
public String[] getTypes() {
return TYPES;
}
+
+ private ResourceParameter m_template;
+
+ public GenericOrganizationLoader() {
+ super();
+ m_template = new ResourceParameter("com.arsdigita.cms.contenttypes.genericorganization.template",
+ Parameter.REQUIRED,
+ "/WEB-INF/content-types/com/arsdigita/cms/contenttypes/genericorganization-item.jsp");
+ register(m_template);
+ }
+
+ @Override
+ protected void prepareSection(final ContentSection section,
+ final ContentType type,
+ final LifecycleDefinition ld,
+ final WorkflowTemplate wf) {
+ super.prepareSection(section, type, ld, wf);
+
+ setDefaultTemplate("GenericOrganization-genericorganization-item",
+ "genericorganization-item",
+ (InputStream)get(m_template),
+ section,
+ type,
+ ld,
+ wf);
+ }
}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunction.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunction.java
deleted file mode 100644
index 0d413ecd1..000000000
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunction.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * OrganizationFunction
- *
- * Part of GenericOrganization
- *
- *
- */
-
-package com.arsdigita.cms.contenttypes;
-
-import com.arsdigita.cms.ContentPage;
-import com.arsdigita.cms.ContentItem;
-import com.arsdigita.domain.DomainObject;
-import com.arsdigita.persistence.DataObject;
-import com.arsdigita.domain.DataObjectNotFoundException;
-import com.arsdigita.persistence.OID;
-import java.math.BigDecimal;
-import org.apache.log4j.Logger;
-
-
-public class OrganizationFunction extends ContentItem {
-
- private static final Logger s_log = Logger.getLogger(OrganizationFunction.class);
-
- public static final String FUNCTIONNAME = "functionname";
-
- public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrganizationFunction";
-
- public OrganizationFunction() {
- super(BASE_DATA_OBJECT_TYPE);
- }
-
- public OrganizationFunction(BigDecimal id) throws DataObjectNotFoundException {
- super(new OID(BASE_DATA_OBJECT_TYPE, id));
- }
-
- public OrganizationFunction(String typeName) {
- super(typeName);
- }
-
- public OrganizationFunction(OID oid) throws DataObjectNotFoundException {
- super(oid);
- }
-
- public OrganizationFunction(DataObject dataObject) {
- super(dataObject);
- }
-
- public String getBaseDataObjectType() {
- return BASE_DATA_OBJECT_TYPE;
- }
-
- //Accessors
- public String getFunctionName() {
- return (String)get(FUNCTIONNAME);
- }
-
- public void setFunctionName(String functionName) {
- set(FUNCTIONNAME, functionName);
- }
-}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunctionCollection.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunctionCollection.java
deleted file mode 100644
index 2b590807a..000000000
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationFunctionCollection.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * OrganizationFunctionCollection
- */
-
-package com.arsdigita.cms.contenttypes;
-
-import com.arsdigita.domain.DomainCollection;
-import com.arsdigita.persistence.DataCollection;
-import org.apache.log4j.Logger;
-
-/**
- * @author Jens Pelzetter
- */
-public class OrganizationFunctionCollection extends DomainCollection {
-
- public OrganizationFunctionCollection(DataCollection collection) {
- super(collection);
- }
-
- public final String getFunctionName() {
- return (String)getOrganizationFunction().getFunctionName();
- }
-
- public OrganizationFunction getOrganizationFunction() {
- //return (OrganizationFunction)getDomainObject();
- return new OrganizationFunction(m_dataCollection.getDataObject());
- }
-
-}
\ 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..3d7bd019d
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRole.java
@@ -0,0 +1,74 @@
+package com.arsdigita.cms.contenttypes;
+
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.ContentPage;
+import com.arsdigita.cms.ContentSection;
+import com.arsdigita.cms.ImageAsset;
+import com.arsdigita.cms.TextAsset;
+import com.arsdigita.kernel.ACSObject;
+import com.arsdigita.domain.DataObjectNotFoundException;
+import com.arsdigita.domain.DomainObjectFactory;
+import com.arsdigita.kernel.permissions.PermissionService;
+import com.arsdigita.persistence.DataObject;
+import com.arsdigita.persistence.OID;
+
+import org.apache.log4j.Logger;
+
+import java.math.BigDecimal;
+
+public class OrganizationRole extends ContentPage {
+
+ private static final Logger logger = Logger.getLogger(OrganizationRole.class);
+ public static final String ROLENAME = "rolename";
+ public static final String BASE_DATA_OBJECT_TYPE = "com.arsdigita.cms.contenttypes.OrganizationRole";
+
+ public OrganizationRole() {
+ super(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 getBaseDataObjectType() {
+ return BASE_DATA_OBJECT_TYPE;
+ }
+
+ //Accessors
+ public String getRolename() {
+ return (String) get(ROLENAME);
+ }
+
+ public void setRolename(String rolename) {
+ set(ROLENAME, rolename);
+ }
+
+ @Override
+ public ContentSection getContentSection() {
+ ContentSection ct = super.getContentSection();
+
+ if (ct != null) {
+ return ct;
+ } else {
+ ACSObject parent = getParent();
+ if ((parent != null) && parent instanceof GenericOrganization) {
+ ct = ((ContentItem) parent).getContentSection();
+ return ct;
+ }
+ }
+
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java
new file mode 100644
index 000000000..31f05f6f5
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/OrganizationRoleCollection.java
@@ -0,0 +1,23 @@
+package com.arsdigita.cms.contenttypes;
+
+import com.arsdigita.domain.DomainCollection;
+import com.arsdigita.domain.DomainObject;
+import com.arsdigita.persistence.DataCollection;
+
+public class OrganizationRoleCollection extends DomainCollection {
+
+ //public static final String versionId = "$Id: OrganizationRoleCollection.java 001 2009-05-28 12:40:00Z jensp $";
+
+ public OrganizationRoleCollection(DataCollection dataCollection) {
+ super(dataCollection);
+ }
+
+ @Override
+ public DomainObject getDomainObject() {
+ return new OrganizationRole(m_dataCollection.getDataObject());
+ }
+
+ public OrganizationRole getOrganizationRole() {
+ return (OrganizationRole) getDomainObject();
+ }
+}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertiesStep.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertiesStep.java
deleted file mode 100644
index 93e14629a..000000000
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertiesStep.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2009 Jens Pelzetter, for the Center of Social Politics of the University of Bremen
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-package com.arsdigita.cms.contenttypes.ui.genericOrganization;
-
-import com.arsdigita.bebop.Component;
-import com.arsdigita.bebop.PageState;
-import com.arsdigita.cms.ContentItem;
-import com.arsdigita.cms.ContentPage;
-import com.arsdigita.cms.ContentSection;
-import com.arsdigita.cms.ItemSelectionModel;
-import com.arsdigita.cms.contenttypes.GenericOrganization;
-import com.arsdigita.domain.DomainObject;
-import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
-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.cms.util.GlobalizationUtil;
-
-import java.text.DateFormat;
-
-public class GenericOrganizationPropertiesStep extends SimpleEditStep {
-
- public static final String EDIT_SHEET_NAME = "edit";
-
- public GenericOrganizationPropertiesStep(ItemSelectionModel itemModel,
- AuthoringKitWizard parent) {
- super(itemModel, parent);
-
- setDefaultEditKey(EDIT_SHEET_NAME);
- BasicPageForm editSheet;
-
- editSheet = new GenericOrganizationPropertyForm(itemModel, this);
- add(EDIT_SHEET_NAME, "Edit",
- new WorkflowLockedComponentAccess(editSheet, itemModel),
- editSheet.getSaveCancelSection().getCancelButton());
-
- setDisplayComponent(getGenericOrganizationPropertySheet(itemModel));
- }
-
- public static Component getGenericOrganizationPropertySheet(ItemSelectionModel itemModel) {
- DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
-
- sheet.add((String)GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.name").localize(), GenericOrganization.ORGANIZATIONNAME);
- sheet.add((String)GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.nameaddendum").localize(), GenericOrganization.ORGANIZATIONNAMEADDENDUM);
- sheet.add((String)GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.description").localize(), GenericOrganization.DESCRIPTION);
-
- if(!ContentSection.getConfig().getHideLaunchDate()) {
- sheet.add((String)GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date").localize(),
- ContentPage.LAUNCH_DATE,
- new DomainObjectPropertySheet.AttributeFormatter() {
- public String format(DomainObject item,
- String attribute,
- PageState state) {
- ContentPage page = (ContentPage)item;
- if (page.getLaunchDate() != null) {
- return DateFormat.getDateInstance(DateFormat.LONG).format(page.getLaunchDate());
- }
- else {
- return (String)GlobalizationUtil.globalize("cms.ui.unknown").localize();
- }
- }
- });
- }
-
- return sheet;
- }
-}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertyForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertyForm.java
deleted file mode 100644
index 4311e04d9..000000000
--- a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericOrganization/GenericOrganizationPropertyForm.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2009 Jens Pelzetter, for the Center of Social Politics of the University of Bremen
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
-
-package com.arsdigita.cms.contenttypes.ui.genericOrganization;
-
-import com.arsdigita.bebop.FormData;
-import com.arsdigita.bebop.FormProcessException;
-import com.arsdigita.bebop.Label;
-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.ParameterEvent;
-import com.arsdigita.bebop.event.ParameterListener;
-import com.arsdigita.bebop.form.Option;
-import com.arsdigita.bebop.form.SingleSelect;
-import com.arsdigita.bebop.form.TextArea;
-import com.arsdigita.bebop.form.TextField;
-import com.arsdigita.bebop.parameters.NotNullValidationListener;
-import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
-import com.arsdigita.bebop.parameters.ParameterModel;
-import com.arsdigita.bebop.parameters.StringParameter;
-import com.arsdigita.bebop.parameters.URLValidationListener;
-import com.arsdigita.bebop.parameters.ParameterData;
-import com.arsdigita.cms.ItemSelectionModel;
-import com.arsdigita.cms.contenttypes.GenericOrganization;
-import com.arsdigita.cms.ui.authoring.BasicPageForm;
-import com.arsdigita.domain.DomainCollection;
-import org.apache.log4j.Logger;
-import org.apache.log4j.Level;
-import com.arsdigita.cms.util.GlobalizationUtil;
-
-
-/**
- * Form to edit the properties of an organization.
- *
- * @author: Jens Pelzetter
- */
-public class GenericOrganizationPropertyForm extends BasicPageForm implements FormProcessListener, FormInitListener, FormSubmissionListener {
-
- private static final Logger s_log = Logger.getLogger(GenericOrganizationPropertyForm.class);
-
- private GenericOrganizationPropertiesStep m_step;
-
- public static final String ORGANIZATIONNAME = GenericOrganization.ORGANIZATIONNAME;
- public static final String ORGANIZATIONNAMEADDENDUM = GenericOrganization.ORGANIZATIONNAMEADDENDUM;
- 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);
- }
-
- protected void addWidgets() {
- super.addWidgets();
-
- add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.organizationname")));
- ParameterModel organizationNameParam = new StringParameter(ORGANIZATIONNAME);
- TextField organizationName = new TextField(organizationNameParam);
- add(organizationName);
-
- add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.organizationnameaddendum")));
- ParameterModel organizationNameAddendumParam = new StringParameter(ORGANIZATIONNAMEADDENDUM);
- TextField organizationNameAddendum = new TextField(organizationNameAddendumParam);
- add(organizationNameAddendum);
-
- add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.description")));
- ParameterModel descriptionParam = new StringParameter(DESCRIPTION);
- TextArea description = new TextArea(descriptionParam);
- description.setCols(40);
- description.setRows(5);
- add(description);
- }
-
- public void init(FormSectionEvent fse) {
- FormData data = fse.getFormData();
- GenericOrganization orga = (GenericOrganization)super.initBasicWidgets(fse);
-
- data.put(ORGANIZATIONNAME, orga.getOrganizationName());
- data.put(ORGANIZATIONNAMEADDENDUM, orga.getOrganizationNameAddendum());
- data.put(DESCRIPTION, orga.getDescription());
- }
-
- public void submitted(FormSectionEvent fse) {
- if (m_step != null
- && getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) {
- m_step.cancelStreamlinedCreation(fse.getPageState());
- }
- }
-
- public void process(FormSectionEvent fse) {
- FormData data = fse.getFormData();
-
- GenericOrganization orga = (GenericOrganization)super.processBasicWidgets(fse);
-
- if (orga != null
- && getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
-
- orga.setOrganizationName((String)data.get(ORGANIZATIONNAME));
- orga.setOrganizationNameAddendum((String)data.get(ORGANIZATIONNAMEADDENDUM));
- orga.setDescription((String)data.get(DESCRIPTION));
-
- orga.save();
- }
-
- if (m_step != null) {
- m_step.maybeForwardToNextStep(fse.getPageState());
- }
- }
-}
-
-
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationCreate.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationCreate.java
new file mode 100644
index 000000000..f78bd786e
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationCreate.java
@@ -0,0 +1,85 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.ColumnPanel;
+import com.arsdigita.bebop.FormData;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.PageState;
+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.cms.ContentBundle;
+import com.arsdigita.cms.ContentSection;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection;
+import com.arsdigita.cms.ui.authoring.CreationComponent;
+import com.arsdigita.cms.ui.authoring.CreationSelector;
+import com.arsdigita.ui.util.GlobalizationUtil;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class GenericOrganizationCreate extends GenericOrganizationForm implements FormInitListener, FormProcessListener, FormSubmissionListener, FormValidationListener, CreationComponent {
+ private CreationSelector m_parent;
+ private ApplyWorkflowFormSection m_workflowSection;
+
+ public GenericOrganizationCreate(ItemSelectionModel itemModel, CreationSelector parent) {
+ super("GenericOrganizationCreate", itemModel);
+ m_parent = parent;
+ m_workflowSection.setCreationSelector(m_parent);
+ m_workflowSection.setContentType(m_itemModel.getContentType());
+ addSubmissionListener(this);
+ getSaveCancelSection().getSaveButton().setButtonLabel("Create");
+ }
+
+ @Override
+ protected void addWidgets() {
+ m_workflowSection = new ApplyWorkflowFormSection();
+ add(m_workflowSection, ColumnPanel.INSERT);
+ super.addWidgets();
+ }
+
+ public ApplyWorkflowFormSection getWorkflowSection() {
+ return m_workflowSection;
+ }
+
+ public void init(FormSectionEvent event) throws FormProcessException {
+ //Nothing yet
+ }
+
+ public void submitted(FormSectionEvent event) throws FormProcessException {
+ PageState state = event.getPageState();
+
+ if(getSaveCancelSection().getCancelButton().isSelected(state)) {
+ m_parent.redirectBack(state);
+ throw new FormProcessException((String)GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.submission_canceled").localize());
+ }
+ }
+
+ public void validate(FormSectionEvent event) throws FormProcessException {
+ //Nothing yet
+ }
+
+ public void process(final FormSectionEvent event) throws FormProcessException {
+ final FormData data = event.getFormData();
+ final PageState state = event.getPageState();
+ final ContentSection section = m_parent.getContentSection(state);
+
+ final GenericOrganization orga = createGenericOrganization(state);
+
+ orga.setOrganizationName((String)data.get(ORGANIZATIONAME));
+ orga.setOrganizationNameAddendum((String)data.get(ORGANIZATIONNAMEADDENDUM));
+ orga.setDescription((String)data.get(DESCRIPTION));
+
+ final ContentBundle bundle = new ContentBundle(orga);
+ bundle.setParent(m_parent.getFolder(state));
+ bundle.setContentSection(section);
+
+ m_workflowSection.applyWorkflow(state, orga);
+
+ m_parent.editItem(state, orga);
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEdit.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEdit.java
new file mode 100644
index 000000000..3fa359f16
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEdit.java
@@ -0,0 +1,42 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.Component;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
+import com.arsdigita.cms.ui.authoring.SimpleEditStep;
+import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
+import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
+import com.arsdigita.ui.util.GlobalizationUtil;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class GenericOrganizationEdit extends SimpleEditStep {
+
+ public GenericOrganizationEdit(ItemSelectionModel itemModel, AuthoringKitWizard parent) {
+ super(itemModel, parent);
+
+ setDefaultEditKey("edit");
+ GenericOrganizationForm form = getForm(itemModel);
+ add("edit", "Edit", new WorkflowLockedComponentAccess(form, itemModel), form.getSaveCancelSection().getCancelButton());
+
+ setDisplayComponent(getGenericOrganizationPropertiesSheet(itemModel));
+ }
+
+ protected GenericOrganizationForm getForm(ItemSelectionModel model) {
+ return new GenericOrganizationEditForm(model, this);
+ }
+
+ public Component getGenericOrganizationPropertiesSheet(ItemSelectionModel model) {
+
+ DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(model);
+
+ 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);
+
+ return sheet;
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEditForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEditForm.java
new file mode 100644
index 000000000..f33869d34
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationEditForm.java
@@ -0,0 +1,77 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.FormData;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.event.FormSectionEvent;
+import com.arsdigita.bebop.event.FormSubmissionListener;
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.Folder;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.ui.authoring.SimpleEditStep;
+import com.arsdigita.util.Assert;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class GenericOrganizationEditForm extends GenericOrganizationForm implements FormSubmissionListener {
+
+ private SimpleEditStep m_step;
+
+ public GenericOrganizationEditForm(ItemSelectionModel itemModel, SimpleEditStep step) {
+ super("GenericOrganizationEditForm", itemModel);
+ addSubmissionListener(this);
+ m_step = step;
+ }
+
+ public void init(FormSectionEvent e) throws FormProcessException {
+ super.initBasicWidgets(e);
+ }
+
+ public void submitted(FormSectionEvent fse) {
+ if (getSaveCancelSection().getCancelButton().isSelected(fse.getPageState())) {
+ m_step.cancelStreamlinedCreation(fse.getPageState());
+ }
+ }
+
+ public void process(FormSectionEvent fse) throws FormProcessException {
+ PageState state = fse.getPageState();
+ GenericOrganization orga = processBasicWidgets(fse);
+ m_step.maybeForwardToNextStep(fse.getPageState());
+ }
+
+ /**
+ * This function does nothing real usefull yet. It will maybe removed later.
+ *
+ * @param fse
+ * @throws FormProcessException
+ */
+ public void validate(FormSectionEvent fse) throws FormProcessException {
+ PageState state = fse.getPageState();
+ FormData data = fse.getFormData();
+
+ GenericOrganization orga = (GenericOrganization) m_itemModel.getSelectedObject(state);
+ Assert.exists(orga, GenericOrganization.class);
+
+ String newOrganizationName = (String)data.get(GenericOrganizationForm.ORGANIZATIONAME);
+ String oldOrganizationName = orga.getOrganizationName();
+
+ boolean valid = true;
+
+ if(!valid) {
+ throw new FormProcessException("error");
+ }
+ }
+
+ private Folder getParentFolder(GenericOrganization orga) {
+ ContentItem parent = (ContentItem)orga.getParent();
+ while((parent != null)
+ && (!(parent instanceof Folder))) {
+ parent = (ContentItem)parent.getParent();
+ }
+
+ return (Folder)parent;
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationForm.java
new file mode 100644
index 000000000..0adfb25df
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationForm.java
@@ -0,0 +1,142 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+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.event.FormInitListener;
+import com.arsdigita.bebop.event.FormProcessListener;
+import com.arsdigita.bebop.event.FormSectionEvent;
+import com.arsdigita.bebop.event.FormValidationListener;
+import com.arsdigita.bebop.SaveCancelSection;
+import com.arsdigita.bebop.form.TextArea;
+import com.arsdigita.bebop.form.TextField;
+import com.arsdigita.bebop.parameters.NotNullValidationListener;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.persistence.metadata.Element;
+import com.arsdigita.ui.util.GlobalizationUtil;
+import com.arsdigita.util.Assert;
+import javax.servlet.ServletException;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public abstract class GenericOrganizationForm extends FormSection implements FormInitListener, FormProcessListener, FormValidationListener {
+
+ protected ItemSelectionModel m_itemModel;
+ protected SaveCancelSection m_saveCancelSection;
+
+ private Label m_script = new Label("");
+
+ public static final String ORGANIZATIONAME = GenericOrganization.ORGANIZATIONNAME;
+ public static final String ORGANIZATIONNAMEADDENDUM = GenericOrganization.ORGANIZATIONNAMEADDENDUM;
+ public static final String DESCRIPTION = GenericOrganization.DESCRIPTION;
+ private static final Logger logger = Logger.getLogger(GenericOrganizationForm.class);
+
+ public GenericOrganizationForm(String formName, ItemSelectionModel itemModel) {
+ super(new ColumnPanel(2));
+
+ m_itemModel = itemModel;
+
+ ColumnPanel panel = (ColumnPanel) getPanel();
+ panel.setBorder(false);
+ panel.setPadColor("#ffffff");
+ panel.setColumnWidth(1, "20%");
+ panel.setColumnWidth(2, "80%");
+ panel.setWidth("100%");
+
+ addWidgets();
+
+ addSaveCancelSection();
+
+ addInitListener(this);
+ addProcessListener(this);
+ addValidationListener(this);
+ }
+
+ public void addSaveCancelSection() {
+ m_saveCancelSection = new SaveCancelSection();
+ add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
+ }
+
+ public SaveCancelSection getSaveCancelSection() {
+ return m_saveCancelSection;
+ }
+
+ protected void addWidgets() {
+ add(new Label(GlobalizationUtil.globalize("cms.contenttypes.genericorganization.ui.organizationname")));
+ TextField organizationName = new TextField(ORGANIZATIONAME);
+ 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);
+ }
+
+ public abstract void init (FormSectionEvent e) throws FormProcessException;
+ public abstract void process (FormSectionEvent e) throws FormProcessException;
+ public abstract void validate (FormSectionEvent e) throws FormProcessException;
+
+ public GenericOrganization initBasicWidgets(FormSectionEvent e) {
+ Assert.exists(m_itemModel, ItemSelectionModel.class);
+
+ FormData data = e.getFormData();
+ PageState state = e.getPageState();
+ GenericOrganization orga = (GenericOrganization)m_itemModel.getSelectedObject(state);
+
+ if (orga != null) {
+ data.put(ORGANIZATIONAME, orga.getOrganizationName());
+ data.put(ORGANIZATIONNAMEADDENDUM, orga.getOrganizationNameAddendum());
+ data.put(DESCRIPTION, orga.getDescription());
+ }
+
+ return orga;
+ }
+
+ public GenericOrganization processBasicWidgets(FormSectionEvent e) {
+ Assert.exists(m_itemModel, ItemSelectionModel.class);
+
+ FormData data = e.getFormData();
+ PageState state = e.getPageState();
+ GenericOrganization orga = (GenericOrganization)m_itemModel.getSelectedObject(state);
+
+ if(orga != null) {
+ orga.setOrganizationName((String)data.get(ORGANIZATIONAME));
+ orga.setOrganizationNameAddendum((String)data.get(ORGANIZATIONNAMEADDENDUM));
+ orga.setDescription((String)data.get(DESCRIPTION));
+ }
+
+ return orga;
+ }
+
+ public GenericOrganization createGenericOrganization(PageState state) throws FormProcessException {
+ Assert.exists(m_itemModel, ItemSelectionModel.class);
+
+ GenericOrganization orga = null;
+
+ try {
+ orga = (GenericOrganization)m_itemModel.createItem();
+ } catch(ServletException e) {
+ logger.error("ServletException: " + e.getMessage(), e);
+ throw new FormProcessException(e.getMessage(), e);
+ }
+
+ if(m_itemModel.getSelectedKey(state) == null) {
+ m_itemModel.setSelectedObject(state, orga);
+ }
+
+ return orga;
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationViewRoles.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationViewRoles.java
new file mode 100644
index 000000000..60bffaee0
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/GenericOrganizationViewRoles.java
@@ -0,0 +1,250 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.ActionLink;
+import com.arsdigita.bebop.ColumnPanel;
+import com.arsdigita.bebop.Container;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.Page;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.event.ActionEvent;
+import com.arsdigita.bebop.event.ActionListener;
+import com.arsdigita.bebop.event.ChangeEvent;
+import com.arsdigita.bebop.event.ChangeListener;
+import com.arsdigita.bebop.event.FormSectionEvent;
+import com.arsdigita.bebop.event.FormSubmissionListener;
+import com.arsdigita.bebop.event.PrintEvent;
+import com.arsdigita.bebop.event.PrintListener;
+import com.arsdigita.bebop.event.TableActionEvent;
+import com.arsdigita.bebop.event.TableActionListener;
+import com.arsdigita.bebop.parameters.BigDecimalParameter;
+import com.arsdigita.bebop.table.TableColumn;
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.SecurityManager;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.contenttypes.OrganizationRole;
+import com.arsdigita.cms.contenttypes.ui.ResettableContainer;
+import com.arsdigita.cms.dispatcher.Utilities;
+import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
+import com.arsdigita.ui.util.GlobalizationUtil;
+import com.arsdigita.util.Assert;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class GenericOrganizationViewRoles extends ResettableContainer {
+
+ /* Ids for the editing panels */
+ public static final String ROLES_TABLE = "rolesTable";
+ public static final String ROLES_EDIT = "rolesEdit";
+ public static final String ROLES_DELETE = "rolesDelete";
+
+ /* class attributes */
+ public static final String DATA_TABLE = "dataTable";
+ public static final String ACTION_LINK = "actionLink";
+ protected AuthoringKitWizard m_wizard;
+ protected ItemSelectionModel m_selectionOrganization;
+ protected ItemSelectionModel m_selectionRole;
+ protected ItemSelectionModel m_moveRole;
+ protected BigDecimalParameter m_moveParameter;
+
+ /* Visual components doing the word */
+ protected RoleTable m_roleTable;
+ protected RoleEditForm m_roleEdit;
+ protected RoleDeleteForm m_roleDelete;
+ protected ActionLink m_beginLink;
+ private Label m_moveRoleLabel;
+ private String m_typeIdStr;
+
+ public GenericOrganizationViewRoles(ItemSelectionModel selOrga, AuthoringKitWizard wizard) {
+ super();
+ m_selectionOrganization = selOrga;
+ m_wizard = wizard;
+ m_typeIdStr = wizard.getContentType().getID().toString();
+ Assert.exists(m_selectionOrganization, ItemSelectionModel.class);
+
+ add(buildRoleTable(), true);
+ add(buildRoleEdit(), false);
+ add(buildRoleDelete(), false);
+ }
+
+ protected Container buildRoleTable() {
+ ColumnPanel c = new ColumnPanel(1);
+ c.setKey(ROLES_TABLE + m_typeIdStr);
+ c.setBorderColor("#ffffff");
+ c.setPadColor("#ffffff");
+
+ m_moveParameter = new BigDecimalParameter("moveRole");
+ m_moveRole = new ItemSelectionModel(OrganizationRole.class.getName(), OrganizationRole.BASE_DATA_OBJECT_TYPE, m_moveParameter);
+ m_roleTable = new RoleTable(m_selectionOrganization, m_moveRole);
+ m_roleTable.setClassAttr(DATA_TABLE);
+
+ m_selectionRole = new ItemSelectionModel(OrganizationRole.class.getName(), OrganizationRole.BASE_DATA_OBJECT_TYPE, m_roleTable.getRowSelectionModel());
+
+ m_roleTable.setRoleModel(m_selectionRole);
+
+ Label emptyView = new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.no_roles_yet"));
+ m_roleTable.setEmptyView(emptyView);
+
+ m_moveRoleLabel = new Label("Role Name");
+ c.add(m_moveRoleLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
+
+ m_beginLink = new ActionLink((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.move_to_beginning").localize());
+ c.add(m_beginLink);
+
+ m_beginLink.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent event) {
+ PageState state = event.getPageState();
+ GenericOrganization orga = (GenericOrganization) m_selectionOrganization.getSelectedObject(state);
+
+ m_moveRole.setSelectedKey(state, null);
+ }
+ });
+
+ m_moveRole.addChangeListener(new ChangeListener() {
+
+ public void stateChanged(ChangeEvent e) {
+ PageState state = e.getPageState();
+ if (m_moveRole.getSelectedKey(state) == null) {
+ m_beginLink.setVisible(state, false);
+ m_moveRoleLabel.setVisible(state, false);
+ } else {
+ m_beginLink.setVisible(state, true);
+ m_moveRoleLabel.setVisible(state, true);
+ m_moveRoleLabel.setLabel((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.move_role_name").localize() + ((OrganizationRole) m_moveRole.getSelectedObject(state)).getRolename(), state);
+ }
+ }
+ });
+
+ m_roleTable.addTableActionListener(new TableActionListener() {
+
+ public void cellSelected(TableActionEvent e) {
+ PageState state = e.getPageState();
+
+ TableColumn col = m_roleTable.getColumnModel().get(e.getColumn().intValue());
+ String colName = (String) col.getHeaderValue();
+
+ if (RoleTable.COL_DEL.equals(colName)) {
+ onlyShowComponent(state, ROLES_DELETE + m_typeIdStr);
+ } else if (RoleTable.COL_EDIT.equals(colName)) {
+ onlyShowComponent(state, ROLES_EDIT + m_typeIdStr);
+ }
+ }
+
+ public void headSelected(TableActionEvent e) {
+ //Nothing
+ }
+ });
+
+ c.add(m_roleTable);
+
+ c.add(buildAddLink());
+
+ return c;
+ }
+
+ protected Container buildRoleEdit() {
+ ColumnPanel c = new ColumnPanel(1);
+ c.setKey(ROLES_EDIT + m_typeIdStr);
+ c.setBorderColor("#ffffff");
+ c.setPadColor("#ffffff");
+
+ c.add(new Label(new PrintListener() {
+
+ public void prepare(PrintEvent event) {
+ PageState state = event.getPageState();
+ Label label = (Label) event.getTarget();
+
+ if (m_selectionRole.getSelectedKey(state) == null) {
+ label.setLabel((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.add_role").localize());
+ } else {
+ label.setLabel((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.edit_role").localize());
+ }
+ }
+ }));
+
+ m_roleEdit = new RoleEditForm(m_selectionOrganization, m_selectionRole, this);
+ c.add(m_roleEdit);
+
+ c.add(buildViewAllLink());
+ c.add(buildAddLink());
+
+ return c;
+ }
+
+ protected Container buildRoleDelete() {
+ ColumnPanel c = new ColumnPanel(1);
+ c.setKey(ROLES_DELETE + m_typeIdStr);
+ c.setBorderColor("#ffffff");
+ c.setPadColor("#ffffff");
+
+ c.add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.delete_role")));
+ m_roleDelete = new RoleDeleteForm(m_selectionOrganization, m_selectionRole);
+ m_roleDelete.addSubmissionListener(new FormSubmissionListener() {
+
+ public void submitted(FormSectionEvent e) throws FormProcessException {
+ PageState state = e.getPageState();
+ onlyShowComponent(state, ROLES_TABLE + m_typeIdStr);
+ }
+ });
+ c.add(m_roleDelete);
+
+ c.add(buildViewAllLink());
+
+ return c;
+ }
+
+ protected ActionLink buildViewAllLink() {
+ ActionLink viewAllLink = new ActionLink((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.view_all_roles").localize());
+ viewAllLink.setClassAttr(ACTION_LINK);
+ viewAllLink.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ onlyShowComponent(e.getPageState(), ROLES_TABLE + m_typeIdStr);
+ }
+ });
+
+ return viewAllLink;
+ }
+
+ protected ActionLink buildAddLink() {
+ ActionLink addLink = new ActionLink((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorgnization.add_new_role").localize()) {
+
+ @Override
+ public boolean isVisible(PageState state) {
+ SecurityManager sm = Utilities.getSecurityManager(state);
+ ContentItem item = (ContentItem) m_selectionOrganization.getSelectedObject(state);
+
+ return (super.isVisible(state) && sm.canAccess(state.getRequest(), SecurityManager.EDIT_ITEM, item));
+ }
+ };
+
+ addLink.setClassAttr(ACTION_LINK);
+ addLink.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ PageState state = e.getPageState();
+ m_selectionRole.clearSelection(state);
+ onlyShowComponent(state, ROLES_EDIT + m_typeIdStr);
+ }
+ });
+
+ return addLink;
+ }
+
+ @Override
+ public void register(Page p) {
+ super.register(p);
+ p.addGlobalStateParam(m_moveParameter);
+ p.setVisibleDefault(m_beginLink, false);
+ p.setVisibleDefault(m_moveRoleLabel, false);
+
+ }
+
+ public String getTypeIdStr() {
+ return m_typeIdStr;
+ }
+}
\ No newline at end of file
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleDeleteForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleDeleteForm.java
new file mode 100644
index 000000000..0ab3eeb4a
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleDeleteForm.java
@@ -0,0 +1,95 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.ColumnPanel;
+import com.arsdigita.bebop.Form;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.SaveCancelSection;
+import com.arsdigita.bebop.event.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.cms.contenttypes.OrganizationRole;
+import com.arsdigita.cms.util.GlobalizationUtil;
+import com.arsdigita.util.Assert;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class RoleDeleteForm extends Form implements FormInitListener, FormSubmissionListener, FormProcessListener {
+
+ private static final Logger logger = Logger.getLogger(RoleDeleteForm.class);
+ protected ItemSelectionModel m_selectionOrganization;
+ protected ItemSelectionModel m_selectionRole;
+ protected SaveCancelSection m_saveCancelSection;
+ private Label m_roleNameLabel;
+
+ public RoleDeleteForm(ItemSelectionModel selectionOrganization, ItemSelectionModel selectionRole) {
+ super("RoleDeleteForm", new ColumnPanel(2));
+
+ m_selectionOrganization = selectionOrganization;
+ m_selectionRole = selectionRole;
+
+ ColumnPanel panel = (ColumnPanel) getPanel();
+ panel.setBorder(false);
+ panel.setPadColor("#ffffff");
+ panel.setColumnWidth(1, "20%");
+ panel.setColumnWidth(2, "80%");
+ panel.setWidth("100%");
+
+ m_roleNameLabel = new Label("Role Name");
+ add(m_roleNameLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
+ addSaveCancelSection();
+
+ addInitListener(this);
+ addSubmissionListener(this);
+ addProcessListener(this);
+ }
+
+ protected SaveCancelSection addSaveCancelSection() {
+ m_saveCancelSection = new SaveCancelSection();
+ m_saveCancelSection.getSaveButton().setButtonLabel("Delete");
+ add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
+ return m_saveCancelSection;
+ }
+
+ public void init(FormSectionEvent e) throws FormProcessException {
+ PageState state = e.getPageState();
+
+ OrganizationRole role = (OrganizationRole) m_selectionRole.getSelectedObject(state);
+
+ if(role == null) {
+ logger.error("No role selected");
+ }
+ else {
+ m_roleNameLabel.setLabel(role.getRolename(), state);
+ }
+ }
+
+ public void submitted(FormSectionEvent e) throws FormProcessException {
+ PageState state = e.getPageState();
+
+ if (m_saveCancelSection.getCancelButton().isSelected(state)) {
+ throw new FormProcessException((String) GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.submission_canceled").localize());
+ }
+ }
+
+ public void process(FormSectionEvent e) throws FormProcessException {
+ PageState state = e.getPageState();
+
+ GenericOrganization orga = (GenericOrganization) m_selectionOrganization.getSelectedObject(state);
+ OrganizationRole role = (OrganizationRole) m_selectionRole.getSelectedObject(state);
+
+ Assert.exists(orga, GenericOrganization.class);
+ Assert.exists(role, OrganizationRole.class);
+
+ orga.removeOrganizationRole(role);
+
+ logger.info(String.format("role %s delete", m_selectionRole.getSelectedKey(state)));
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleEditForm.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleEditForm.java
new file mode 100644
index 000000000..9321b3bb5
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleEditForm.java
@@ -0,0 +1,168 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.ColumnPanel;
+import com.arsdigita.bebop.Form;
+import com.arsdigita.bebop.FormData;
+import com.arsdigita.bebop.FormProcessException;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.Page;
+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.form.TextField;
+import com.arsdigita.bebop.parameters.BigDecimalParameter;
+import com.arsdigita.bebop.parameters.NotNullValidationListener;
+import com.arsdigita.bebop.parameters.TrimmedStringParameter;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.contenttypes.OrganizationRole;
+import com.arsdigita.cms.util.GlobalizationUtil;
+import com.arsdigita.domain.DataObjectNotFoundException;
+import com.arsdigita.util.UncheckedWrapperException;
+import java.math.BigDecimal;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class RoleEditForm extends Form {
+
+ private static final Logger logger = Logger.getLogger(RoleEditForm.class);
+
+ private ItemSelectionModel m_selectionOrganization;
+ private ItemSelectionModel m_selectionRole;
+
+ //private BigDecimalParameter m_textParam;
+ private GenericOrganizationViewRoles m_container;
+
+ private SaveCancelSection m_saveCancelSection;
+
+ public static final String ROLENAME = "rolename";
+
+ public RoleEditForm(ItemSelectionModel selectionOrganization, ItemSelectionModel selectionRole) {
+ this(selectionOrganization, selectionRole, null);
+ }
+
+ public RoleEditForm(ItemSelectionModel selectionOrganization, ItemSelectionModel selectionRole, GenericOrganizationViewRoles container) {
+ super("RoleEditForm", new ColumnPanel(2));
+
+ m_selectionOrganization = selectionOrganization;
+ m_selectionRole = selectionRole;
+ m_container = container;
+
+ setMethod(Form.POST);
+ setEncType("multipart/form-data");
+
+ ColumnPanel panel = (ColumnPanel)getPanel();
+ panel.setBorder(false);
+ panel.setPadColor("#ffffff");
+ panel.setColumnWidth(1, "20%");
+ panel.setColumnWidth(2, "80%");
+ panel.setWidth("100%");
+
+ addWidgets();
+ addSaveCancelSection();
+
+ addInitListener(new RoleInitListener());
+ addSubmissionListener(new RoleSubmissionListener());
+ addProcessListener(new RoleProcessListener());
+ }
+
+ protected SaveCancelSection addSaveCancelSection() {
+ m_saveCancelSection = new SaveCancelSection();
+ add(m_saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
+ return m_saveCancelSection;
+ }
+
+ public SaveCancelSection getSaveCancelSection() {
+ return m_saveCancelSection;
+ }
+
+ protected void addWidgets() {
+ logger.info("Adding widgets for role form...");
+ add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.rolename")));
+ TextField nameWidget = new TextField(new TrimmedStringParameter(ROLENAME));
+ nameWidget.addValidationListener(new NotNullValidationListener());
+ add(nameWidget);
+ }
+
+ private class RoleInitListener implements FormInitListener {
+ public void init(FormSectionEvent event) throws FormProcessException {
+ PageState state = event.getPageState();
+ FormData data = event.getFormData();
+
+ if(m_selectionRole.getSelectedKey(state) != null) {
+ BigDecimal id = new BigDecimal(m_selectionRole.getSelectedKey(state).toString());
+
+ try {
+ OrganizationRole role = new OrganizationRole(id);
+
+ data.put(ROLENAME, role.getRolename());
+ } catch(DataObjectNotFoundException e) {
+ logger.error(String.format("Role(%d) could not be found", id));
+ }
+ }
+ }
+ }
+
+ private class RoleSubmissionListener implements FormSubmissionListener {
+ public void submitted(FormSectionEvent event) throws FormProcessException {
+ PageState state = event.getPageState();
+
+ if((m_saveCancelSection.getCancelButton().isSelected(state)) &&
+ (m_container != null)) {
+ m_container.onlyShowComponent(state, GenericOrganizationViewRoles.ROLES_TABLE + m_container.getTypeIdStr());
+ throw new FormProcessException((String)GlobalizationUtil.globalize("cms.contenttypes.ui.genericorganization.submission_canceled").localize());
+ }
+ }
+ }
+
+ private class RoleProcessListener implements FormProcessListener {
+ public void process(FormSectionEvent event) throws FormProcessException {
+ logger.info("Processing edit event...");
+ PageState state = event.getPageState();
+ FormData data = event.getFormData();
+
+ BigDecimal id = new BigDecimal(m_selectionOrganization.getSelectedKey(state).toString());
+ GenericOrganization orga = null;
+ try {
+ orga = new GenericOrganization(id);
+ } catch(DataObjectNotFoundException e) {
+ throw new UncheckedWrapperException(e);
+ }
+
+ //Get role or create new one if role is not existing yet
+ OrganizationRole role = (OrganizationRole)m_selectionRole.getSelectedObject(state);
+ if(role == null) {
+ role = createRole(event, orga);
+ orga.addOrganizationRole(role);
+ }
+
+ role.setRolename((String)data.get(OrganizationRole.ROLENAME));
+ }
+ }
+
+ protected OrganizationRole createRole(FormSectionEvent event, GenericOrganization orga) {
+ logger.info("creating new role...");
+
+ PageState state = event.getPageState();
+ FormData data = event.getFormData();
+
+ OrganizationRole role = new OrganizationRole();
+
+ role.setRolename((String)data.get(ROLENAME));
+ role.setName(orga.getName() + ": " + (String)data.get(OrganizationRole.ROLENAME));
+
+ logger.info("new role created");
+ return role;
+ }
+
+ @Override
+ public void register(Page page) {
+ super.register(page);
+ }
+}
diff --git a/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleTable.java b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleTable.java
new file mode 100644
index 000000000..5290eb121
--- /dev/null
+++ b/ccm-cms-types-genericorganization/src/com/arsdigita/cms/contenttypes/ui/genericorganization/RoleTable.java
@@ -0,0 +1,215 @@
+package com.arsdigita.cms.contenttypes.ui.genericorganization;
+
+import com.arsdigita.bebop.Component;
+import com.arsdigita.bebop.ControlLink;
+import com.arsdigita.bebop.Label;
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.Table;
+import com.arsdigita.bebop.event.TableActionEvent;
+import com.arsdigita.bebop.event.TableActionListener;
+import com.arsdigita.bebop.table.TableCellRenderer;
+import com.arsdigita.bebop.table.TableColumn;
+import com.arsdigita.bebop.table.TableColumnModel;
+import com.arsdigita.bebop.table.TableModel;
+import com.arsdigita.bebop.table.TableModelBuilder;
+import com.arsdigita.cms.ContentItem;
+import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.cms.SecurityManager;
+import com.arsdigita.cms.contenttypes.GenericOrganization;
+import com.arsdigita.cms.contenttypes.OrganizationRole;
+import com.arsdigita.cms.contenttypes.OrganizationRoleCollection;
+import com.arsdigita.cms.dispatcher.Utilities;
+import com.arsdigita.domain.DomainObjectFactory;
+import com.arsdigita.persistence.OID;
+import com.arsdigita.util.LockableImpl;
+import java.math.BigDecimal;
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * @author Jens Pelzetter
+ */
+public class RoleTable extends Table {
+
+ private final static Logger logger = Logger.getLogger(RoleTable.class);
+
+ // columns headings
+ public static final String COL_TITLE = "Role";
+ public static final String COL_EDIT = "Edit";
+ public static final String COL_MOVE = "Move";
+ public static final String COL_DEL = "Delete";
+ private ItemSelectionModel m_selectionOrganization;
+ private ItemSelectionModel m_selectionRole;
+ private ItemSelectionModel m_moveRole;
+
+ public RoleTable(ItemSelectionModel selOrga, ItemSelectionModel moveRole) {
+ super();
+ m_selectionOrganization = selOrga;
+ m_moveRole = moveRole;
+
+ TableColumnModel model = getColumnModel();
+ model.add(new TableColumn(0, COL_TITLE));
+ model.add(new TableColumn(1, COL_EDIT));
+ model.add(new TableColumn(2, COL_MOVE));
+ model.add(new TableColumn(3, COL_DEL));
+
+ model.get(1).setCellRenderer(new RoleTableCellRenderer(true));
+ model.get(2).setCellRenderer(new RoleTableCellRenderer(true));
+ model.get(3).setCellRenderer(new RoleTableCellRenderer(true));
+
+ setModelBuilder(new RoleTableModelBuilder(m_selectionOrganization, m_moveRole));
+
+ addTableActionListener(new TableActionListener() {
+
+ public void cellSelected(TableActionEvent e) {
+ PageState state = e.getPageState();
+
+ TableColumn col = getColumnModel().get(e.getColumn().intValue());
+ String colName = (String) col.getHeaderValue();
+
+ if (COL_MOVE.equals(colName)) {
+ if (m_moveRole.getSelectedKey(state) == null) {
+ m_moveRole.setSelectedKey(state, m_selectionRole.getSelectedKey(state));
+ } else {
+ GenericOrganization orga = (GenericOrganization) m_selectionOrganization.getSelectedObject(state);
+
+ BigDecimal id = (BigDecimal) m_moveRole.getSelectedKey(state);
+ OrganizationRole role = (OrganizationRole) DomainObjectFactory.newInstance(new OID(OrganizationRole.BASE_DATA_OBJECT_TYPE, id));
+
+ BigDecimal dest = new BigDecimal((String) e.getRowKey());
+ OrganizationRole destRole = (OrganizationRole) DomainObjectFactory.newInstance(new OID(OrganizationRole.BASE_DATA_OBJECT_TYPE, "dest"));
+
+ m_moveRole.setSelectedKey(state, null);
+ }
+ }
+ }
+
+ public void headSelected(TableActionEvent e) {
+ //Nothing
+ }
+ });
+
+ }
+
+ public void setRoleModel(ItemSelectionModel itemModel) {
+ if (itemModel == null) {
+ logger.warn("null item model");
+ }
+ m_selectionRole = itemModel;
+ }
+
+ protected class RoleTableModelBuilder extends LockableImpl implements TableModelBuilder {
+
+ protected ItemSelectionModel m_selectionOrganization;
+ protected ItemSelectionModel m_moveRole;
+
+ public RoleTableModelBuilder(ItemSelectionModel selectionOrganization, ItemSelectionModel moveRole) {
+ m_selectionOrganization = selectionOrganization;
+ m_moveRole = moveRole;
+ }
+
+ public TableModel makeModel(Table table, PageState state) {
+ table.getRowSelectionModel().clearSelection(state);
+
+ GenericOrganization orga = (GenericOrganization) m_selectionOrganization.getSelectedObject(state);
+
+ return new RoleTableModel(table, state, orga, m_moveRole);
+ }
+ }
+
+ protected class RoleTableModel implements TableModel {
+
+ private TableColumnModel m_colModel;
+ private RoleTable m_table;
+ private PageState m_state;
+ private OrganizationRoleCollection m_roles;
+ private ItemSelectionModel m_moveRole;
+ private OrganizationRole m_role;
+
+ public RoleTableModel(Table table, PageState state, GenericOrganization orga, ItemSelectionModel moveRole) {
+ m_colModel = table.getColumnModel();
+ m_table = (RoleTable) table;
+ m_state = state;
+ m_roles = orga.getOrganizationRoles();
+ m_moveRole = moveRole;
+ }
+
+ public int getColumnCount() {
+ return m_colModel.size();
+ }
+
+ public boolean nextRow() {
+ if (m_roles.next()) {
+ m_role = m_roles.getOrganizationRole();
+ return true;
+ }
+ return false;
+ }
+
+ public Object getElementAt(int columnIndex) {
+ if (m_colModel == null) {
+ return null;
+ }
+
+ TableColumn col = m_colModel.get(columnIndex);
+ String colName = (String) col.getHeaderValue();
+
+ if (COL_TITLE.equals(colName)) {
+ return m_role.getRolename();
+ } else if(COL_EDIT.equals(colName)) {
+ return "edit";
+ } else if(COL_DEL.equals(colName)) {
+ return "delete";
+ } else if(COL_MOVE.equals(colName)) {
+ if(m_moveRole.getSelectedKey(m_state) == null) {
+ return "move";
+ } else {
+ return "move below here";
+ }
+ }
+
+ return null;
+ }
+
+ public Object getKeyAt(int columnIndex) {
+ return m_role.getID();
+ }
+ }
+
+ public class RoleTableCellRenderer extends LockableImpl implements TableCellRenderer {
+
+ private boolean m_active;
+
+ public RoleTableCellRenderer() {
+ this(false);
+ }
+
+ public RoleTableCellRenderer(boolean active) {
+ m_active = active;
+ }
+
+ public Component getComponent(Table table, PageState state, Object value, boolean isSelected, Object key, int row, int column) {
+ Component ret = null;
+ SecurityManager sm = Utilities.getSecurityManager(state);
+ ContentItem item = (ContentItem) m_selectionOrganization.getSelectedObject(state);
+
+ boolean active = m_active && sm.canAccess(state.getRequest(), SecurityManager.EDIT_ITEM, item);
+
+ if (value instanceof Component) {
+ ret = (Component) value;
+ } else {
+ if (value == null) {
+ ret = new Label("", false);
+ } else {
+ if (active) {
+ ret = new ControlLink(value.toString());
+ } else {
+ ret = new Label(value.toString());
+ }
+ }
+ }
+
+ return ret;
+ }
+ }
+}