AbstractPageModContentFactoryImpl.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.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.pagelinks.api.PageModeMenuCommand;
  29. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  30. import com.vaadin.server.Sizeable.Unit;
  31. import com.vaadin.ui.HorizontalLayout;
  32. import com.vaadin.ui.TabSheet;
  33. import com.vaadin.ui.TabSheet.Tab;
  34. import com.vaadin.ui.VerticalLayout;

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

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

  41.     /** The Constant DEFAULT_RESULTS_PER_PAGE. */
  42.     public static final int DEFAULT_RESULTS_PER_PAGE = 250;

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

  45.     /** The admin chart data manager. */
  46.     @Autowired
  47.     private AdminChartDataManager adminChartDataManager;

  48.     /** The application manager. */
  49.     @Autowired
  50.     private ApplicationManager applicationManager;

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

  54.     /** The grid factory. */
  55.     @Autowired
  56.     private GridFactory gridFactory;

  57.     /** The menu item factory. */
  58.     @Autowired
  59.     private ApplicationMenuItemFactory menuItemFactory;

  60.     /** The page action event helper. */
  61.     @Autowired
  62.     private PageActionEventHelper pageActionEventHelper;

  63.     /** The page link factory. */
  64.     @Autowired
  65.     private PageLinkFactory pageLinkFactory;

  66.     /**
  67.      * Instantiates a new abstract page mod content factory impl.
  68.      */
  69.     protected AbstractPageModContentFactoryImpl() {
  70.         super();
  71.     }

  72.     /**
  73.      * Creates the page visit history.
  74.      *
  75.      * @param pageName
  76.      *            the page name
  77.      * @param pageId
  78.      *            the page id
  79.      * @param panelContent
  80.      *            the panel content
  81.      */
  82.     protected final void createPageVisitHistory(final String pageName, final String pageId,
  83.             final VerticalLayout panelContent) {

  84.         final TabSheet tabsheet = createTabSheet(panelContent);

  85.         final HorizontalLayout tabContentPageItemRankHistory = createTabContent(tabsheet, CURRENT_PAGE_VISIT_HISTORY);
  86.         adminChartDataManager.createApplicationActionEventPageElementDailySummaryChart(tabContentPageItemRankHistory,
  87.                 pageName, pageId);

  88.         final HorizontalLayout tabContentPageModeSummary = createTabContent(tabsheet, GENERAL_PAGE_MODE_PAGE_VISIT);
  89.         adminChartDataManager.createApplicationActionEventPageModeDailySummaryChart(tabContentPageModeSummary,
  90.                 pageName);

  91.     }

  92.     /**
  93.      * Creates the panel content.
  94.      *
  95.      * @return the vertical layout
  96.      */
  97.     protected static final VerticalLayout createPanelContent() {
  98.         final VerticalLayout panelContent = new VerticalLayout();
  99.         panelContent.setMargin(true);
  100.         panelContent.setWidth(100, Unit.PERCENTAGE);
  101.         panelContent.setHeight(100, Unit.PERCENTAGE);
  102.         panelContent.setStyleName("v-layout-content-overview-panel-level1");
  103.         return panelContent;
  104.     }

  105.     /**
  106.      * Gets the admin chart data manager.
  107.      *
  108.      * @return the admin chart data manager
  109.      */
  110.     protected final AdminChartDataManager getAdminChartDataManager() {
  111.         return adminChartDataManager;
  112.     }

  113.     /**
  114.      * Gets the application manager.
  115.      *
  116.      * @return the application manager
  117.      */
  118.     protected final ApplicationManager getApplicationManager() {
  119.         return applicationManager;
  120.     }

  121.     /**
  122.      * Gets the form factory.
  123.      *
  124.      * @return the form factory
  125.      */
  126.     protected final FormFactory getFormFactory() {
  127.         return formFactory;
  128.     }

  129.     /**
  130.      * Gets the grid factory.
  131.      *
  132.      * @return the grid factory
  133.      */
  134.     protected final GridFactory getGridFactory() {
  135.         return gridFactory;
  136.     }

  137.     /**
  138.      * Gets the menu item factory.
  139.      *
  140.      * @return the menu item factory
  141.      */
  142.     protected final ApplicationMenuItemFactory getMenuItemFactory() {
  143.         return menuItemFactory;
  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.      * Gets the page id.
  155.      *
  156.      * @param parameters
  157.      *            the parameters
  158.      * @return the page id
  159.      */
  160.     protected static final String getPageId(final String parameters) {
  161.         return PageModeMenuCommand.getPageId(parameters);
  162.     }

  163.     /**
  164.      * Gets the page link factory.
  165.      *
  166.      * @return the page link factory
  167.      */
  168.     protected final PageLinkFactory getPageLinkFactory() {
  169.         return pageLinkFactory;
  170.     }

  171.     /**
  172.      * Gets the page nr.
  173.      *
  174.      * @param parameters the parameters
  175.      * @return the page nr
  176.      */
  177.     protected static final int getPageNr(final String parameters) {
  178.         final String cleanedString = parameters;
  179.         String pageNrValue;
  180.         if (cleanedString != null && cleanedString.contains("[") && cleanedString.contains("]")) {
  181.             pageNrValue = cleanedString.substring(cleanedString.indexOf('[') + 1, cleanedString.lastIndexOf(']'));
  182.         } else {
  183.             pageNrValue = "";
  184.         }

  185.         int pageNr = 1;

  186.         if (pageNrValue.length() > 0 && !pageNrValue.contains("/")) {
  187.             pageNr = Integer.parseInt(pageNrValue);
  188.         }
  189.         return pageNr;
  190.     }

  191.     /**
  192.      * Creates a TabSheet and adds it to the given panel content.
  193.      *
  194.      * @param panelContent the panel content
  195.      * @return the created TabSheet
  196.      */
  197.     private TabSheet createTabSheet(final VerticalLayout panelContent) {
  198.         final TabSheet tabsheet = new TabSheet();
  199.         tabsheet.setWidth(100, Unit.PERCENTAGE);
  200.         tabsheet.setHeight(100, Unit.PERCENTAGE);

  201.         panelContent.addComponent(tabsheet);
  202.         panelContent.setExpandRatio(tabsheet, ContentRatio.LARGE);

  203.         return tabsheet;
  204.     }

  205.     /**
  206.      * Creates a HorizontalLayout for a tab and adds it to the given TabSheet.
  207.      *
  208.      * @param tabsheet the TabSheet
  209.      * @param caption  the caption for the tab
  210.      * @return the created HorizontalLayout
  211.      */
  212.     private HorizontalLayout createTabContent(final TabSheet tabsheet, final String caption) {
  213.         final HorizontalLayout tabContent = new HorizontalLayout();
  214.         tabContent.setWidth(100, Unit.PERCENTAGE);
  215.         tabContent.setHeight(100, Unit.PERCENTAGE);
  216.         final Tab tab = tabsheet.addTab(tabContent);
  217.         tab.setCaption(caption);
  218.         return tabContent;
  219.     }
  220. }