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

org.ioc.commons.ui.impl.HasTextAdapter Maven / Gradle / Ivy

Go to download

Library which contains some extension classes for the library IOC-Commons. It provides some interface definitions and some tool classes which are non-dependent from the used technology; i.e. the classes and interfaces from this library do not depend on the choosen ioc-commons-implementation library.

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

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

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

public class HasTextAdapter implements HasText {

	protected String value;

	public HasTextAdapter() {
		// Nothing
	}

	public HasTextAdapter(String initialValue) {
		this.value = initialValue;
	}

	@Override
	public void setText(String value) {
		// Override me
		this.value = value;
	}

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

	private static final Map globalFields = new HashMap();

	/**
	 * It creates a new adapter instance for a field owned by a widget and keep
	 * it in memory for reusing in the next calls. The widget will be
	 * responsible for cleaning them from memory when it is not going to use
	 * them anymore by calling cleaningAdapter() method.
	 * 
	 * @param fieldName
	 *            Unique name of the field on the owner
	 * @param fieldOwner
	 *            The owner of the field
	 * @return An unique instance for this field in this field owner.
	 */
	public static  HasTextAdapter forField(String fieldName, IsWidget fieldOwner) {
		Field field = new Field(fieldName, fieldOwner);
		HasTextAdapter adapter = globalFields.get(field);
		if (adapter == null) {
			adapter = new HasTextAdapter();
			globalFields.put(field, adapter);
		}
		return (HasTextAdapter) adapter;
	}

	/**
	 * Clean all the instantiated adapters for this owner using
	 * {@link HasTextAdapter#forField(String, IsWidget)} method.
	 * 
	 * @param fromOwner
	 *            Owner of the fields
	 */
	public static void cleanAdapters(IsWidget fromOwner) {
		cleanAdapters((Object) fromOwner);
	}

	public static void cleanAdapters(Object fromField) {
		for (Iterator it = globalFields.keySet().iterator(); it.hasNext();) {
			Field field = it.next();
			if (fromField.equals(field.getFieldOwner())) {
				it.remove();
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy