{
if (log.isDebugEnabled())
log.debug("add own person");
UserVO user = (UserVO) request.getSession().getAttribute(Globals.USER_KEY);
ContactVO contact = (ContactVO) getPanel().getEntity();
if (user.getPerson() != null)
{
PersonContactVO pc = new PersonContactVO(user.getPerson(), contact);
if (!contact.getPersonContacts().contains(pc))
contact.getPersonContacts().add(pc);
}
return Panel.getForward(getPanel().getActivePage().getAction(), request);
}
else if(form.getDoAddPerson().isSelected())
{
if (log.isDebugEnabled())
log.debug("add person");
return mapping.findForward("addPerson");
}
else if(form.getDoAddCompany().isSelected())
{
if (log.isDebugEnabled())
log.debug("add company");
return mapping.findForward("addCompany");
}
else if(form.getDoRemovePerson() > 0)
{
if (log.isDebugEnabled())
log.debug("remove person with id: "+form.getDoRemovePerson());
ContactVO contact = (ContactVO) getPanel().getEntity();
if(contact.getPersonContacts().size() > 1 || contact.getCompany() != null)
{
Iterator<PersonContactVO> it = contact.getPersonContacts().iterator();
while(it.hasNext()) {
if(it.next().getPerson().getId().intValue() == form.getDoRemovePerson()) {
it.remove();
break;
}
}
}
else
log.info("tried to delete last person of contact / no company available");
return Panel.getForward(getPanel().getActivePage().getAction(), request);
}
else if(form.getDoRemoveCompany().isSelected()) {
if (log.isDebugEnabled())
log.debug("remove company");
ContactVO contact = (ContactVO) getPanel().getEntity();
if (contact.getPersonContacts().size() > 0)
contact.setCompany(null);
else
log.info("tried to delete company of contact / no persons available");
return Panel.getForward(getPanel().getActivePage().getAction(), request);
}