PartyRankingMenuItemFactoryImpl.java

  1. /*
  2.  * Copyright 2010-2025 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.PartyRankingMenuItemFactory;
  24. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandPartyRankingConstants;
  25. import com.hack23.cia.web.impl.ui.application.views.common.rows.RowUtil;
  26. import com.jarektoro.responsivelayout.ResponsiveRow;
  27. import com.vaadin.icons.VaadinIcons;
  28. import com.vaadin.ui.MenuBar;
  29. import com.vaadin.ui.MenuBar.MenuItem;
  30. import com.vaadin.ui.VerticalLayout;

  31. /**
  32.  * The Class PartyRankingMenuItemFactoryImpl.
  33.  *
  34.  * <p>
  35.  * Responsible for creating and organizing party ranking menu items, charts, and
  36.  * overview pages. Enhances user navigation to analyze party influence, roles,
  37.  * and performance within EU, government, committees, and parliament. Leverages
  38.  * VaadinIcons to visually communicate context and concise descriptions focusing
  39.  * on political significance.
  40.  * </p>
  41.  */
  42. @Service
  43. public final class PartyRankingMenuItemFactoryImpl extends AbstractMenuItemFactoryImpl
  44.                 implements PartyRankingMenuItemFactory {

  45.         /** Application menu item factory for integrating ranking menus. */
  46.         @Autowired
  47.         private ApplicationMenuItemFactory applicationMenuItemFactory;

  48.         /**
  49.          * Instantiates a new party ranking menu item factory implementation.
  50.          */
  51.         public PartyRankingMenuItemFactoryImpl() {
  52.                 super();
  53.         }

  54.         /**
  55.          * Creates the overview page with concise, politically focused descriptions.
  56.          * Each button link is accompanied by ~50 character descriptions highlighting
  57.          * political context rather than technical details.
  58.          *
  59.          * @param panelContent the vertical layout to hold the overview content
  60.          */
  61.         @Override
  62.         public void createOverviewPage(final VerticalLayout panelContent) {
  63.                 final ResponsiveRow grid = RowUtil.createGridLayout(panelContent);

  64.                 createButtonLink(grid, PART_LEADERS_SCOREBOARD, VaadinIcons.TROPHY,
  65.                         COMMAND_PARTY_LEADER_SCOREBOARD, DESC_LEADERS_SCOREBOARD);

  66.                 createButtonLink(grid, TOTAL_MEMBERS, VaadinIcons.USERS,
  67.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_DATAGRID, DESC_ALL_PARTIES_ROLES);

  68.                 createButtonLink(grid, CURRENT_PARTIES_ACTIVE_IN_MINISTRIES_HEAD_COUNT_TEXT, VaadinIcons.INSTITUTION,
  69.                                 COMMAND_CHARTS_CURRENT_GOVERNMENT_PARTIES, DESC_GOVERNMENT_HEADCOUNT);

  70.                 createButtonLink(grid, CURRENT_PARTIES_ACTIVE_IN_COMMITTEES_HEAD_COUNT, VaadinIcons.GROUP,
  71.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_CHARTS_CURRENT_PARTIES, DESC_COMMITTEES_HEADCOUNT);

  72.                 createButtonLink(grid, CURRENT_PARTIES_ACTIVE_IN_PARLIAMENT_HEAD_COUNT, VaadinIcons.INSTITUTION,
  73.                                 COMMAND_CHARTS_CURRENT_GOVERNMENT_PARTIES, DESC_PARLIAMENT_HEADCOUNT);

  74.                 createButtonLink(grid, ALL_PARTIES_TOTAL_DAYS_SERVED_IN_PARLIAMENT, VaadinIcons.CLOCK,
  75.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_CHARTS_ALL_PARTIES, DESC_DAYS_SERVED_PARLIAMENT);

  76.                 createButtonLink(grid, RANKING_PAGE_VISIT_TEXT, VaadinIcons.CHART,
  77.                                 PARTY_RANKING_COMMAND_PAGEVISIT_HISTORY, RANKING_PAGE_VISIT_DESC);
  78.         }

  79.         /**
  80.          * Creates the party ranking menu bar and integrates it into the main
  81.          * application
  82.          * menu. Ensures consistent icon usage and logical grouping of party ranking
  83.          * topics.
  84.          *
  85.          * @param menuBar the main menu bar to which the party ranking items will be
  86.          *                added
  87.          */
  88.         @Override
  89.         public void createPartyRankingMenuBar(final MenuBar menuBar) {
  90.                 initApplicationMenuBar(menuBar);
  91.                 applicationMenuItemFactory.addRankingMenu(menuBar);

  92.                 // Suitable icon (e.g., LINE_CHART) for ranking visualization
  93.                 createPartyRankingTopics(menuBar.addItem(PARTY_RANKING, VaadinIcons.LINE_CHART, null));
  94.         }

  95.         /**
  96.          * Adds party ranking topics to the specified menu item. Uses icons that reflect
  97.          * the content context, such as charts for data visualization, groups or
  98.          * institutions for organizational structures, and history for past activity.
  99.          *
  100.          * @param partynMenuItem the parent menu item to which party ranking topics are
  101.          *                       added
  102.          */
  103.         @Override
  104.         public void createPartyRankingTopics(final MenuItem partynMenuItem) {
  105.                 // Use specific ranking commands instead of generic ones
  106.                 partynMenuItem.addItem(RANKING_OVERVIEW_TEXT, VaadinIcons.DASHBOARD,
  107.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_OVERVIEW);

  108.                 partynMenuItem.addItem(OVERVIEW_TEXT, VaadinIcons.DASHBOARD, PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_OVERVIEW);

  109.                 partynMenuItem.addItem(PART_LEADERS_SCOREBOARD, VaadinIcons.TROPHY,
  110.                         COMMAND_PARTY_LEADER_SCOREBOARD);

  111.                 // Total members using USERS icon for multiple people
  112.                 final MenuItem listItem = partynMenuItem.addItem(TOTAL_MEMBERS, VaadinIcons.USERS, PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_DATAGRID);
  113.                 listItem.setDescription(PARTY_BY_TOTAL_MEMBERS_BASED_ON_ROLES_IN_DEPARTMENTS_COMMITTEES_AND_PARLIAMENT);

  114.                 final MenuItem chartByTopic = partynMenuItem.addItem(CHART_BY_TOPIC_TEXT, VaadinIcons.CHART, null);

  115.                 chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_MINISTRIES_HEAD_COUNT_TEXT, VaadinIcons.INSTITUTION,
  116.                         PageCommandPartyRankingConstants.COMMAND_CHARTS_CURRENT_GOVERNMENT_PARTIES);

  117.                 chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_COMMITTEES_HEAD_COUNT, VaadinIcons.GROUP,
  118.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_CHARTS_CURRENT_PARTIES);

  119.                 chartByTopic.addItem(CURRENT_PARTIES_ACTIVE_IN_PARLIAMENT_HEAD_COUNT, VaadinIcons.INSTITUTION,
  120.                                 COMMAND_CHARTS_CURRENT_GOVERNMENT_PARTIES);

  121.                 chartByTopic.addItem(ALL_PARTIES_TOTAL_DAYS_SERVED_IN_PARLIAMENT, VaadinIcons.CLOCK,
  122.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_CHARTS_ALL_PARTIES);

  123.                 partynMenuItem.addItem(RANKING_PAGE_VISIT_TEXT, VaadinIcons.CHART,
  124.                                 PARTY_RANKING_COMMAND_PAGEVISIT_HISTORY);

  125.                 partynMenuItem.addItem(RANKING_OVERVIEW_TEXT, VaadinIcons.DASHBOARD,
  126.                         PageCommandPartyRankingConstants.COMMAND_PARTY_RANKING_OVERVIEW);

  127.                 partynMenuItem.addItem(RANKING_PAGE_VISIT_TEXT, VaadinIcons.CHART,
  128.                                 PARTY_RANKING_COMMAND_PAGEVISIT_HISTORY);
  129.         }
  130. }