All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ioc.commons.impl.gwt.client.ui.HasTextWrapper Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package org.ioc.commons.impl.gwt.client.ui;

import org.ioc.commons.ui.HasStorage;
import org.ioc.commons.ui.HasText;

import com.google.gwt.dom.client.Element;


public class HasTextWrapper implements HasText {

	private com.google.gwt.user.client.ui.HasText wrapped;

	private HasTextWrapper(com.google.gwt.user.client.ui.HasText wrapped) {
		this.wrapped = wrapped;
	}

	@Override
	public void setText(String value) {
		this.wrapped.setText(value);
	}

	@Override
	public String getText() {
		return this.wrapped.getText();
	}

	public static HasText from(com.google.gwt.user.client.ui.HasText gwtHasText) {
		return new HasTextWrapper(gwtHasText);
	}

	public static HasText from(com.google.gwt.user.client.ui.HasText gwtHasValue, HasStorage cache) {
		Object cached = cache.retrieve(gwtHasValue);
		HasText hasValue = (cached instanceof HasText ? (HasText) cached : null);
		if (hasValue == null) {
			hasValue = new HasTextWrapper(gwtHasValue);
			cache.store(gwtHasValue, hasValue);
		}
		return hasValue;
	}
	
	public static HasText from(final Element elm) {
		return from(new com.google.gwt.user.client.ui.HasText(){

			@Override
			public String getText() {
				return elm.getInnerText();
			}

			@Override
			public void setText(String text) {
				elm.setInnerText(text);
			}
			
		});
	}

	/**
	 * Helpful method for setting a text property on several components at the
	 * same time.
	 * 
	 * @param text
	 * @param gwtHasTextArray
	 */
	public static void setText(String text, com.google.gwt.user.client.ui.HasText... gwtHasTextArray) {
		if (gwtHasTextArray != null) {
			for (com.google.gwt.user.client.ui.HasText gwtHasText : gwtHasTextArray) {
				gwtHasText.setText(text);
			}
		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy