com.github.spirylics.xgwt.essential.ModelEvent Maven / Gradle / Ivy
package com.github.spirylics.xgwt.essential;
import com.google.gwt.event.shared.GwtEvent;
import com.google.web.bindery.event.shared.EventBus;
import java.util.HashMap;
import java.util.Map;
public class ModelEvent extends GwtEvent> {
public static final Map, Type>> TYPES = new HashMap<>();
public static Type getType(Class clazz) {
if (!TYPES.containsKey(clazz)) {
TYPES.put(clazz, new Type>());
}
return TYPES.get(clazz);
}
public static void fire(EventBus source, Class clazz, D old, D data) {
source.fireEvent(new ModelEvent(clazz, old, data));
}
@Override
public Type> getAssociatedType() {
return getType(clazz);
}
@Override
protected void dispatch(ModelHandler handler) {
if (old == null) {
handler.onCreateModel(data);
} else {
if (data == null) {
handler.onDeleteModel(old);
} else {
handler.onUpdateModel(old, data);
}
}
}
final Class clazz;
final D old;
final D data;
public ModelEvent(Class clazz, D old, D data) {
this.clazz = clazz;
this.old = old;
this.data = data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy