RuleViolationPageItemRendererClickListener.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.pageclicklistener;

  20. import java.util.Set;

  21. import com.hack23.cia.model.internal.application.data.rules.impl.ResourceType;
  22. import com.hack23.cia.model.internal.application.data.rules.impl.RuleViolation;
  23. import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserViews;
  24. import com.vaadin.event.selection.SelectionEvent;
  25. import com.vaadin.ui.UI;
  26. import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent;

  27. /**
  28.  * The Class RuleViolationPageItemRendererClickListener.
  29.  *
  30.  * @see RuleViolationPageItemRendererClickEvent
  31.  */

  32. public final class RuleViolationPageItemRendererClickListener implements PageItemRendererClickListener<RuleViolation> {

  33.     /** The Constant PAGE_SEPARATOR. */
  34.     private static final Character PAGE_SEPARATOR = '/';

  35.     /** The Constant serialVersionUID. */
  36.     private static final long serialVersionUID = 1L;

  37.     /**
  38.      * Instantiates a new rule violation page item renderer click listener.
  39.      */
  40.     public RuleViolationPageItemRendererClickListener() {
  41.         super();
  42.     }

  43.     /**
  44.      * Navigate to page.
  45.      *
  46.      * @param violation
  47.      *            the violation
  48.      */
  49.     private static void navigateToPage(final RuleViolation violation) {
  50.         if (violation.getResourceType() == ResourceType.PARTY) {
  51.             UI.getCurrent().getNavigator().navigateTo(UserViews.PARTY_VIEW_NAME + PAGE_SEPARATOR + violation.getReferenceId());
  52.         } else {
  53.             UI.getCurrent().getNavigator().navigateTo(UserViews.POLITICIAN_VIEW_NAME + PAGE_SEPARATOR + violation.getReferenceId());
  54.         }
  55.     }

  56.     @Override
  57.     public void click(final RendererClickEvent<RuleViolation> event) {
  58.         navigateToPage(event.getItem());

  59.     }


  60.     @Override
  61.     public void selectionChange(final SelectionEvent<RuleViolation> event) {
  62.         final Set<RuleViolation> added =event.getAllSelectedItems();

  63.         if (!added.isEmpty()) {
  64.             navigateToPage(added.iterator().next());
  65.         }
  66.     }
  67. }