001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 - 2017 GwtMaterialDesign 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package gwt.material.design.client.base; 021 022import com.google.gwt.dom.client.Element; 023import com.google.gwt.editor.client.IsEditor; 024import com.google.gwt.editor.client.LeafValueEditor; 025import com.google.gwt.editor.ui.client.adapters.HasTextEditor; 026import com.google.gwt.safehtml.shared.SafeHtmlUtils; 027import com.google.gwt.user.client.ui.HasHTML; 028 029/** 030 * @author Ben Dol 031 */ 032public abstract class AbstractTextWidget extends AbstractValueWidget<String> implements HasId, HasHTML, 033 IsEditor<LeafValueEditor<String>> { 034 035 private LeafValueEditor<String> editor; 036 037 protected AbstractTextWidget(Element element) { 038 super(element); 039 } 040 041 @Override 042 public String getValue() { 043 return getElement().getInnerText(); 044 } 045 046 @Override 047 public void setValue(String value, boolean fireEvents) { 048 getElement().setInnerText(value); 049 super.setValue(value, fireEvents); 050 } 051 052 @Override 053 public void setText(final String text) { 054 setValue(text); 055 } 056 057 @Override 058 public String getText() { 059 return getValue(); 060 } 061 062 @Override 063 public String getHTML() { 064 return getElement().getInnerHTML(); 065 } 066 067 @Override 068 public void setHTML(final String html) { 069 getElement().setInnerSafeHtml(SafeHtmlUtils.fromString(html)); 070 } 071 072 @Override 073 public LeafValueEditor<String> asEditor() { 074 if (editor == null) { 075 editor = HasTextEditor.of(this); 076 } 077 return editor; 078 } 079}