KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > user > component > UIGroupForm


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

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 /**
17  * Sat, Jan 03, 2004 @ 11:16
18  * @author: Tuan Nguyen
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: UIGroupForm.java,v 1.11 2004/10/21 15:25:17 tuan08 Exp $
21  */

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 JavaDoc {
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 JavaDoc parentGroupId) throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc {
88       UIGroupForm uiForm = (UIGroupForm) event.getComponent() ;
89         uiForm.setRenderedSibling(UIGroupExplorer.class);
90     }
91   }
92 }
Popular Tags