001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.acacia.client.widgets; 029 030import org.opencms.acacia.client.css.I_CmsWidgetsLayoutBundle; 031import org.opencms.gwt.client.util.CmsDomUtil; 032 033import java.text.ParseException; 034 035import com.google.gwt.dom.client.Element; 036import com.google.gwt.event.dom.client.FocusEvent; 037import com.google.gwt.event.dom.client.FocusHandler; 038import com.google.gwt.event.logical.shared.ValueChangeEvent; 039import com.google.gwt.event.logical.shared.ValueChangeHandler; 040import com.google.gwt.event.shared.HandlerRegistration; 041import com.google.gwt.user.client.ui.Composite; 042import com.google.gwt.user.client.ui.PasswordTextBox; 043import com.google.gwt.user.client.ui.SimplePanel; 044 045/** 046 * Provides a standard HTML form password widget, for use on a widget dialog.<p> 047 * 048 * */ 049public class CmsPasswordWidget extends Composite implements I_CmsEditWidget { 050 051 /**The main panel of this widget. */ 052 SimplePanel m_mainPanel = new SimplePanel(); 053 054 /** Value of the activation. */ 055 private boolean m_active = true; 056 057 /** The Password input field. */ 058 private PasswordTextBox m_passwordTextBox = new PasswordTextBox(); 059 060 /** 061 * Constructs an CmsComboWidget.<p> 062 */ 063 public CmsPasswordWidget() { 064 065 // All composites must call initWidget() in their constructors. 066 m_mainPanel.add(m_passwordTextBox); 067 initWidget(m_mainPanel); 068 m_mainPanel.setStyleName(I_CmsWidgetsLayoutBundle.INSTANCE.widgetCss().passwordTextBox()); 069 m_passwordTextBox.addValueChangeHandler(new ValueChangeHandler<String>() { 070 071 public void onValueChange(ValueChangeEvent<String> event) { 072 073 fireChangeEvent(); 074 075 } 076 077 }); 078 m_passwordTextBox.addFocusHandler(new FocusHandler() { 079 080 public void onFocus(FocusEvent event) { 081 082 CmsDomUtil.fireFocusEvent(CmsPasswordWidget.this); 083 } 084 }); 085 } 086 087 /** 088 * @see com.google.gwt.event.dom.client.HasFocusHandlers#addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) 089 */ 090 public HandlerRegistration addFocusHandler(FocusHandler handler) { 091 092 return addDomHandler(handler, FocusEvent.getType()); 093 } 094 095 /** 096 * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) 097 */ 098 public HandlerRegistration addValueChangeHandler(ValueChangeHandler<String> handler) { 099 100 return addHandler(handler, ValueChangeEvent.getType()); 101 } 102 103 /** 104 * Represents a value change event.<p> 105 * 106 */ 107 public void fireChangeEvent() { 108 109 ValueChangeEvent.fire(this, m_passwordTextBox.getValue()); 110 } 111 112 /** 113 * @see com.google.gwt.user.client.ui.HasValue#getValue() 114 */ 115 public String getValue() { 116 117 try { 118 return m_passwordTextBox.getValueOrThrow(); 119 } catch (ParseException e) { 120 e.printStackTrace(); 121 } 122 return null; 123 } 124 125 /** 126 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#isActive() 127 */ 128 public boolean isActive() { 129 130 return m_active; 131 } 132 133 /** 134 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#onAttachWidget() 135 */ 136 public void onAttachWidget() { 137 138 super.onAttach(); 139 } 140 141 /** 142 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#owns(com.google.gwt.dom.client.Element) 143 */ 144 public boolean owns(Element element) { 145 146 // TODO implement this in case we want the delete behavior for optional fields 147 return false; 148 149 } 150 151 /** 152 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setActive(boolean) 153 */ 154 public void setActive(boolean active) { 155 156 if (m_active == active) { 157 return; 158 } 159 160 m_active = active; 161 if (m_active) { 162 getElement().setAttribute("contentEditable", "true"); 163 getElement().removeClassName(org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive()); 164 getElement().focus(); 165 } else { 166 getElement().setAttribute("contentEditable", "false"); 167 getElement().addClassName(org.opencms.acacia.client.css.I_CmsLayoutBundle.INSTANCE.form().inActive()); 168 } 169 if (active) { 170 fireChangeEvent(); 171 } 172 173 } 174 175 /** 176 * @see org.opencms.acacia.client.widgets.I_CmsEditWidget#setName(java.lang.String) 177 */ 178 public void setName(String name) { 179 180 // no input field so nothing to do 181 182 } 183 184 /** 185 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object) 186 */ 187 public void setValue(String value) { 188 189 setValue(value, false); 190 191 } 192 193 /** 194 * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object, boolean) 195 */ 196 public void setValue(String value, boolean fireEvents) { 197 198 m_passwordTextBox.setValue(value, fireEvents); 199 } 200 201}