CT Contact nach ccm-ldn-types-contact verschoben. Läßt sich nicht zudammen mit dem neuen Contact installieren.

git-svn-id: https://svn.libreccm.org/ccm/trunk@443 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-05-26 11:16:44 +00:00
parent 3348d271ce
commit ade5b33dd6
39 changed files with 3317 additions and 0 deletions

View File

@ -0,0 +1 @@
build

View File

@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ccm:application xmlns:ccm="http://ccm.redhat.com/ccm-project"
name="ccm-ldn-types-contact"
prettyName="Red Hat CCM Content Types"
version="6.6.0"
release="1"
webapp="ROOT">
<ccm:dependencies>
<ccm:requires name="ccm-core" version="6.6.0" relation="ge"/>
<ccm:requires name="ccm-cms" version="6.6.0" relation="ge"/>
</ccm:dependencies>
<ccm:directories>
<ccm:directory name="pdl"/>
<ccm:directory name="sql"/>
<ccm:directory name="src"/>
</ccm:directories>
<ccm:contacts>
<ccm:contact uri="http://www.redhat.com/software/rhea" type="website"/>
<ccm:contact uri="mailto:rhea@redhat.com" type="support"/>
</ccm:contacts>
<ccm:description>
The London Contact Content Type for the Red Hat CCM CMS.
</ccm:description>
</ccm:application>

View File

@ -0,0 +1,88 @@
//
// Copyright (C) 2004 Red Hat Inc. 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
//
// $Id: Contact.pdl 1689 2007-10-26 11:06:23Z chrisg23 $
// $DateTime: 2004/08/17 23:15:09 $
model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentItem;
// object type to hold Contact content type
object type Contact extends ContentPage {
String [0..1] givenName = ct_contacts.given_name VARCHAR(1000);
String [0..1] familyName = ct_contacts.family_name VARCHAR(1000);
String [0..1] suffix = ct_contacts.suffix VARCHAR(100);
String [0..1] emails = ct_contacts.emails VARCHAR(500);
String [0..1] description = ct_contacts.description VARCHAR(2000);
String [0..1] orgName = ct_contacts.orgname VARCHAR(2000);
String [0..1] deptName = ct_contacts.deptname VARCHAR(2000);
String [0..1] role = ct_contacts.role VARCHAR(2000);
// type of contact e.g. Enquiry,Complaint etc...
ContactType [0..1] contactType = join ct_contacts.type_id
to ct_contact_types.type_id;
component ContactAddress [0..1] contactAddress = join ct_contacts.address_id
to ct_contact_address.address_id;
component ContactPhone [0..n] phones = join ct_contacts.contact_id
to ct_contact_phones.contact_id;
reference key ( ct_contacts.contact_id );
}
association {
Contact[0..1] associatedContactForItem =
join cms_items.item_id to contact_content_item_map.item_id,
join contact_content_item_map.contact_id to ct_contacts.contact_id;
ContentItem[0..n] associatedContentItemsForContact =
join ct_contacts.contact_id to contact_content_item_map.contact_id,
join contact_content_item_map.item_id to cms_items.item_id;
}
// the above association works fine for adding but for some strange reason when
// you try to remove an item from the association it also tries to delete it
// so instead you have to use a data operation
data operation removeContactFromContentItemAssociation {
do {
delete from contact_content_item_map where item_id = :itemID
}
}
data operation removeContactFromAllAssociations {
do {
delete from contact_content_item_map where contact_id = :contactID
}
}
query getContactForItem {
BigDecimal contactID;
BigDecimal itemID;
do {
select contact_id, item_id
from
contact_content_item_map
where
item_id = :itemID
} map {
contactID = contact_id;
itemID = item_id;
}
}

View File

@ -0,0 +1,42 @@
//
// Copyright (C) 2004 Red Hat Inc. 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
//
// $Id: ContactAddress.pdl 287 2005-02-22 00:29:02Z sskracic $
// $DateTime: 2004/08/17 23:15:09 $
model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
// object type to hold ContactAddress domain object type
object type ContactAddress extends ContentItem {
String [0..1] saon = ct_contact_address.saon VARCHAR(2000);
String [1..1] paon = ct_contact_address.paon VARCHAR(2000);
String [1..1] streetDesc = ct_contact_address.street_desc VARCHAR(2000);
String [0..1] streetRefNo =
ct_contact_address.unique_street_ref_no VARCHAR(2000);
String [0..1] locality = ct_contact_address.locality VARCHAR(2000);
String [0..1] town = ct_contact_address.town VARCHAR(1000);
String [0..1] administrativeArea =
ct_contact_address.administrativeArea VARCHAR(2000);
String [0..1] postTown = ct_contact_address.post_town VARCHAR(1000);
String [0..1] postCode = ct_contact_address.post_code VARCHAR(1000);
String [0..1] referenceNo =
ct_contact_address.unique_prop_ref_no VARCHAR(2000);
reference key ( ct_contact_address.address_id );
}

View File

@ -0,0 +1,31 @@
//
// Copyright (C) 2004 Red Hat Inc. 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
//
// $Id: ContactPhone.pdl 287 2005-02-22 00:29:02Z sskracic $
// $DateTime: 2004/08/17 23:15:09 $
model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
object type ContactPhone extends ContentItem{
String [1..1] phoneType = ct_contact_phones.phoneType VARCHAR(100);
String [1..1] phoneNumber = ct_contact_phones.phoneNumber VARCHAR(100);
reference key ( ct_contact_phones.phone_id );
}

View File

@ -0,0 +1,32 @@
//
// Copyright (C) 2004 Red Hat Inc. 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
//
// $Id: ContactType.pdl 287 2005-02-22 00:29:02Z sskracic $
// $DateTime: 2004/08/17 23:15:09 $
model com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.ContentItem;
// object type to hold ContactType object type
object type ContactType extends ContentItem {
String [1..1] typeName = ct_contact_types.type_name VARCHAR(1000);
reference key ( ct_contact_types.type_id );
}

View File

@ -0,0 +1,16 @@
create table contact_content_item_map (
item_id INTEGER not null
constraint cont_con_ite_map_ite_i_p_scqe9
primary key,
-- referential constraint for item_id deferred due to circular dependencies
contact_id INTEGER not null
-- referential constraint for contact_id deferred due to circular dependencies
);
alter table contact_content_item_map add
constraint cont_con_ite_map_con_i_f_lanid foreign key (contact_id)
references ct_contacts(contact_id);
alter table contact_content_item_map add
constraint cont_con_ite_map_ite_i_f_fr0po foreign key (item_id)
references cms_items(item_id);

View File

@ -0,0 +1,22 @@
--
-- Copyright (C) 2004 Red Hat Inc. 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
--
-- $Id: oracle-se-create.sql 287 2005-02-22 00:29:02Z sskracic $
-- $DateTime: 2004/08/17 23:15:09 $
@@ ddl/oracle-se/create.sql
@@ ddl/oracle-se/deferred.sql

View File

@ -0,0 +1,23 @@
--
-- Copyright (C) 2004 Red Hat Inc. 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
--
-- $Id: postgres-create.sql 287 2005-02-22 00:29:02Z sskracic $
-- $DateTime: 2004/08/17 23:15:09 $
\i ddl/postgres/create.sql
\i ddl/postgres/deferred.sql

View File

@ -0,0 +1,19 @@
--
-- Copyright (C) 2007 Magpie. 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
--
@@ ../default/upgrade/6.5.0-6.5.1/contact_content_item_map_table.sql

View File

@ -0,0 +1,21 @@
--
-- Copyright (C) 2007 Magpie. All Rights Reserved.
--
-- The contents of this file are subject to the CCM Public
-- License (the "License"); you may not use this file except in
-- compliance with the License. You may obtain a copy of the
-- License at http://www.redhat.com/licenses/ccmpl.html.
--
-- Software distributed under the License is distributed on an
-- "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
-- or implied. See the License for the specific language governing
-- rights and limitations under the License.
--
\echo Red Hat Enterprise CMS 6.5.0 -> 6.5.1 Upgrade Script (PostgreSQL)
begin;
\i ../default/upgrade/6.5.0-6.5.1/contact_content_item_map_table.sql
commit;

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<ctd:content-types xmlns:ctd="http://xmlns.redhat.com/cms/content-types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.redhat.com/cms/content-types content-types.xsd">
<ctd:content-type
label="Contact"
description="A London Contact person in CMS"
objectType="com.arsdigita.cms.contenttypes.Contact"
classname="com.arsdigita.cms.contenttypes.Contact">
<ctd:authoring-kit createComponent="com.arsdigita.cms.contenttypes.ui.contact.ContactCreate">
<ctd:authoring-step
label="Contact Properties"
description="Edit the basic contact properties"
descriptionBundle="com.arsdigita.cms.contenttypes.ContactResources"
component="com.arsdigita.cms.contenttypes.ui.contact.ContactPropertiesStep"/>
<ctd:authoring-step
label="Contact Address Properties"
description="Edit the basic contact properties"
descriptionBundle="com.arsdigita.cms.contenttypes.ContactResources"
component="com.arsdigita.cms.contenttypes.ui.contact.AddressProperties"/>
<ctd:authoring-step
label="Contact Phones"
description="Edit the Phones associated with contact"
descriptionBundle="com.arsdigita.cms.contenttypes.ContactResources"
component="com.arsdigita.cms.contenttypes.ui.contact.PhonesPanel"/>
</ctd:authoring-kit>
</ctd:content-type>
</ctd:content-types>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<xrd:adapters
xmlns:xrd="http://xmlns.redhat.com/schemas/waf/xml-renderer-rules"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://rhea.redhat.com/schemas/waf/xml-renderer-rules xml-renderer-rules.xsd">
<!--
Extend adapter for ContentItemPanel to also output the associated objects.
The default properties for Contact are left as is and are inherited from ContentPage
-->
<xrd:context name="com.arsdigita.cms.dispatcher.SimpleXMLGenerator">
<xrd:adapter objectType="com.arsdigita.cms.contenttypes.Contact" extends="com.arsdigita.cms.ContentPage">
<xrd:associations rule="include">
<xrd:property name="/object/phones"/>
<xrd:property name="/object/contactType"/>
<xrd:property name="/object/contactAddress"/>
</xrd:associations>
</xrd:adapter>
</xrd:context>
</xrd:adapters>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<registry>
<!-- nothing yet -->
</registry>

