PoliticianRankingChartsAllPartiesPageModContentFactoryImpl.java

  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.user.politician.pagemode;

  20. import org.apache.commons.lang3.StringUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.security.access.annotation.Secured;
  23. import org.springframework.stereotype.Service;

  24. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  25. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  26. import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.ChartDataManager;
  27. import com.hack23.cia.web.impl.ui.application.views.common.dataseriesfactory.api.PartyDataSeriesFactory;
  28. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ChartIndicators;
  29. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
  30. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  31. import com.vaadin.ui.Layout;
  32. import com.vaadin.ui.MenuBar;
  33. import com.vaadin.ui.Panel;
  34. import com.vaadin.ui.VerticalLayout;

  35. /**
  36.  * The Class PoliticianRankingChartsAllPartiesPageModContentFactoryImpl.
  37.  */
  38. @Service
  39. public final class PoliticianRankingChartsAllPartiesPageModContentFactoryImpl
  40.         extends AbstractPoliticianRankingPageModContentFactoryImpl {

  41.     /** The Constant NAME. */
  42.     public static final String NAME = UserViews.POLITICIAN_RANKING_VIEW_NAME;

  43.     /** The Constant CHARTS. */
  44.     private static final String CHARTS = "Charts:All parties";

  45.     /** The chart data manager. */
  46.     @Autowired
  47.     private ChartDataManager chartDataManager;

  48.     /** The data series factory. */
  49.     @Autowired
  50.     private PartyDataSeriesFactory dataSeriesFactory;

  51.     /**
  52.      * Instantiates a new politician ranking charts all parties page mod content
  53.      * factory impl.
  54.      */
  55.     public PoliticianRankingChartsAllPartiesPageModContentFactoryImpl() {
  56.         super();
  57.     }

  58.     @Override
  59.     public boolean matches(final String page, final String parameters) {
  60.         return NAME.equals(page)
  61.                 && (!StringUtils.isEmpty(parameters) && parameters.contains(PageMode.CHARTS.toString()) && parameters.contains(ChartIndicators.ALLPARTIES.toString()));
  62.     }

  63.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  64.     @Override
  65.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  66.         final VerticalLayout panelContent = createPanelContent();

  67.         final String pageId = getPageId(parameters);

  68.         getPoliticianRankingMenuItemFactory().createPoliticianRankingMenuBar(menuBar);

  69.         chartDataManager
  70.                 .createChartPanel(panelContent,dataSeriesFactory.createPartyChartTimeSeriesAll(), "All");


  71.         panel.setCaption(CHARTS);

  72.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_POLITICIAN_RANKING_VIEW, ApplicationEventGroup.USER,
  73.                 NAME, parameters, pageId);

  74.         return panelContent;

  75.     }

  76. }