AdminAgencyPageModContentFactoryImpl.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.admin.system.pagemode;

  20. import java.util.List;

  21. import org.springframework.security.access.annotation.Secured;
  22. import org.springframework.stereotype.Component;

  23. import com.hack23.cia.model.internal.application.system.impl.Agency;
  24. import com.hack23.cia.model.internal.application.system.impl.Agency_;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  26. import com.hack23.cia.model.internal.application.system.impl.Portal;
  27. import com.hack23.cia.service.api.DataContainer;
  28. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  29. import com.hack23.cia.web.impl.ui.application.views.admin.AdminViewConstants;
  30. import com.hack23.cia.web.impl.ui.application.views.common.converters.ListPropertyConverter;
  31. import com.hack23.cia.web.impl.ui.application.views.common.pagemode.CardInfoRowUtil;
  32. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  33. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentSize;
  34. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.AdminViews;
  35. import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.PageItemPropertyClickListener;
  36. import com.vaadin.icons.VaadinIcons;
  37. import com.vaadin.server.Responsive;
  38. import com.vaadin.ui.HorizontalLayout;
  39. import com.vaadin.ui.Layout;
  40. import com.vaadin.ui.MenuBar;
  41. import com.vaadin.ui.Panel;
  42. import com.vaadin.ui.VerticalLayout;

  43. /**
  44.  * The Class AdminAgencyPageModContentFactoryImpl.
  45.  */
  46. @Component
  47. public final class AdminAgencyPageModContentFactoryImpl extends AbstractAdminSystemPageModContentFactoryImpl {

  48.     /** The Constant AGENCY. */
  49.     private static final String AGENCY = "Agency";

  50.     /** The Constant AGENCY_GRID_COLLECTION_PROPERTY_CONVERTERS. */
  51.     private static final ListPropertyConverter[] AGENCY_GRID_COLLECTION_PROPERTY_CONVERTERS = {
  52.             new ListPropertyConverter("portalName", "portals") };

  53.     /** The Constant AGENCY_GRID_COLUMN_ORDER. */
  54.     private static final String[] AGENCY_GRID_COLUMN_ORDER = { "hjid", "agencyName", "description", "portals",
  55.             "modelObjectVersion" };

  56.     /** The Constant AGENCY_GRID_HIDE_COLUMNS. */
  57.     private static final String[] AGENCY_GRID_HIDE_COLUMNS = { "hjid", "modelObjectId", "modelObjectVersion" };

  58.     /** The Constant AGENCY_GRID_LISTENER. */
  59.     private static final PageItemPropertyClickListener AGENCY_GRID_LISTENER = new PageItemPropertyClickListener(
  60.             AdminViews.ADMIN_AGENCY_VIEW_NAME, "hjid");

  61.     /** The Constant NAME. */
  62.     public static final String NAME = AdminViews.ADMIN_AGENCY_VIEW_NAME;

  63.     /** The Constant PORTAL. */
  64.     private static final String PORTAL = "Portal";

  65.     /** The Constant PORTAL_GRID_COLUMN_ORDER. */
  66.     private static final String[] PORTAL_GRID_COLUMN_ORDER = { "hjid", "portalName", "description", "portalType",
  67.             "googleMapApiKey", "modelObjectVersion" };

  68.     /** The Constant PORTAL_GRID_HIDE_COLUMNS. */
  69.     private static final String[] PORTAL_GRID_HIDE_COLUMNS = { "hjid", "modelObjectId", "modelObjectVersion",
  70.             "googleMapApiKey" };

  71.     /** The Constant PORTAL_GRID_LISTENER. */
  72.     private static final PageItemPropertyClickListener PORTAL_GRID_LISTENER = new PageItemPropertyClickListener(
  73.             AdminViews.ADMIN_PORTAL_VIEW_NAME, "hjid");

  74.     /**
  75.      * Instantiates a new admin agency page mod content factory impl.
  76.      */
  77.     public AdminAgencyPageModContentFactoryImpl() {
  78.         super(NAME);
  79.     }

  80.     @Secured({ "ROLE_ADMIN" })
  81.     @Override
  82.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  83.         final VerticalLayout content = createPanelContent();

  84.         final String pageId = getPageId(parameters);
  85.         final int pageNr = getPageNr(parameters);

  86.         getMenuItemFactory().createMainPageMenuBar(menuBar);

  87.         CardInfoRowUtil.createPageHeader(panel, content, AdminViewConstants.ADMIN_AGENCY_MANAGEMENT, "Agency Overview",
  88.                 AdminViewConstants.AGENCY_OVERVIEW);

  89.         final DataContainer<Agency, Long> dataContainer = getApplicationManager().getDataContainer(Agency.class);
  90.         final List<Agency> pageOrderBy = dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE,
  91.                 Agency_.agencyName);

  92.         getPagingUtil().createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr,
  93.                 DEFAULT_RESULTS_PER_PAGE);

  94.         getGridFactory().createBasicBeanItemGrid(content, Agency.class, pageOrderBy, AGENCY,
  95.                 AGENCY_GRID_COLUMN_ORDER, AGENCY_GRID_HIDE_COLUMNS, AGENCY_GRID_LISTENER, null,
  96.                 AGENCY_GRID_COLLECTION_PROPERTY_CONVERTERS);

  97.         if (pageId != null && !pageId.isEmpty()) {
  98.             final HorizontalLayout horizontalLayout = new HorizontalLayout();
  99.             horizontalLayout.setWidth(ContentSize.FULL_SIZE);
  100.             content.addComponent(horizontalLayout);
  101.             content.setExpandRatio(horizontalLayout, ContentRatio.LARGE_FORM);

  102.             final VerticalLayout leftLayout = new VerticalLayout();
  103.             leftLayout.setSizeFull();
  104.             leftLayout.addStyleName("v-layout-content-overview-panel-level1");

  105.             final VerticalLayout rightLayout = new VerticalLayout();
  106.             rightLayout.setSizeFull();
  107.             rightLayout.addStyleName("v-layout-content-overview-panel-level2");

  108.             horizontalLayout.addComponents(leftLayout, rightLayout);

  109.             final Agency agency = dataContainer.load(Long.valueOf(pageId));
  110.             if (agency != null) {
  111.                 // Card panel for Agency details
  112.                 final Panel cardPanel = new Panel();
  113.                 cardPanel.addStyleName("politician-overview-card"); // Reuse existing card style
  114.                 cardPanel.setWidth("100%");
  115.                 cardPanel.setHeightUndefined();
  116.                 Responsive.makeResponsive(cardPanel);

  117.                 final VerticalLayout cardContent = new VerticalLayout();
  118.                 cardContent.setMargin(true);
  119.                 cardContent.setSpacing(true);
  120.                 cardContent.setWidth("100%");
  121.                 cardPanel.setContent(cardContent);

  122.                 leftLayout.addComponent(cardPanel);

  123.                 CardInfoRowUtil.createCardHeader(cardContent, "Agency Details");

  124.                 // Attributes layout
  125.                 final VerticalLayout attributesLayout = new VerticalLayout();
  126.                 attributesLayout.setSpacing(true);
  127.                 attributesLayout.setWidth("100%");
  128.                 cardContent.addComponent(attributesLayout);

  129.                 // Display fields in a card layout (skipping null or empty ones)
  130.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Agency Name:", agency.getAgencyName(), VaadinIcons.FLAG);
  131.                 CardInfoRowUtil.addInfoRowIfNotNull(attributesLayout, "Description:", agency.getDescription(), VaadinIcons.FILE_TEXT);

  132.                 // Right layout: portals grid
  133.                 getGridFactory().createBasicBeanItemGrid(rightLayout, Portal.class, agency.getPortals(),
  134.                         PORTAL, PORTAL_GRID_COLUMN_ORDER, PORTAL_GRID_HIDE_COLUMNS,
  135.                         PORTAL_GRID_LISTENER, null, null);
  136.             }
  137.         }

  138.         getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_AGENCY_VIEW, ApplicationEventGroup.ADMIN,
  139.                 NAME, null, pageId);

  140.         return content;
  141.     }

  142. }