001 /**
002 * Copyright 2010 The Kuali Foundation Licensed under the
003 * Educational Community License, Version 2.0 (the "License"); you may
004 * not use this file except in compliance with the License. You may
005 * obtain a copy of the License at
006 *
007 * http://www.osedu.org/licenses/ECL-2.0
008 *
009 * Unless required by applicable law or agreed to in writing,
010 * software distributed under the License is distributed on an "AS IS"
011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing
013 * permissions and limitations under the License.
014 */
015
016 package org.kuali.student.common.ui.client.mvc;
017
018 import com.google.gwt.event.shared.GwtEvent;
019
020 /**
021 * Event that is fired when the model is changed.
022 *
023 * @author Kuali Student Team
024 * @param <T>
025 */
026 public class ModelChangeEvent extends GwtEvent<ModelChangeHandler> {
027 public static final Type<ModelChangeHandler> TYPE = new Type<ModelChangeHandler>();
028
029 /**
030 * The actions that can be performed on a model.
031 *
032 * @author Kuali Student Team
033 */
034 public enum Action {
035 ADD, REMOVE, UPDATE, RELOAD
036 }
037
038 private final Action action;
039 private final Model source;
040
041 /**
042 * Constructs a new ModelChangeEvent with an action and a value
043 *
044 * @param action
045 * @param value
046 */
047 public ModelChangeEvent(Action action, Model source) {
048 this.action = action;
049 this.source = source;
050 }
051
052 @Override
053 protected void dispatch(ModelChangeHandler handler) {
054 handler.onModelChange(this);
055 }
056
057 @Override
058 @SuppressWarnings("unchecked")
059 public Type<ModelChangeHandler> getAssociatedType() {
060 return (Type) TYPE;
061 }
062
063 /**
064 * Returns the action (ADD/UPDATE/REMOVE) associated with the event
065 *
066 * @return
067 */
068 public Action getAction() {
069 return this.action;
070 }
071
072 /**
073 * Returns the model from which this event originated
074 *
075 * @return the model from which this event originated
076 */
077 public Model getSource() {
078 return this.source;
079 }
080 }