KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.List JavaDoc;
8 import org.exoplatform.faces.core.component.UIExoCommand;
9 import org.exoplatform.faces.core.component.model.Parameter;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.services.communication.message.*;
13 /**
14  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
15  * @since Aug 27, 2004
16  * @version $Id: UIAccount.java,v 1.9 2004/10/23 01:58:56 tuan08 Exp $
17  */

18 public class UIAccount extends UIExoCommand {
19   public final static String JavaDoc COMPOSE_ACTION = "compose" ;
20   public final static String JavaDoc SYNCHRONIZE_ACTION = "synchronize" ;
21   public final static String JavaDoc CHANGE_FOLDER_ACTION = "changeFolder" ;
22
23   public final static String JavaDoc FOLDER_NAME = "folderName" ;
24   public static Parameter[] composeParams_ = {new Parameter(ACTION, COMPOSE_ACTION)} ;
25   public static Parameter[] synchronizeParams_ = {new Parameter(ACTION, SYNCHRONIZE_ACTION)} ;
26   public static Parameter changeFolderParam_ = new Parameter(ACTION, CHANGE_FOLDER_ACTION) ;
27   
28   private MessageService service_ ;
29   private Account account_ ;
30   private List JavaDoc folders_ ;
31   private Folder selectFolder_ ;
32   
33   public UIAccount(MessageService service ,
34                    UIViewMessage uiViewMessage,
35                    UIMessageForm uiMessageForm,
36                    UISummary uiSummary) {
37     setId("UIAccount") ;
38     setClazz("UIAccount");
39     setRendererType("AccountRenderer");
40     service_ = service ;
41     List JavaDoc children = getChildren() ;
42     
43     uiMessageForm.setRendered(false) ;
44     children.add(uiMessageForm) ;
45     uiViewMessage.setRendered(false) ;
46     children.add(uiViewMessage) ;
47     uiSummary.setRendered(true) ;
48     children.add(uiSummary) ;
49     
50     addActionListener(SynchronizeActionListener.class, SYNCHRONIZE_ACTION) ;
51     addActionListener(ComposeActionListener.class, COMPOSE_ACTION) ;
52     addActionListener(ChangeFolderActionListener.class, CHANGE_FOLDER_ACTION) ;
53   }
54   
55   public Account getAccount() { return account_ ; }
56   
57   public List JavaDoc getFolders() { return folders_ ; }
58   
59   public Folder getSelectFolder() { return selectFolder_ ; }
60   
61   public void setAccount(Account account) throws Exception JavaDoc {
62     account_ = account ;
63     if(account != null) {
64       folders_ = service_.getFolders(account.getId()) ;
65       setSelectFolder(MessageService.INBOX_FOLDER) ;
66       UISummary uiSummary =
67         (UISummary)getChildComponentOfType(UISummary.class) ;
68       uiSummary.changeAccount(this) ;
69       uiSummary.changeFolder(selectFolder_) ;
70       setRenderedComponent(UISummary.class) ;
71     }
72   }
73   
74   public void setSelectFolder(String JavaDoc name) throws Exception JavaDoc {
75     selectFolder_ = getFolder(name) ;
76   }
77   
78   public Folder getFolder(String JavaDoc name) {
79     for(int i = 0 ; i < folders_.size() ; i++) {
80       Folder folder = (Folder) folders_.get(i) ;
81       if(name.equals(folder.getName())) {
82         return folder ;
83       }
84     }
85     return null ;
86   }
87   
88   static public class ComposeActionListener extends ExoActionListener {
89     public void execute(ExoActionEvent event) throws Exception JavaDoc {
90       UIAccount uiAccount = (UIAccount) event.getSource() ;
91       UIMessageForm uiMessageForm =
92         (UIMessageForm)uiAccount.getChildComponentOfType(UIMessageForm.class) ;
93       uiMessageForm.setFormData(uiAccount.account_, null) ;
94       uiAccount.setRenderedComponent(UIMessageForm.class) ;
95     }
96   }
97   
98   static public class SynchronizeActionListener extends ExoActionListener {
99     public void execute(ExoActionEvent event) throws Exception JavaDoc {
100       UIAccount uiAccount = (UIAccount) event.getSource() ;
101       uiAccount.service_.synchronizeAccount(uiAccount.account_) ;
102       UISummary uiSummary =
103         (UISummary)uiAccount.getChildComponentOfType(UISummary.class) ;
104       uiAccount.setSelectFolder(MessageService.INBOX_FOLDER) ;
105       uiSummary.changeFolder(uiAccount.selectFolder_) ;
106       uiAccount.setRenderedComponent(UISummary.class) ;
107     }
108   }
109   
110   static public class ChangeFolderActionListener extends ExoActionListener {
111     public void execute(ExoActionEvent event) throws Exception JavaDoc {
112       UIAccount uiAccount = (UIAccount) event.getSource() ;
113       String JavaDoc folderName = event.getParameter(FOLDER_NAME) ;
114       uiAccount.setSelectFolder(folderName) ;
115       UISummary uiSummary =
116         (UISummary)uiAccount.getChildComponentOfType(UISummary.class) ;
117       uiSummary.changeFolder(uiAccount.selectFolder_) ;
118       uiAccount.setRenderedComponent(UISummary.class) ;
119     }
120   }
121   
122   public String JavaDoc getFamily() {
123     return "org.exoplatform.portlets.communication.message.component.UIAccount" ;
124   }
125 }
Popular Tags