View File

@ -0,0 +1,20 @@
<load>
<requires>
<table name="inits"/>
<table name="acs_objects"/>
<table name="cms_items"/>
<initializer class="com.arsdigita.cms.Initializer"/>
</requires>
<provides>
<table name="ct_contact_types"/>
<table name="ct_contact_address"/>
<table name="ct_contact_phones"/>
<table name="ct_contacts"/>
<initializer class="com.arsdigita.cms.contenttypes.ContactInitializer"/>
</provides>
<scripts>
<schema directory="ccm-ldn-types-contact"/>
<data class="com.arsdigita.cms.contenttypes.ContactLoader"/>
</scripts>
</load>

View File

@ -0,0 +1,5 @@
<upgrade>
<version from="6.5.0" to="6.5.1">
<script sql="ccm-ldn-types-contact/upgrade/::database::-6.5.0-6.5.1.sql"/>
</version>
</upgrade>

View File

@ -0,0 +1,350 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentType;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.DataOperation;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.util.Assert;
/**
* <code>DomainObject</code> class to represent Contact <code>ContentType</code>
* objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: Contact.java 1689 2007-10-26 11:06:23Z chrisg23 $
*/
public class Contact extends ContentPage {
/** PDL property names */
/*
* Flattened out Person object properties.Next 3 properties can be moved out
* to seperate object if needed.
*/
public static final String GIVEN_NAME = "givenName";
public static final String FAMILY_NAME = "familyName";
public static final String SUFFIX = "suffix";
public static final String EMAILS = "emails";
public static final String DESCRIPTION = "description";
public static final String ORG_NAME = "orgName";
public static final String DEPT_NAME = "deptName";
public static final String ROLE = "role";
/* Composite objects used by this class */
public static final String CONTACT_TYPE = "contactType";
public static final String CONTACT_ADDRESS = "contactAddress";
public static final String PHONES = "phones";
public static final String ITEMS = "associatedContentItemsForContact";
private static final Logger s_log = Logger.getLogger(Contact.class);
/** data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.Contact";
/** Default constructor. */
public Contact() {
super(BASE_DATA_OBJECT_TYPE);
}
/**
* Adds an association between this contact and the given content item.
* @param item
*/
public void addContentItem(ContentItem item) {
s_log.debug("item is " + item);
item.addToAssociation(getItemsForContact());
}
/**
* Deletes the association between this contact and the given content item.
* @param item
*/
public void removeContentItem(ContentItem item) {
s_log.debug("item is " + item);
DataOperation operation = SessionManager
.getSession()
.retrieveDataOperation(
"com.arsdigita.cms.contenttypes.removeContactFromContentItemAssociation");
operation.setParameter("itemID", new Integer(item.getID().intValue()));
operation.execute();
}
/**
* Removes all mappings between this contact and any other content item.
*
*/
private void removeItemMappings() {
DataOperation operation = SessionManager
.getSession()
.retrieveDataOperation(
"com.arsdigita.cms.contenttypes.removeContactFromAllAssociations");
operation.setParameter("contactID", new Integer(this.getID().intValue()));
operation.execute();
}
/**
* Gets the DataAssociation that holds the mapping between this contact
* and any content items.
* @return
*/
public DataAssociation getItemsForContact() {
return (DataAssociation) get(ITEMS);
}
/**
* Returns the Contact for a given content item.
* @param item
* @return
*/
public static Contact getContactForItem(ContentItem item) {
s_log.debug("getting contact for item " + item);
DataQuery query = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getContactForItem");
query.setParameter("itemID", item.getID());
BigDecimal contactID;
Contact contact = null;
while (query.next()) {
contactID = (BigDecimal) query.get("contactID");
contact = new Contact(contactID);
}
s_log.debug("returning contact " + contact);
return contact;
}
/**
* Constructor. Retrieves an object instance with the given id.
* @param id the id of the object to retrieve
*/
public Contact( BigDecimal id ) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id));
}
/**
* Constructor. Retrieves an object instance with the given OID.
*
* @param oid the object id of the object to retrieve
*/
public Contact(OID oid) throws DataObjectNotFoundException {
super(oid);
}
/**
* Constructor. Create a Contact domain object using the given data object.
* @param obj the object data to use
*/
public Contact( DataObject obj ) {
super(obj);
}
/** Constructor. */
public Contact( String type ) {
super(type);
}
public void beforeSave() {
super.beforeSave();
Assert.exists(getContentType(), ContentType.class);
}
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
/** Accessor. Get the GIVEN_NAME for this Contact. */
public String getGivenName(){
return (String) get(GIVEN_NAME);
}
/** Mutator. Set the GIVEN_NAME for this Contact. */
public void setGivenName(String gn){
set(GIVEN_NAME , gn);
}
/** Accessor. Get the FAMILY_NAME for this Contact. */
public String getFamilyName(){
return (String) get(FAMILY_NAME);
}
/** Mutator. Set the FAMILY_NAME for this Contact. */
public void setFamilyName(String fn){
set(FAMILY_NAME , fn);
}
/** Accessor. Get the SUFFIX for this Contact. */
public String getSuffix(){
return (String) get(SUFFIX);
}
/** Mutator. Set the DESCRIPTION for this Contact. */
public void setSuffix(String suf){
set(SUFFIX , suf);
}
/** Accessor. Get the EMAILS for this Contact. */
public String getEmails(){
return (String) get(EMAILS);
}
/** Mutator. Set the EMAILS for this Contact. */
public void setEmails(String ems){
set(EMAILS , ems);
}
/** Accessor. Get the CONTACT_TYPE for this Contact. */
public String getContactTypeName() {
String ctTypeName = "";
if(getContactType() != null){
ctTypeName = getContactType().getTypeName();
}
return ctTypeName;
}
/** Accessor. Get the DESCRIPTION for this Contact. */
public String getDescription() {
return (String) get(DESCRIPTION);
}
/** Mutator. Set the DESCRIPTION for this Contact. */
public void setDescription( String desc ) {
set(DESCRIPTION , desc);
}
/** Accessor. Get the ORG_NAME for this Contact. */
public String getOrganisationName() {
return (String) get(ORG_NAME);
}
/** Mutator. Set the ORG_NAME for this Contact. */
public void setOrganisationName( String orgName ) {
set(ORG_NAME , orgName);
}
/** Accessor. Get the DEPT_NAME for this Contact. */
public String getDeptName() {
return (String) get(DEPT_NAME);
}
/** Mutator. Set the DEPT_NAME for this Contact. */
public void setDeptName( String deptName ) {
set(DEPT_NAME , deptName);
}
/** Accessor. Get the ROLE for this Contact. */
public String getRole() {
return (String) get(ROLE);
}
/** Mutator. Set the ROLE for this Contact. */
public void setRole( String role ) {
set(ROLE , role);
}
/**
* return type of Contact associated with this Contact object.
*
* @return null if there is no associated <code><ContactType/code> object.
*/
public ContactType getContactType(){
DataObject obj = retrieveDataobject( CONTACT_TYPE );
if(obj != null){
return new ContactType(obj);
}
return null;
}
/** Mutator. Set the CONTACT_TYPE for this Contact. */
public void setContactType( ContactType ct ) {
setAssociation(CONTACT_TYPE , ct);
}
/******* ContactAddress object manipulation methods *********************/
/**
* set the ContactAddress object association.
*/
public void setContactAddress(ContactAddress caddr){
setAssociation(CONTACT_ADDRESS , caddr);
}
/**
* Get the associated ContactAddress object for this Contact.
* @return null if no Address is present.
*/
public ContactAddress getContactAddress(){
DataObject obj = retrieveDataobject( CONTACT_ADDRESS);
if(obj != null){
return new ContactAddress(obj);
}
return null;
}
/******* ContactPhone object manipulation methods *********************/
/**
* Add a Phone object to the collection of the phone objects this contact
* has.
*/
public void addPhone(ContactPhone ph){
add(PHONES , ph);
save();
}
/**
* Remove the passed in Phone object from the list of phones this contact
* object has.
*/
public void removePhone(ContactPhone ph){
ph.delete();
save();
}
/**
* Return collection of Phone objects associated with this Contact object.
*/
public PhonesCollection getPhones(){
DataAssociationCursor dac = ((DataAssociation) get(PHONES)).cursor();
return new PhonesCollection(dac);
}
private DataObject retrieveDataobject(String attr){
return ( DataObject ) get( attr );
}
} //End of class.

