CommitteeOverviewPageModContentFactoryImpl.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.committee.pagemode;

  20. import java.util.Arrays;

  21. import org.apache.commons.lang3.StringUtils;
  22. import org.springframework.security.access.annotation.Secured;
  23. import org.springframework.stereotype.Component;

  24. import com.hack23.cia.model.internal.application.data.committee.impl.ViewRiksdagenCommittee;
  25. import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
  26. import com.hack23.cia.service.api.DataContainer;
  27. import com.hack23.cia.web.impl.ui.application.action.ViewAction;
  28. import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
  29. import com.hack23.cia.web.impl.ui.application.views.common.sizing.ContentRatio;
  30. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.PageMode;
  31. import com.vaadin.data.util.BeanItem;
  32. import com.vaadin.ui.Layout;
  33. import com.vaadin.ui.Link;
  34. import com.vaadin.ui.MenuBar;
  35. import com.vaadin.ui.Panel;
  36. import com.vaadin.ui.VerticalLayout;

  37. /**
  38.  * The Class CommitteeOverviewPageModContentFactoryImpl.
  39.  */
  40. @Component
  41. public final class CommitteeOverviewPageModContentFactoryImpl extends AbstractCommitteePageModContentFactoryImpl {

  42.     /** The Constant COMMITTEE. */
  43.     private static final String COMMITTEE = "Committee:";

  44.     /** The Constant OVERVIEW. */
  45.     private static final String OVERVIEW = "overview";

  46.     /**
  47.      * Instantiates a new committee overview page mod content factory impl.
  48.      */
  49.     public CommitteeOverviewPageModContentFactoryImpl() {
  50.         super();
  51.     }

  52.     @Override
  53.     public boolean matches(final String page, final String parameters) {
  54.         final String pageId = getPageId(parameters);
  55.         return NAME.equals(page) && (StringUtils.isEmpty(parameters) || parameters.equals(pageId)
  56.                 || parameters.contains(PageMode.OVERVIEW.toString()));
  57.     }

  58.     @Secured({ "ROLE_ANONYMOUS", "ROLE_USER", "ROLE_ADMIN" })
  59.     @Override
  60.     public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
  61.         final VerticalLayout panelContent = createPanelContent();

  62.         final String pageId = getPageId(parameters);


  63.         final DataContainer<ViewRiksdagenCommittee, String> dataContainer = getApplicationManager()
  64.                 .getDataContainer(ViewRiksdagenCommittee.class);

  65.         final ViewRiksdagenCommittee viewRiksdagenCommittee = dataContainer.load(pageId);

  66.         if (viewRiksdagenCommittee != null) {

  67.             getCommitteeMenuItemFactory().createCommitteeeMenuBar(menuBar, pageId);

  68.                 LabelFactory.createHeader2Label(panelContent,OVERVIEW);

  69.                 final VerticalLayout overviewLayout = new VerticalLayout();
  70.                 overviewLayout.setSizeFull();

  71.                 panelContent.addComponent(overviewLayout);
  72.                 panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

  73.                 getCommitteeMenuItemFactory().createOverviewPage(overviewLayout, pageId);


  74.                 final Link addCommitteePageLink = getPageLinkFactory().addCommitteePageLink(viewRiksdagenCommittee);
  75.                 panelContent.addComponent(addCommitteePageLink);

  76.                 getFormFactory().addFormPanelTextFields(panelContent, new BeanItem<>(viewRiksdagenCommittee),
  77.                         ViewRiksdagenCommittee.class,
  78.                         Arrays.asList(new String[] { "embeddedId.detail", "active", "firstAssignmentDate",
  79.                                 "lastAssignmentDate", "totalAssignments", "totalDaysServed",
  80.                                 "currentMemberSize" }));


  81.                 panelContent.setExpandRatio(addCommitteePageLink,ContentRatio.SMALL);

  82.                 panel.setCaption(COMMITTEE + viewRiksdagenCommittee.getEmbeddedId().getDetail());
  83.                 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_COMMITTEE_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
  84.         }
  85.         return panelContent;

  86.     }


  87. }