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,18 +42,19 @@ 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();
static { static {
s_config.load(); s_config.load();
} }
/** Data object type for tihs domain object */ /** Data object type for tihs domain object */
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.contenttypes.GenericContact"; "com.arsdigita.cms.contenttypes.GenericContact";
public GenericContact() { public GenericContact() {
super(BASE_DATA_OBJECT_TYPE); super(BASE_DATA_OBJECT_TYPE);
@ -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,39 +48,37 @@ 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;
/** /**
* Creates a new instance of GenericContactEntriesTable * Creates a new instance of GenericContactEntriesTable
*/ */
public GenericContactEntriesTable(final ItemSelectionModel itemModel) { public GenericContactEntriesTable(final ItemSelectionModel itemModel) {
super(); super();
this.m_itemModel = itemModel; this.m_itemModel = itemModel;
// if table is empty: // if table is empty:
setEmptyView(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.none"))); setEmptyView(new Label(ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.none")));
TableColumnModel tab_model = getColumnModel(); TableColumnModel tab_model = getColumnModel();
// define columns // define columns
tab_model.add(new TableColumn(0, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.key").localize(), TABLE_COL_EDIT)); tab_model.add(new TableColumn(0, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.key").localize(), TABLE_COL_EDIT));
tab_model.add(new TableColumn(1, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.value").localize())); tab_model.add(new TableColumn(1, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.value").localize()));
tab_model.add(new TableColumn(2, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.description").localize())); tab_model.add(new TableColumn(2, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.description").localize()));
tab_model.add(new TableColumn(3, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.action").localize(), TABLE_COL_DEL)); tab_model.add(new TableColumn(3, ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.contact.contactEntry.action").localize(), TABLE_COL_DEL));
setModelBuilder(new ContactTableModelBuilder(itemModel)); setModelBuilder(new ContactTableModelBuilder(itemModel));
tab_model.get(0).setCellRenderer(new EditCellRenderer()); tab_model.get(0).setCellRenderer(new EditCellRenderer());
tab_model.get(3).setCellRenderer(new DeleteCellRenderer()); tab_model.get(3).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this); addTableActionListener(this);
} }
/** /**
@ -86,24 +86,19 @@ public class GenericContactEntriesTable extends Table implements TableActionList
* *
*/ */
private class ContactTableModelBuilder extends LockableImpl implements TableModelBuilder { private class ContactTableModelBuilder extends LockableImpl implements TableModelBuilder {
private ItemSelectionModel m_itemModel; private ItemSelectionModel m_itemModel;
public ContactTableModelBuilder(ItemSelectionModel itemModel) { public ContactTableModelBuilder(ItemSelectionModel itemModel) {
m_itemModel = itemModel; m_itemModel = itemModel;
} }
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.getSelectedObject(state); GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
return new ContactTableModel(table, state, contact);
// if (contact != null && contact.hasContactEntries()) {
return new ContactTableModel(table, state, contact);
// } else {
// return Table.EMPTY_MODEL;
// }
} }
} }
@ -112,22 +107,21 @@ 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;
private ContactTableModel(Table t, PageState ps, GenericContact contact) { private ContactTableModel(Table t, PageState ps, GenericContact contact) {
m_table = t; m_table = t;
m_contactEntryCollection = contact.getContactEntries(); m_contactEntryCollection = contact.getContactEntries();
} }
public int getColumnCount() { public int getColumnCount() {
return m_table.getColumnModel().size(); return m_table.getColumnModel().size();
} }
/** /**
* Check collection for the existence of another row. * Check collection for the existence of another row.
* *
@ -135,39 +129,44 @@ public class GenericContactEntriesTable extends Table implements TableActionList
* into m_contactEntry class variable. * into m_contactEntry class variable.
*/ */
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;
} else { } else {
return false; return false;
} }
} }
/** /**
* Return the * Return the
* @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:
return (m_contactEntry.getDescription() != null && m_contactEntry.getDescription().length() > MAX_DESC_LENGTH) return (m_contactEntry.getDescription() != null && m_contactEntry.getDescription().length() > MAX_DESC_LENGTH)
? m_contactEntry.getDescription().substring(0, MAX_DESC_LENGTH) ? m_contactEntry.getDescription().substring(0, MAX_DESC_LENGTH)
: m_contactEntry.getDescription(); : m_contactEntry.getDescription();
case 3: case 3:
return GlobalizationUtil.globalize("cms.ui.delete").localize(); return GlobalizationUtil.globalize("cms.ui.delete").localize();
default: default:
return null; return null;
} }
} }
/** /**
* *
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int) * @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
@ -175,26 +174,25 @@ 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();
} }
} }
/** /**
* Check for the permissions to edit item and put either a Label or * Check for the permissions to edit item and put either a Label or
* a ControlLink accordingly. * 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); SecurityManager sm = Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state); GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
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 {
@ -202,24 +200,24 @@ public class GenericContactEntriesTable extends Table implements TableActionList
} }
} }
} }
/** /**
* Check for the permissions to delete item and put either a Label or * Check for the permissions to delete item and put either a Label or
* a ControlLink accordingly. * 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); SecurityManager sm = Utilities.getSecurityManager(state);
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state); GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
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;
@ -228,38 +226,37 @@ public class GenericContactEntriesTable extends Table implements TableActionList
} }
} }
} }
/** /**
* Provide implementation to TableActionListener method. * Provide implementation to TableActionListener method.
* Code that comes into picture when a link on the table is clicked. * Code that comes into picture when a link on the table is clicked.
* Handles edit and delete event. * Handles edit and delete event.
*/ */
public void cellSelected(TableActionEvent evt) { public void cellSelected(TableActionEvent evt) {
PageState state = evt.getPageState(); PageState state = evt.getPageState();
// Get selected GenericContactEntry // Get selected GenericContactEntry
GenericContactEntry contactEntry = GenericContactEntry contactEntry =
new GenericContactEntry(new BigDecimal(evt.getRowKey().toString())); new GenericContactEntry(new BigDecimal(evt.getRowKey().toString()));
// Get GenericContact // Get GenericContact
GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state); GenericContact contact = (GenericContact) m_itemModel.getSelectedObject(state);
// Get selected column // Get selected column
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);
} }
} }
/** /**
* provide Implementation to TableActionListener method. * provide Implementation to TableActionListener method.
* Does nothing in our case. * Does nothing in our case.
@ -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,11 +99,10 @@ 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);
} }
} }
@ -108,8 +113,8 @@ public class GenericContactPersonSheet
private boolean m_done; private boolean m_done;
public GenericContactPersonSheetModel(Table table, public GenericContactPersonSheetModel(Table table,
PageState state, PageState state,
GenericContact contact) { GenericContact contact) {
m_table = table; m_table = table;
m_person = contact.getPerson(); m_person = contact.getPerson();
if (m_person == null) { if (m_person == null) {
@ -119,7 +124,7 @@ public class GenericContactPersonSheet
} }
} }
public int getColumnCount() { public int getColumnCount() {
return m_table.getColumnModel().size(); return m_table.getColumnModel().size();
} }
@ -160,14 +165,40 @@ public class GenericContactPersonSheet
@Override @Override
public Component getComponent(Table table, public Component getComponent(Table table,
PageState state, PageState state,
Object value, Object value,
boolean isSelected, boolean isSelected,
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());
}
} }
} }
@ -177,16 +208,15 @@ public class GenericContactPersonSheet
@Override @Override
public Component getComponent(Table table, public Component getComponent(Table table,
PageState state, PageState state,
Object value, Object value,
boolean isSelected, boolean isSelected,
Object key, Object key,
int row, int row,
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());
@ -209,7 +238,7 @@ public class GenericContactPersonSheet
} }
} }
@Override @Override
public void cellSelected(TableActionEvent event) { public void cellSelected(TableActionEvent event) {
PageState state = event.getPageState(); PageState state = event.getPageState();

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;
@ -50,49 +55,48 @@ import java.util.Locale;
* @author Sören Bernstein (quasimodo) quasi@zes.uni-bremen.de * @author Sören Bernstein (quasimodo) quasi@zes.uni-bremen.de
*/ */
public class CategoryLocalizationTable extends Table implements TableActionListener { public class CategoryLocalizationTable extends Table implements TableActionListener {
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";
/** /**
* Creates a new instance of CategoryLocalizationTable * Creates a new instance of CategoryLocalizationTable
*/ */
public CategoryLocalizationTable(final CategoryRequestLocal category, public CategoryLocalizationTable(final CategoryRequestLocal category,
final SingleSelectionModel model) { final SingleSelectionModel model) {
super(); super();
m_category = category; m_category = category;
m_model = model; m_model = model;
// if table is empty: // if table is empty:
setEmptyView(new Label(GlobalizationUtil.globalize( setEmptyView(new Label(GlobalizationUtil.globalize(
"cms.ui.category.localization_none"))); "cms.ui.category.localization_none")));
TableColumnModel tab_model = getColumnModel(); TableColumnModel tab_model = getColumnModel();
// define columns // define columns
// XXX globalize // XXX globalize
tab_model.add(new TableColumn(0, GlobalizationUtil.globalize( tab_model.add(new TableColumn(0, GlobalizationUtil.globalize(
"cms.ui.category.localization.locale").localize(), TABLE_COL_LANG)); "cms.ui.category.localization.locale").localize(), TABLE_COL_LANG));
tab_model.add(new TableColumn(1, GlobalizationUtil.globalize( tab_model.add(new TableColumn(1, GlobalizationUtil.globalize(
"cms.ui.category.localization_name").localize())); "cms.ui.category.localization_name").localize()));
tab_model.add(new TableColumn(2, GlobalizationUtil.globalize( tab_model.add(new TableColumn(2, GlobalizationUtil.globalize(
"cms.ui.category.localization_description").localize())); "cms.ui.category.localization_description").localize()));
tab_model.add(new TableColumn(3, GlobalizationUtil.globalize( tab_model.add(new TableColumn(3, GlobalizationUtil.globalize(
"cms.ui.category.localization_url").localize())); "cms.ui.category.localization_url").localize()));
tab_model.add(new TableColumn(4, GlobalizationUtil.globalize( tab_model.add(new TableColumn(4, GlobalizationUtil.globalize(
"cms.ui.category.localization_action").localize(), TABLE_COL_DEL)); "cms.ui.category.localization_action").localize(), TABLE_COL_DEL));
setModelBuilder(new CategoryLocalizationTableModelBuilder()); setModelBuilder(new CategoryLocalizationTableModelBuilder());
tab_model.get(0).setCellRenderer(new EditCellRenderer()); tab_model.get(0).setCellRenderer(new EditCellRenderer());
tab_model.get(4).setCellRenderer(new DeleteCellRenderer()); tab_model.get(4).setCellRenderer(new DeleteCellRenderer());
addTableActionListener(this); addTableActionListener(this);
} }
/** /**
@ -101,10 +105,10 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
*/ */
private class CategoryLocalizationTableModelBuilder extends LockableImpl private class CategoryLocalizationTableModelBuilder extends LockableImpl
implements TableModelBuilder { implements TableModelBuilder {
public TableModel makeModel(Table table, PageState state) { public TableModel makeModel(Table table, PageState state) {
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
if (category != null && category.hasLocalizations()) { if (category != null && category.hasLocalizations()) {
return new CategoryLocalizationTableModel(table, state, category); return new CategoryLocalizationTableModel(table, state, category);
} else { } else {
@ -118,22 +122,21 @@ 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;
private CategoryLocalizationTableModel(Table t, PageState ps, Category category) { private CategoryLocalizationTableModel(Table t, PageState ps, Category category) {
m_table = t; m_table = t;
m_categoryLocalizations = new CategoryLocalizationCollection(category); m_categoryLocalizations = new CategoryLocalizationCollection(category);
} }
public int getColumnCount() { public int getColumnCount() {
return m_table.getColumnModel().size(); return m_table.getColumnModel().size();
} }
/** /**
* Check collection for the existence of another row. * Check collection for the existence of another row.
* *
@ -141,24 +144,24 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
* into m_categoryLocalization class variable. * into m_categoryLocalization class variable.
*/ */
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;
} else { } else {
return false; return false;
} }
} }
/** /**
* Return the * Return the
* @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,19 +169,19 @@ 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;
} }
} }
/** /**
* *
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int) * @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
@ -186,97 +189,76 @@ 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); ControlLink link = new ControlLink(value.toString());
// CategoryLocalization categoryLocalization = link.setConfirmation((String) GlobalizationUtil.globalize(
// new CategoryLocalization(new BigDecimal(evt.getRowKey().toString())); "cms.ui.category.localization_confirm_delete").localize());
return link;
// boolean canDelete = sm.canAccess(state.getRequest(),
// SecurityManager.DELETE_ITEM,
// categoryLocalization);
// if (canDelete) {
if (true) {
ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete").localize());
// link.setConfirmation("Delete this localization?");
return link;
} else {
return new Label(value.toString());
}
} }
} }
/** /**
* Provide implementation to TableActionListener method. * Provide implementation to TableActionListener method.
* Code that comes into picture when a link on the table is clicked. * Code that comes into picture when a link on the table is clicked.
* Handles edit and delete event. * Handles edit and delete event.
*/ */
public void cellSelected(TableActionEvent evt) { public void cellSelected(TableActionEvent evt) {
PageState state = evt.getPageState(); PageState state = evt.getPageState();
// Get selected CategoryLocalization // Get selected CategoryLocalization
CategoryLocalization categoryLocalization = CategoryLocalization categoryLocalization =
new CategoryLocalization(new BigDecimal(evt.getRowKey().toString())); new CategoryLocalization(new BigDecimal(evt.getRowKey().toString()));
// Get Category // Get Category
Category category = m_category.getCategory(state); Category category = m_category.getCategory(state);
// Get selected column // Get selected column
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());
} }
} }
/** /**
* provide Implementation to TableActionListener method. * provide Implementation to TableActionListener method.
* Does nothing in our case. * Does nothing in our case.
@ -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");
} }
} }