AbstractPageModContentFactoryImpl.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.common.pagemode;

  20. import org.springframework.beans.factory.annotation.Autowired;

  21. import com.hack23.cia.service.api.ApplicationManager;
  22. import com.hack23.cia.web.impl.ui.application.action.PageActionEventHelper;
  23. import com.hack23.cia.web.impl.ui.application.views.common.chartfactory.api.AdminChartDataManager;
  24. import com.hack23.cia.web.impl.ui.application.views.common.formfactory.api.FormFactory;
  25. import com.hack23.cia.web.impl.ui.application.views.common.gridfactory.api.GridFactory;
  26. import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.ApplicationMenuItemFactory;
  27. import com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageLinkFactory;
  28. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  29. import com.vaadin.server.Sizeable.Unit;
  30. import com.vaadin.ui.HorizontalLayout;
  31. import com.vaadin.ui.TabSheet;
  32. import com.vaadin.ui.TabSheet.Tab;
  33. import com.vaadin.ui.VerticalLayout;

  34. /**
  35.  * The Class AbstractPageModContentFactoryImpl.
  36.  */
  37. public abstract class AbstractPageModContentFactoryImpl implements PageModeContentFactory {

  38.     /** The Constant GENERAL_PAGE_MODE_PAGE_VISIT. */
  39.     public static final String GENERAL_PAGE_MODE_PAGE_VISIT = "General Page Mode Page Visit";

  40.     /** The Constant CURRENT_PAGE_VISIT_HISTORY. */
  41.     public static final String CURRENT_PAGE_VISIT_HISTORY = "Current Page Visit History";

  42.     /** The application manager. */
  43.     @Autowired
  44.     private ApplicationManager applicationManager;

  45.     /** The menu item factory. */
  46.     @Autowired
  47.     private ApplicationMenuItemFactory menuItemFactory;

  48.     /** The grid factory. */
  49.     @Autowired
  50.     private GridFactory gridFactory;

  51.     /** The form factory. */
  52.     @Autowired
  53.     private FormFactory formFactory;

  54.     /** The page link factory. */
  55.     @Autowired
  56.     private PageLinkFactory pageLinkFactory;

  57.     /** The page action event helper. */
  58.     @Autowired
  59.     private PageActionEventHelper pageActionEventHelper;

  60.     /** The admin chart data manager. */
  61.     @Autowired
  62.     private AdminChartDataManager adminChartDataManager;

  63.     /**
  64.      * Instantiates a new abstract page mod content factory impl.
  65.      */
  66.     protected AbstractPageModContentFactoryImpl() {
  67.         super();
  68.     }

  69.     /**
  70.      * Gets the page id.
  71.      *
  72.      * @param parameters
  73.      *            the parameters
  74.      * @return the page id
  75.      */
  76.     protected final String getPageId(final String parameters) {
  77.         if (parameters != null) {
  78.             final int pageNr = getPageNr(parameters);
  79.             final String cleanedString = parameters.replace("[" + pageNr + "]", "");

  80.             return cleanedString.substring(cleanedString.lastIndexOf('/') + "/".length(), cleanedString.length());
  81.         } else {
  82.             return "";
  83.         }
  84.     }

  85.     /**
  86.      * Gets the page nr.
  87.      *
  88.      * @param parameters
  89.      *            the parameters
  90.      * @return the page nr
  91.      */
  92.     protected final int getPageNr(final String parameters) {
  93.         String pageNrValue;
  94.         if (parameters != null && parameters.contains("[") && parameters.contains("]")) {
  95.             pageNrValue = parameters.substring(parameters.indexOf('[') + 1, parameters.lastIndexOf(']'));
  96.         } else {
  97.             pageNrValue = "";
  98.         }

  99.         int pageNr = 1;

  100.         if (pageNrValue.length() > 0) {
  101.             pageNr = Integer.parseInt(pageNrValue);
  102.         }
  103.         return pageNr;
  104.     }

  105.     /**
  106.      * Gets the application manager.
  107.      *
  108.      * @return the application manager
  109.      */
  110.     protected final ApplicationManager getApplicationManager() {
  111.         return applicationManager;
  112.     }

  113.     /**
  114.      * Gets the menu item factory.
  115.      *
  116.      * @return the menu item factory
  117.      */
  118.     protected final ApplicationMenuItemFactory getMenuItemFactory() {
  119.         return menuItemFactory;
  120.     }

  121.     /**
  122.      * Gets the grid factory.
  123.      *
  124.      * @return the grid factory
  125.      */
  126.     protected final GridFactory getGridFactory() {
  127.         return gridFactory;
  128.     }

  129.     /**
  130.      * Gets the form factory.
  131.      *
  132.      * @return the form factory
  133.      */
  134.     protected final FormFactory getFormFactory() {
  135.         return formFactory;
  136.     }

  137.     /**
  138.      * Gets the page link factory.
  139.      *
  140.      * @return the page link factory
  141.      */
  142.     protected final PageLinkFactory getPageLinkFactory() {
  143.         return pageLinkFactory;
  144.     }

  145.     /**
  146.      * Gets the page action event helper.
  147.      *
  148.      * @return the page action event helper
  149.      */
  150.     protected final PageActionEventHelper getPageActionEventHelper() {
  151.         return pageActionEventHelper;
  152.     }

  153.     /**
  154.      * Creates the panel content.
  155.      *
  156.      * @return the vertical layout
  157.      */
  158.     protected final VerticalLayout createPanelContent() {
  159.         final VerticalLayout panelContent = new VerticalLayout();
  160.         panelContent.setMargin(true);
  161.         panelContent.setWidth(100, Unit.PERCENTAGE);
  162.         panelContent.setHeight(100, Unit.PERCENTAGE);
  163.         panelContent.setStyleName("Header");
  164.         return panelContent;
  165.     }

  166.     /**
  167.      * Creates the page visit history.
  168.      *
  169.      * @param pageName
  170.      *            the page name
  171.      * @param pageId
  172.      *            the page id
  173.      * @param panelContent
  174.      *            the panel content
  175.      */
  176.     protected final void createPageVisitHistory(final String pageName, final String pageId,
  177.             final VerticalLayout panelContent) {

  178.         final TabSheet tabsheet = new TabSheet();
  179.         tabsheet.setWidth(100, Unit.PERCENTAGE);
  180.         tabsheet.setHeight(100, Unit.PERCENTAGE);

  181.         panelContent.addComponent(tabsheet);
  182.         panelContent.setExpandRatio(tabsheet, ContentRatio.LARGE);

  183.         final HorizontalLayout tabContentPageItemRankHistory = new HorizontalLayout();
  184.         tabContentPageItemRankHistory.setWidth(100, Unit.PERCENTAGE);
  185.         tabContentPageItemRankHistory.setHeight(100, Unit.PERCENTAGE);
  186.         final Tab tabPageItemRankHistory = tabsheet.addTab(tabContentPageItemRankHistory);

  187.         tabPageItemRankHistory.setCaption(CURRENT_PAGE_VISIT_HISTORY);
  188.         adminChartDataManager.createApplicationActionEventPageElementDailySummaryChart(tabContentPageItemRankHistory,
  189.                 pageName, pageId);

  190.         final HorizontalLayout tabContentPageModeSummary = new HorizontalLayout();
  191.         tabContentPageModeSummary.setWidth(100, Unit.PERCENTAGE);
  192.         tabContentPageModeSummary.setHeight(100, Unit.PERCENTAGE);
  193.         final Tab tabPageModeSummary = tabsheet.addTab(tabContentPageModeSummary);
  194.         tabPageModeSummary.setCaption(GENERAL_PAGE_MODE_PAGE_VISIT);

  195.         adminChartDataManager.createApplicationActionEventPageModeDailySummaryChart(tabContentPageModeSummary,
  196.                 pageName);

  197.     }

  198. }