AbstractPageItemRendererClickListener.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.web.impl.ui.application.views.common.viewnames.PageMode;
  22. import com.vaadin.event.selection.SelectionEvent;
  23. import com.vaadin.ui.UI;
  24. import com.vaadin.ui.renderers.ClickableRenderer.RendererClickEvent;

  25. /**
  26.  * The class AbstractPageItemRendererClickListener.
  27.  *
  28.  * @param <T>            the generic type
  29.  * @see AbstractPageItemRendererClickEvent
  30.  */
  31. public abstract class AbstractPageItemRendererClickListener<T> implements PageItemRendererClickListener<T> {

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

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

  36.     /** The page. */
  37.     private final String page;

  38.     /**
  39.      * Instantiates a new abstract page item renderer click listener.
  40.      *
  41.      * @param page
  42.      *            the page
  43.      */
  44.     public AbstractPageItemRendererClickListener(final String page) {
  45.         this.page = page;
  46.     }

  47.     @Override
  48.     public final void click(final RendererClickEvent<T> event) {
  49.         UI.getCurrent().getNavigator().navigateTo(page + PAGE_SEPARATOR + PageMode.OVERVIEW.toString() + PAGE_SEPARATOR +  getPageId(event.getItem()));
  50.     }


  51.     /**
  52.      * Gets the page id.
  53.      *
  54.      * @param t
  55.      *            the t
  56.      * @return the page id
  57.      */
  58.     protected abstract String getPageId(T t);


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

  62.         if (!added.isEmpty()) {
  63.             UI.getCurrent().getNavigator().navigateTo(page + PAGE_SEPARATOR + PageMode.OVERVIEW.toString() + PAGE_SEPARATOR + getPageId(added.iterator().next()));

  64.         }
  65.     }

  66. }