View File

@ -0,0 +1,171 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.math.BigDecimal;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
/**
* DomainObject class to represent objects of type <code>ContactAddress</code>
* These objects are associated with Contact objects in this package.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactAddress.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactAddress extends ContentItem {
/** data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.ContactAddress";
public static final String SAON = "saon";
public static final String PAON = "paon";
public static final String STREET_DESC = "streetDesc";
public static final String STREET_REF_NO = "streetRefNo";
public static final String LOCALITY = "locality";
public static final String TOWN = "town";
public static final String ADMINISTRATIVE_AREA = "administrativeArea";
public static final String POST_TOWN = "postTown";
public static final String POST_CODE = "postCode";
public static final String PROP_REF_NO = "referenceNo";
/** Default constructor. */
public ContactAddress() {
super(BASE_DATA_OBJECT_TYPE);
}
/**
* Constructor. Retrieves an object instance with the given id.
* @param id the id of the object to retrieve
*/
public ContactAddress(BigDecimal id) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id));
}
/**
* Constructor. Create a Contact domain object using the given data object.
* @param obj the object data to use
*/
public ContactAddress(DataObject obj) {
super(obj);
}
/**
* Constructor. Retrieves an object instance with the given OID.
*
* @param oid the object id of the object to retrieve
*/
public ContactAddress(OID oid) throws DataObjectNotFoundException {
super(oid);
}
/** Constructor. */
public ContactAddress( String type ) {
super(type);
}
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
public String getSaon() {
return (String) get(SAON);
}
public void setSaon(String saon) {
set(SAON,saon);
}
public String getPaon() {
return (String) get(PAON);
}
public void setPaon(String paon) {
set(PAON , paon);
}
public String getStreetDesc() {
return (String) get(STREET_DESC);
}
public void setStreetDesc(String desc) {
set(STREET_DESC,desc);
}
public String getStreetRefNo() {
return (String) get(STREET_REF_NO);
}
public void setStreetRefNo(String refno) {
set(STREET_REF_NO,refno);
}
public String getLocality() {
return (String) get(LOCALITY);
}
public void setLocality(String locality) {
set(LOCALITY,locality);
}
public String getTown() {
return (String) get(TOWN);
}
public void setTown(String town) {
set(TOWN,town);
}
public String getAdministrativeArea() {
return (String) get(ADMINISTRATIVE_AREA);
}
public void setAdministrativeArea(String adArea) {
set(ADMINISTRATIVE_AREA,adArea);
}
public String getPostTown() {
return (String) get(POST_TOWN);
}
public void setPostTown(String ptown) {
set(POST_TOWN, ptown);
}
public String getPostCode() {
return (String) get(POST_CODE);
}
public void setPostCode(String pcode) {
set(POST_CODE, pcode);
}
public String getReferenceNo() {
return (String) get(PROP_REF_NO);
}
public void setReferenceNo(String refno) {
set(PROP_REF_NO, refno);
}
}

View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.util.ArrayList;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.contenttypes.ui.contact.AddContactPropertiesStep;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
// import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.runtime.DomainInitEvent;
// import com.arsdigita.runtime.LegacyInitEvent;
/**
* Initializer class to initialize <code>ContentType Contact</code>.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactInitializer.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactInitializer extends ContentTypeInitializer {
public ContactInitializer() {
super("ccm-ldn-types-contact.pdl.mf", Contact.BASE_DATA_OBJECT_TYPE);
}
public String[] getStylesheets() {
return new String [] {
"/static/content-types/com/arsdigita/cms/contenttypes/Contact.xsl",
};
}
public String getTraversalXML() {
return "/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/Contact.xml";
}
private static ArrayList phoneTypesList = new ArrayList(10);
static {
phoneTypesList.add("Office");
phoneTypesList.add("Mobile");
phoneTypesList.add("Fax");
phoneTypesList.add("Home");
phoneTypesList.add("Minicom");
}
/**
* Return the statically initialized list of phone types.
*/
public static ArrayList getPhoneTypes(){
return phoneTypesList;
}
// public void init(LegacyInitEvent evt) {
public void init(DomainInitEvent evt) {
super.init(evt);
if (ContentSection.getConfig().getHasContactsAuthoringStep()) {
// Add the "Contact"authoring step
AuthoringKitWizard.registerAssetStep(
getBaseType(),
getAuthoringStep(), getAuthoringStepLabel(),
getAuthoringStepDescription(), getAuthoringStepSortKey());
// and sort out the display - at the moment this is just the
// basic properties, addresses and phones
ContentItemTraversalAdapter associatedContactTraversalAdapter =
new ContentItemTraversalAdapter();
associatedContactTraversalAdapter.addAssociationProperty("/object/phones");
associatedContactTraversalAdapter.addAssociationProperty("/object/contactAddress");
ContentItemTraversalAdapter.registerAssetAdapter(
"associatedContactForItem",
associatedContactTraversalAdapter,
"com.arsdigita.cms.dispatcher.SimpleXMLGenerator");
}
}
private int getAuthoringStepSortKey() {
// TODO - workout what this does and possibly make it configurable
return 1;
}
private GlobalizedMessage getAuthoringStepDescription() {
return new GlobalizedMessage(
"com.arsdigita.cms.contenttypes.contact_authoring_step_description",
"com.arsdigita.cms.contenttypes.ContactResources");
}
private GlobalizedMessage getAuthoringStepLabel() {
return new GlobalizedMessage(
"com.arsdigita.cms.contenttypes.contact_authoring_step_label",
"com.arsdigita.cms.contenttypes.ContactResources");
}
private Class getAuthoringStep() {
return AddContactPropertiesStep.class;
}
private String getBaseType() {
return ContentPage.BASE_DATA_OBJECT_TYPE;
}
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.runtime.ScriptContext;
/**
* Loader for <code>ContentType</code> <code>Contact</code>.
*
* Also loads a fixed set of <code>ContactType</code> objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: ContactLoader.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class ContactLoader extends AbstractContentTypeLoader {
private static final String[] TYPES = {
"/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Contact.xml"
};
/**
* @see com.arsdigita.cms.contenttypes.AbstractContentTypeLoader#getTypes()
*/
public String[] getTypes() {
return TYPES;
}
/**
* @see com.arsdigita.runtime.Script#run(com.arsdigita.runtime.ScriptContext)
*/
public void run(ScriptContext context) {
super.run(context);
loadContactTypes();
}
/**
* Create the fixed set of ContactTypes.
* This is a quick hack for now.If we need to extend it then we have
* to move it into an XML file and load it from initializer after
* checking it.
*/
protected void loadContactTypes(){
ContactType ct = new ContactType();
ct.setName("ContactType-Service-Provision");
ct.setTypeName("Service Provision");
ct.save();
ct = new ContactType();
ct.setName("ContactType-Enquiry");
ct.setTypeName("Enquiry");
ct.save();
ct = new ContactType();
ct.setName("ContactType-Complaint");
ct.setTypeName("Complaint");
ct.save();
ct = new ContactType();
ct.setName("ContactType-Escalation");
ct.setTypeName("Escalation");
ct.save();
}
}

View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.math.BigDecimal;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
/**
* DomainObject class to represent objects of type <code>ContactPhone</code>.
* This object represents type of phone and it's number.
* They are associated with <code>Contact</code> objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: ContactPhone.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class ContactPhone extends ContentItem {
/** data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.ContactPhone";
/** PDL property names */
public static final String PHONE_TYPE = "phoneType";
public static final String PHONE_NUMBER = "phoneNumber";
/** Default constructor. */
public ContactPhone() {
super(BASE_DATA_OBJECT_TYPE);
}
/**
* Constructor. Retrieves an object instance with the given OID.
*
* @param oid the object id of the object to retrieve
*/
public ContactPhone(OID oid) throws DataObjectNotFoundException {
super(oid);
}
/**
* Constructor. Retrieves an object instance with the given id.
* @param id the id of the object to retrieve
*/
public ContactPhone( BigDecimal id ) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id));
}
/**
* Constructor. Create a Contact domain object using the given data object.
* @param obj the object data to use
*/
public ContactPhone( DataObject obj ) {
super(obj);
}
/** Constructor. */
public ContactPhone( String type ) {
super(type);
}
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
//Accessors
public String getPhoneType(){
return (String) get(PHONE_TYPE);
}
public String getPhoneNumber(){
return (String) get(PHONE_NUMBER);
}
public void setPhoneNumber(String num){
set(PHONE_NUMBER,num);
}
public void setPhoneType(String type){
set(PHONE_TYPE, type);
}
}

View File

@ -0,0 +1,26 @@
cms.contenttypes.ui.contact.address_saon=SAON
cms.contenttypes.ui.contact.address_paon=PAON
cms.contenttypes.ui.contact.address_streetdesc=Street Description
cms.contenttypes.ui.contact.address_streetrefno=Street Reference No
cms.contenttypes.ui.contact.address_locality=Locality
cms.contenttypes.ui.contact.address_town=Town
cms.contenttypes.ui.contact.address_administrative_area=Administrative Area
cms.contenttypes.ui.contact.address_posttown=Postal Town
cms.contenttypes.ui.contact.address_postcode=Postal Code
cms.contenttypes.ui.contact.address_proprefno=Property Reference No
cms.contenttypes.ui.contact_type=Contact Type
cms.contenttypes.ui.contact_orgname=Organization Name
cms.contenttypes.ui.contact_deptname=Department Name
cms.contenttypes.ui.contact_role=Role of Contact
cms.contenttypes.ui.contact_givenname=Given Name
cms.contenttypes.ui.contact_familyname=Family Name
cms.contenttypes.ui.contact_suffix=Suffix
cms.contenttypes.ui.contact_description=Contact Description
cms.contenttypes.ui.contact.phone_number=Number
cms.contenttypes.ui.phone_type=Types
cms.contenttypes.ui.contact_emails=Emails
com.arsdigita.cms.contenttypes.contact_authoring_step_description=Contact
com.arsdigita.cms.contenttypes.contact_authoring_step_label=Contact
cms.contenttypes.ui.name=Name
cms.contenttypes.ui.title=Title
cms.contenttypes.ui.description=Description

View File

@ -0,0 +1,90 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.math.BigDecimal;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.OID;
/**
* DomainObject class to represent objects of <code>ContactType</code>.
* These objects are associated with <code>Contact</code> objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactType.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactType extends ContentItem {
/** data object type for this domain object */
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.ContactType";
public static final String TYPE_NAME = "typeName";
/** Default constructor. */
public ContactType() {
super(BASE_DATA_OBJECT_TYPE);
}
/**
* Constructor. Retrieves an object instance with the given id.
* @param id the id of the object to retrieve
*/
public ContactType( BigDecimal id ) throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id));
}
/**
* Constructor. Retrieves an object instance with the given OID.
*
* @param oid the object id of the object to retrieve
*/
public ContactType(OID oid) throws DataObjectNotFoundException {
super(oid);
}
/**
* Constructor. Create a Contact domain object using the given data object.
* @param obj the object data to use
*/
public ContactType( DataObject obj ) {
super(obj);
}
/** Constructor. */
public ContactType( String type ) {
super(type);
}
public String getBaseDataObjectType() {
return BASE_DATA_OBJECT_TYPE;
}
public String getTypeName(){
return (String) get(TYPE_NAME);
}
public void setTypeName(String tname){
set(TYPE_NAME,tname);
}
}

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import java.math.BigDecimal;
import com.arsdigita.domain.DomainCollection;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.SessionManager;
/**
* Class which represents a collection of ContactTypes.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactTypesCollection.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactTypesCollection extends DomainCollection {
/** Retrieve the collection of ContactTypes. */
public static ContactTypesCollection getContactTypesCollection(){
DataCollection typesColl = SessionManager.getSession().
retrieve(ContactType.BASE_DATA_OBJECT_TYPE);
return new ContactTypesCollection(typesColl);
}
/**
* private Constructor.Single ton type of class.
*
**/
private ContactTypesCollection(DataCollection dataCollection) {
super(dataCollection);
}
/**
* Returns a <code>DomainObject</code> for the current position in
* the collection.
*
**/
public DomainObject getDomainObject() {
return new ContactType(m_dataCollection.getDataObject());
}
/**
* Returns a <code>ContactType</code> for the current position in
* the collection.
*
**/
public ContactType getContactType() {
return (ContactType) getDomainObject();
}
/**
* Return the name of ContactType from current row.
*/
public String getContactTypeName(){
return getContactType().getTypeName();
}
/**
* Return the ID of ContactType from current row.
*/
public BigDecimal getContactTypeID(){
return getContactType().getID();
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes;
import com.arsdigita.domain.DomainCollection;
import com.arsdigita.persistence.DataCollection;
/**
* Collection of <code>ContactPhone</code>S objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: PhonesCollection.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class PhonesCollection extends DomainCollection {
/**
* Constructor.
*
**/
public PhonesCollection(DataCollection dataCollection) {
super(dataCollection);
}
/**
* Returns a <code>DomainObject</code> for the current position in
* the collection.
*
**/
public ContactPhone getPhone() {
return new ContactPhone(m_dataCollection.getDataObject());
}
public String getPhoneType(){
return getPhone().getPhoneType();
}
public String getPhoneNumber(){
return getPhone().getPhoneNumber();
}
}

View File

@ -0,0 +1,23 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Content type Contact</title>
</head>
<body bgcolor="white">
<p>
Implementation of a Contact content type.</p>
<p>
Contact attributes include
</p>
<ul>
<li>Given name, family name, title and other personal characteristics</li>
<li>Contact type (e.g. service)</li>
<li>Contact details as e-mail, oranisation name, etc.</li>
<li>Address details (street, area, postal code, etc.y</li>
<li>Phone (number and type) several may be added</li>
</ul>
<p>Because of these attributes this content type is especially useful for
<i>United Kingdom</i> residents and UK local authorities.</p>
</body>
</html>

View File

@ -0,0 +1,243 @@
package com.arsdigita.cms.contenttypes.ui.contact;
import org.apache.log4j.Logger;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.FormSection;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.ui.ResettableContainer;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.workflow.WorkflowLockedContainer;
import com.arsdigita.domain.DomainObject;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import com.arsdigita.util.Assert;
/**
*
*/
public class AddContactPropertiesStep extends ResettableContainer {
private static final Logger s_log = Logger
.getLogger(AddContactPropertiesStep.class);
public static final String EDIT_SHEET_NAME = "edit";
public Form m_form;
private ItemSelectionModel m_itemSelectionModel;
public ContactSelectionModel m_contactSelectionModel;
private AuthoringKitWizard m_parent;
protected Component m_contactPropertySheet;
private ContactDisplay m_display;
public AddContactPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
m_parent = parent;
m_itemSelectionModel = itemModel;
m_contactSelectionModel = new ContactSelectionModel(
m_itemSelectionModel);
Form display = new Form("display");
display.add(getContactDisplay());
add(display);
m_form = new Form("contactSearchForm");
m_form.add(getFindContactSheet());
WorkflowLockedContainer edit = new WorkflowLockedContainer(itemModel);
edit.add(m_form);
add(edit);
}
protected Component getContactDisplay() {
m_display = new ContactDisplay();
return m_display;
}
public void toggleDisplay(PageState state) throws FormProcessException {
m_display.toggle(state);
}
private Component getFindContactSheet() {
return new AddContactToItemForm(this);
}
public ItemSelectionModel getItemSelectionModel() {
return m_itemSelectionModel;
}
public ItemSelectionModel getContactSelectionModel() {
return m_contactSelectionModel;
}
public AuthoringKitWizard getParent() {
return m_parent;
}
public ContentItem getItem(PageState state) {
return m_itemSelectionModel.getSelectedItem(state);
}
public Contact getContact(PageState state) {
return (Contact) m_contactSelectionModel.getSelectedItem(state);
}
protected class ContactSelectionModel extends ItemSelectionModel {
private RequestLocal m_contact;
public ContactSelectionModel(ItemSelectionModel m) {
super(m);
m_contact = new RequestLocal() {
protected Object initialValue(PageState s) {
ContentItem item = (ContentItem) ((ItemSelectionModel) getSingleSelectionModel())
.getSelectedObject(s);
Assert.exists(item);
return Contact.getContactForItem(item);
}
};
}
public Object getSelectedKey(PageState s) {
Contact contact = (Contact) getSelectedObject(s);
return (contact == null) ? null : contact.getID();
}
public DomainObject getSelectedObject(PageState s) {
return (DomainObject) m_contact.get(s);
}
public void setSelectedObject(PageState s, DomainObject o) {
m_contact.set(s, o);
}
public void setSelectedKey(PageState s, Object key) {
throw new UnsupportedOperationException((String) GlobalizationUtil
.globalize("cms.ui.authoring.not_implemented").localize());
}
public boolean isSelected(PageState s) {
return (getSelectedObject(s) != null);
}
}
private class ContactDisplay extends FormSection implements
FormInitListener {
private Label m_noContact;
public ContactDisplay() {
addInitListener(this);
addWidgets();
}
public void toggle(PageState state) {
s_log.debug("toggle");
m_contactPropertySheet.setVisible(state, false);
m_noContact.setVisible(state, true);
}
private void addWidgets() {
m_contactPropertySheet = getContactPropertySheet(m_contactSelectionModel);
m_noContact = new Label("This item does not have a contact.");
m_noContact.setFontWeight(Label.ITALIC);
add(m_contactPropertySheet);
add(m_noContact);
}
public void init(FormSectionEvent e) throws FormProcessException {
s_log.debug("init");
PageState state = e.getPageState();
if (m_contactSelectionModel.getSelectedItem(state) != null) {
m_contactPropertySheet.setVisible(state, true);
m_noContact.setVisible(state, false);
} else {
m_noContact.setVisible(state, true);
m_contactPropertySheet.setVisible(state, false);
}
}
private Component getContactPropertySheet(ItemSelectionModel itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(
itemModel);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.name"), Contact.NAME);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.title"), Contact.TITLE);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_givenname"),
Contact.GIVEN_NAME);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_familyname"),
Contact.FAMILY_NAME);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_type"),
Contact.CONTACT_TYPE,
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute, PageState state) {
Contact contact = (Contact) item;
if (contact != null
&& contact.getContactType() != null) {
return contact.getContactTypeName();
} else {
return "unknown";
}
}
});
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.description"),
Contact.DESCRIPTION);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_emails"),
Contact.EMAILS);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_suffix"),
Contact.SUFFIX);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_orgname"),
Contact.ORG_NAME);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_deptname"),
Contact.DEPT_NAME);
sheet.add(ContactGlobalizationUtil
.globalize("cms.contenttypes.ui.contact_role"),
Contact.ROLE);
return sheet;
}
}
}

View File

@ -0,0 +1,151 @@
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.bebop.ActionLink;
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.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
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.util.GlobalizationUtil;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.ui.ItemSearchWidget;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
public class AddContactToItemForm extends FormSection implements
FormInitListener, FormValidationListener, FormProcessListener,
FormSubmissionListener {
private ContentItem m_item;
private ItemSearchWidget m_itemSearch;
private SaveCancelSection m_saveCancelSection;
private ItemSelectionModel m_itemSelectionModel;
private final String CONTACT_SEARCH = "contact";
private Contact m_contact;
private Label m_searchFormLabel;
private AddContactPropertiesStep m_step;
private AuthoringKitWizard m_parent;
private Label m_removeLinkText = new Label(GlobalizationUtil
.globalize("Remove contact"));
private ActionLink m_removeLink;
public AddContactToItemForm(AddContactPropertiesStep step) {
m_step = step;
m_parent = m_step.getParent();
m_itemSelectionModel = m_step.getItemSelectionModel();
addInitListener(this);
addWidgets();
addSaveCancelSection();
addProcessListener(this);
addValidationListener(this);
addSubmissionListener(this);
}
public void addWidgets() {
m_removeLink = new ActionLink(m_removeLinkText);
m_removeLink.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Contact contact = m_step.getContact(e.getPageState());
if (contact != null) {
PageState state = e.getPageState();
contact.removeContentItem(m_step.getItem(state));
m_step.m_contactSelectionModel.setSelectedObject(state,
null);
try {
m_step.toggleDisplay(state);
} catch (FormProcessException e1) {
e1.printStackTrace();
}
}
}
});
add(m_removeLink, ColumnPanel.FULL_WIDTH);
m_searchFormLabel = new Label("Search for Contact:");
add(m_searchFormLabel);
m_itemSearch = new ItemSearchWidget(CONTACT_SEARCH,
Contact.BASE_DATA_OBJECT_TYPE);
add(m_itemSearch);
}
public AddContactToItemForm getThis() {
return this;
}
/** Adds the saveCancelSection */
public void addSaveCancelSection() {
m_saveCancelSection = new SaveCancelSection();
m_saveCancelSection.getSaveButton().setButtonLabel("Add");
add(m_saveCancelSection, ColumnPanel.FULL_WIDTH);
}
protected ContentItem getContentItem(PageState s) {
return (ContentItem) m_itemSelectionModel.getSelectedObject(s);
}
public void validate(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
if (data.get(CONTACT_SEARCH) == null) {
throw new FormProcessException("Contact selection is required.");
}
}
public void process(FormSectionEvent e) throws FormProcessException {
FormData data = e.getFormData();
PageState ps = e.getPageState();
m_contact = (Contact) data.get(CONTACT_SEARCH);
m_contact.addContentItem(getContentItem(ps));
init(e);
}
public void submitted(FormSectionEvent e) throws FormProcessException {
if (m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) {
m_parent.reset(e.getPageState());
throw new FormProcessException("cancelled");
}
}
public void init(FormSectionEvent e) throws FormProcessException {
PageState ps = e.getPageState();
m_item = getContentItem(ps);
m_contact = Contact.getContactForItem(m_item);
if (m_contact != null) {
m_removeLink.setVisible(ps, true);
m_searchFormLabel.setVisible(ps, false);
m_itemSearch.setVisible(ps, false);
m_saveCancelSection.setVisible(ps, false);
} else {
m_removeLink.setVisible(ps, false);
m_searchFormLabel.setVisible(ps, true);
m_itemSearch.setVisible(ps, true);
m_saveCancelSection.setVisible(ps, true);
}
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.bebop.Component;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
/**
* Authoring kit step to manipulate <code>ContactAddress</code> object
* associated with <code>Contact</code> object.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: AddressProperties.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class AddressProperties extends SimpleEditStep {
/** The name of the editing sheet added to this step */
public static String EDIT_SHEET_NAME = "edit-contact-address";
public AddressProperties(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
super(itemModel, parent);
BasicItemForm form;
form = new AddressPropertyForm(itemModel);
add(EDIT_SHEET_NAME,
"Edit",
new WorkflowLockedComponentAccess(form, itemModel),
form.getSaveCancelSection().getCancelButton());
setDisplayComponent(getAddressPropertySheet(itemModel));
}
/**
* Returns a component that displays the properties of the Contact
* specified by the ItemSelectionModel passed in.
*
* @param itemModel The ItemSelectionModel to use
* @pre itemModel != null
* @return A component to display the state of the basic properties
* of the
**/
public static Component getAddressPropertySheet(ItemSelectionModel itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_saon"),
"contactAddress.saon");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_paon"),
"contactAddress.paon");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_streetdesc"),
"contactAddress.streetDesc");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_streetrefno"),
"contactAddress.streetRefNo");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_locality"),
"contactAddress.locality");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_town"),
"contactAddress.town");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_administrative_area"),
"contactAddress.administrativeArea");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_posttown"),
"contactAddress.postTown");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_postcode"),
"contactAddress.postCode");
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_proprefno"),
"contactAddress.referenceNo");
return sheet;
}
}

View File

@ -0,0 +1,223 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import org.apache.log4j.Logger;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.ContactAddress;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
/**
* A form class to edit the properties of <code>ContactAddress</code> object.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: AddressPropertyForm.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class AddressPropertyForm extends BasicItemForm {
/** Name of this form */
private static final String ID = "Contact_address_edit";
private static final Logger s_log = Logger.getLogger(AddressPropertyForm.class);
/**
* Creates a new form to edit the <code>ContactAddress</code> object
* properties associated with the <code>Contact</code> object specified by
* the item selection model passed in.
*
* @param itemModel The ItemSelectionModel to use to obtain the Contact
* object to work on
**/
public AddressPropertyForm(ItemSelectionModel itemModel) {
super(ID, itemModel);
}
/**
* Adds widgets to edit the address properties to form.
* Only paon and streetDesc are required, rest are optional.
* This was cut down into small methods for subclasses to pick and choose.
**/
protected void addWidgets() {
addSAON();
addPAON();
addStreetDesc();
addStreetRefNo();
addLocality();
addTown();
addArea();
addPostTown();
addPostCode();
addPropRefNo();
}
protected void addSAON() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_saon")));
ParameterModel saonParam = new StringParameter(ContactAddress.SAON);
TextField saon = new TextField(saonParam);
add(saon);
}
protected void addPAON() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_paon")));
ParameterModel paonParam = new StringParameter(ContactAddress.PAON);
TextField paon = new TextField(paonParam);
paon.addValidationListener(new NotNullValidationListener());
add(paon);
}
protected void addStreetDesc() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_streetdesc")));
ParameterModel streetDescParam = new StringParameter(ContactAddress.STREET_DESC);
TextField streetDesc = new TextField(streetDescParam);
streetDesc.addValidationListener(new NotNullValidationListener());
add(streetDesc);
}
protected void addStreetRefNo() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_streetrefno")));
ParameterModel streetRefNoParam = new StringParameter(ContactAddress.STREET_REF_NO);
TextField streetRefNo = new TextField(streetRefNoParam);
add(streetRefNo);
}
protected void addLocality() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_locality")));
ParameterModel localityParam = new StringParameter(ContactAddress.LOCALITY);
TextField locality = new TextField(localityParam);
add(locality);
}
protected void addTown() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_town")));
ParameterModel townParam = new StringParameter(ContactAddress.TOWN);
TextField town = new TextField(townParam);
add(town);
}
protected void addArea() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_administrative_area")));
ParameterModel adAreaParam = new StringParameter(ContactAddress.ADMINISTRATIVE_AREA);
TextField adArea = new TextField(adAreaParam);
add(adArea);
}
protected void addPostTown() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_posttown")));
ParameterModel postTownParam = new StringParameter(ContactAddress.POST_TOWN);
TextField postTown = new TextField(postTownParam);
add(postTown);
}
protected void addPostCode() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_postcode")));
ParameterModel postCodeParam = new StringParameter(ContactAddress.POST_CODE);
TextField postCode = new TextField(postCodeParam);
add(postCode);
}
protected void addPropRefNo() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact.address_proprefno")));
ParameterModel propRefNoParam = new StringParameter(ContactAddress.PROP_REF_NO);
TextField propRefNo = new TextField(propRefNoParam);
add(propRefNo);
}
/**
* Initialize Form values from Contact object.
*/
public void init(FormSectionEvent fse) {
FormData data = fse.getFormData();
Contact contact = (Contact) this.getItemSelectionModel().getSelectedObject(fse.getPageState());
ContactAddress ctAddress = contact.getContactAddress();
if(ctAddress != null){
data.put(ContactAddress.PAON, ctAddress.getPaon());
data.put(ContactAddress.SAON, ctAddress.getSaon());
data.put(ContactAddress.STREET_DESC, ctAddress.getStreetDesc());
data.put(ContactAddress.STREET_REF_NO, ctAddress.getStreetRefNo());
data.put(ContactAddress.LOCALITY, ctAddress.getLocality());
data.put(ContactAddress.TOWN, ctAddress.getTown());
data.put(ContactAddress.ADMINISTRATIVE_AREA, ctAddress.getAdministrativeArea());
data.put(ContactAddress.POST_TOWN, ctAddress.getPostTown());
data.put(ContactAddress.POST_CODE, ctAddress.getPostCode());
data.put(ContactAddress.PROP_REF_NO, ctAddress.getReferenceNo());
}
}
/**
* Process the form submission event.
* Create a new <code>ContactAddress</code> object and associate it with
* <code>Contact</code> object if one does not exist yet.
*/
public void process(FormSectionEvent fse) {
FormData data = fse.getFormData();
Contact contact = (Contact) this.getItemSelectionModel().getSelectedObject(fse.getPageState());
s_log.debug("Process Event Object :" + contact);
// save only if save button was pressed
if (contact != null
&& getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
ContactAddress ctAddress = contact.getContactAddress();
//User submitted the Form.If the associated ContactAddress does not exist
//just create it.
if(ctAddress == null){
ctAddress = new ContactAddress();
ctAddress.setName("address-for-contact-"+ contact.getID());
}
ctAddress.setPaon((String) data.get(ContactAddress.PAON));
ctAddress.setSaon((String) data.get(ContactAddress.SAON));
ctAddress.setStreetDesc((String) data.get(ContactAddress.STREET_DESC));
ctAddress.setStreetRefNo((String) data.get(ContactAddress.STREET_REF_NO));
ctAddress.setLocality((String) data.get(ContactAddress.LOCALITY));
ctAddress.setTown((String) data.get(ContactAddress.TOWN));
ctAddress.setAdministrativeArea((String) data.get(ContactAddress.ADMINISTRATIVE_AREA));
ctAddress.setPostTown((String) data.get(ContactAddress.POST_TOWN));
ctAddress.setPostCode((String) data.get(ContactAddress.POST_CODE));
ctAddress.setReferenceNo((String) data.get(ContactAddress.PROP_REF_NO));
ctAddress.save();
//If not present then only set and save Contact object.
if(contact.getContactAddress() == null){
contact.setContactAddress(ctAddress);
contact.save();
}
}
}
}

View File

@ -0,0 +1,99 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.CreationSelector;
import com.arsdigita.cms.ui.authoring.PageCreate;
/**
* Authoring kit create component to create objects of <code>Contact</code>
* ContentType objects.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: ContactCreate.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class ContactCreate extends PageCreate {
private CreationSelector m_parent;
public ContactCreate(ItemSelectionModel itemModel,
CreationSelector parent) {
super(itemModel, parent);
m_parent = parent;
}
protected void addWidgets () {
super.addWidgets();
TextField givenName = new TextField(Contact.GIVEN_NAME);
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_givenname")));
givenName.addValidationListener(new NotNullValidationListener());
add(givenName);
TextField familyName = new TextField(Contact.FAMILY_NAME);
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_familyname")));
familyName.addValidationListener(new NotNullValidationListener());
add(familyName);
}
public void process ( FormSectionEvent e ) throws FormProcessException{
FormData data = e.getFormData();
PageState state = e.getPageState();
// try to get the contact section from the state parameter
Folder f = m_parent.getFolder(state);
ContentSection sec = m_parent.getContentSection(state);
Contact contact = (Contact) createContentPage(state);
contact.setLanguage((String) data.get(LANGUAGE));
contact.setName((String)data.get(NAME));
contact.setTitle((String)data.get(TITLE));
contact.setGivenName((String)data.get(Contact.GIVEN_NAME));
contact.setFamilyName((String)data.get(Contact.FAMILY_NAME));
contact.save();
final ContentBundle bundle = new ContentBundle(contact);
bundle.setParent(f);
bundle.setContentSection(m_parent.getContentSection(state));
bundle.save();
// aplaws default workflow
getWorkflowSection().applyWorkflow(state, contact);
m_parent.editItem(state, contact);
}
}

View File

@ -0,0 +1,134 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.bebop.Component;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
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 com.arsdigita.domain.DomainObject;
import com.arsdigita.toolbox.ui.DomainObjectPropertySheet;
import com.arsdigita.bebop.PageState;
/**
* Authoring kit step to view/edit basic properties of Contact object.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: ContactPropertiesStep.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class ContactPropertiesStep extends SimpleEditStep {
/** The name of the editing sheet added to this step */
public static String EDIT_SHEET_NAME = "edit";
public ContactPropertiesStep(ItemSelectionModel itemModel,
AuthoringKitWizard parent) {
super(itemModel, parent);
BasicPageForm editSheet;
editSheet = new ContactPropertyForm(itemModel);
add(
EDIT_SHEET_NAME,
"Edit",
new WorkflowLockedComponentAccess(editSheet, itemModel),
editSheet.getSaveCancelSection().getCancelButton());
setDisplayComponent(getContactPropertySheet(itemModel));
}
/**
* Returns a component that displays the properties of the Contact specified
* by the ItemSelectionModel passed in.
*
* @param itemModel
* The ItemSelectionModel to use @pre itemModel != null
* @return A component to display the state of the basic properties of the
*/
public static Component getContactPropertySheet(ItemSelectionModel itemModel) {
DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel);
sheet.add(
GlobalizationUtil.globalize("cms.contenttypes.ui.name"),
Contact.NAME);
sheet.add(
GlobalizationUtil.globalize("cms.contenttypes.ui.title"),
Contact.TITLE);
sheet.add(
ContactGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact_givenname"),
Contact.GIVEN_NAME);
sheet.add(
ContactGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact_familyname"),
Contact.FAMILY_NAME);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_type"),
Contact.CONTACT_TYPE,
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,String attribute,PageState state) {
Contact contact = (Contact) item;
if (contact.getContactType() != null) {
return contact.getContactTypeName();
} else {
return "unknown";
}
}
});
sheet.add(
GlobalizationUtil.globalize("cms.contenttypes.ui.description"),
Contact.DESCRIPTION);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_emails"),
Contact.EMAILS);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_suffix"),
Contact.SUFFIX);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_orgname"),
Contact.ORG_NAME);
sheet.add(
ContactGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact_deptname"),
Contact.DEPT_NAME);
sheet.add(
ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_role"),
Contact.ROLE);
return sheet;
}
}

View File

@ -0,0 +1,205 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import java.math.BigDecimal;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.event.FormSectionEvent;
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.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.ContactType;
import com.arsdigita.cms.contenttypes.ContactTypesCollection;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.BasicPageForm;
/**
* Form to edit basic properties of <code>Contact</code> object. Used by
* <code>ContactPropertiesStep</code> authoring kit step.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactPropertyForm.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactPropertyForm extends BasicPageForm {
/** Name of this form */
public static final String ID = "Contact_edit";
/**
* Creates a new form to edit the Contact object specified by the item
* selection model passed in.
*
* @param itemModel
* The ItemSelectionModel to use to obtain the Contact to work on
*/
public ContactPropertyForm(ItemSelectionModel itemModel) {
super(ID, itemModel);
}
/**
* Adds widgets to the form. This has been cut into small methods
* so that subclasses can pick and choose.
*/
protected void addWidgets() {
addBasicPageFormWidgets();
addGivenNameWidget();
addFamilyNameWidget();
addSuffixWidget();
addContactTypeWidget();
addDescriptionWidget();
addEmailsWidget();
addOrganizationNameWidget();
addDepartmentNameWidget();
addRoleWidget();
}
protected void addBasicPageFormWidgets() {
super.addWidgets();
}
protected void addGivenNameWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_givenname")));
ParameterModel givenNameParam = new StringParameter(Contact.GIVEN_NAME);
TextField givenName = new TextField(givenNameParam);
add(givenName);
}
protected void addFamilyNameWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_familyname")));
ParameterModel familyNameParam = new StringParameter(Contact.FAMILY_NAME);
TextField familyName = new TextField(familyNameParam);
add(familyName);
}
protected void addSuffixWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_suffix")));
ParameterModel suffixParam = new StringParameter(Contact.SUFFIX);
TextField suffix = new TextField(suffixParam);
add(suffix);
}
protected void addContactTypeWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_type")));
ParameterModel contactTypeParam = new StringParameter(Contact.CONTACT_TYPE);
SingleSelect contactType = new SingleSelect(contactTypeParam);
add(contactType);
// retrieve Contact types
ContactTypesCollection ctTypes = ContactTypesCollection.getContactTypesCollection();
while (ctTypes.next()) {
contactType.addOption(new Option(ctTypes.getContactTypeID().toString(), ctTypes.getContactTypeName()));
}
}
protected void addDescriptionWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_description")));
ParameterModel descParam = new StringParameter(Contact.DESCRIPTION);
TextArea desc = new TextArea(descParam);
desc.setRows(5);
add(desc);
}
protected void addEmailsWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_emails")));
ParameterModel emailsParam = new StringParameter(Contact.EMAILS);
TextField emails = new TextField(emailsParam);
add(emails);
}
protected void addOrganizationNameWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_orgname")));
ParameterModel orgNameParam = new StringParameter(Contact.ORG_NAME);
TextField orgName = new TextField(orgNameParam);
add(orgName);
}
protected void addDepartmentNameWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_deptname")));
ParameterModel deptParam = new StringParameter(Contact.DEPT_NAME);
TextField deptName = new TextField(deptParam);
add(deptName);
}
protected void addRoleWidget() {
add(new Label(ContactGlobalizationUtil.globalize("cms.contenttypes.ui.contact_role")));
ParameterModel roleParam = new StringParameter(Contact.ROLE);
TextField role = new TextField(roleParam);
add(role);
}
/**
* Initialize Form values from Contact object.
*/
public void init(FormSectionEvent fse) {
FormData data = fse.getFormData();
Contact contact = (Contact) super.initBasicWidgets(fse);
if (contact.getContactType() != null) {
data.put(Contact.CONTACT_TYPE, contact.getContactType().getID());
}
data.put(Contact.GIVEN_NAME, contact.getGivenName());
data.put(Contact.FAMILY_NAME, contact.getFamilyName());
data.put(Contact.SUFFIX, contact.getSuffix());
data.put(Contact.EMAILS, contact.getEmails());
data.put(Contact.DESCRIPTION, contact.getDescription());
data.put(Contact.ORG_NAME, contact.getOrganisationName());
data.put(Contact.DEPT_NAME, contact.getDeptName());
data.put(Contact.ROLE, contact.getRole());
}
/**
* Process the form submission event.
*/
public void process(FormSectionEvent fse) {
FormData data = fse.getFormData();
Contact contact = (Contact) super.processBasicWidgets(fse);
// save only if save button was pressed
if (contact != null
&& getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
contact.setGivenName((String) data.get(Contact.GIVEN_NAME));
contact.setFamilyName((String) data.get(Contact.FAMILY_NAME));
contact.setSuffix((String) data.get(Contact.SUFFIX));
contact.setEmails((String) data.get(Contact.EMAILS));
String contactTypeIDStr = (String) data.get(Contact.CONTACT_TYPE);
if (contactTypeIDStr != null) {
BigDecimal contactTypeID =
new BigDecimal(contactTypeIDStr);
ContactType ctType = new ContactType(contactTypeID);
contact.setContactType(ctType);
}
contact.setDescription((String) data.get(Contact.DESCRIPTION));
contact.setOrganisationName((String) data.get(Contact.ORG_NAME));
contact.setDeptName((String) data.get(Contact.DEPT_NAME));
contact.setRole((String) data.get(Contact.ROLE));
contact.save();
}
}
}

View File

@ -0,0 +1,121 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.ContactInitializer;
import com.arsdigita.cms.contenttypes.ContactPhone;
import com.arsdigita.cms.contenttypes.util.ContactGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import java.util.ArrayList;
/**
* Form to Create objects of type <code>ContactPhone</code>.
*
* @author Shashin Shinde <sshinde@redhat.com>
*
* @version $Id: CreatePhone.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
class CreatePhone extends BasicItemForm {
private ItemSelectionModel m_model;
/**
* Creates a new form to create the <code>ContactPhone</code> object
* type associated with the <code>Contact</code> object specified
* by the item selection model passed in.
*
* @param itemModel
* The ItemSelectionModel to use to obtain the Contact object to
* work on
*/
public CreatePhone(ItemSelectionModel itemModel) {
super("Contact_phone_create", itemModel);
m_model = itemModel;
}
/**
* Adds widgets to edit the address properties to form. Only paon and
* streetDesc are required, rest are optional.
*/
protected void addWidgets() {
add(new Label(ContactGlobalizationUtil.globalize(
"cms.contenttypes.ui.contact.phone_number")));
ParameterModel phoneNoParam = new StringParameter(ContactPhone.PHONE_NUMBER);
TextField phoneNo = new TextField(phoneNoParam);
phoneNo.addValidationListener(new NotNullValidationListener());
add(phoneNo);
add(new Label(ContactGlobalizationUtil.globalize(
"cms.contenttypes.ui.phone_type")));
ParameterModel phoneTypeParam = new StringParameter(ContactPhone.PHONE_TYPE);
SingleSelect phoneType = new SingleSelect(phoneTypeParam);
add(phoneType);
// retrieve static Phone types
ArrayList phTypes = ContactInitializer.getPhoneTypes();
for (int i = 0; i < phTypes.size(); i++) {
phoneType.addOption(
new Option(phTypes.get(i).toString(), phTypes.get(i).toString()));
}
}
/**
*/
public void init(FormSectionEvent e) {
//Do nothing.
}
/**
* Create an object of type <code>ContactPhone</code> and add it to Contact
* object retrieved from passed in ItemSelectionModel.
*/
public void process(FormSectionEvent fse) {
FormData data = fse.getFormData();
Contact contact = (Contact) m_model.getSelectedObject(fse.getPageState());
// save only if save button was pressed
if (contact != null
&& getSaveCancelSection().getSaveButton().isSelected(
fse.getPageState())) {
ContactPhone cph = new ContactPhone();
cph.setName("phone-for-contact-" + contact.getID());
cph.setPhoneType((String) data.get(ContactPhone.PHONE_TYPE));
cph.setPhoneNumber((String) data.get(ContactPhone.PHONE_NUMBER));
cph.save();
//Add it to the contact.
contact.addPhone(cph);
}
}
}

View File

@ -0,0 +1,57 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.AuthoringKitWizard;
import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
/**
* A UI step to manipulate <code>Phones </code> for the Contact object
* which is retrieved from the ItemSelectionModel.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: PhonesPanel.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
public class PhonesPanel extends SimpleEditStep {
/** The name of the editing sheet added to this step */
private static String EDIT_SHEET_NAME = "manage-phones";
public PhonesPanel(ItemSelectionModel itemModel, AuthoringKitWizard parent) {
super(itemModel, parent);
BasicItemForm form = new CreatePhone(itemModel);
add(
EDIT_SHEET_NAME,
"Add Phone",
new WorkflowLockedComponentAccess(form, itemModel),
form.getSaveCancelSection().getCancelButton());
PhonesTable phTable = new PhonesTable(itemModel);
setDisplayComponent(phTable);
}
}

View File

