com.sksamuel.jqm4gwt.events.JQMEventFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jqm4gwt-standalone Show documentation
Show all versions of jqm4gwt-standalone Show documentation
jqm4gwt bundled with all of its dependencies
The newest version!
package com.sksamuel.jqm4gwt.events;
import java.util.HashMap;
import java.util.Map;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.GwtEvent.Type;
public class JQMEventFactory {
private JQMEventFactory() {} // static class
private interface EventInstantiator {
JQMEvent create(JavaScriptObject jQueryEvent);
GwtEvent.Type getType();
}
private static final Map> instantiators =
new HashMap>();
static {
instantiators.put(JQMComponentEvents.CHANGE, new EventInstantiator() {
private final Type TYPE = new Type();
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new JQMEvent(jQueryEvent, getType());
}
@Override
public Type getType() {
return TYPE;
}});
instantiators.put(JQMComponentEvents.INPUT, new EventInstantiator() {
private final Type TYPE = new Type();
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new JQMEvent(jQueryEvent, getType());
}
@Override
public Type getType() {
return TYPE;
}});
instantiators.put(JQMComponentEvents.VCLICK, new EventInstantiator() {
private final Type TYPE = new Type();
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new JQMEvent(jQueryEvent, getType());
}
@Override
public Type getType() {
return TYPE;
}});
instantiators.put(JQMComponentEvents.TAP_EVENT, new EventInstantiator() {
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new TapEvent(jQueryEvent);
}
@Override
public Type getType() {
return TapEvent.getType();
}});
instantiators.put(JQMComponentEvents.TAP_HOLD_EVENT, new EventInstantiator() {
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new TapHoldEvent(jQueryEvent);
}
@Override
public Type getType() {
return TapHoldEvent.getType();
}});
instantiators.put(JQMComponentEvents.ORIENTATIONCHANGE, new EventInstantiator() {
private final Type TYPE = new Type();
@Override
public JQMEvent create(JavaScriptObject jQueryEvent) {
return new JQMEvent(jQueryEvent, getType());
}
@Override
public Type getType() {
return TYPE;
}});
}
public static JQMEvent> createEvent(String jqmEventName, JavaScriptObject jQueryEvent) {
EventInstantiator> i = instantiators.get(jqmEventName);
if (i != null) return i.create(jQueryEvent);
throw new RuntimeException("Cannot create event: " + jqmEventName);
}
public static Type> getType(String jqmEventName) {
EventInstantiator> i = instantiators.get(jqmEventName);
if (i != null) return i.getType();
throw new RuntimeException("Unknown event: " + jqmEventName);
}
/**
* @param handlerClass - needed for getting typed result
*/
public static Type getType(String jqmEventName, Class handlerClass) {
Type> t = getType(jqmEventName);
@SuppressWarnings("unchecked")
Type rslt = (Type) t;
return rslt;
}
}