BallotMenuItemFactoryImpl.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.stereotype.Service;

  21. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.BallotMenuItemFactory;
  22. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.pagecommands.PageCommandBallotConstants;
  23. import com.hack23.cia.web.impl.ui.application.views.common.rows.RowUtil;
  24. import com.jarektoro.responsivelayout.ResponsiveRow;
  25. import com.vaadin.icons.VaadinIcons;
  26. import com.vaadin.ui.MenuBar;
  27. import com.vaadin.ui.VerticalLayout;

  28. /**
  29.  * The Class BallotMenuItemFactoryImpl.
  30.  *
  31.  * This class is responsible for creating and managing the ballot menu items
  32.  * and overview pages in the Citizen Intelligence Agency web application.
  33.  * It provides methods to initialize the ballot menu bar and generate
  34.  * overview pages with relevant descriptions and icons.
  35.  */
  36. @Service
  37. public final class BallotMenuItemFactoryImpl extends AbstractMenuItemFactoryImpl implements BallotMenuItemFactory {

  38.     /** The Constant CHARTS_TEXT. */
  39.     private static final String CHARTS_TEXT = "Charts";

  40.     /** The Constant OVERVIEW_TEXT. */
  41.     private static final String OVERVIEW_TEXT = "Overview";

  42.     /** The Constant BALLOT_RESULTS_DESCRIPTION. */
  43.     private static final String BALLOT_RESULTS_DESCRIPTION = "Ballot results: vote breakdown by party.";

  44.     /**
  45.      * Instantiates a new ballot menu item factory impl.
  46.      */
  47.     public BallotMenuItemFactoryImpl() {
  48.         super();
  49.     }

  50.     /**
  51.      * Creates the ballot menu bar.
  52.      *
  53.      * @param menuBar the menu bar
  54.      * @param pageId the page id
  55.      */
  56.     @Override
  57.     public void createBallotMenuBar(final MenuBar menuBar, final String pageId) {
  58.         initApplicationMenuBar(menuBar);

  59.         menuBar.addItem(OVERVIEW_TEXT, VaadinIcons.PIE_CHART,
  60.                 PageCommandBallotConstants.COMMAND_BALLOT_OVERVIEW.createItemPageCommand(pageId));
  61.         menuBar.addItem(CHARTS_TEXT, VaadinIcons.PIE_CHART,
  62.                 PageCommandBallotConstants.COMMAND_BALLOT_CHARTS.createItemPageCommand(pageId));
  63.     }

  64.     /**
  65.      * Creates the overview page.
  66.      *
  67.      * @param panelContent the panel content
  68.      * @param pageId the page id
  69.      */
  70.     @Override
  71.     public void createOverviewPage(final VerticalLayout panelContent, final String pageId) {
  72.         final ResponsiveRow grid = RowUtil.createGridLayout(panelContent);

  73.         createButtonLink(grid, CHARTS_TEXT, VaadinIcons.PIE_CHART,
  74.                 PageCommandBallotConstants.COMMAND_BALLOT_CHARTS.createItemPageCommand(pageId), BALLOT_RESULTS_DESCRIPTION);
  75.     }

  76. }