KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > message > component > UIFolderForm


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.communication.message.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.model.*;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.services.communication.message.Account;
13 import org.exoplatform.services.communication.message.Folder;
14 import org.exoplatform.services.communication.message.MessageService;
15 /**
16  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
17  * @since Aug 27, 2004
18  * @version $Id: UIFolderForm.java,v 1.2 2004/09/10 03:56:17 tuan08 Exp $
19  */

20 public class UIFolderForm extends UISimpleForm {
21
22   private MessageService service_ ;
23   private Account account_ ;
24   private Folder folder_ ;
25   
26   private UIStringInput nameInput_;
27   private UIStringInput labelInput_;
28   
29   public UIFolderForm(MessageService service) throws Exception JavaDoc {
30     super("folderForm", "post", null) ;
31     setId("UIFolderForm") ;
32     setClazz("UIFolderForm");
33     service_ = service ;
34     
35     nameInput_ = new UIStringInput("name", "") ;
36     labelInput_ = new UIStringInput("label", "") ;
37     
38     add(new HeaderRow().
39         add(new Cell("#{UIFolderForm.header.add-edit-folder}").
40             addColspan("2")));
41     add(new Row().
42         add(new LabelCell("#{UIFolderForm.label.folder-name}")).
43         add(new ComponentCell(this, nameInput_)));
44     add(new Row().
45         add(new LabelCell("#{UIFolderForm.label.folder-label}")).
46         add(new ComponentCell(this, labelInput_)));
47    
48     add(new Row().
49         add(new ListComponentCell().
50             add(new FormButton("#{UIFolderForm.button.delete}", DELETE_ACTION)).
51             add(new FormButton("#{UIFolderForm.button.save}", SAVE_ACTION)).
52             add(new FormButton("#{UIFolderForm.button.cancel}", CANCEL_ACTION)).
53             addColspan("2").addAlign("center"))) ;
54     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
55     addActionListener(CancelActionListener.class, CANCEL_ACTION) ;
56     addActionListener(DeleteActionListener.class, DELETE_ACTION) ;
57   }
58   
59   public void setFormData(Account account , Folder folder) {
60     account_ = account ;
61     folder_ = folder ;
62     if(folder == null) {
63       nameInput_.setValue("") ;
64       nameInput_.setEditable(true) ;
65       labelInput_.setValue("") ;
66     } else {
67       nameInput_.setValue(folder.getName()) ;
68       nameInput_.setEditable(false) ;
69       labelInput_.setValue(folder.getLabel()) ;
70     }
71   }
72   
73   static public class SaveActionListener extends ExoActionListener {
74     public void execute(ExoActionEvent event) throws Exception JavaDoc {
75       UIFolderForm uiForm = (UIFolderForm) event.getSource();
76       UIAccountConfiguration uiAccConfig =
77         (UIAccountConfiguration) uiForm.getSibling(UIAccountConfiguration.class) ;
78       Folder folder = uiForm.folder_ ;
79       boolean newFolder = false ;
80       if(folder == null) {
81         folder = uiForm.service_.createFolderInstance() ;
82         folder.setName(uiForm.nameInput_.getValue()) ;
83         newFolder = true ;
84       }
85       folder.setLabel(uiForm.labelInput_.getValue()) ;
86       if(newFolder) {
87         uiForm.service_.createFolder(uiForm.account_, folder) ;
88       } else {
89         uiForm.service_.updateFolder(folder) ;
90       }
91       uiAccConfig.updateSelectAccount(uiForm.account_.getAccountName()) ;
92       uiForm.setRenderedSibling(UIAccountConfiguration.class) ;
93     }
94   }
95   
96   static public class CancelActionListener extends ExoActionListener {
97     public void execute(ExoActionEvent event) throws Exception JavaDoc {
98       UIFolderForm uiForm = (UIFolderForm) event.getSource();
99       uiForm.setRenderedSibling(UIAccountConfiguration.class) ;
100     }
101   }
102   
103   static public class DeleteActionListener extends ExoActionListener {
104     public void execute(ExoActionEvent event) throws Exception JavaDoc {
105       UIFolderForm uiForm = (UIFolderForm) event.getSource();
106       if(uiForm.folder_ != null) {
107         uiForm.service_.removeFolder(uiForm.folder_) ;
108         UIAccountConfiguration uiAccConfig =
109           (UIAccountConfiguration) uiForm.getSibling(UIAccountConfiguration.class) ;
110         uiAccConfig.updateSelectAccount(uiForm.account_.getAccountName()) ;
111       }
112       uiForm.setRenderedSibling(UIAccountConfiguration.class) ;
113     }
114   }
115 }
Popular Tags