
org.ioc.commons.ui.impl.HasLoaderAdapter Maven / Gradle / Ivy
package org.ioc.commons.ui.impl;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.ioc.commons.ui.HasLoader;
import org.ioc.commons.ui.IsWidget;
public class HasLoaderAdapter implements HasLoader {
protected boolean loading;
@Override
public void setLoading(boolean loading) {
// Override me
this.loading = loading;
}
@Override
public boolean isLoading() {
return loading;
}
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 HasLoaderAdapter forField(String fieldName, IsWidget fieldOwner) {
Field field = new Field(fieldName, fieldOwner);
HasLoaderAdapter adapter = globalFields.get(field);
if (adapter == null) {
adapter = new HasLoaderAdapter();
globalFields.put(field, adapter);
}
return (HasLoaderAdapter) adapter;
}
/**
* Clean all the instantiated adapters for this owner using
* {@link HasLoaderAdapter#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 - 2025 Weber Informatics LLC | Privacy Policy