Source Code Cross Referenced for GlobalSelectItems.java in  » Project-Management » EmForce » ru » emdev » EmForge » web » bean » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Project Management » EmForce » ru.emdev.EmForge.web.bean 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package ru.emdev.EmForge.web.bean;
002:
003:        import java.util.ArrayList;
004:        import java.util.Collection;
005:
006:        import javax.faces.model.SelectItem;
007:
008:        import org.apache.commons.lang.ObjectUtils;
009:        import org.emforge.projectmanager.ProjectService;
010:        import org.emforge.projectmanager.base.ProjectDO;
011:        import org.emforge.report.ReportView;
012:        import org.emforge.xfer.EmForgeObject;
013:        import org.emforge.xfer.PriorityTO;
014:
015:        import ru.emdev.EmForge.security.EmForgeUserDetails;
016:        import ru.emdev.EmForge.security.UserFactory;
017:        import ru.emdev.EmForge.security.dao.Role;
018:        import ru.emdev.EmForge.security.web.SiteRole;
019:
020:        /**
021:         *
022:         */
023:        public class GlobalSelectItems {
024:
025:            private UserFactory m_userFactory;
026:            private ProjectService m_projectService;
027:
028:            /**
029:             * Sets a reference to user factory bean to manipulate users. Called by Spring Framework.
030:             * 
031:             * @param i_userFactory is a user factory bean to set
032:             */
033:            public void setUserFactory(UserFactory i_userFactory) {
034:
035:                m_userFactory = i_userFactory;
036:            }
037:
038:            /**
039:             * Sets a reference to project bean to manipulate projects. Called by Spring Framework.
040:             * 
041:             * @param i_projectService is a project bean to set
042:             */
043:            public void setProjectService(ProjectService i_projectService) {
044:
045:                m_projectService = i_projectService;
046:            }
047:
048:            /**
049:             * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
050:             */
051:            public void afterPropertiesSet() throws Exception {
052:
053:                if (m_userFactory == null) {
054:                    throw new IllegalArgumentException(
055:                            "userFactory should be specified for "
056:                                    + this .getClass());
057:                }
058:                if (m_projectService == null) {
059:                    throw new IllegalArgumentException(
060:                            "projectService should be specified for "
061:                                    + this .getClass());
062:                }
063:            }
064:
065:            /** Priorities */
066:            protected Collection<SelectItem> m_priorities;
067:
068:            /**
069:             * Gets List of Priorities
070:             */
071:            public Collection<SelectItem> getPriorities() {
072:
073:                if (m_priorities == null) {
074:                    m_priorities = new ArrayList<SelectItem>();
075:
076:                    for (PriorityTO priority : PriorityTO.values()) {
077:                        m_priorities.add(new SelectItem(priority, priority
078:                                .getName()));
079:                    }
080:                }
081:
082:                return m_priorities;
083:            }
084:
085:            /**
086:             * Get list of projects. Since list of project may be changed we calculates it every time
087:             * 
088:             * @todo move empty select item out
089:             */
090:            public Collection<SelectItem> getProjects() {
091:
092:                Collection<SelectItem> result = new ArrayList<SelectItem>();
093:
094:                Collection<ProjectDO> projects = m_projectService
095:                        .getAllProjects();
096:                for (ProjectDO project : projects) {
097:                    String displayName = ObjectUtils.toString(project
098:                            .getDisplayName());
099:                    result.add(new SelectItem(project, displayName));
100:                }
101:
102:                return result;
103:            }
104:
105:            /**
106:             * Retrieves milestones of specified project
107:             * 
108:             * @param i_projectWikiName is a wiki page name of required project
109:             * @return Collection of milestones of specified project or empty collection if required objects are absent
110:             */
111:            public Collection<SelectItem> getMilestones(String i_projectWikiName) {
112:
113:                ProjectDO project = m_projectService
114:                        .getProject(i_projectWikiName);
115:                return getSelectItems(m_projectService.getMilestones(project));
116:            }
117:
118:            /**
119:             * Get list of users
120:             * 
121:             * @todo Move out from here new SelectItem("", "")
122:             * @depricated use getUsers and converter instead
123:             * @return
124:             * @throws Exception
125:             */
126:            public Collection<SelectItem> getUserNames() throws Exception {
127:
128:                Collection<SelectItem> result = new ArrayList<SelectItem>();
129:
130:                Collection<EmForgeUserDetails> users = m_userFactory.getUsers();
131:                for (EmForgeUserDetails user : users) {
132:                    result.add(new SelectItem(user.getUsername(), user
133:                            .getDisplayName()));
134:                }
135:
136:                return result;
137:            }
138:
139:            /**
140:             * @return
141:             * @throws Exception
142:             */
143:            public Collection<SelectItem> getUsers() {
144:
145:                Collection<SelectItem> result = new ArrayList<SelectItem>();
146:
147:                Collection<EmForgeUserDetails> users = m_userFactory.getUsers();
148:
149:                for (EmForgeUserDetails user : users) {
150:                    result.add(new SelectItem(user, user.getDisplayName()));
151:                }
152:
153:                return result;
154:            }
155:
156:            /**
157:             * Retrieves users of specified project
158:             * 
159:             * @param i_projectWikiName is a wiki page name of required project
160:             * @return Collection of users of specified project or empty collection if required objects are absent
161:             */
162:            public Collection<SelectItem> getProjectUsers(
163:                    String i_projectWikiName) {
164:
165:                ProjectDO project = m_projectService
166:                        .getProject(i_projectWikiName);
167:                return getSelectItemsForUsers(m_projectService
168:                        .getAllProjectUsers(project));
169:            }
170:
171:            /**
172:             * Retrieves users of specified project and role
173:             * 
174:             * @param i_projectWikiName is a wiki page name of required project
175:             * @param i_roleName is a project role
176:             * @return Collection of users of specified project and role or empty collection if required objects are absent
177:             */
178:            public Collection<SelectItem> getProjectUsers(
179:                    String i_projectWikiName, String i_roleName) {
180:
181:                ProjectDO project = m_projectService
182:                        .getProject(i_projectWikiName);
183:                return getSelectItemsForUsers(m_projectService.getUsers(
184:                        project, i_roleName));
185:            }
186:
187:            /**
188:             * Requires users with specified site role
189:             * 
190:             * @param i_siteRoleName is a site role name 
191:             * @return Collection of users with specified site role
192:             */
193:            public Collection<SelectItem> getSiteRoleUsers(String i_siteRoleName) {
194:
195:                Collection<EmForgeUserDetails> users = null;
196:                if (SiteRole.isSiteRole(i_siteRoleName)) {
197:                    users = m_userFactory.getUsers(i_siteRoleName);
198:                }
199:                return getSelectItemsForUsers(users);
200:            }
201:
202:            /**
203:             * Requires all existing roles
204:             * 
205:             * @return Collection of roles
206:             */
207:            public Collection<SelectItem> getRoles() {
208:
209:                return getSelectItems(m_userFactory.getRoles());
210:            }
211:
212:            /**
213:             * Requires all existing site roles
214:             * 
215:             * @return Collection of site roles
216:             */
217:            public Collection<SelectItem> getSiteRoles() {
218:
219:                Collection<Role> result = new ArrayList<Role>();
220:
221:                for (Role role : m_userFactory.getRoles()) {
222:                    if (SiteRole.isSiteRole(role.getName())) {
223:                        result.add(role);
224:                    }
225:                }
226:                return getSelectItems(result);
227:            }
228:
229:            /**
230:             * @return
231:             * @throws Exception
232:             */
233:            public Collection<SelectItem> getReportFormats() throws Exception {
234:
235:                return ReportView.getSelectItems();
236:            }
237:
238:            /**
239:             * @param <E> is any instance of EmForgeObject
240:             * @param i_objects is a collection of EmForge objects
241:             * @return Collection of SelectItems based on specified EmForge objects
242:             */
243:            protected <E extends EmForgeObject> Collection<SelectItem> getSelectItems(
244:                    Collection<E> i_objects) {
245:
246:                Collection<SelectItem> result = new ArrayList<SelectItem>();
247:
248:                if (i_objects != null) {
249:                    for (E obj : i_objects) {
250:                        result.add(new SelectItem(obj, obj.getName()));
251:                    }
252:                }
253:
254:                return result;
255:            }
256:
257:            /**
258:             * @param <E> is an instance of EmForgeUserDetails
259:             * @param i_objects is a collection of EmForge users
260:             * @return Collection of SelectItems based on specified EmForge users
261:             * @todo it's a workaround to get collection of SelectItems for EmForge users. EmForgeUserDetails should expand
262:             *       EmForgeObject!
263:             */
264:            protected <E extends EmForgeUserDetails> Collection<SelectItem> getSelectItemsForUsers(
265:                    Collection<E> i_objects) {
266:
267:                Collection<SelectItem> result = new ArrayList<SelectItem>();
268:
269:                if (i_objects != null) {
270:                    for (E obj : i_objects) {
271:                        result.add(new SelectItem(obj, obj.getDisplayName()));
272:                    }
273:                }
274:
275:                return result;
276:            }
277:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.