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.base;
017
018import com.github.gwtbootstrap.client.ui.constants.Constants;
019import com.google.gwt.dom.client.Element;
020import com.google.gwt.user.client.ui.Widget;
021
022
023/**
024 * The hepper class for {@link IsSearchQuery}.
025 * 
026 * @since 2.0.4.0
027 * @author ohashi keisuke
028 */
029public class SearchQueryStyleHelper {
030
031        /**
032         * Set search-query style to the element.
033         * @param widget applied style widget
034         * @param searchQuery true:add search-query css-class/false:remove search-query css-class
035         */
036        public static void setSearchQuery(Widget widget , boolean searchQuery) {
037                setSearchQuery(widget.getElement(), searchQuery);
038        }
039        
040        /**
041         * is the element search-query style?
042         * @param widget target widget
043         * @return true:has search-query css-class/false:has no search-query cass-class.
044         */
045        public static boolean isSearchQuery(Widget widget) {
046                return isSearchQuery(widget.getElement());
047        }
048
049        /**
050         * Set search-query style to the element.
051         * @param elem the applied style element
052         * @param searchQuery true:add search-query css-class/false:remove search-query css-class
053         */
054        public static void setSearchQuery(Element elem, boolean searchQuery) {
055                if(isSearchQuery(elem)) {
056                        elem.removeClassName(Constants.SEARCH_QUERY);
057                }
058                
059                if(searchQuery) {
060                        elem.addClassName(Constants.SEARCH_QUERY);
061                }
062        }
063        
064        /**
065         * is the element search-query style?
066         * @param elem target element.
067         * @return true:has search-query css-class/false:has no search-query cass-class.
068         */
069        public static boolean isSearchQuery(Element elem) {
070                return elem.getClassName().contains(Constants.SEARCH_QUERY);
071        }
072
073}