jsupload.client.JsChangeClosure Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsupload Show documentation
Show all versions of jsupload Show documentation
JsUpload library: JavaScript ready to use in non gwt web apps and cgi-bin server script.
/*
* Copyright 2010 Manuel Carrasco Moñino. (manolo at apache/org)
* http://code.google.com/p/gwtupload
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package jsupload.client;
import gwtupload.client.HasJsData;
import gwtupload.client.IUploader;
import gwtupload.client.PreloadedImage;
import gwtupload.client.PreloadedImage.OnLoadPreloadedImageHandler;
import org.timepedia.exporter.client.Export;
import org.timepedia.exporter.client.ExportClosure;
import org.timepedia.exporter.client.ExportPackage;
import org.timepedia.exporter.client.Exportable;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
/**
* @author Manolo Carrasco Moñino
*
* An exportable closure
*
*/
@Export
@ExportPackage("jsu")
@ExportClosure
public interface JsChangeClosure extends Exportable {
@Export void onChange(Object object);
}
/**
* @author Manolo Carrasco Moñino
*
* An utility class for storing static methods
*
*/
class JsUtils {
/**
* Creates a valueChangeHandler that executes a ChangeClosure.
*
* @param
* @param clazz
* @param jsChange
* @return
*/
public static final ValueChangeHandler getClosureHandler(final T clazz, final JsChangeClosure jsChange) {
return new ValueChangeHandler() {
public void onValueChange(ValueChangeEvent event) {
Object data = null;
if (jsChange != null) {
if (event != null && event.getValue() != null) {
data = event.getValue().getData();
}
jsChange.onChange(data);
}
}
};
}
public static final ValueChangeHandler getDataHandler(final JsChangeClosure jsChange) {
return new ValueChangeHandler() {
public void onValueChange(ValueChangeEvent event) {
Object data = null;
if (jsChange != null) {
if (event != null && event.getValue() != null) {
data = event.getValue().getData();
}
jsChange.onChange(data);
}
}
};
}
public static final IUploader.OnCancelUploaderHandler getOnCancelUploaderHandler(final JsChangeClosure jsChange) {
return new IUploader.OnCancelUploaderHandler() {
public void onCancel(IUploader u) {
if (jsChange != null) {
}
jsChange.onChange(u.getData());
}
};
}
public static final IUploader.OnChangeUploaderHandler getOnChangeUploaderHandler(final JsChangeClosure jsChange) {
return new IUploader.OnChangeUploaderHandler() {
public void onChange(IUploader u) {
if (jsChange != null) {
}
jsChange.onChange(u.getData());
}
};
}
public static final IUploader.OnFinishUploaderHandler getOnFinishUploaderHandler(final JsChangeClosure jsChange) {
return new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader u) {
if (jsChange != null) {
}
jsChange.onChange(u.getData());
}
};
}
public static final OnLoadPreloadedImageHandler getOnLoadPreloadedImageHandler(final JsChangeClosure jsChange) {
return new OnLoadPreloadedImageHandler() {
public void onLoad(PreloadedImage image) {
if (jsChange != null) {
}
jsChange.onChange(image.getData());
}
};
}
public static final IUploader.OnStartUploaderHandler getOnStartUploaderHandler(final JsChangeClosure jsChange) {
return new IUploader.OnStartUploaderHandler() {
public void onStart(IUploader u) {
if (jsChange != null) {
}
jsChange.onChange(u.getData());
}
};
}
public static final IUploader.OnStatusChangedHandler getStatusChangedHandler(final JsChangeClosure jsChange) {
return new IUploader.OnStatusChangedHandler() {
public void onStatusChanged(IUploader u) {
if (jsChange != null) {
}
jsChange.onChange(u.getData());
}
};
}
}