View Javadoc

1   package org.gnomekr.potron.web.view;
2   
3   import static org.gnomekr.potron.util.NavigationCases.NAV_PROJECT_CREATE;
4   import static org.gnomekr.potron.util.NavigationCases.NAV_PROJECT_LIST;
5   
6   import java.util.Date;
7   import java.util.List;
8   
9   import javax.faces.application.FacesMessage;
10  
11  import org.apache.myfaces.util.MessageUtils;
12  import org.gnomekr.potron.data.Project;
13  import org.gnomekr.potron.service.IProjectManager;
14  import org.gnomekr.potron.service.ProjectExistsException;
15  
16  /***
17   * ProjectView.java
18   * @author Xavier Cho
19   * @version $Revision 1.1 $ $Date: 2005/07/21 21:36:45 $
20   * @jsf.bean
21   *              name = "project"
22   *              scope = "request"
23   * @jsf.navigation
24   *              from = "*"
25   *              to = "/admin/project/create.jsf"
26   *              result = "project.create"
27   * @jsf.navigation
28   *              from = "*"
29   *              to = "/admin/project/update.jsf"
30   *              result = "project.update"
31   * @jsf.navigation
32   *              from = "*"
33   *              to = "/admin/project/list.jsf"
34   *              result = "project.list"
35   * @jsf.navigation
36   *              from = "*"
37   *              to = "/user/project.jsf"
38   *              result = "project.info"
39   */
40  public class ProjectView extends AbstractFacesView {
41  
42      private IProjectManager manager;
43  
44      private String id;
45      private String name;
46      private String version;
47      private String description;
48      private Date registeredDate;
49      private String homepage;
50  
51      /***
52       * @return
53       * @jsf.managed-property
54       *          value = "#{projectManager}"
55       */
56      public IProjectManager getManager() {
57          return manager;
58      }
59  
60      public String createProject() {
61          Project project = new Project();
62          project.setId(id);
63          project.setName(name);
64          project.setHomepage(homepage);
65          project.setVersion(version);
66          project.setDescription(description);
67  
68          try {
69              manager.createProject(project);
70          } catch (ProjectExistsException e) {
71              MessageUtils.addMessage(
72                      FacesMessage.SEVERITY_WARN,
73                      "error.project.exists",
74                      null);
75  
76              return NAV_PROJECT_CREATE;
77          }
78  
79          MessageUtils.addMessage(
80                  FacesMessage.SEVERITY_INFO,
81                  "msg.project.create.successful",
82                  null);
83  
84          refreshNavigationTree();
85  
86          return NAV_PROJECT_LIST;
87      }
88  
89      public String updateProject() {
90          Project project = manager.getProject(id);
91  
92          project.setName(name);
93          project.setVersion(version);
94          project.setDescription(description);
95          project.setHomepage(homepage);
96  
97          manager.updateProject(project);
98  
99          MessageUtils.addMessage(
100                 FacesMessage.SEVERITY_INFO,
101                 "msg.project.update.successful",
102                 null);
103 
104         refreshNavigationTree();
105 
106         return NAV_PROJECT_LIST;
107     }
108 
109     public String deleteProject() {
110         manager.deleteProject(id);
111 
112         MessageUtils.addMessage(
113                 FacesMessage.SEVERITY_INFO,
114                 "msg.project.delete.successful",
115                 null);
116 
117         refreshNavigationTree();
118 
119         return NAV_PROJECT_LIST;
120     }
121 
122     public List<Project> getProjects() {
123         return manager.getProjects();
124     }
125 
126     /***
127      * @param manager The manager to set.
128      */
129     public void setManager(IProjectManager manager) {
130         this.manager = manager;
131     }
132 
133     /***
134      * @return Returns the description.
135      */
136     public String getDescription() {
137         return description;
138     }
139 
140     /***
141      * @param description The description to set.
142      */
143     public void setDescription(String description) {
144         this.description = description;
145     }
146 
147     /***
148      * @return Returns the homepage.
149      */
150     public String getHomepage() {
151         return homepage;
152     }
153 
154     /***
155      * @param homepage The homepage to set.
156      */
157     public void setHomepage(String homepage) {
158         this.homepage = homepage;
159     }
160 
161     /***
162      * @return Returns the id.
163      */
164     public String getId() {
165         return id;
166     }
167 
168     /***
169      * @param id The id to set.
170      */
171     public void setId(String id) {
172         this.id = id;
173 
174         Project project = manager.getProject(id);
175 
176         if (project != null) {
177             this.name = project.getName();
178             this.version = project.getVersion();
179             this.description = project.getDescription();
180             this.registeredDate = project.getRegisteredDate();
181             this.homepage = project.getHomepage();
182         }
183     }
184 
185     /***
186      * @return Returns the name.
187      */
188     public String getName() {
189         return name;
190     }
191 
192     /***
193      * @param name The name to set.
194      */
195     public void setName(String name) {
196         this.name = name;
197     }
198 
199     /***
200      * @return Returns the registeredDate.
201      */
202     public Date getRegisteredDate() {
203         return registeredDate;
204     }
205 
206     /***
207      * @param registeredDate The registeredDate to set.
208      */
209     public void setRegisteredDate(Date registeredDate) {
210         this.registeredDate = registeredDate;
211     }
212 
213     /***
214      * @return Returns the version.
215      */
216     public String getVersion() {
217         return version;
218     }
219 
220     /***
221      * @param version The version to set.
222      */
223     public void setVersion(String version) {
224         this.version = version;
225     }
226 }