Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@GenEvent tag doesn't manage generic event #821

Open
Veknelyon opened this issue Mar 31, 2017 · 0 comments
Open

@GenEvent tag doesn't manage generic event #821

Veknelyon opened this issue Mar 31, 2017 · 0 comments

Comments

@Veknelyon
Copy link

Generic event class are not well generated with GenEvent tag.

Example :

import com.gwtplatform.dispatch.annotation.GenEvent;

@GenEvent
public class Save<T> {
    private T savedObject;
}

Generate not compilable class SaveEvent (because Class and static methods are not generic) :

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.web.bindery.event.shared.HandlerRegistration;

import com.google.gwt.event.shared.HasHandlers;

public class SaveEvent extends GwtEvent<SaveEvent.SaveHandler> {

  private T savedObject;

  protected SaveEvent() {
    // Possibly for serialization.
  }

  public SaveEvent(T savedObject) {
    this.savedObject = savedObject;
  }

  public static void fire(HasHandlers source, T savedObject) {
    SaveEvent eventInstance = new SaveEvent(savedObject);
    source.fireEvent(eventInstance);
  }

  public static void fire(HasHandlers source, SaveEvent eventInstance) {
    source.fireEvent(eventInstance);
  }

  public interface HasSaveHandlers extends HasHandlers {
    HandlerRegistration addSaveHandler(SaveHandler handler);
  }

  public interface SaveHandler extends EventHandler {
    public void onSave(SaveEvent event);
  }

  private static final Type<SaveHandler> TYPE = new Type<SaveHandler>();

  public static Type<SaveHandler> getType() {
    return TYPE;
  }

  @Override
  public Type<SaveHandler> getAssociatedType() {
    return TYPE;
  }

  @Override
  protected void dispatch(SaveHandler handler) {
    handler.onSave(this);
  }

  public T getSavedObject(){
    return savedObject;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
        return true;
    if (obj == null)
        return false;
    if (getClass() != obj.getClass())
        return false;
    SaveEvent other = (SaveEvent) obj;
    if (savedObject == null) {
      if (other.savedObject != null)
        return false;
    } else if (!savedObject.equals(other.savedObject))
      return false;
    return true;
  }

  @Override
  public int hashCode() {
    int hashCode = 23;
    hashCode = (hashCode * 37) + (savedObject == null ? 1 : savedObject.hashCode());
    return hashCode;
  }

  @Override
  public String toString() {
    return "SaveEvent["
                 + savedObject
    + "]";
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant