GenericContact

* UI zum Bearbeiten von Personen angepaßt
 * ContactEntryType verwendet nun RelationAttribute für die Typisierung

Diverse kleine Änderungen

git-svn-id: https://svn.libreccm.org/ccm/trunk@598 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-11-08 11:56:38 +00:00
parent 478a66f4b9
commit 78f895d701
11 changed files with 285 additions and 272 deletions

View File

@ -8,7 +8,6 @@ import com.arsdigita.domain.DomainCollection;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.SessionManager;
import org.apache.log4j.Logger;
/** /**
* *

View File

@ -67,15 +67,15 @@ cms.contenttypes.ui.contact.contactEntry.value=Inhalt
cms.contenttypes.ui.contact.contactEntry.description=Beschreibung (wird nicht \u00f6ffentlich angezeigt) cms.contenttypes.ui.contact.contactEntry.description=Beschreibung (wird nicht \u00f6ffentlich angezeigt)
cms.contenttypes.ui.contact.contactEntry.action=Aktionen cms.contenttypes.ui.contact.contactEntry.action=Aktionen
cms.contenttypes.ui.contact.contactEntry.key.contact_type=Kontaktart #cms.contenttypes.ui.contact.contactEntry.key.contact_type=Kontaktart
cms.contenttypes.ui.contact.contactEntry.key.office_hours=\u00d6ffnungszeiten #cms.contenttypes.ui.contact.contactEntry.key.office_hours=\u00d6ffnungszeiten
cms.contenttypes.ui.contact.contactEntry.key.phone_office=Telefon (B\u00fcro) #cms.contenttypes.ui.contact.contactEntry.key.phone_office=Telefon (B\u00fcro)
cms.contenttypes.ui.contact.contactEntry.key.phone_private=Telefon (Privat) #cms.contenttypes.ui.contact.contactEntry.key.phone_private=Telefon (Privat)
cms.contenttypes.ui.contact.contactEntry.key.phone_mobile=Telefon (Mobil) #cms.contenttypes.ui.contact.contactEntry.key.phone_mobile=Telefon (Mobil)
cms.contenttypes.ui.contact.contactEntry.key.email=E-Mail #cms.contenttypes.ui.contact.contactEntry.key.email=E-Mail
cms.contenttypes.ui.contact.contactEntry.key.fax=Fax #cms.contenttypes.ui.contact.contactEntry.key.fax=Fax
cms.contenttypes.ui.contact.contactEntry.key.im=Instant Messenger #cms.contenttypes.ui.contact.contactEntry.key.im=Instant Messenger
cms.contenttypes.ui.contact.contactEntry.key.www=Homepage #cms.contenttypes.ui.contact.contactEntry.key.www=Homepage
cms.contenttypes.ui.contact.contactEntry.none=Zur Zeit sind keine Kontaktinformationen vorhanden cms.contenttypes.ui.contact.contactEntry.none=Zur Zeit sind keine Kontaktinformationen vorhanden

View File

@ -42,8 +42,9 @@ public class GenericContact extends ContentPage implements
// public static final String CONTACT_TYPE = ""; // public static final String CONTACT_TYPE = "";
public static final String ADDRESS = "address"; public static final String ADDRESS = "address";
public static final String CONTACT_ENTRIES = "contactentries"; public static final String CONTACT_ENTRIES = "contactentries";
private static final String RELATION_ATTRIBUTES = public static final String CONTACTS_KEY = GenericPersonContactCollection.CONTACTS_KEY;
"GenericContactType;GenericContactEntryType"; private static final String RELATION_ATTRIBUTES = "GenericContactType;GenericContactEntryType";
// Config // Config
private static final GenericContactConfig s_config = private static final GenericContactConfig s_config =
new GenericContactConfig(); new GenericContactConfig();
@ -114,7 +115,7 @@ public class GenericContact extends ContentPage implements
} }
// Set the person for this contact // Set the person for this contact
public void setPerson(GenericPerson person) { public void setPerson(GenericPerson person, String contactType) {
//set(PERSON, person); //set(PERSON, person);
if (getPerson() != null) { if (getPerson() != null) {
unsetPerson(); unsetPerson();
@ -123,8 +124,8 @@ public class GenericContact extends ContentPage implements
if (person != null) { if (person != null) {
Assert.exists(person, GenericPerson.class); Assert.exists(person, GenericPerson.class);
DataObject link = add(PERSON, person); DataObject link = add(PERSON, person);
link.set(GenericPerson.CONTACTS_ORDER, link.set(GenericPerson.CONTACTS_KEY, contactType);
new BigDecimal(person.getContacts().size())); link.set(GenericPerson.CONTACTS_ORDER, new BigDecimal(person.getContacts().size()));
link.save(); link.save();
} }
} }
@ -182,6 +183,30 @@ public class GenericContact extends ContentPage implements
remove(CONTACT_ENTRIES, contactEntry); remove(CONTACT_ENTRIES, contactEntry);
} }
public String getContactType() {
GenericPerson person = getPerson();
if(person != null) {
GenericPersonContactCollection collection = person.getContacts();
collection.next();
return (String) collection.getContactType();
} else {
return null;
}
}
public void setContactType(String contactType) {
GenericPerson person = getPerson();
if(person != null) {
GenericPersonContactCollection collection = person.getContacts();
collection.next();
DataObject link = (DataObject) collection.get("link");
link.set(CONTACTS_KEY, contactType);
}
}
public boolean hasPerson() { public boolean hasPerson() {
return !(this.getPerson() == null); return !(this.getPerson() == null);
} }

View File

@ -16,9 +16,7 @@ import com.arsdigita.persistence.DataCollection;
*/ */
public class GenericContactTypeCollection extends RelationAttributeCollection { public class GenericContactTypeCollection extends RelationAttributeCollection {
public static final String CONTACTS_KEY = GenericPerson.CONTACTS_KEY; public static final String ATTRIBUTE_NAME = "GenericContactTypes";
public static final String CONTACTS_ORDER = GenericPerson.CONTACTS_ORDER;
public static final String ATTRIBUTE_NAME = "person";
/** /**
* Creates a new instance of GenericContactEntryCollection * Creates a new instance of GenericContactEntryCollection
@ -28,18 +26,10 @@ public class GenericContactTypeCollection extends RelationAttributeCollection {
} }
public GenericContactTypeCollection(String key) { public GenericContactTypeCollection(String key) {
super(ATTRIBUTE_NAME, CONTACTS_KEY); super(ATTRIBUTE_NAME, key);
} }
public GenericContactTypeCollection(DataCollection dataCollection) { public GenericContactTypeCollection(DataCollection dataCollection) {
super(dataCollection); super(dataCollection);
} }
// public void setContactOrder(String contact_order) {
// set(CONTACT_ORDER, contact_order);
// }
public String getContactOrder() {
return (String) get(CONTACTS_ORDER);
}
} }

View File

@ -91,7 +91,7 @@ public class GenericContactAttachPersonPropertyForm extends BasicPageForm implem
// GenericContact type field // GenericContact type field
add(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.contact.type"))); add(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.contact.type")));
ParameterModel contactTypeParam = new StringParameter(GenericPersonContactCollection.CONTACTS_KEY); ParameterModel contactTypeParam = new StringParameter(CONTACTS_KEY);
SingleSelect contactType = new SingleSelect(contactTypeParam); SingleSelect contactType = new SingleSelect(contactTypeParam);
contactType.addValidationListener(new NotNullValidationListener()); contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize()))); contactType.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize())));
@ -117,7 +117,7 @@ public class GenericContactAttachPersonPropertyForm extends BasicPageForm implem
if (contact != null) { if (contact != null) {
data.put(ITEM_SEARCH, contact.getPerson()); data.put(ITEM_SEARCH, contact.getPerson());
// data.put(CONTACTS_KEY, contact.getContactType()); data.put(CONTACTS_KEY, contact.getContactType());
} }
} }
@ -127,8 +127,7 @@ public class GenericContactAttachPersonPropertyForm extends BasicPageForm implem
GenericContact contact = (GenericContact) getItemSelectionModel().getSelectedObject(state); GenericContact contact = (GenericContact) getItemSelectionModel().getSelectedObject(state);
if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) { if (!this.getSaveCancelSection().getCancelButton().isSelected(state)) {
contact.setPerson((GenericPerson) data.get(ITEM_SEARCH)); contact.setPerson((GenericPerson) data.get(ITEM_SEARCH), (String) data.get(CONTACTS_KEY));
// contact.setContactType(data.get(CONTACTS_KEY));
} }
init(fse); init(fse);
} }

View File

@ -15,16 +15,22 @@ import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener; import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener; import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.RelationAttribute;
import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericContactTypeCollection;
import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.GenericPersonContactCollection;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -36,10 +42,13 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm implemen
private static final Logger logger = Logger.getLogger(GenericContactPropertyForm.class); private static final Logger logger = Logger.getLogger(GenericContactPropertyForm.class);
private GenericContactPersonPropertiesStep m_step; private GenericContactPersonPropertiesStep m_step;
public static final String SURNAME = GenericPerson.SURNAME; public static final String SURNAME = GenericPerson.SURNAME;
public static final String GIVENNAME = GenericPerson.GIVENNAME; public static final String GIVENNAME = GenericPerson.GIVENNAME;
public static final String TITLEPRE = GenericPerson.TITLEPRE; public static final String TITLEPRE = GenericPerson.TITLEPRE;
public static final String TITLEPOST = GenericPerson.TITLEPOST; public static final String TITLEPOST = GenericPerson.TITLEPOST;
public static final String CONTACTS_KEY = GenericPersonContactCollection.CONTACTS_KEY;
/** /**
* ID of the form * ID of the form
*/ */
@ -93,6 +102,24 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm implemen
titlepostParam.addParameterListener(new StringInRangeValidationListener(0, 1000)); titlepostParam.addParameterListener(new StringInRangeValidationListener(0, 1000));
TextField titlepost = new TextField(titlepostParam); TextField titlepost = new TextField(titlepostParam);
add(titlepost); add(titlepost);
// GenericContact type field
add(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.contact.type")));
ParameterModel contactTypeParam = new StringParameter(CONTACTS_KEY);
SingleSelect contactType = new SingleSelect(contactTypeParam);
contactType.addValidationListener(new NotNullValidationListener());
contactType.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize())));
// Add the Options to the SingleSelect widget
GenericContactTypeCollection contacttypes = new GenericContactTypeCollection();
contacttypes.addLanguageFilter(DispatcherHelper.getNegotiatedLocale().getLanguage());
while (contacttypes.next()) {
RelationAttribute ct = contacttypes.getRelationAttribute();
contactType.addOption(new Option(ct.getKey(), ct.getName()));
}
add(contactType);
} }
public void init(FormSectionEvent fse) { public void init(FormSectionEvent fse) {
@ -105,6 +132,7 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm implemen
data.put(GIVENNAME, contact.getPerson().getGivenName()); data.put(GIVENNAME, contact.getPerson().getGivenName());
data.put(TITLEPRE, contact.getPerson().getTitlePre()); data.put(TITLEPRE, contact.getPerson().getTitlePre());
data.put(TITLEPOST, contact.getPerson().getTitlePost()); data.put(TITLEPOST, contact.getPerson().getTitlePost());
// data.put(CONTACTS_KEY, contact.getContactType());
} }
} }
@ -122,16 +150,17 @@ public class GenericContactEditPersonPropertyForm extends BasicPageForm implemen
if (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) { if (getSaveCancelSection().getSaveButton().isSelected(fse.getPageState())) {
if (contact.getPerson() == null) { // if (contact.getPerson() == null) {
contact.setPerson(new GenericPerson()); // contact.setPerson(new GenericPerson());
contact.getPerson().setName("Person for " + contact.getName() + "(" + contact.getID() + ")"); // contact.getPerson().setName("Person for " + contact.getName() + "(" + contact.getID() + ")");
contact.getPerson().setTitle("Person for " + contact.getName() + "(" + contact.getID() + ")"); // contact.getPerson().setTitle("Person for " + contact.getName() + "(" + contact.getID() + ")");
} // }
contact.getPerson().setSurname((String) data.get(SURNAME)); contact.getPerson().setSurname((String) data.get(SURNAME));
contact.getPerson().setGivenName((String) data.get(GIVENNAME)); contact.getPerson().setGivenName((String) data.get(GIVENNAME));
contact.getPerson().setTitlePre((String) data.get(TITLEPRE)); contact.getPerson().setTitlePre((String) data.get(TITLEPRE));
contact.getPerson().setTitlePost((String) data.get(TITLEPOST)); contact.getPerson().setTitlePost((String) data.get(TITLEPOST));
// contact.setContactType((String) data.get(CONTACTS_KEY));
contact.getPerson().save(); contact.getPerson().save();
} }

