com.google.gwt.requestfactory.shared.EntityProxyChange Maven / Gradle / Ivy
/*
* Copyright 2010 Google Inc.
*
* 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 com.google.gwt.requestfactory.shared;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
/**
* Abstract base class for an event announcing changes to an
* {@link EntityProxy}.
*
* Note that this event includes an unpopulated copy of the changed proxy
* — all properties are undefined except it's id. That is, the event
* includes only enough information for receivers to issue requests to get
* themselves fresh copies of the proxy.
*
* TODO: use ProxyId rather than an empty proxy
*
*
RequestFactory has moved to
* com.google.web.bindery.requestfactory
. This package will be
* removed in a future version of GWT.
*
* @param the type of the proxy
*/
@Deprecated
public class EntityProxyChange
extends
GwtEvent> {
/**
* Implemented by methods that handle EntityProxyChange events.
*
* @param the proxy type
*
*
RequestFactory has moved to
* com.google.web.bindery.requestfactory
. This package will be
* removed in a future version of GWT.
*/
@Deprecated
public interface Handler extends EventHandler {
/**
* Called when an {@link EntityProxyChange} event is fired.
*
* @param event an {@link EntityProxyChange} instance
*/
void onProxyChange(EntityProxyChange
event);
}
private static final Type> TYPE = new Type>();
/**
* Register a handler for a EntityProxyChange events for a particular proxy
* class.
*
* @param eventBus the {@link EventBus}
* @param proxyType a Class instance of type P
* @param handler an {@link EntityProxyChange.Handler} instance of type P
* @return an {@link EntityProxy} instance
*/
public static HandlerRegistration registerForProxyType(
EventBus eventBus, Class
proxyType,
EntityProxyChange.Handler
handler) {
return eventBus.addHandlerToSource(TYPE, proxyType, handler);
}
private P proxy;
private WriteOperation writeOperation;
/**
* Constructs an EntityProxyChange object.
*
* @param proxy an {@link EntityProxy} instance of type P
* @param writeOperation a {@link WriteOperation} instance
*/
public EntityProxyChange(P proxy, WriteOperation writeOperation) {
this.proxy = proxy;
this.writeOperation = writeOperation;
}
/**
* Returns the type associated with this instance.
*
* @return an instance of {@link GwtEvent.Type} of type Handler<P>
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public GwtEvent.Type> getAssociatedType() {
/*
* The instance knows its handler is of type P, but the TYPE field itself
* does not, so we have to do an unsafe cast here.
*/
return (Type) TYPE;
}
/**
* Returns an unpopulated copy of the changed proxy — all properties are
* undefined except its id.
*
* @return an instance of {@link EntityProxyId}<P>
*/
@SuppressWarnings("unchecked")
public EntityProxyId getProxyId() {
return (EntityProxyId
) proxy.stableId();
}
/**
* Returns the {@link WriteOperation} associated with this instance.
*
* @return a {@link WriteOperation} instance
*/
public WriteOperation getWriteOperation() {
return writeOperation;
}
@Override
protected void dispatch(Handler
handler) {
handler.onProxyChange(this);
}
}