CardInfoRowUtil.java

  1. package com.hack23.cia.web.impl.ui.application.views.common.pagemode;

  2. import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
  3. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  4. import com.vaadin.icons.VaadinIcons;
  5. import com.vaadin.server.Responsive;
  6. import com.vaadin.server.Sizeable.Unit;
  7. import com.vaadin.shared.ui.ContentMode;
  8. import com.vaadin.ui.HorizontalLayout;
  9. import com.vaadin.ui.Label;
  10. import com.vaadin.ui.Panel;
  11. import com.vaadin.ui.VerticalLayout;

  12. /**
  13.  * The Class CardInfoRowUtil.
  14.  */
  15. public class CardInfoRowUtil {

  16.     /** The Constant CARD_TENURE. */
  17.     public static final String CARD_TENURE = "card-tenure";

  18.     /** The Constant CARD_EXPERIENCE. */
  19.     public static final String CARD_EXPERIENCE = "card-experience-section";

  20.     /** The Constant CARD_INFO_VALUE. */
  21.     public static final String CARD_INFO_VALUE = "card-info-value";

  22.     /** The Constant CARD_INFO_ICON. */
  23.     public static final String CARD_INFO_ICON = "card-info-icon";

  24.     /** The Constant METRIC_LABEL. */
  25.     public static final String METRIC_LABEL = "metric-label";

  26.     /**
  27.      * Creates the page header.
  28.      *
  29.      * @param panel           the panel
  30.      * @param panelContent    the panel content
  31.      * @param header          the header
  32.      * @param pageHeader      the page header
  33.      * @param pageDescription the page description
  34.      */
  35.     public static final void createPageHeader(final Panel panel, final VerticalLayout panelContent, final String header,
  36.             final String pageHeader, final String pageDescription) {
  37.         panel.setCaption(header);
  38.         LabelFactory.createHeader2Label(panelContent, pageHeader);
  39.         final Label descriptionLabel = new Label(pageDescription);
  40.         descriptionLabel.addStyleName("itembox");
  41.         Responsive.makeResponsive(descriptionLabel);
  42.         descriptionLabel.setWidth(100, Unit.PERCENTAGE);
  43.         panelContent.addComponent(descriptionLabel);
  44.         panelContent.setExpandRatio(descriptionLabel, ContentRatio.SMALL);
  45.     }

  46.     /**
  47.      * Adds an info row to the parent layout if value is not null or empty.
  48.      *
  49.      * @param parent  the parent layout
  50.      * @param caption the caption
  51.      * @param value   the value
  52.      * @param icon    the icon
  53.      */
  54.     public static final void addInfoRowIfNotNull(final VerticalLayout parent, final String caption, final String value,
  55.             final VaadinIcons icon) {
  56.         if (value != null && !value.trim().isEmpty() && !"null".equalsIgnoreCase(value)) {
  57.             parent.addComponent(CardInfoRowUtil.createInfoRow(caption, value, icon));
  58.         }
  59.     }

  60.     /**
  61.      * Creates a simple info row (caption and value) with optional icon.
  62.      *
  63.      * @param caption the field caption
  64.      * @param value   the field value
  65.      * @param icon    a VaadinIcons icon
  66.      * @return a HorizontalLayout representing the info row
  67.      */
  68.     public static final HorizontalLayout createInfoRow(final String caption, final String value,
  69.             final VaadinIcons icon) {
  70.         return CardInfoRowUtil.createInfoRow(caption, value, icon, null);
  71.     }

  72.     /**
  73.      * Creates a row displaying a caption and value, with optional icon and tooltip.
  74.      *
  75.      * @param caption the field caption
  76.      * @param value   the field value
  77.      * @param icon    a VaadinIcons icon for better visual cue
  78.      * @param tooltip optional tooltip to provide more info
  79.      * @return a HorizontalLayout representing the info row
  80.      */
  81.     public static final HorizontalLayout createInfoRow(final String caption, final String value, final VaadinIcons icon,
  82.             final String tooltip) {
  83.         final HorizontalLayout layout = new HorizontalLayout();
  84.         layout.setSpacing(true);
  85.         layout.addStyleName("metric-label");
  86.         layout.setWidthUndefined();

  87.         if (icon != null) {
  88.             final Label iconLabel = new Label(icon.getHtml(), ContentMode.HTML);
  89.             iconLabel.addStyleName("card-info-icon");
  90.             if (tooltip != null && !tooltip.isEmpty()) {
  91.                 iconLabel.setDescription(tooltip);
  92.             }
  93.             layout.addComponent(iconLabel);
  94.         }

  95.         final Label captionLabel = new Label(caption);
  96.         captionLabel.addStyleName("card-info-caption");
  97.         if (tooltip != null && !tooltip.isEmpty()) {
  98.             captionLabel.setDescription(tooltip);
  99.         }

  100.         final Label valueLabel = new Label(value != null ? value : "");
  101.         valueLabel.addStyleName("card-info-value");

  102.         layout.addComponents(captionLabel, valueLabel);
  103.         return layout;
  104.     }

  105.     /**
  106.      * Creates a section layout with a title and consistent styling.
  107.      *
  108.      * @param title the section title
  109.      * @return the vertical layout configured for the section
  110.      */
  111.     public static VerticalLayout createSectionLayout(final String title) {
  112.         final VerticalLayout layout = new VerticalLayout();
  113.         layout.setSpacing(true);
  114.         layout.setMargin(true);
  115.         layout.addStyleName("card-details-column");
  116.         layout.setWidth("100%");

  117.         final Label header = new Label(title);
  118.         header.addStyleName("card-section-title");
  119.         layout.addComponent(header);

  120.         // Add some vertical padding after the header
  121.         final Label padding = new Label();
  122.         padding.setHeight("10px");
  123.         layout.addComponent(padding);

  124.         return layout;
  125.     }

  126.     /**
  127.      * Creates the metric row.
  128.      *
  129.      * @param icon          the icon
  130.      * @param linkComponent the link component
  131.      * @param description   the description
  132.      * @param valueText     the value text
  133.      * @return the horizontal layout
  134.      */
  135.     public static final HorizontalLayout createMetricRow(final VaadinIcons icon,
  136.             final com.vaadin.ui.Component linkComponent, final String description, final String valueText) {
  137.         final HorizontalLayout layout = new HorizontalLayout();
  138.         layout.setSpacing(true);
  139.         layout.addStyleName("metric-label");
  140.         layout.setWidthUndefined();

  141.         final Label iconLabel = new Label(icon.getHtml(), ContentMode.HTML);
  142.         iconLabel.setDescription(description);

  143.         // Value displayed outside of the link
  144.         Label valueLabel = null;
  145.         if (valueText != null && !valueText.isEmpty()) {
  146.             valueLabel = new Label(valueText);
  147.             valueLabel.addStyleName("metric-value");
  148.         }

  149.         layout.addComponent(iconLabel);
  150.         layout.addComponent(linkComponent);
  151.         if (valueLabel != null) {
  152.             layout.addComponent(valueLabel);
  153.         }

  154.         return layout;
  155.     }

  156.     /**
  157.      * Creates the card header.
  158.      *
  159.      * @param cardContent the card content
  160.      * @param titleText   the title text
  161.      */
  162.     public static final void createCardHeader(final VerticalLayout cardContent, final String titleText) {
  163.         // Card Header
  164.         final HorizontalLayout headerLayout = new HorizontalLayout();
  165.         headerLayout.setSpacing(true);
  166.         headerLayout.setWidth("100%");
  167.         headerLayout.addStyleName("card-header-section");

  168.         final Label titleLabel = new Label(titleText, ContentMode.HTML);
  169.         titleLabel.addStyleName("card-title");
  170.         titleLabel.setWidthUndefined();
  171.         headerLayout.addComponent(titleLabel);

  172.         cardContent.addComponent(headerLayout);

  173.         // Divider line
  174.         final Label divider = new Label("<hr/>", ContentMode.HTML);
  175.         divider.addStyleName("card-divider");
  176.         divider.setWidth("100%");
  177.         cardContent.addComponent(divider);
  178.     }

  179.     /**
  180.      * Creates a standard stats container.
  181.      *
  182.      * @return the vertical layout configured for the stats container
  183.      */
  184.     public static final VerticalLayout createStatsContainer() {
  185.         final VerticalLayout layout = new VerticalLayout();
  186.         layout.setSpacing(false);
  187.         layout.addStyleName("card-stats-container");
  188.         layout.setWidth("100%");
  189.         return layout;
  190.     }

  191.     /**
  192.      * Creates the standard row.
  193.      *
  194.      * @return the horizontal layout
  195.      */
  196.     public static HorizontalLayout createStandardRow() {
  197.         final HorizontalLayout layout = new HorizontalLayout();
  198.         layout.setSpacing(true);
  199.         layout.setWidthUndefined();
  200.         return layout;
  201.     }

  202.     /**
  203.      * Creates the icon label.
  204.      *
  205.      * @param icon    the icon
  206.      * @param tooltip the tooltip
  207.      * @return the label
  208.      */
  209.     public static Label createIconLabel(final VaadinIcons icon, final String tooltip) {
  210.         final Label iconLabel = new Label(icon.getHtml(), ContentMode.HTML);
  211.         iconLabel.addStyleName(CARD_INFO_ICON);
  212.         if (tooltip != null) {
  213.             iconLabel.setDescription(tooltip);
  214.         }
  215.         return iconLabel;
  216.     }

  217. }