@ -0,0 +1,211 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.ui.contact;
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.ItemSelectionModel;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.contenttypes.Contact;
import com.arsdigita.cms.contenttypes.ContactPhone;
import com.arsdigita.cms.contenttypes.PhonesCollection;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
/**
* A Table to display the Phones associated with the Contact object.
* Provides links to delete the corresponding phone in each row.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
*
* @version $Id: PhonesTable.java 287 2005-02-22 00:29:02Z sskracic $
*
*/
class PhonesTable extends Table implements TableActionListener{
private ItemSelectionModel m_contactSel;
private static final String COL_PHONE_TYPE ="Phone Type";
private static final String COL_PHONE_NUM="Phone Number";
private static final String COL_DELETE ="Delete";
/**
* Constructor.Create an instance of this class.
*
* @param selContact , ItemSelectionModel which provides the
* <code>Contact</code> object whose Phones are to be manipulated.
*/
public PhonesTable(ItemSelectionModel selContact) {
super();
m_contactSel = selContact;
setEmptyView(new Label("No Phones associated with this Contact"));
TableColumnModel model = getColumnModel();
model.add( new TableColumn( 0, COL_PHONE_TYPE ));
model.add( new TableColumn( 1, COL_PHONE_NUM ));
model.add( new TableColumn( 2, COL_DELETE ));
setModelBuilder(new PhonesTableModelBuilder(selContact));
model.get(2).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this);
}
private class PhonesTableModelBuilder extends LockableImpl implements TableModelBuilder {
private ItemSelectionModel m_sel;
private PhonesTableModelBuilder(ItemSelectionModel sel){
m_sel = sel;
}
public TableModel makeModel ( Table table, PageState state ) {
table.getRowSelectionModel().clearSelection(state);
Contact contact = (Contact) m_sel.getSelectedObject(state);
return new PhonesTableModel(table, state, contact);
}
}
private class PhonesTableModel implements TableModel{
private Table m_table;
private PhonesCollection m_phones;
private ContactPhone m_phone;
private PhonesTableModel(Table t,PageState ps,Contact c){
m_table = t;
m_phones = c.getPhones();
}
public int getColumnCount() {
return m_table.getColumnModel().size();
}
/**
* check collection for the existence of another row.If it has fetch the
* value of Current Phone object into m_phone class variable.
*/
public boolean nextRow() {
if(m_phones != null && m_phones.next()){
m_phone = m_phones.getPhone();
return true;
} else {
return false;
}
}
/**
* Return the phoneType and phoneNumber attributes for the Type and
* Number columns respectively.
* @see com.arsdigita.bebop.table.TableModel#getElementAt(int)
*/
public Object getElementAt(int columnIndex) {
switch (columnIndex){
case 0:
return m_phone.getPhoneType();
case 1:
return m_phone.getPhoneNumber();
case 2:
return "Delete";
default:
return null;
}
}
/**
* Always return the ID of <code>Phone</code> represented by current row.
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
*/
public Object getKeyAt(int columnIndex) {
return m_phone.getID();
}
}
/**
* Check for the permissions to delete item and put either a Lable or
* a ControlLink accordingly.
*/
private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer{
public Component getComponent(Table table,PageState state,Object value,
boolean isSelected,Object key,
int row,int column) {
SecurityManager sm = Utilities.getSecurityManager(state);
Contact item = (Contact) m_contactSel.getSelectedObject(state);
boolean canDelete = sm.canAccess(state.getRequest(),
SecurityManager.DELETE_ITEM,
item);
if ( canDelete) {
ControlLink link = new ControlLink(value.toString());
link.setConfirmation("Delete this Phone ?");
return link;
} else {
return new Label(value.toString());
}
}
}
/**
* Provide implementation to TableActionListener method.
* Code that comes into picture when a link on the table is clicked.
* Handles delete event.
*/
public void cellSelected(TableActionEvent evt) {
PageState state = evt.getPageState();
TableColumn col = getColumnModel().get(evt.getColumn().intValue());
String colName = (String) col.getHeaderValue();
if ( COL_DELETE.equals(colName) ) {
BigDecimal phoneID = new BigDecimal(evt.getRowKey().toString());
Contact contact = (Contact) m_contactSel.getSelectedObject(state);
ContactPhone ph = new ContactPhone(phoneID);
contact.removePhone(ph);
}
}
/**
* provide Implementation to TableActionListener method.
* Does nothing in our case.
*/
public void headSelected(TableActionEvent e) {
throw new UnsupportedOperationException("Not Implemented");
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.util;
import com.arsdigita.globalization.GlobalizedMessage;
/**
* <p>
* Contains methods to simplify globalizing keys related to Contact
* ContentType object.
* </p>
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactGlobalizationUtil.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactGlobalizationUtil {
final public static String BUNDLE_NAME =
"com.arsdigita.cms.contenttypes.util.ContactResourceBundle";
/**
* This returns a globalized message using the type specific bundle,
* BUNDLE_NAME
*/
public static GlobalizedMessage globalize(String key) {
return new GlobalizedMessage(key, BUNDLE_NAME);
}
/**
* This returns a globalized message using the type specific bundle,
* BUNDLE_NAME
*/
public static GlobalizedMessage globalize(String key, Object[] args) {
return new GlobalizedMessage(key, BUNDLE_NAME, args);
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2004 Red Hat Inc. 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
*
*/
package com.arsdigita.cms.contenttypes.util;
import java.util.PropertyResourceBundle;
import com.arsdigita.globalization.ChainedResourceBundle;
import com.arsdigita.cms.CMSGlobalized;
/**
* Resource Bundle used in UI for Contact ContentType.
*
* @author Shashin Shinde <a href="mailto:sshinde@redhat.com">sshinde@redhat.com</a>
* @version $Id: ContactResourceBundle.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class ContactResourceBundle extends ChainedResourceBundle implements CMSGlobalized {
public final static String CONTACT_BUNDLE_NAME =
"com.arsdigita.cms.contenttypes.ContactResources";
public ContactResourceBundle() {
super();
addBundle((PropertyResourceBundle)getBundle(CONTACT_BUNDLE_NAME));
addBundle((PropertyResourceBundle)getBundle(BUNDLE_NAME));
}
}

View File

@ -0,0 +1,153 @@
<!DOCTYPE stylesheet [
<!ENTITY nbsp "&#160;" ><!-- no-break space = non-breaking space, U+00A0 ISOnum -->
]>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:cms="http://www.arsdigita.com/cms/1.0"
version="1.0">
<xsl:template match="cms:item[objectType='com.arsdigita.cms.contenttypes.Contact']" mode="cms:CT_graphics"
name="cms:CT_graphics_com_arsdigita_cms_contenttypes_Contact">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td class="contentTitle" align="left" valign="top"><xsl:value-of select="./title"/></td>
<td>Contact Address Details</td>
<td>Contact Phones</td>
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th valign="top">Given Name:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./givenName"/></td>
</tr>
<tr>
<th valign="top">Family Name:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./familyName"/></td>
</tr>
<tr>
<th valign="top">Contact Type:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./contactType/typeName"/></td>
</tr>
<tr>
<th valign="top">Description:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of disable-output-escaping="yes" select="./description"/></td>
</tr>
<tr>
<th valign="top">Contact Emails:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./emails"/></td>
</tr>
<tr>
<th valign="top">Suffix:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./suffix"/></td>
</tr>
<tr>
<th valign="top" nowrap="true">Organisation Name:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./orgName"/></td>
</tr>
<tr>
<th valign="top">Department Name:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./deptName"/></td>
</tr>
<tr>
<th valign="top">Role:</th>
<td valign="top" class="contentText" align="left"><xsl:value-of select="./role"/></td>
</tr>
</table>
</td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th valign="top">SAON:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/saon"/></td>
</tr>
<tr>
<th valign="top">PAON:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/paon"/></td>
</tr>
<tr>
<th valign="top">Street Description:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/streetDesc"/></td>
</tr>
<tr>
<th valign="top">Locality:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/locality"/></td>
</tr>
<tr>
<th valign="top">Town:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/town"/></td>
</tr>
<tr>
<th valign="top">Postal Code:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/postCode"/></td>
</tr>
<tr>
<th valign="top">Postal Town:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/postTown"/></td>
</tr>
<tr>
<th valign="top" nowrap="true">Administrative Area:</th>
<td valign="top" class="contentText" align="left">
<xsl:value-of select="./contactAddress/administrativeArea"/></td>
</tr>
</table>
</td>
<td valign="top">
<table width="100%" border="0" cellspacing="2" cellpadding="1">
<tr bgcolor="#eeeee">
<th nowrap="true" align="left">Phone Type</th>
<th nowrap="true">Phone Number</th>
</tr>
<xsl:for-each select="./phones">
<tr>
<td class="contentText" valign="top" align="left"><xsl:value-of select="./phoneType"/></td>
<td class="contentText" valign="top" align="left"><xsl:value-of select="./phoneNumber"/></td>
</tr>
</xsl:for-each>
</table>
</td>
</tr>
</table>
</xsl:template>
<xsl:template match="cms:item[objectType='com.arsdigita.cms.contenttypes.Contact']" mode="cms:CT_text"
name="cms:CT_text_com_arsdigita_cms_contenttypes_Contact">
<h1 class="title">CONTACT<xsl:text disable-output-escaping="yes">&amp;</xsl:text>gt; <xsl:value-of select="./title"/></h1>
<span class="subtitle">Given Name</span>
<span class="text"><xsl:value-of select="./givenName"/></span><br/>
<span class="subtitle">Family Name</span>
<span class="text"><xsl:value-of select="./familyName"/></span><br/>
<span class="subtitle">Contact Suffix</span>
<span class="text"><xsl:value-of select="./suffix"/></span><br/>
<span class="subtitle">Contact Type</span>
<span class="text"><xsl:value-of select="./contactType"/></span><br/>
<span class="subtitle">Description</span>
<span class="text"><xsl:value-of select="./description"/></span><br/>
<span class="subtitle">Organisation Name</span>
<span class="text"><xsl:value-of select="./orgName"/></span><br/>
<span class="subtitle">Department Name</span>
<span class="text"><xsl:value-of select="./deptName"/></span><br/>
<span class="subtitle">Role</span>
<span class="text"><xsl:value-of select="./role"/></span><br/>
<br/>
</xsl:template>
<xsl:template
match="cms:item[objectType='com.arsdigita.cms.contenttypes.ContactPhone']"
mode="cms:CT_text"
name="cms:CT_text_com_arsdigita_cms_contenttypes_ContactPhone">
<span class="subtitle">Contact Phone Type</span>
<span class="textCap"><xsl:value-of select="./phoneType"/></span><br/>
<span class="subtitle">Contact Phone Number</span>
<span class="textCap"><xsl:value-of select="./phoneNumber"/></span><br/>
</xsl:template>
</xsl:stylesheet>