View File

@ -35,9 +35,11 @@ import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericContactEntry; import com.arsdigita.cms.contenttypes.GenericContactEntry;
import com.arsdigita.cms.contenttypes.GenericContactEntryCollection; import com.arsdigita.cms.contenttypes.GenericContactEntryCollection;
import com.arsdigita.cms.contenttypes.GenericContactEntryKeys;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal; import java.math.BigDecimal;
@ -46,12 +48,10 @@ import java.math.BigDecimal;
* *
* @author Sören Bernstein (quasimodo) quasi@barkhof.uni-bremen.de * @author Sören Bernstein (quasimodo) quasi@barkhof.uni-bremen.de
*/ */
public class GenericContactEntriesTable extends Table implements TableActionListener{ public class GenericContactEntriesTable extends Table implements TableActionListener {
private final String TABLE_COL_EDIT = "table_col_edit"; private final String TABLE_COL_EDIT = "table_col_edit";
private final String TABLE_COL_DEL = "table_col_del"; private final String TABLE_COL_DEL = "table_col_del";
private ItemSelectionModel m_itemModel; private ItemSelectionModel m_itemModel;
/** /**
@ -98,12 +98,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
table.getRowSelectionModel().clearSelection(state); table.getRowSelectionModel().clearSelection(state);
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state); GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
// if (contact != null && contact.hasContactEntries()) {
return new ContactTableModel(table, state, contact); return new ContactTableModel(table, state, contact);
// } else {
// return Table.EMPTY_MODEL;
// }
} }
} }
@ -114,7 +109,6 @@ public class GenericContactEntriesTable extends Table implements TableActionList
private class ContactTableModel implements TableModel { private class ContactTableModel implements TableModel {
final private int MAX_DESC_LENGTH = 25; final private int MAX_DESC_LENGTH = 25;
private Table m_table; private Table m_table;
private GenericContactEntryCollection m_contactEntryCollection; private GenericContactEntryCollection m_contactEntryCollection;
private GenericContactEntry m_contactEntry; private GenericContactEntry m_contactEntry;
@ -136,7 +130,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
*/ */
public boolean nextRow() { public boolean nextRow() {
if(m_contactEntryCollection != null && m_contactEntryCollection.next()){ if (m_contactEntryCollection != null && m_contactEntryCollection.next()) {
m_contactEntry = m_contactEntryCollection.getContactEntry(); m_contactEntry = m_contactEntryCollection.getContactEntry();
return true; return true;
@ -152,9 +146,14 @@ public class GenericContactEntriesTable extends Table implements TableActionList
* @see com.arsdigita.bebop.table.TableModel#getElementAt(int) * @see com.arsdigita.bebop.table.TableModel#getElementAt(int)
*/ */
public Object getElementAt(int columnIndex) { public Object getElementAt(int columnIndex) {
switch (columnIndex){ switch (columnIndex) {
case 0: case 0:
return (String)ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.key." + m_contactEntry.getKey()).localize(); GenericContactEntryKeys keys = new GenericContactEntryKeys(m_contactEntry.getKey());
keys.addLanguageFilter(DispatcherHelper.getNegotiatedLocale().getLanguage());
if (keys.next()) {
return keys.getName();
}
return m_contactEntry.getKey();
case 1: case 1:
return m_contactEntry.getValue(); return m_contactEntry.getValue();
case 2: case 2:
@ -175,7 +174,6 @@ public class GenericContactEntriesTable extends Table implements TableActionList
public Object getKeyAt(int columnIndex) { public Object getKeyAt(int columnIndex) {
return m_contactEntry.getID(); return m_contactEntry.getID();
} }
} }
/** /**
@ -194,7 +192,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
boolean canEdit = sm.canAccess(state.getRequest(), boolean canEdit = sm.canAccess(state.getRequest(),
SecurityManager.EDIT_ITEM, SecurityManager.EDIT_ITEM,
contact); contact);
if(canEdit) { if (canEdit) {
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
return link; return link;
} else { } else {
@ -219,7 +217,7 @@ public class GenericContactEntriesTable extends Table implements TableActionList
boolean canDelete = sm.canAccess(state.getRequest(), boolean canDelete = sm.canAccess(state.getRequest(),
SecurityManager.DELETE_ITEM, SecurityManager.DELETE_ITEM,
contact); contact);
if(canDelete) { if (canDelete) {
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.confirm_delete").localize()); link.setConfirmation((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.confirm_delete").localize());
return link; return link;
@ -249,12 +247,11 @@ public class GenericContactEntriesTable extends Table implements TableActionList
TableColumn col = getColumnModel().get(evt.getColumn().intValue()); TableColumn col = getColumnModel().get(evt.getColumn().intValue());
// Edit // Edit
if(col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) { if (col.getHeaderKey().toString().equals(TABLE_COL_EDIT)) {
} }
// Delete // Delete
if(col.getHeaderKey().toString().equals(TABLE_COL_DEL)) { if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
contact.removeContactEntry(contactEntry); contact.removeContactEntry(contactEntry);
} }
@ -267,6 +264,4 @@ public class GenericContactEntriesTable extends Table implements TableActionList
public void headSelected(TableActionEvent e) { public void headSelected(TableActionEvent e) {
throw new UnsupportedOperationException("Not Implemented"); throw new UnsupportedOperationException("Not Implemented");
} }
} }

View File

@ -32,7 +32,8 @@ import com.arsdigita.cms.contenttypes.GenericContactEntry;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.cms.ui.authoring.BasicItemForm; import com.arsdigita.cms.ui.authoring.BasicItemForm;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import java.util.StringTokenizer; import com.arsdigita.cms.contenttypes.GenericContactEntryKeys;
import com.arsdigita.dispatcher.DispatcherHelper;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -63,10 +64,11 @@ public class GenericContactEntryAddForm extends BasicItemForm {
contactEntryKey.addOption(new Option("", new Label((String)ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize()))); contactEntryKey.addOption(new Option("", new Label((String)ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize())));
// Add the Options to the SingleSelect widget // Add the Options to the SingleSelect widget
StringTokenizer keyList = GenericContact.getConfig().getContactEntryKeys(); GenericContactEntryKeys keyList = new GenericContactEntryKeys();
while(keyList.hasMoreElements()) { keyList.addLanguageFilter(DispatcherHelper.getNegotiatedLocale().getLanguage());
String currentKey = keyList.nextToken(); while(keyList.next()) {
contactEntryKey.addOption(new Option(currentKey, ((String)ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.key." + currentKey).localize()))); String currentKey = keyList.getKey();
contactEntryKey.addOption(new Option(currentKey, keyList.getName()));
} }
add(contactEntryKey); add(contactEntryKey);

View File

@ -15,8 +15,6 @@ import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
/** /**
@ -47,50 +45,17 @@ public class GenericContactPersonPropertiesStep extends SimpleEditStep {
addPerson = new WorkflowLockedComponentAccess(addPersonSheet, itemModel); addPerson = new WorkflowLockedComponentAccess(addPersonSheet, itemModel);
add(ADD_PERSON_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.attach_person").localize(), addPerson, addPersonSheet.getSaveCancelSection().getCancelButton()); add(ADD_PERSON_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.attach_person").localize(), addPerson, addPersonSheet.getSaveCancelSection().getCancelButton());
BasicPageForm editPersonSheet = new GenericContactEditPersonPropertyForm(itemModel, this);
editPerson = new WorkflowLockedComponentAccess(editPersonSheet, itemModel);
add(EDIT_PERSON_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.edit_person").localize(), editPerson, editPersonSheet.getSaveCancelSection().getCancelButton());
BasicPageForm deletePersonSheet = new GenericContactDeletePersonForm(itemModel, this);
delPerson = new WorkflowLockedComponentAccess(deletePersonSheet, itemModel);
add(DELETE_PERSON_SHEET_NAME, (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.delete_person").localize(), delPerson, deletePersonSheet.getSaveCancelSection().getCancelButton());
/* Set the displayComponent for this step */ /* Set the displayComponent for this step */
setDisplayComponent(getPersonPropertySheet(itemModel)); setDisplayComponent(getPersonPropertySheet(itemModel));
} }
public static Component getPersonPropertySheet(ItemSelectionModel itemModel) { public static Component getPersonPropertySheet(ItemSelectionModel itemModel) {
/*DomainObjectPropertySheet sheet = new DomainObjectPropertySheet(itemModel); GenericContactPersonSheet sheet = new GenericContactPersonSheet(itemModel);
sheet.add(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.surname"), "person." + GenericPerson.SURNAME);
sheet.add(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.givenname"), "person." + GenericPerson.GIVENNAME);
sheet.add(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepre"), "person." + GenericPerson.TITLEPRE);
sheet.add(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepost"), "person." + GenericPerson.TITLEPOST);*/
GenericContactPersonSheet sheet = new GenericContactPersonSheet(
itemModel);
return sheet; return sheet;
} }
public static Component getEmptyPersonPropertySheet(ItemSelectionModel itemModel) { public static Component getEmptyPersonPropertySheet(ItemSelectionModel itemModel) {
return new Label(((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.emptyPerson").localize())); return new Label(((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.emptyPerson").localize()));
} }
@Override
public boolean isVisible(PageState ps) {
if(((GenericContact) getItemSelectionModel().getSelectedItem(ps)).hasPerson() == false) {
addPerson.getComponent().setVisible(ps, true);
editPerson.getComponent().setVisible(ps, false);
delPerson.getComponent().setVisible(ps, false);
} else {
addPerson.getComponent().setVisible(ps, false);
editPerson.getComponent().setVisible(ps, true);
delPerson.getComponent().setVisible(ps, true);
}
return super.isVisible(ps);
}
} }

View File

@ -22,6 +22,7 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink; import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table; import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent; import com.arsdigita.bebop.event.TableActionEvent;
@ -31,13 +32,18 @@ import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel; import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel; import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder; import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.contenttypes.GenericContact; import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil; import com.arsdigita.cms.contenttypes.util.ContenttypesGlobalizationUtil;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
/** /**
* *
@ -93,8 +99,7 @@ public class GenericContactPersonSheet
@Override @Override
public TableModel makeModel(Table table, PageState state) { public TableModel makeModel(Table table, PageState state) {
table.getRowSelectionModel().clearSelection(state); table.getRowSelectionModel().clearSelection(state);
GenericContact contact = (GenericContact) m_itemModel. GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
getSelectedObject(state);
return new GenericContactPersonSheetModel(table, return new GenericContactPersonSheetModel(table,
state, state,
contact); contact);
@ -166,8 +171,34 @@ public class GenericContactPersonSheet
Object key, Object key,
int row, int row,
int column) { int column) {
Label label = new Label(value.toString());
return label; com.arsdigita.cms.SecurityManager securityManager = Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
boolean canEdit = securityManager.canAccess(
state.getRequest(),
com.arsdigita.cms.SecurityManager.EDIT_ITEM,
contact);
if (canEdit) {
GenericPerson person;
try {
person = new GenericPerson((BigDecimal) key);
} catch (DataObjectNotFoundException ex) {
return new Label(value.toString());
}
ContentSection section = CMS.getContext().getContentSection();
ItemResolver resolver = section.getItemResolver();
return new Link(value.toString(), resolver.generateItemURL(state, person, section, person.getVersion()));
} else {
return new Label(value.toString());
}
} }
} }
@ -185,8 +216,7 @@ public class GenericContactPersonSheet
int col) { int col) {
SecurityManager securityManager = SecurityManager securityManager =
Utilities.getSecurityManager(state); Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel. GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(
getSelectedObject(
state); state);
boolean canEdit = securityManager.canAccess( boolean canEdit = securityManager.canAccess(
@ -196,8 +226,7 @@ public class GenericContactPersonSheet
if (canEdit) { if (canEdit) {
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) ContenttypesGlobalizationUtil. link.setConfirmation((String) ContenttypesGlobalizationUtil.globalize(
globalize(
"cms.contenttypes.ui.contact.person" "cms.contenttypes.ui.contact.person"
+ ".confirm_remove"). + ".confirm_remove").
localize()); localize());

View File

@ -21,6 +21,7 @@ package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink; import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Table; import com.arsdigita.bebop.Table;
@ -34,9 +35,13 @@ import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryLocalization; import com.arsdigita.categorization.CategoryLocalization;
import com.arsdigita.categorization.CategoryLocalizationCollection; import com.arsdigita.categorization.CategoryLocalizationCollection;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.SecurityManager; import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities; import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
@ -53,7 +58,6 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
private final String TABLE_COL_LANG = "table_col_lang"; private final String TABLE_COL_LANG = "table_col_lang";
private final String TABLE_COL_DEL = "table_col_del"; private final String TABLE_COL_DEL = "table_col_del";
@ -120,7 +124,6 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
private class CategoryLocalizationTableModel implements TableModel { private class CategoryLocalizationTableModel implements TableModel {
final private int MAX_DESC_LENGTH = 25; final private int MAX_DESC_LENGTH = 25;
private Table m_table; private Table m_table;
private CategoryLocalizationCollection m_categoryLocalizations; private CategoryLocalizationCollection m_categoryLocalizations;
private CategoryLocalization m_categoryLocalization; private CategoryLocalization m_categoryLocalization;
@ -142,7 +145,7 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
*/ */
public boolean nextRow() { public boolean nextRow() {
if(m_categoryLocalizations != null && m_categoryLocalizations.next()){ if (m_categoryLocalizations != null && m_categoryLocalizations.next()) {
m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization(); m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization();
return true; return true;
@ -158,7 +161,7 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
* @see com.arsdigita.bebop.table.TableModel#getElementAt(int) * @see com.arsdigita.bebop.table.TableModel#getElementAt(int)
*/ */
public Object getElementAt(int columnIndex) { public Object getElementAt(int columnIndex) {
switch (columnIndex){ switch (columnIndex) {
case 0: case 0:
Locale clLocale = new Locale(m_categoryLocalization.getLocale()); Locale clLocale = new Locale(m_categoryLocalization.getLocale());
return clLocale.getDisplayLanguage(/*Locale*/); return clLocale.getDisplayLanguage(/*Locale*/);
@ -166,14 +169,14 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
return m_categoryLocalization.getName(); return m_categoryLocalization.getName();
case 2: case 2:
String desc = m_categoryLocalization.getDescription(); String desc = m_categoryLocalization.getDescription();
if(desc != null && desc.length() > MAX_DESC_LENGTH) if (desc != null && desc.length() > MAX_DESC_LENGTH) {
desc = desc.substring(MAX_DESC_LENGTH - 3).concat("..."); desc = desc.substring(MAX_DESC_LENGTH - 3).concat("...");
}
return desc; return desc;
case 3: case 3:
return m_categoryLocalization.getURL(); return m_categoryLocalization.getURL();
case 4: case 4:
return GlobalizationUtil.globalize("cms.ui.delete").localize(); return GlobalizationUtil.globalize("cms.ui.delete").localize();
// return "Delete";
default: default:
return null; return null;
} }
@ -186,63 +189,43 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
public Object getKeyAt(int columnIndex) { public Object getKeyAt(int columnIndex) {
return m_categoryLocalization.getID(); return m_categoryLocalization.getID();
} }
} }
/**
* Check for the permissions to edit item and put either a Label or
* a ControlLink accordingly.
*/
private class EditCellRenderer extends LockableImpl implements TableCellRenderer { private class EditCellRenderer extends LockableImpl implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
SecurityManager sm = Utilities.getSecurityManager(state); //
// CategoryLocalization cl =
// (CategoryLocalization) m_clSel.getSelectedObject(state);
// boolean canEdit = sm.canAccess(state.getRequest(),
// SecurityManager.DELETE_ITEM,
// cl);
// if (canEdit) { // if (canEdit) {
if (true) { // CategoryLocalization cl;
//
// try {
// cl = new CategoryLocalization((BigDecimal) key);
// } catch (DataObjectNotFoundException ex) {
// return new Label(value.toString());
// }
//
// ContentSection section = CMS.getContext().getContentSection();
// ItemResolver resolver = section.getItemResolver();
//
// return new Link(value.toString(), resolver.generateItemURL(state, cl, section, cl.getVersion()));
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
return link; return link;
} else {
return new Label(value.toString());
}
} }
} }
/**
* Check for the permissions to delete item and put either a Label or
* a ControlLink accordingly.
*/
private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer { private class DeleteCellRenderer extends LockableImpl implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
// SecurityManager sm = Utilities.getSecurityManager(state);
// CategoryLocalization categoryLocalization =
// new CategoryLocalization(new BigDecimal(evt.getRowKey().toString()));
// boolean canDelete = sm.canAccess(state.getRequest(),
// SecurityManager.DELETE_ITEM,
// categoryLocalization);
// if (canDelete) {
if (true) {
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) GlobalizationUtil.globalize( link.setConfirmation((String) GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete").localize()); "cms.ui.category.localization_confirm_delete").localize());
// link.setConfirmation("Delete this localization?");
return link; return link;
} else {
return new Label(value.toString());
}
} }
} }
@ -266,12 +249,11 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
TableColumn col = getColumnModel().get(evt.getColumn().intValue()); TableColumn col = getColumnModel().get(evt.getColumn().intValue());
// Edit // Edit
if(col.getHeaderKey().toString().equals(TABLE_COL_LANG)) { if (col.getHeaderKey().toString().equals(TABLE_COL_LANG)) {
} }
// Delete // Delete
if(col.getHeaderKey().toString().equals(TABLE_COL_DEL)) { if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
category.delLanguage(categoryLocalization.getLocale()); category.delLanguage(categoryLocalization.getLocale());
} }
@ -284,6 +266,4 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
public void headSelected(TableActionEvent e) { public void headSelected(TableActionEvent e) {
throw new UnsupportedOperationException("Not Implemented"); throw new UnsupportedOperationException("Not Implemented");
} }
} }