1 5 package org.exoplatform.portlets.user.component; 6 7 import java.util.ArrayList ; 8 import java.util.Collection ; 9 import java.util.Iterator ; 10 import java.util.List ; 11 import org.exoplatform.faces.application.ExoFacesMessage; 12 import org.exoplatform.faces.core.component.*; 13 import org.exoplatform.faces.core.component.model.*; 14 import org.exoplatform.faces.core.event.ExoActionEvent; 15 import org.exoplatform.faces.core.event.ExoActionListener; 16 import org.exoplatform.faces.user.validator.ValidUserValidator; 17 import org.exoplatform.services.organization.Group; 18 import org.exoplatform.services.organization.MembershipType; 19 import org.exoplatform.services.organization.OrganizationService; 20 import org.exoplatform.services.portal.community.CommunityConfigService; 21 import org.exoplatform.services.portal.community.CommunityNavigation; 22 28 public class UICommunityNavForm extends UISimpleForm { 29 private UISelectBox membershipInput_ ; 30 private UIStringInput navigationInput_ ; 31 private UITextArea descriptionInput_ ; 32 private CommunityConfigService service_ ; 33 private CommunityNavigation communityNav_ ; 34 35 public UICommunityNavForm(CommunityConfigService service, 36 OrganizationService orgService) throws Exception { 37 super("communityNavForm", "post", null) ; 38 service_ = service ; 39 Collection memberships = orgService.findMembershipTypes() ; 40 Iterator i = memberships.iterator() ; 41 List mtypes = new ArrayList (10) ; 42 while(i.hasNext()) { 43 MembershipType mt = (MembershipType) i.next(); 44 String name = mt.getName() ; 45 mtypes.add(new SelectItem(name, name)) ; 46 } 47 membershipInput_ = new UISelectBox("membership", "", mtypes) ; 48 navigationInput_ = new UIStringInput("navigation", ""). 49 addValidator(ValidUserValidator.class) ; 50 descriptionInput_ = new UITextArea("description", "") ; 51 add(new HeaderRow(). 52 add(new Cell("#{UICommunityNavForm.header.community-navigation}"). 53 addColspan("2"))); 54 add(new Row(). 55 add(new LabelCell("#{UICommunityNavForm.label.membership}")). 56 add(new ComponentCell(this, membershipInput_))); 57 add(new Row(). 58 add(new LabelCell("#{UICommunityNavForm.label.navigation}")). 59 add(new ComponentCell(this, navigationInput_))); 60 add(new Row(). 61 add(new LabelCell("#{UICommunityNavForm.label.description}")). 62 add(new ComponentCell(this, descriptionInput_))); 63 add(new Row(). 64 add(new ListComponentCell(). 65 add(new FormButton("#{UICommunityNavForm.button.save}", SAVE_ACTION)). 66 add(new FormButton("#{UICommunityNavForm.button.cancel}", CANCEL_ACTION)). 67 addColspan("2").addAlign("center"))) ; 68 69 addActionListener(SaveUpdateListener.class, SAVE_ACTION) ; 70 addActionListener(CancelActionListener.class, CANCEL_ACTION) ; 71 } 72 73 public void setCommunityNavigation(CommunityNavigation cn) { 74 communityNav_ = cn; 75 if(cn == null) { 76 membershipInput_.setValue("") ; 77 navigationInput_.setValue("") ; 78 descriptionInput_.setValue("") ; 79 } else { 80 membershipInput_.setValue(cn.getMembership()) ; 81 navigationInput_.setValue(cn.getNavigation()) ; 82 descriptionInput_.setValue(cn.getDescription()) ; 83 } 84 } 85 86 static public class SaveUpdateListener extends ExoActionListener { 87 public void execute(ExoActionEvent event) throws Exception { 88 UICommunityNavForm uiForm = (UICommunityNavForm) event.getComponent() ; 89 CommunityNavigation cn = uiForm.communityNav_ ; 90 if(cn == null) { 91 UIGroupExplorer uiExplorer = 92 (UIGroupExplorer) uiForm.getAncestorOfType(UIGroupExplorer.class) ; 93 Group currentGroup = uiExplorer.getCurrentGroup() ; 94 if(currentGroup == null) { 95 InformationProvider iprovider = findInformationProvider(uiForm); 96 iprovider.addMessage(new ExoFacesMessage("#{UICommunityNavForm.msg.no-group}")) ; 97 uiForm.setRenderedSibling(UIGroupCommunityInfo.class) ; 98 return ; 99 } 100 cn = new CommunityNavigation() ; 101 cn.setGroupId(currentGroup.getId()) ; 102 } 103 cn.setMembership(uiForm.membershipInput_.getValue()) ; 104 cn.setNavigation(uiForm.navigationInput_.getValue()) ; 105 cn.setDescription(uiForm.descriptionInput_.getValue()) ; 106 uiForm.service_.addCommunityNavigation(cn) ; 107 UIGroupCommunityInfo uiInfo = 108 (UIGroupCommunityInfo) uiForm.getSibling(UIGroupCommunityInfo.class); 109 uiInfo.setCommunityNavigation(cn) ; 110 uiForm.setRenderedSibling(UIGroupCommunityInfo.class) ; 111 } 112 } 113 114 static public class CancelActionListener extends ExoActionListener { 115 public void execute(ExoActionEvent event) throws Exception { 116 UICommunityNavForm uiForm = (UICommunityNavForm) event.getComponent() ; 117 uiForm.setRenderedSibling(UIGroupCommunityInfo.class) ; 118 } 119 } 120 } | Popular Tags |