PlaceChangeRequestEvent class
Event thrown when the user may go to a new place in the app, or tries to leave it. Receivers can call {@link #setWarning(String)} request that the user be prompted to confirm the change.
class PlaceChangeRequestEvent extends DwtEvent { /** * A singleton instance of Type<Handler>. */ static EventType<PlaceChangeRequestEventHandler> TYPE = new EventType<PlaceChangeRequestEventHandler>(); String _warning; final Place newPlace; /** * Constructs a PlaceChangeRequestEvent for the given {@link Place}. * * @param newPlace a {@link Place} instance */ PlaceChangeRequestEvent(this.newPlace); EventType<PlaceChangeRequestEventHandler> getAssociatedType() { return TYPE; } /** * Returns the place we may navigate to, or null on window close. * * @return a {@link Place} instance */ Place getNewPlace() { return newPlace; } /** * Returns the warning message to show the user before allowing the place * change, or null if none has been set. * * @return the warning message as a String * @see #setWarning(String) */ String getWarning() { return _warning; } /** * Set a message to warn the user that it might be unwise to navigate away * from the current place, e.g. due to unsaved changes. If the user clicks * okay to that message, navigation will be canceled. * <p> * Calling with a null warning is the same as not calling the method at all -- * the user will not be prompted. * <p> * Only the first non-null call to setWarning has any effect. That is, once * the warning message has been set it cannot be cleared. * * @param warning the warning message as a String * @see #getWarning() */ void setWarning(String warning) { if (this._warning == null) { this._warning = warning; } } void dispatch(PlaceChangeRequestEventHandler handler) { handler.onPlaceChangeRequest(this); } }
Extends
IEvent<H> > DwtEvent > PlaceChangeRequestEvent
Static Properties
EventType<PlaceChangeRequestEventHandler> TYPE #
A singleton instance of Type<Handler>.
static EventType<PlaceChangeRequestEventHandler> TYPE = new EventType<PlaceChangeRequestEventHandler>()
Constructors
Methods
void assertLive() #
Asserts that the event still should be accessed. All events are considered to be "dead" after their original handler manager finishes firing them. An event can be revived by calling {@link GwtEvent#revive()}.
void assertLive() { assert (!_dead) ; //: "This event has already finished being processed by its original handler manager, so you can no longer access it"; }
void dispatch(PlaceChangeRequestEventHandler handler) #
Implemented by subclasses to invoke their handlers in a type safe
manner. Intended to be called by EventBus#fireEvent(Event)
or
EventBus#fireEventFromSource(Event, Object)
.
@param handler handler @see EventBus#dispatchEvent(Event, Object)
void dispatch(PlaceChangeRequestEventHandler handler) { handler.onPlaceChangeRequest(this); }
EventType<PlaceChangeRequestEventHandler> getAssociatedType() #
Place getNewPlace() #
Returns the place we may navigate to, or null on window close.
@return a {@link Place} instance
Place getNewPlace() { return newPlace; }
Object getSource() #
Returns the source for this event. The type and meaning of the source is
arbitrary, and is most useful as a secondary key for handler registration.
(See EventBus#addHandlerToSource
, which allows a handler to
register for events of a particular type, tied to a particular source.)
Note that the source is actually set at dispatch time, e.g. via
EventBus#fireEventFromSource(Event, Object)
.
@return object representing the source of this event
Object getSource() { assertLive(); return super.getSource(); }
String getWarning() #
Returns the warning message to show the user before allowing the place change, or null if none has been set.
@return the warning message as a String @see #setWarning(String)
String getWarning() { return _warning; }
bool isLive() #
Is the event current live?
@return whether the event is live
bool isLive() { return !_dead; }
void kill() #
Kill the event. After the event has been killed, users cannot really on its values or functions being available.
void kill() { _dead = true; setSource(null); }
void overrideSource(Object source) #
void overrideSource(Object source) { super.setSource(source); }
void revive() #
Revives the event. Used when recycling event instances.
void revive() { _dead = false; setSource(null); }
void setSource(source) #
Set the source that triggered this event. Intended to be called by the EventBus during dispatch.
@param source the source of this event. @see EventBus#fireEventFromSource(Event, Object) @see EventBus#setSourceOfEvent(Event, Object)
void setSource(dynamic source) { this._source = source; }
void setWarning(String warning) #
Set a message to warn the user that it might be unwise to navigate away from the current place, e.g. due to unsaved changes. If the user clicks okay to that message, navigation will be canceled. <p> Calling with a null warning is the same as not calling the method at all -- the user will not be prompted. <p> Only the first non-null call to setWarning has any effect. That is, once the warning message has been set it cannot be cleared.
@param warning the warning message as a String @see #getWarning()
void setWarning(String warning) { if (this._warning == null) { this._warning = warning; } }