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 */
016package com.github.gwtbootstrap.client.ui;
017
018import com.github.gwtbootstrap.client.ui.base.HoverBase;
019import com.github.gwtbootstrap.client.ui.constants.Placement;
020import com.github.gwtbootstrap.client.ui.constants.VisibilityChange;
021import com.google.gwt.dom.client.Element;
022
023//@formatter:off
024/**
025 * Popover that 
026 * 
027 * @since 2.0.4.0
028 * 
029 * @author Dominik Mayer
030 * @author ohashi keisuke
031 * 
032 * @see <a href="http://twitter.github.com/bootstrap/javascript.html#popovers">Bootstrap documentation</a>
033 * @see Tooltip
034 */
035//@formatter:on
036public class Popover extends HoverBase {
037
038        private String content;
039        private String heading;
040
041        /**
042         * Creates an empty Popover.
043         */
044        public Popover() {
045                super();
046                placement = Placement.RIGHT;
047        }
048
049        /**
050         * {@inheritDoc}
051         */
052        public void setText(String content) {
053                this.content = content;
054        }
055
056        /**
057         * {@inheritDoc}
058         */
059        public String getText() {
060                return this.content;
061        }
062
063        public void setHeading(String heading) {
064                this.heading = heading;
065        }
066        
067        public String getHeading() {
068                return this.heading;
069        }
070
071        /**
072         * {@inheritDoc}
073         */
074        @Override
075        public void reconfigure() {
076                
077                removeDataIfExists();
078                
079                setDataAttribute(getWidget().getElement(), "original-title", heading);
080                
081                setDataAttribute(getWidget().getElement(), "content", content);
082                
083                configure(getWidget().getElement(), getAnimation(), getPlacement().get(),
084                                getTrigger().get(), getShowDelay(), getHideDelay());
085        }
086
087        /**
088         * {@inheritDoc}
089         */
090        @Override
091        protected void changeVisibility(VisibilityChange visibilityChange) {
092                changeVisibility(getWidget().getElement(), visibilityChange.get());
093        }
094
095        private native void configure(Element element, boolean animated,
096                        String placement, String trigger, int showDelay, int hideDelay) /*-{
097                $wnd.jQuery(element).popover({
098                        animation : animated,
099                        placement : placement,
100                        trigger : trigger,
101                        delay : {
102                                show : showDelay,
103                                hide : hideDelay
104                        }
105                });
106        }-*/;
107
108        private native void changeVisibility(Element e, String visibility) /*-{
109                $wnd.jQuery(e).popover(visibility);
110        }-*/;
111
112        @Override
113        protected String getDataName() {
114                return "popover";
115        }
116}