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

org.ioc.commons.flowcontrol.operationmanager.impl.HasLoaderOperationHandler 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.flowcontrol.operationmanager.impl;

import org.ioc.commons.flowcontrol.operationmanager.IsOperation;
import org.ioc.commons.flowcontrol.operationmanager.OperationHandler;
import org.ioc.commons.ui.HasLoader;
import org.ioc.commons.utils.FormatterLogger;

/**
 * It wraps an operation handler from some HasLoaders.
 * 
 * Instanciated from {@link OperationHandlerFactory}
 * 
 * @author Jesús Lunar Pérez
 * 
 * @param 
 *            Operation type
 */
public class HasLoaderOperationHandler & IsOperation> implements OperationHandler {

	private static final FormatterLogger logger = FormatterLogger.getLogger(HasLoaderOperationHandler.class);

	private HasLoader[] loaders;
	private boolean logWhenNull;

	HasLoaderOperationHandler(boolean logWhenNull, HasLoader... loaders) {
		this.loaders = loaders;
		this.logWhenNull = logWhenNull;
	}

	@Override
	public void onOperationBeginning(Object sender, O operation) {
		if (this.loaders != null) {
			for (HasLoader loader : loaders) {
				if (loader != null) {
					loader.setLoading(true);
				} else if (logWhenNull) {
					logger.warn("Ignoring null loader component assigned");
				}
			}
		}
	}

	@Override
	public void onOperationFinished(Object sender, O operation, boolean success) {
		if (this.loaders != null) {
			for (HasLoader loader : loaders) {
				if (loader != null) {
					loader.setLoading(false);
				} else if (logWhenNull) {
					logger.warn("Ignoring null loader component assigned");
				}
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy