Source Code Cross Referenced for ResultsProducer.java in  » ERP-CRM-Financial » sakai » org » sakaiproject » poll » tool » producers » 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 » ERP CRM Financial » sakai » org.sakaiproject.poll.tool.producers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************************
002:         * $URL: $
003:         * $Id:  $
004:         ***********************************************************************************
005:         *
006:         * Copyright (c) 2006,2007 The Sakai Foundation.
007:         * 
008:         * Licensed under the Educational Community License, Version 1.0 (the "License"); 
009:         * you may not use this file except in compliance with the License. 
010:         * You may obtain a copy of the License at
011:         * 
012:         *      http://www.opensource.org/licenses/ecl1.php
013:         * 
014:         * Unless required by applicable law or agreed to in writing, software 
015:         * distributed under the License is distributed on an "AS IS" BASIS, 
016:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
017:         * See the License for the specific language governing permissions and 
018:         * limitations under the License.
019:         *
020:         **********************************************************************************/package org.sakaiproject.poll.tool.producers;
021:
022:        import org.sakaiproject.tool.api.ToolManager;
023:        import org.sakaiproject.poll.model.Option;
024:        import org.sakaiproject.poll.logic.PollListManager;
025:        import org.sakaiproject.poll.logic.PollVoteManager;
026:        import org.sakaiproject.poll.model.OptionImpl;
027:        import org.sakaiproject.poll.model.Poll;
028:        import org.sakaiproject.poll.model.Vote;
029:        import org.sakaiproject.user.api.UserDirectoryService;
030:
031:        import uk.org.ponder.beanutil.entity.EntityID;
032:        import uk.org.ponder.messageutil.MessageLocator;
033:        import uk.org.ponder.rsf.components.UIContainer;
034:        import uk.org.ponder.rsf.view.ComponentChecker;
035:        import uk.org.ponder.rsf.view.ViewComponentProducer;
036:        import uk.org.ponder.rsf.viewstate.EntityCentredViewParameters;
037:        import uk.org.ponder.rsf.viewstate.ViewParameters;
038:        import uk.org.ponder.rsf.flow.jsfnav.NavigationCase;
039:        import uk.org.ponder.localeutil.LocaleGetter;
040:        import uk.org.ponder.rsf.viewstate.SimpleViewParameters;
041:        import uk.org.ponder.rsf.flow.jsfnav.NavigationCase;
042:        import uk.org.ponder.rsf.flow.jsfnav.NavigationCaseReporter;
043:        import uk.org.ponder.rsf.viewstate.ViewParamsReporter;
044:        import uk.org.ponder.rsf.components.UIBranchContainer;
045:        import uk.org.ponder.rsf.components.UIOutput;
046:        import uk.org.ponder.rsf.components.UIForm;
047:        import uk.org.ponder.rsf.components.UICommand;
048:        import uk.org.ponder.util.NumberFormatter;
049:
050:        import java.util.List;
051:        import java.util.ArrayList;
052:        import java.math.BigDecimal;
053:        import java.math.BigInteger;
054:
055:        import org.apache.commons.logging.Log;
056:        import org.apache.commons.logging.LogFactory;
057:
058:        public class ResultsProducer implements  ViewComponentProducer,
059:                NavigationCaseReporter, ViewParamsReporter {
060:
061:            public static final String VIEW_ID = "voteResults";
062:
063:            private UserDirectoryService userDirectoryService;
064:            private PollListManager pollListManager;
065:            private PollVoteManager pollVoteManager;
066:            private ToolManager toolManager;
067:            private MessageLocator messageLocator;
068:            private LocaleGetter localegetter;
069:
070:            private static Log m_log = LogFactory.getLog(ResultsProducer.class);
071:
072:            public String getViewID() {
073:                // TODO Auto-generated method stub
074:                return VIEW_ID;
075:            }
076:
077:            public void setMessageLocator(MessageLocator messageLocator) {
078:
079:                this .messageLocator = messageLocator;
080:            }
081:
082:            public void setUserDirectoryService(
083:                    UserDirectoryService userDirectoryService) {
084:                this .userDirectoryService = userDirectoryService;
085:            }
086:
087:            public void setPollListManager(PollListManager pollListManager) {
088:                this .pollListManager = pollListManager;
089:            }
090:
091:            public void setToolManager(ToolManager toolManager) {
092:                this .toolManager = toolManager;
093:            }
094:
095:            public void setLocaleGetter(LocaleGetter localegetter) {
096:                this .localegetter = localegetter;
097:            }
098:
099:            public void setPollVoteManager(PollVoteManager pvm) {
100:                this .pollVoteManager = pvm;
101:            }
102:
103:            public void fillComponents(UIContainer tofill,
104:                    ViewParameters viewparams, ComponentChecker checker) {
105:
106:                EntityCentredViewParameters ecvp = (EntityCentredViewParameters) viewparams;
107:
108:                //m_log.info(ecvp.toPathInfo());
109:
110:                //m_log.info(ecvp.getELPath());
111:
112:                //hack but this needs to work
113:                String strId = ecvp.getELPath().substring(
114:                        ecvp.getELPath().indexOf(".") + 1);
115:                m_log.debug("got id of " + strId);
116:                Poll poll = pollListManager.getPollById(new Long(strId));
117:
118:                //get the number of votes
119:                int voters = pollVoteManager.getDisctinctVotersForPoll(poll);
120:                //Object[] args = new Object[] { new Integer(voters).toString()};
121:                if (poll.getMaxOptions() > 1)
122:                    UIOutput.make(tofill, "poll-size", messageLocator
123:                            .getMessage("results_poll_size",
124:                                    new Integer(voters).toString()));
125:
126:                m_log.debug(voters + " have voted on this poll");
127:
128:                UIOutput.make(tofill, "question", poll.getText());
129:                m_log.debug("got poll " + poll.getText());
130:                List pollOptions = poll.getPollOptions();
131:
132:                m_log.debug("got a list of " + pollOptions.size() + " options");
133:                //appeng an option for no votes
134:                if (poll.getMinOptions() == 0) {
135:                    Option noVote = new OptionImpl(new Long(0));
136:                    noVote.setOptionText(messageLocator
137:                            .getMessage("result_novote"));
138:                    noVote.setPollId(poll.getPollId());
139:                    pollOptions.add(noVote);
140:                }
141:
142:                List votes = pollVoteManager.getAllVotesForPoll(poll);
143:                int totalVotes = votes.size();
144:                m_log.debug("got " + totalVotes + " votes");
145:                List collation = new ArrayList();
146:
147:                for (int i = 0; i < pollOptions.size(); i++) {
148:                    CollatedVote collatedVote = new CollatedVote();
149:                    Option option = (Option) pollOptions.get(i);
150:                    collatedVote.setoptionId(option.getId());
151:                    collatedVote.setOptionText(option.getOptionText());
152:                    for (int q = 0; q < votes.size(); q++) {
153:                        Vote vote = (Vote) votes.get(q);
154:                        if (vote.getPollOption().equals(option.getId())) {
155:                            m_log.debug("got a vote for option "
156:                                    + option.getId());
157:                            collatedVote.incrementVotes();
158:
159:                        }
160:
161:                    }
162:                    collation.add(collatedVote);
163:
164:                }
165:
166:                UIOutput.make(tofill, "answers-title", messageLocator
167:                        .getMessage("results_answers_title"));
168:
169:                for (int i = 0; i < collation.size(); i++) {
170:                    CollatedVote cv = (CollatedVote) collation.get(i);
171:                    UIBranchContainer resultRow = UIBranchContainer.make(
172:                            tofill, "answer-row:");
173:                    UIOutput.make(resultRow, "answer-option", cv
174:                            .getOptionText());
175:                    UIOutput.make(resultRow, "answer-numVotes", new Long(cv
176:                            .getVotes()).toString());
177:                    m_log.debug("about to do the calc: (" + cv.getVotes() + "/"
178:                            + totalVotes + ")*100");
179:                    double percent = (double) 0;
180:                    if (totalVotes > 0)
181:                        percent = ((double) cv.getVotes() / (double) totalVotes)
182:                                * (double) 100;
183:                    else
184:                        percent = (double) 0;
185:                    m_log.debug("result is " + percent);
186:                    NumberFormatter nf = new NumberFormatter();
187:                    UIOutput.make(resultRow, "answer-percVotes", nf
188:                            .format(percent)
189:                            + "%");
190:
191:                }
192:                UIOutput.make(tofill, "votes-total", new Integer(totalVotes)
193:                        .toString());
194:                //the cancel button
195:                UIForm form = UIForm.make(tofill, "actform");
196:                UICommand
197:                        .make(form, "cancel", messageLocator
198:                                .getMessage("results_cancel"),
199:                                "#{pollToolBean.cancel}");
200:
201:            }
202:
203:            public List reportNavigationCases() {
204:                List togo = new ArrayList(); // Always navigate back to this view.
205:                togo.add(new NavigationCase(null, new SimpleViewParameters(
206:                        VIEW_ID)));
207:                togo.add(new NavigationCase("cancel", new SimpleViewParameters(
208:                        PollToolProducer.VIEW_ID)));
209:                return togo;
210:            }
211:
212:            public ViewParameters getViewParameters() {
213:                return new EntityCentredViewParameters(VIEW_ID, new EntityID(
214:                        "Poll", null));
215:
216:            }
217:
218:            private class CollatedVote {
219:                private Long optionId;
220:                private String optionText;
221:                private int votes;
222:
223:                public CollatedVote() {
224:                    this .votes = 0;
225:                }
226:
227:                public void setoptionId(Long val) {
228:                    this .optionId = val;
229:                }
230:
231:                public Long getoptionId() {
232:                    return this .optionId;
233:                }
234:
235:                public void setOptionText(String t) {
236:                    this .optionText = t;
237:                }
238:
239:                public String getOptionText() {
240:                    return this .optionText;
241:                }
242:
243:                public void setVotes(int i) {
244:                    this .votes = i;
245:                }
246:
247:                public int getVotes() {
248:                    return this .votes;
249:                }
250:
251:                public void incrementVotes() {
252:                    this.votes++;
253:                }
254:
255:            }
256:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.