001package com.github.gwtbootstrap.client.ui;
002
003import com.github.gwtbootstrap.client.ui.constants.IconSize;
004import com.github.gwtbootstrap.client.ui.constants.IconType;
005import com.google.gwt.cell.client.AbstractCell;
006import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
007
008/**
009 * 
010 * <h3>Example</h3>
011 * <p>
012 * <pre>
013 * {@code  
014 * final IconCell iCell = new IconCell(IconType.INFO_SIGN, IconSize.LARGE);
015 *
016 * Column<OneObject, Void> iconColumn = new Column<OneObject, Void>(iCell) {
017 *      
018 *      public Void getValue(OneObject object) {
019 *              if (object.getOneValue() > 0) {
020 *                      iCell.setIconType(IconType.PLUS_SIGN);
021 *                      iCell.setTooltip("High");
022 *              }
023 *              if (object.getOneValue() < 0) {
024 *                      iCell.setIconType(IconType.MINUS_SIGN);
025 *                      iCell.setTooltip("Low");
026 *              }
027 *              return null;
028 *      }
029 * };
030 * }
031 * </pre>
032 * </p>
033 */
034public class IconCell extends AbstractCell<Void> {
035        
036        private IconType iconType;
037        private IconSize iconSize;
038        private String tooltip;
039        
040        /**
041         * Construct a new {@link IconCell} with the specified icon type
042         * 
043         * @param iconType
044         */
045        public IconCell(IconType iconType) {
046                this(iconType, IconSize.DEFAULT);
047        }
048        
049        /**
050         * Construct a new {@link IconCell} with the specified icon type and icon size
051         * 
052         * @param iconType
053         * @param iconSize
054         */
055        public IconCell(IconType iconType, IconSize iconSize) {
056                this.iconType = iconType;
057                this.iconSize = iconSize;
058        }
059        
060        @Override
061        public void render(Context context, Void value, SafeHtmlBuilder sb) {
062                sb.appendHtmlConstant("<i" + (tooltip == null ? "" : " title=\"" + tooltip + "\"") + " class=\"" + iconType.get() + " " + iconSize.get() + "\"></i>");
063        }
064        
065        public IconType getIconType() {
066                return iconType;
067        }
068
069        public void setIconType(IconType iconType) {
070                this.iconType = iconType;
071        }
072
073        public IconSize getIconSize() {
074                return iconSize;
075        }
076
077        public void setIconSize(IconSize iconSize) {
078                this.iconSize = iconSize;
079        }
080        
081        public String getTooltip() {
082                return tooltip;
083        }
084
085        public void setTooltip(String tooltip) {
086                this.tooltip = tooltip;
087        }
088
089}