View Javadoc
1   /*
2    * Copyright 2014 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.web.impl.ui.application.views.common.menufactory.impl;
20  
21  import org.springframework.beans.factory.annotation.Autowired;
22  import org.springframework.stereotype.Service;
23  
24  import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ApplicationMenuItemFactory;
25  import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ParliamentMenuItemFactory;
26  import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageModeMenuCommand;
27  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ChartIndicators;
28  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
29  import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
30  import com.vaadin.server.FontAwesome;
31  import com.vaadin.ui.GridLayout;
32  import com.vaadin.ui.MenuBar;
33  import com.vaadin.ui.MenuBar.MenuItem;
34  import com.vaadin.ui.VerticalLayout;
35  
36  /**
37   * The Class ParliamentMenuItemFactoryImpl.
38   */
39  @Service
40  public final class ParliamentMenuItemFactoryImpl extends AbstractMenuItemFactoryImpl implements ParliamentMenuItemFactory {
41  
42  	/** The Constant AVERAGE_AGE. */
43  	private static final String AVERAGE_AGE = "Average age";
44  
45  	/** The Constant PARTY_AGE. */
46  	private static final String PARTY_AGE = "Party Age";
47  
48  	/** The Constant AVERAGE_PERCENTAGE_MALE. */
49  	private static final String AVERAGE_PERCENTAGE_MALE = "Average percentage male";
50  
51  	/** The Constant PARTY_GENDER. */
52  	private static final String PARTY_GENDER = "Party Gender";
53  
54  	/** The Constant COMMAND_PAGEVISITHISTORY. */
55  	private static final PageModeMenuCommand COMMAND_PAGEVISITHISTORY = new PageModeMenuCommand(UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.PAGEVISITHISTORY);
56  
57  	/** The Constant COMMAND_DECISION_ACTIVITY. */
58  	private static final PageModeMenuCommand COMMAND_DECISION_ACTIVITY = new PageModeMenuCommand(
59  			UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.CHARTS, ChartIndicators.DECISIONACTIVITYBYTYPE.toString());
60  
61  	/** The Constant COMMAND_DOCUMENT_ACTIVITY. */
62  	private static final PageModeMenuCommand COMMAND_DOCUMENT_ACTIVITY = new PageModeMenuCommand(
63  			UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.CHARTS, ChartIndicators.DOCUMENTACTIVITYBYTYPE.toString());
64  
65  	/** The Constant COMMAND_CHARTS_PARTY_WINNER. */
66  	private static final PageModeMenuCommand COMMAND_CHARTS_PARTY_WINNER = new PageModeMenuCommand(
67  			UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.CHARTS, ChartIndicators.PARTYWINNER.toString());
68  
69  	/** The Constant COMMAND_CHARTS_PARTY_GENDER. */
70  	private static final PageModeMenuCommand COMMAND_CHARTS_PARTY_GENDER = new PageModeMenuCommand(
71  			UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.CHARTS, ChartIndicators.PARTYGENDER.toString());
72  
73  	/** The Constant COMMAND_CHARTS_PARTY_AGE. */
74  	private static final PageModeMenuCommand COMMAND_CHARTS_PARTY_AGE = new PageModeMenuCommand(
75  			UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.CHARTS, ChartIndicators.PARTYAGE.toString());
76  
77  
78  	/** The Constant COMMAND_OVERVIEW. */
79  	private static final PageModeMenuCommand COMMAND_OVERVIEW = new PageModeMenuCommand(UserViews.PARLIAMENT_RANKING_VIEW_NAME, PageMode.OVERVIEW);
80  
81  	/** The Constant DAILY_TOTAL_OF_NUMBER_OF_DECSIONS_MADE. */
82  	private static final String DAILY_TOTAL_OF_NUMBER_OF_DECSIONS_MADE = "daily total of number of decsions made";
83  
84  	/** The Constant DECISION_ACTIVITY_BY_TYPE. */
85  	private static final String DECISION_ACTIVITY_BY_TYPE = "Decision activity by type";
86  
87  	/** The Constant DAILY_TOTAL_OF_NUMBER_PUBLISHED_DOCUMENTS. */
88  	private static final String DAILY_TOTAL_OF_NUMBER_PUBLISHED_DOCUMENTS = "daily total of number published documents";
89  
90  	/** The Constant DOCUMENT_ACTIVITY_BY_TYPE. */
91  	private static final String DOCUMENT_ACTIVITY_BY_TYPE = "Document activity by type";
92  
93  	/** The Constant DAILY_AVERAGE_WON_BALLOTS. */
94  	private static final String DAILY_AVERAGE_WON_BALLOTS = "daily average % won ballots";
95  
96  	/** The Constant PARTY_WINNER. */
97  	private static final String PARTY_WINNER = "Party Winner";
98  
99  	/** The Constant SWEDISH_PARLIAMENT_INDICATORS. */
100 	private static final String SWEDISH_PARLIAMENT_INDICATORS = "Swedish parliament Indicators";
101 
102 	/** The Constant PARLIAMENT_RANKING_TEXT. */
103 	private static final String PARLIAMENT_RANKING_TEXT = "Parliament Ranking";
104 
105 	/** The Constant OVERVIEW_TEXT. */
106 	private static final String OVERVIEW_TEXT = "Overview";
107 
108 	/** The Constant PAGE_VISIT_HISTORY_TEXT. */
109 	private static final String PAGE_VISIT_HISTORY_TEXT = "Page Visit History";
110 
111 	/** The application menu item factory. */
112 	@Autowired
113 	private ApplicationMenuItemFactory applicationMenuItemFactory;
114 
115 	/**
116 	 * Instantiates a new parliament menu item factory impl.
117 	 */
118 	public ParliamentMenuItemFactoryImpl() {
119 		super();
120 	}
121 
122 	@Override
123 	public void createParliamentTopicMenu(final MenuBar menuBar) {
124 		initApplicationMenuBar(menuBar);
125 
126 		applicationMenuItemFactory.addRankingMenu(menuBar);
127 
128 		createParliamentTopicMenu(menuBar.addItem(PARLIAMENT_RANKING_TEXT, FontAwesome.INSTITUTION, null));
129 
130 	}
131 
132 	@Override
133 	public void createParliamentTopicMenu(final MenuItem charts) {
134 		charts.addItem(OVERVIEW_TEXT, FontAwesome.INSTITUTION,
135 				COMMAND_OVERVIEW);
136 
137 		// Submenu item with a sub-submenu
138 		final MenuItem chartIndicators = charts.addItem(SWEDISH_PARLIAMENT_INDICATORS, FontAwesome.INSTITUTION, null);
139 
140 		final MenuItem addItem = chartIndicators.addItem(PARTY_WINNER,FontAwesome.INSTITUTION, COMMAND_CHARTS_PARTY_WINNER);
141 		addItem.setDescription(DAILY_AVERAGE_WON_BALLOTS);
142 
143 		final MenuItem addItem2 = chartIndicators.addItem(PARTY_GENDER,FontAwesome.INSTITUTION, COMMAND_CHARTS_PARTY_GENDER);
144 		addItem2.setDescription(AVERAGE_PERCENTAGE_MALE);
145 
146 		final MenuItem addItem3 = chartIndicators.addItem(PARTY_AGE, FontAwesome.INSTITUTION,COMMAND_CHARTS_PARTY_AGE);
147 		addItem3.setDescription(AVERAGE_AGE);
148 
149 
150 		final MenuItem addItem4 = chartIndicators.addItem(DOCUMENT_ACTIVITY_BY_TYPE,FontAwesome.INSTITUTION, COMMAND_DOCUMENT_ACTIVITY);
151 		addItem4.setDescription(DAILY_TOTAL_OF_NUMBER_PUBLISHED_DOCUMENTS);
152 		final MenuItem addItem5 = chartIndicators.addItem(DECISION_ACTIVITY_BY_TYPE, FontAwesome.INSTITUTION,COMMAND_DECISION_ACTIVITY);
153 		addItem5.setDescription(DAILY_TOTAL_OF_NUMBER_OF_DECSIONS_MADE);
154 
155 
156 		charts.addItem(PAGE_VISIT_HISTORY_TEXT, FontAwesome.INSTITUTION,
157 				COMMAND_PAGEVISITHISTORY);
158 	}
159 
160 	@Override
161 	public void createOverviewPage(final VerticalLayout panelContent) {
162 		final GridLayout grid = createGridLayout(panelContent);
163 
164 		createButtonLink(grid,PARTY_WINNER,FontAwesome.INSTITUTION, COMMAND_CHARTS_PARTY_WINNER, "Default description");
165 
166 		createButtonLink(grid,PARTY_GENDER,FontAwesome.INSTITUTION, COMMAND_CHARTS_PARTY_GENDER, "Default description");
167 
168 		createButtonLink(grid,PARTY_AGE, FontAwesome.INSTITUTION,COMMAND_CHARTS_PARTY_AGE, "Default description");
169 
170 
171 		createButtonLink(grid,DOCUMENT_ACTIVITY_BY_TYPE,FontAwesome.INSTITUTION, COMMAND_DOCUMENT_ACTIVITY, "Default description");
172 		createButtonLink(grid,DECISION_ACTIVITY_BY_TYPE, FontAwesome.INSTITUTION,COMMAND_DECISION_ACTIVITY, "Default description");
173 
174 
175 		createButtonLink(grid,PAGE_VISIT_HISTORY_TEXT, FontAwesome.INSTITUTION,
176 				COMMAND_PAGEVISITHISTORY, "Default description");
177 
178 	}
179 
180 
181 }