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.google.gwt.dom.client.Document;
019 import com.google.gwt.dom.client.Element;
020 import com.google.gwt.dom.client.InputElement;
021 import com.google.gwt.user.client.ui.RootPanel;
022 import com.google.gwt.user.client.ui.Widget;
023
024 /**
025 * A PasswordTextBox for Bootstrap form.
026 *
027 * @since 2.0.4.0
028 *
029 * @author ohashi keisuke
030 *
031 */
032 public class PasswordTextBox extends TextBox {
033
034 /**
035 * Creates a PasswordTextBox widget that wraps an existing <input
036 * type='password'> element.
037 *
038 * This element must already be attached to the document. If the element is
039 * removed from the document, you must call
040 * {@link RootPanel#detachNow(Widget)}.
041 *
042 * @param element
043 * the element to be wrapped
044 */
045 public static PasswordTextBox wrap(Element element) {
046 // Assert that the element is attached.
047 assert Document.get().getBody().isOrHasChild(element);
048
049 PasswordTextBox textBox = new PasswordTextBox(element);
050
051 // Mark it attached and remember it for cleanup.
052 textBox.onAttach();
053 RootPanel.detachOnWindowClose(textBox);
054
055 return textBox;
056 }
057
058 /**
059 * Creates an empty password text box.
060 */
061 public PasswordTextBox() {
062 super(Document.get().createPasswordInputElement(), "gwt-PasswordTextBox");
063 }
064
065 /**
066 * This constructor may be used by subclasses to explicitly use an existing
067 * element. This element must be an <input> element whose type is
068 * 'password'.
069 *
070 * @param element
071 * the element to be used
072 */
073 protected PasswordTextBox(Element element) {
074 super(element, null);
075 assert InputElement.as(element).getType().equalsIgnoreCase("password");
076 }
077 }