1 5 package org.exoplatform.portlets.user.component; 6 7 import org.exoplatform.faces.core.component.UISimpleForm; 8 import org.exoplatform.faces.core.component.UIStringInput; 9 import org.exoplatform.faces.core.component.UITextArea ; 10 import org.exoplatform.faces.core.component.model.*; 11 import org.exoplatform.faces.core.event.ExoActionEvent; 12 import org.exoplatform.faces.core.event.ExoActionListener; 13 import org.exoplatform.services.organization.Group; 14 import org.exoplatform.services.organization.OrganizationService; 15 16 22 public class UIGroupForm extends UISimpleForm { 23 private UIStringInput groupNameInput_ ; 24 private UIStringInput labelInput_ ; 25 private UITextArea descInput_ ; 26 private OrganizationService service_ ; 27 private Group parentGroup_ ; 28 29 public UIGroupForm(OrganizationService service) throws Exception { 30 super("groupForm", "post", null) ; 31 setId("UIGroupForm"); 32 service_ = service ; 33 groupNameInput_ = new UIStringInput("groupName", "") ; 34 labelInput_ = new UIStringInput("label", "") ; 35 descInput_ = new UITextArea("description", "") ; 36 add(new HeaderRow(). 37 add(new Cell("#{UIGroupForm.header.add-group}"). 38 addColspan("2"))); 39 add(new Row(). 40 add(new LabelCell("#{UIGroupForm.label.group-name}")). 41 add(new ComponentCell(this, groupNameInput_))); 42 add(new Row(). 43 add(new LabelCell("#{UIGroupForm.label.label}")). 44 add(new ComponentCell(this, labelInput_))); 45 add(new Row(). 46 add(new LabelCell("#{UIGroupForm.label.description}")). 47 add(new ComponentCell(this, descInput_))); 48 add(new Row(). 49 add(new ListComponentCell(). 50 add(new FormButton("#{UIGroupForm.button.save}", SAVE_ACTION)). 51 add(new FormButton("#{UIGroupForm.button.cancel}", CANCEL_ACTION)). 52 addColspan("2").addAlign("center"))) ; 53 54 addActionListener(SaveUpdateListener.class, SAVE_ACTION) ; 55 addActionListener(CancelActionListener.class, CANCEL_ACTION) ; 56 } 57 58 public void setParentGroup(String parentGroupId) throws Exception { 59 if(parentGroupId !=null) { 60 parentGroup_ = service_.findGroupById(parentGroupId) ; 61 } else { 62 parentGroup_ = null ; 63 } 64 groupNameInput_.setValue("") ; 65 descInput_.setValue("") ; 66 } 67 68 static public class SaveUpdateListener extends ExoActionListener { 69 public void execute(ExoActionEvent event) throws Exception { 70 UIGroupForm uiForm = (UIGroupForm) event.getComponent() ; 71 Group group = uiForm.service_.createGroupInstance() ; 72 group.setGroupName(uiForm.groupNameInput_.getValue()) ; 73 group.setLabel(uiForm.labelInput_.getValue()) ; 74 group.setDescription(uiForm.descInput_.getValue()) ; 75 if (uiForm.parentGroup_ == null) { 76 uiForm.service_.createGroup(group) ; 77 } else { 78 uiForm.service_.addChild(uiForm.parentGroup_, group) ; 79 } 80 UIGroupExplorer uiGroupExplorer = (UIGroupExplorer)uiForm.getSibling(UIGroupExplorer.class) ; 81 uiGroupExplorer.update() ; 82 uiForm.setRenderedSibling(UIGroupExplorer.class); 83 } 84 } 85 86 static public class CancelActionListener extends ExoActionListener { 87 public void execute(ExoActionEvent event) throws Exception { 88 UIGroupForm uiForm = (UIGroupForm) event.getComponent() ; 89 uiForm.setRenderedSibling(UIGroupExplorer.class); 90 } 91 } 92 } | Popular Tags |