001    /*
002     *  Copyright 2012 GWT-Bootstrap
003     *
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package com.github.gwtbootstrap.client.ui;
017    
018    import com.github.gwtbootstrap.client.ui.base.HoverBase;
019    import com.github.gwtbootstrap.client.ui.constants.Placement;
020    import com.github.gwtbootstrap.client.ui.constants.Trigger;
021    import com.github.gwtbootstrap.client.ui.constants.VisibilityChange;
022    import com.google.gwt.dom.client.Element;
023    import com.google.gwt.user.client.ui.Widget;
024    
025    //@formatter:off
026    /**
027     * Link with a small tooltip with additional information.
028     * <p>
029     * Technically it's an html {@code <a>} tag. The text of the popup will be the
030     * content of the anchor's <code>title</code> attribute. 
031     * 
032     * @since 2.0.4.0
033     * 
034     * @author Dominik Mayer
035     * 
036     * @see <a href="http://twitter.github.com/bootstrap/javascript.html#tooltips">Bootstrap documentation</a>
037     * @see Popover
038     */
039    //@formatter:on
040    public class Tooltip extends HoverBase {
041    
042            private String tooltip;
043    
044            /**
045             * Creates an empty link without text and tooltip text.
046             */
047            public Tooltip() {
048                    super();
049            }
050    
051            /**
052             * Creates a link with the
053             * 
054             * @param tooltip get
055             */
056            public Tooltip(String tooltip) {
057                    this();
058                    setText(tooltip);
059            }
060    
061            /**
062             * Sets the text that should appear in the tooltip.
063             * 
064             * @param tooltop
065             *            the text
066             */
067            public void setText(String tooltop) {
068                    this.tooltip = tooltop;
069            }
070            
071            public String getText() {
072                    return this.tooltip;
073            }
074    
075            /**
076             * {@inheritDoc}
077             */
078            @Override
079            public void reconfigure() {
080                    
081                    removeDataIfExists();
082                    
083                    setDataAttribute(getWidget().getElement(), "original-title", tooltip);
084                    
085                    configure(getWidget().getElement(), getAnimation(), getPlacement().get(),
086                                    getTrigger().get(), getShowDelay(), getHideDelay());
087            }
088    
089            /**
090             * {@inheritDoc}
091             */
092            @Override
093            protected void changeVisibility(VisibilityChange visibilityChange) {
094                    changeVisibility(getWidget().getElement(), visibilityChange.get());
095            }
096            
097            /**
098             * 
099             * @param e
100             * @param animated
101             * @param placement
102             * @param trigger
103             * @param showDelay
104             * @param hideDelay
105             */
106            public static void configure(Widget e,boolean animated,Placement placement,Trigger trigger,int showDelay,int hideDelay) {
107                    configure(e.getElement(), animated, placement.get(),trigger.get(), showDelay, hideDelay);
108            }
109    
110            private static native void configure(Element element, boolean animated,
111                            String placement, String trigger, int showDelay, int hideDelay) /*-{
112                    $wnd.jQuery(element).tooltip({
113                            animation : animated,
114                            placement : placement,
115                            trigger : trigger,
116                            delay : {
117                                    show : showDelay,
118                                    hide : hideDelay
119                            }
120                    });
121            }-*/;
122    
123            public static native void changeVisibility(Element e, String visibility) /*-{
124                    $wnd.jQuery(e).tooltip(visibility);
125            }-*/;
126    
127            /**
128             * {@inheritDoc}
129             */
130            @Override
131            protected String getDataName() {
132                    return "tooltip";
133            }
134    
135    }