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.base;
017
018 import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
019 import com.github.gwtbootstrap.client.ui.constants.Constants;
020 import com.github.gwtbootstrap.client.ui.constants.Device;
021 import com.google.gwt.core.client.GWT;
022 import com.google.gwt.dom.client.Element;
023 import com.google.gwt.text.shared.Parser;
024 import com.google.gwt.text.shared.Renderer;
025
026 /**
027 * A ValueBoxBase extending for Bootstarp style.
028 *
029 * <pre>
030 * It is GWT's {@link com.google.gwt.user.client.ui.ValueBoxBase} extending for Bootstrap style.
031 * </pre>
032 * @since 2.0.4.0
033 *
034 * @author ohashi keisuke
035 * @see com.google.gwt.user.client.ui.ValueBoxBase
036 * @param <T> the value type
037 */
038 public class ValueBoxBase<T> extends com.google.gwt.user.client.ui.ValueBoxBase<T> implements HasPlaceholder, HasAlternateSize, IsSearchQuery, HasSize, HasId, IsResponsive , HasStyle{
039
040 /** placeholderHelper */
041 private PlaceholderHelper placeholderHelper = GWT.create(PlaceholderHelper.class);
042
043 /**
044 * Creates a value box that wraps the given browser element handle. This is
045 * only used by subclasses.
046 *
047 * @param elem
048 * the browser element to wrap
049 */
050 protected ValueBoxBase(Element elem,
051 Renderer<T> renderer,
052 Parser<T> parser) {
053 super(elem, renderer, parser);
054 }
055
056 /**
057 * {@inheritDoc}
058 */
059 @Override
060 public void setPlaceholder(String placeholder) {
061 placeholderHelper.setPlaceholer(getElement(), placeholder);
062 }
063
064 /**
065 * {@inheritDoc}
066 */
067 @Override
068 public String getPlaceholder() {
069 return placeholderHelper.getPlaceholder(getElement());
070 }
071
072 /**
073 * {@inheritDoc}
074 */
075 @Override
076 public void setSearchQuery(boolean searchQuery) {
077 SearchQueryStyleHelper.setSearchQuery(this, searchQuery);
078 }
079
080 /**
081 * {@inheritDoc}
082 */
083 @Override
084 public boolean isSearchQuery() {
085 return SearchQueryStyleHelper.isSearchQuery(this);
086 }
087
088 /**
089 * {@inheritDoc}
090 */
091 @Override
092 public void setAlternateSize(AlternateSize size) {
093 StyleHelper.changeStyle(this, size, AlternateSize.class);
094 }
095
096 /**
097 * {@inheritDoc}
098 */
099 @Override
100 public void setSize(int size) {
101 SizeHelper.setSize(this, size);
102 }
103
104 /**
105 * {@inheritDoc}
106 */
107 @Override
108 public String getId() {
109 return getElement().getId();
110 }
111
112 /**
113 * {@inheritDoc}
114 */
115 @Override
116 public void setId(String id) {
117 getElement().setId(id);
118 }
119
120 /**
121 * {@inheritDoc}
122 */
123 @Override
124 public void setEnabled(boolean enabled) {
125 super.setEnabled(enabled);
126 if (enabled) {
127 removeStyleName(Constants.DISABLED);
128 } else {
129 addStyleName(Constants.DISABLED);
130 }
131 }
132
133 /**
134 * {@inheritDoc}
135 */
136 @Override
137 public void setShowOn(Device device) {
138 ResponsiveHelper.setShowOn(this, device);
139 }
140
141 /**
142 * {@inheritDoc}
143 */
144 @Override
145 public void setHideOn(Device device) {
146 ResponsiveHelper.setHideOn(this, device);
147
148 }
149
150 /**
151 * {@inheritDoc}
152 */
153 @Override
154 public void setStyle(Style style) {
155 StyleHelper.setStyle(this, style);
156 }
157
158 /**
159 * {@inheritDoc}
160 */
161 @Override
162 public void addStyle(Style style) {
163 StyleHelper.addStyle(this, style);
164 }
165
166 /**
167 * {@inheritDoc}
168 */
169 @Override
170 public void removeStyle(Style style) {
171 StyleHelper.removeStyle(this, style);
172
173 }
174 }