001package org.gwtbootstrap3.client.ui; 002 003/* 004 * #%L 005 * GwtBootstrap3 006 * %% 007 * Copyright (C) 2013 - 2014 GwtBootstrap3 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import org.gwtbootstrap3.client.ui.base.HasResponsiveness; 024import org.gwtbootstrap3.client.ui.constants.IconPosition; 025import org.gwtbootstrap3.client.ui.constants.IconSize; 026import org.gwtbootstrap3.client.ui.constants.IconType; 027import org.gwtbootstrap3.client.ui.constants.Styles; 028import org.gwtbootstrap3.client.ui.html.UnorderedList; 029 030import com.google.gwt.event.dom.client.ClickHandler; 031import com.google.web.bindery.event.shared.HandlerRegistration; 032 033/** 034 * Support for Bootstrap pager (http://getbootstrap.com/components/#pagination-pager) 035 * 036 * @author Joshua Godi 037 */ 038public class Pager extends UnorderedList implements HasResponsiveness { 039 private static final String DEFAULT_PREVIOUS = "Previous"; 040 private static final String DEFAULT_NEXT = "Next"; 041 042 private final AnchorListItem previous; 043 private final AnchorListItem next; 044 045 public Pager() { 046 setStyleName(Styles.PAGER); 047 048 previous = new AnchorListItem(DEFAULT_PREVIOUS); 049 next = new AnchorListItem(DEFAULT_NEXT); 050 051 add(previous); 052 add(next); 053 } 054 055 public void setAlignToSides(final boolean alignToSides) { 056 if (alignToSides) { 057 previous.setStyleName(Styles.PREVIOUS); 058 next.setStyleName(Styles.NEXT); 059 } else { 060 previous.removeStyleName(Styles.PREVIOUS); 061 next.removeStyleName(Styles.NEXT); 062 } 063 } 064 065 /** 066 * Adds a click handler to the previous button 067 * 068 * @param clickHandler click handler 069 * @return handler registration of the handler 070 */ 071 public HandlerRegistration addPreviousClickHandler(final ClickHandler clickHandler) { 072 return previous.addClickHandler(clickHandler); 073 } 074 075 /** 076 * Adds a click handler to the next button 077 * 078 * @param clickHandler click handler 079 * @return handler registration of the handler 080 */ 081 public HandlerRegistration addNextClickHandler(final ClickHandler clickHandler) { 082 return next.addClickHandler(clickHandler); 083 } 084 085 public void setPreviousText(final String text) { 086 previous.setText(text); 087 } 088 089 public void setPreviousIcon(final IconType icon) { 090 previous.setIcon(icon); 091 } 092 093 public void setPreviousIconSize(final IconSize iconSize) { 094 previous.setIconSize(iconSize); 095 } 096 097 public void setPreviousEnabled(final boolean enabled) { 098 previous.setEnabled(enabled); 099 } 100 101 public void setPreviousVisible(final boolean visible) { 102 previous.setVisible(visible); 103 } 104 105 public void setNextText(final String text) { 106 next.setText(text); 107 } 108 109 public void setNextIcon(final IconType icon) { 110 next.setIcon(icon); 111 next.setIconPosition(IconPosition.RIGHT); 112 } 113 114 public void setNextIconSize(final IconSize iconSize) { 115 next.setIconSize(iconSize); 116 } 117 118 public void setNextEnabled(final boolean enabled) { 119 next.setEnabled(enabled); 120 } 121 122 public void setNextVisible(final boolean visible) { 123 next.setVisible(visible); 124 } 125}