GovernmentBodyRankingMenuItemFactoryImpl.java

  1. /*
  2.  * Copyright 2010-2024 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. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Service;

  22. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ApplicationMenuItemFactory;
  23. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.GovernmentBodyRankingMenuItemFactory;
  24. import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageModeMenuCommand;
  25. import com.hack23.cia.web.impl.ui.application.views.common.rows.RowUtil;
  26. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.GovernmentBodyPageMode;
  27. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.MinistryPageMode;
  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.jarektoro.responsivelayout.ResponsiveRow;
  31. import com.vaadin.icons.VaadinIcons;
  32. import com.vaadin.ui.MenuBar;
  33. import com.vaadin.ui.VerticalLayout;

  34. /**
  35.  * The Class GovernmentBodyRankingMenuItemFactoryImpl.
  36.  *
  37.  * <p>This class builds menus and overview pages for government body rankings,
  38.  * enabling users to navigate through institutional staffing, revenue streams,
  39.  * expenditure focus, and historical engagement patterns. Through integration
  40.  * with {@link ApplicationMenuItemFactory}, it ensures a coherent experience
  41.  * within the main menu structure.</p>
  42.  */
  43. @Service
  44. public final class GovernmentBodyRankingMenuItemFactoryImpl extends AbstractMenuItemFactoryImpl
  45.         implements GovernmentBodyRankingMenuItemFactory {

  46.     /** Commands for different page modes within the Government Body Ranking view. */
  47.     private static final PageModeMenuCommand COMMAN_OVERVIEW = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  48.             PageMode.OVERVIEW);
  49.     private static final PageModeMenuCommand COMMAND_DATAGRID = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  50.             PageMode.DATAGRID);
  51.     private static final PageModeMenuCommand COMMAND_EXPENDITURE = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  52.             GovernmentBodyPageMode.EXPENDITURE.toString());
  53.     private static final PageModeMenuCommand COMMAND_HEADCOUNT = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  54.             GovernmentBodyPageMode.HEADCOUNT.toString());
  55.     private static final PageModeMenuCommand COMMAND_INCOME = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  56.             GovernmentBodyPageMode.INCOME.toString());
  57.     private static final PageModeMenuCommand COMMAND_PAGEVISITHISTORY = new PageModeMenuCommand(UserViews.GOVERNMENT_BODY_RANKING_VIEW_NAME,
  58.             PageMode.PAGEVISITHISTORY);

  59.     /** The Constant COMMAND_GOVERNMENT_BODIES_EXPENDITURE. */
  60.     private static final PageModeMenuCommand COMMAND_GOVERNMENT_BODIES_EXPENDITURE = new PageModeMenuCommand(UserViews.MINISTRY_RANKING_VIEW_NAME,
  61.             MinistryPageMode.GOVERNMENT_BODIES_EXPENDITURE.toString());

  62.     /** The Constant COMMAND_GOVERNMENT_BODIES_HEADCOUNT. */
  63.     private static final PageModeMenuCommand COMMAND_GOVERNMENT_BODIES_HEADCOUNT = new PageModeMenuCommand(UserViews.MINISTRY_RANKING_VIEW_NAME,
  64.             MinistryPageMode.GOVERNMENT_BODIES_HEADCOUNT.toString());

  65.     /** The Constant COMMAND_GOVERNMENT_BODIES_INCOME. */
  66.     private static final PageModeMenuCommand COMMAND_GOVERNMENT_BODIES_INCOME = new PageModeMenuCommand(UserViews.MINISTRY_RANKING_VIEW_NAME,
  67.             MinistryPageMode.GOVERNMENT_BODIES_INCOME.toString());


  68.     /** The Constant GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY. */
  69.     private static final String GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY = "Government body expenditure by ministry";

  70.     /** The Constant GOVERNMENT_BODIES. */
  71.     private static final String GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY = "Government body headcount by ministry";

  72.     /** The Constant GOVERNMENT_BODY_INCOME_PER_MINISTRY. */
  73.     private static final String GOVERNMENT_BODY_INCOME_PER_MINISTRY = "Government body income by ministry";


  74.     /** The Constant GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY_DESCRIPTION. */
  75.     private static final String GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY_DESCRIPTION = "Chart over total headcount for all goverment bodies governed by ministries";

  76.     /** The Constant GOVERNMENT_BODY_INCOME_PER_MINISTRY_DESCRIPTION. */
  77.     private static final String GOVERNMENT_BODY_INCOME_PER_MINISTRY_DESCRIPTION = "Chart over total income for all goverment bodies governed by ministries";

  78.     /** The Constant GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY_DESCRIPTION. */
  79.     private static final String GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY_DESCRIPTION = "Chart over total spending for all goverment bodies governed by ministries";




  80.     /** Menu labels. */
  81.     private static final String EXPENDITURE = "Expenditure";
  82.     private static final String GOVERNMENT_BODIES = "Government bodies";
  83.     private static final String GOVERNMENT_BODY_RANKING = "GovernmentBody Ranking";
  84.     private static final String HEADCOUNT = "Headcount";
  85.     private static final String INCOME = "Income";
  86.     private static final String OVERVIEW_TEXT = "Overview";
  87.     private static final String PAGE_VISIT_HISTORY_TEXT = "Page Visit History";

  88.     /** Descriptions ~50 chars. */
  89.     private static final String HEADCOUNT_DESCRIPTION = "Staffing levels reveal institutional influence.";
  90.     private static final String INCOME_DESCRIPTION = "Compare institutions by their revenue streams.";
  91.     private static final String EXPENDITURE_DESCRIPTION = "Assess how bodies allocate and prioritize spending.";
  92.     private static final String PAGE_VISIT_HISTORY_DESCRIPTION = "Explore historical interest, engagement patterns.";
  93.     private static final String CURRENT_GOVERNMENT_BODIES_DESCRIPTION = "All bodies: study structural roles and authority.";

  94.     /** The application menu item factory, used to integrate into the main menu. */
  95.     @Autowired
  96.     private ApplicationMenuItemFactory applicationMenuItemFactory;

  97.     /**
  98.      * Instantiates a new government body ranking menu item factory implementation.
  99.      */
  100.     public GovernmentBodyRankingMenuItemFactoryImpl() {
  101.         super();
  102.     }

  103.     /**
  104.      * Creates the government body ranking menu bar and integrates it into the main
  105.      * application menu. Adds government body ranking topics as sub-items.
  106.      *
  107.      * @param menuBar the main application {@link MenuBar} to which the government
  108.      *                body ranking menu will be added.
  109.      */
  110.     @Override
  111.     public void createGovernmentBodyRankingMenuBar(final MenuBar menuBar) {
  112.         initApplicationMenuBar(menuBar);
  113.         applicationMenuItemFactory.addRankingMenu(menuBar);
  114.         createGovernmentBodyRankingTopics(menuBar.addItem(GOVERNMENT_BODY_RANKING, VaadinIcons.BUILDING_O, null));
  115.     }

  116.     /**
  117.      * Adds menu items for various government body ranking topics:
  118.      * <ul>
  119.      *   <li>Overview: General dashboard icon</li>
  120.      *   <li>Government Bodies: Building icon for institutions</li>
  121.      *   <li>Headcount: Multiple users for staffing</li>
  122.      *   <li>Income: Money deposit icon for revenues</li>
  123.      *   <li>Expenditure: Money withdraw icon for spending</li>
  124.      *   <li>Page Visit History: History icon for past engagement</li>
  125.      * </ul>
  126.      *
  127.      * @param menuItem the {@link MenuBar.MenuItem} representing "GovernmentBody Ranking"
  128.      *                 under which these topics will be added.
  129.      */
  130.     @Override
  131.     public void createGovernmentBodyRankingTopics(final MenuBar.MenuItem menuItem) {
  132.         menuItem.addItem(OVERVIEW_TEXT, VaadinIcons.DASHBOARD, COMMAN_OVERVIEW);
  133.         menuItem.addItem(GOVERNMENT_BODIES, VaadinIcons.BUILDING_O, COMMAND_DATAGRID);
  134.         menuItem.addItem(GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY, VaadinIcons.USER_CHECK, COMMAND_GOVERNMENT_BODIES_HEADCOUNT);
  135.         menuItem.addItem(GOVERNMENT_BODY_INCOME_PER_MINISTRY, VaadinIcons.MONEY, COMMAND_GOVERNMENT_BODIES_INCOME);
  136.         menuItem.addItem(GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY, VaadinIcons.MONEY_WITHDRAW, COMMAND_GOVERNMENT_BODIES_EXPENDITURE);

  137.         menuItem.addItem(HEADCOUNT, VaadinIcons.USERS, COMMAND_HEADCOUNT);
  138.         menuItem.addItem(INCOME, VaadinIcons.MONEY_DEPOSIT, COMMAND_INCOME);
  139.         menuItem.addItem(EXPENDITURE, VaadinIcons.MONEY_WITHDRAW, COMMAND_EXPENDITURE);
  140.         menuItem.addItem(PAGE_VISIT_HISTORY_TEXT, VaadinIcons.CHART, COMMAND_PAGEVISITHISTORY);
  141.     }

  142.     /**
  143.      * Creates the overview page with quick-access links to government body ranking topics.
  144.      * Each button uses an icon and a brief description to guide the user:
  145.      * <ul>
  146.      *   <li>Government Bodies: Building icon, structural roles</li>
  147.      *   <li>Headcount: Users icon, staffing influence</li>
  148.      *   <li>Income: Money deposit icon, revenue streams</li>
  149.      *   <li>Expenditure: Money withdraw icon, spending focus</li>
  150.      *   <li>Page Visit History: History icon, past engagement</li>
  151.      * </ul>
  152.      *
  153.      * @param panelContent the {@link VerticalLayout} container that holds the overview
  154.      *                     content. New UI components will be added here.
  155.      */
  156.     @Override
  157.     public void createOverviewPage(final VerticalLayout panelContent) {
  158.         final ResponsiveRow grid = RowUtil.createGridLayout(panelContent);

  159.         createButtonLink(grid, GOVERNMENT_BODIES, VaadinIcons.BUILDING_O, COMMAND_DATAGRID, CURRENT_GOVERNMENT_BODIES_DESCRIPTION);
  160.         createButtonLink(grid, GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY, VaadinIcons.USER_CHECK, COMMAND_GOVERNMENT_BODIES_HEADCOUNT, GOVERNMENT_BODY_HEADCOUNT_PER_MINISTRY_DESCRIPTION);
  161.         createButtonLink(grid, GOVERNMENT_BODY_INCOME_PER_MINISTRY, VaadinIcons.MONEY, COMMAND_GOVERNMENT_BODIES_INCOME, GOVERNMENT_BODY_INCOME_PER_MINISTRY_DESCRIPTION);
  162.         createButtonLink(grid, GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY, VaadinIcons.MONEY_WITHDRAW, COMMAND_GOVERNMENT_BODIES_EXPENDITURE, GOVERNMENT_BODY_EXPENDITURE_PER_MINISTRY_DESCRIPTION);

  163.         createButtonLink(grid, HEADCOUNT, VaadinIcons.USERS, COMMAND_HEADCOUNT, HEADCOUNT_DESCRIPTION);
  164.         createButtonLink(grid, INCOME, VaadinIcons.MONEY_DEPOSIT, COMMAND_INCOME, INCOME_DESCRIPTION);
  165.         createButtonLink(grid, EXPENDITURE, VaadinIcons.MONEY_WITHDRAW, COMMAND_EXPENDITURE, EXPENDITURE_DESCRIPTION);
  166.         createButtonLink(grid, PAGE_VISIT_HISTORY_TEXT, VaadinIcons.CHART, COMMAND_PAGEVISITHISTORY, PAGE_VISIT_HISTORY_DESCRIPTION);
  167.     }
  168. }