001package org.gwtbootstrap3.client.ui; 002 003/* 004 * #%L 005 * GwtBootstrap3 006 * %% 007 * Copyright (C) 2015 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.constants.IconType; 024import org.gwtbootstrap3.client.ui.constants.Placement; 025 026import com.google.gwt.dom.client.Document; 027import com.google.gwt.dom.client.Style.Unit; 028import com.google.gwt.event.dom.client.DomEvent; 029 030/** 031 * Tooltip help block. Tooltips can be styled by specifiying the tooltip-danger class in your css. 032 * 033 * @author Steven Jardine 034 */ 035public class TooltipHelpBlock extends Tooltip { 036 037 private static final String TOOLTIP_DANGER_CLASS = "tooltip-danger"; 038 039 /** 040 * Constructor. 041 */ 042 public TooltipHelpBlock() { 043 super(); 044 setPlacement(Placement.RIGHT); 045 addTooltipClassName(TOOLTIP_DANGER_CLASS); 046 // Create the help block. 047 InlineHelpBlock helpBlock = new InlineHelpBlock() { 048 049 @Override 050 public String getHTML() { 051 return TooltipHelpBlock.this.getTitle(); 052 } 053 054 @Override 055 public String getText() { 056 return TooltipHelpBlock.this.getTitle(); 057 } 058 059 @Override 060 public void setHTML(final String html) { 061 setText(html); 062 TooltipHelpBlock.this.setIsHtml(true); 063 } 064 065 @Override 066 public void setText(final String value) { 067 String oldValue = TooltipHelpBlock.this.getTitle(); 068 TooltipHelpBlock.this.setIsHtml(false); 069 TooltipHelpBlock.this.setTitle(value); 070 if (oldValue != null && !oldValue.equals(value)) { 071 DomEvent.fireNativeEvent(Document.get().createChangeEvent(), this); 072 } 073 } 074 }; 075 helpBlock.getElement().getStyle().setPaddingLeft(0, Unit.PX); 076 helpBlock.setIconType(IconType.EXCLAMATION_TRIANGLE); 077 setWidget(helpBlock); 078 } 079 080 /** 081 * Gets the icon type. 082 * 083 * @return the icon type 084 */ 085 public IconType getIconType() { 086 return ((HelpBlock) getWidget()).getIconType(); 087 } 088 089 /** 090 * Gets the text. 091 * 092 * @return the text 093 */ 094 public String getText() { 095 return getTitle(); 096 } 097 098 /** 099 * Sets the icon type. 100 * 101 * @param iconType the new icon type 102 */ 103 public void setIconType(final IconType iconType) { 104 ((HelpBlock) getWidget()).setIconType(iconType); 105 } 106 107}