package org.jboss.gwt.circuit.sample.todo.client.stores;
import javax.annotation.Generated;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.jboss.gwt.circuit.Action;
import org.jboss.gwt.circuit.Agreement;
import org.jboss.gwt.circuit.Dispatcher;
import org.jboss.gwt.circuit.PropagatesChange.Handler;
import org.jboss.gwt.circuit.StoreCallback;
/*
* WARNING! This class is generated. Do not modify.
*/
@ApplicationScoped
@Generated("org.jboss.gwt.circuit.processor.StoreProcessor")
public class UserStoreAdapter {
private final UserStore delegate;
@Inject
public UserStoreAdapter(final UserStore delegate, final Dispatcher dispatcher) {
this.delegate = delegate;
dispatcher.register(UserStore.class, new StoreCallback() {
@Override
public Agreement voteFor(final Action action) {
if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.LoadUsers) {
return new Agreement(true);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.SelectUser) {
return new Agreement(true);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.AddUser) {
return new Agreement(true);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.RemoveUser) {
return new Agreement(true);
}
else {
return Agreement.NONE;
}
}
@Override
public void complete(final Action action, final Dispatcher.Channel channel) {
if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.LoadUsers) {
delegate.onLoad(channel);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.SelectUser) {
delegate.onSelect(((org.jboss.gwt.circuit.sample.todo.client.actions.SelectUser)action).getPayload(), channel);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.AddUser) {
delegate.onAdd(((org.jboss.gwt.circuit.sample.todo.client.actions.AddUser)action).getPayload(), channel);
}
else if (action instanceof org.jboss.gwt.circuit.sample.todo.client.actions.RemoveUser) {
delegate.onRemove(((org.jboss.gwt.circuit.sample.todo.client.actions.RemoveUser)action).getPayload(), channel);
}
else {
System.out.println("WARN: Unmatched action " + action.getClass().getName() + " in store " + delegate.getClass());
channel.ack();
}
}
@Override
public void signalChange(final Action action) {
Class<? extends Action> actionType = action.getClass();
Iterable<Handler> actionHandlers = delegate.getActionHandler(actionType);
for (Handler actionHandler : actionHandlers) {
actionHandler.onChange(actionType);
}
Iterable<Handler> storeHandlers = delegate.getHandler();
for (Handler storeHandler : storeHandlers) {
storeHandler.onChange(actionType);
}
}
});
}
}