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.dto; 017 018 import java.util.HashMap; 019 import java.util.Map; 020 021 import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId; 022 import org.kuali.student.common.ui.client.mvc.Model; 023 import org.kuali.student.common.ui.client.mvc.ModelChangeEvent; 024 import org.kuali.student.common.ui.client.mvc.ModelChangeHandler; 025 import org.kuali.student.common.ui.client.mvc.ModelChangeEvent.Action; 026 027 import com.google.gwt.event.shared.HandlerManager; 028 import com.google.gwt.event.shared.HandlerRegistration; 029 030 /** 031 * A small model that contains id, type, and state 032 * 033 * @author Kuali Student Team 034 * 035 */ 036 public class ReferenceModel implements HasReferenceId, Model { 037 String referenceId; 038 String referenceTypeKey; 039 String referenceType; 040 String referenceState; 041 Map<String, String> referenceAttributes; // Use referenceAttributes to store misc data from the parent Model 042 private HandlerManager handlers = new HandlerManager(this); 043 044 @Override 045 public HandlerRegistration addModelChangeHandler( 046 ModelChangeHandler handler) { 047 return handlers.addHandler(ModelChangeEvent.TYPE, handler); 048 } 049 050 /** 051 * @see org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId#setReferenceId(java.lang.String) 052 */ 053 @Override 054 public void setReferenceId(String id) { 055 this.referenceId = id; 056 handlers.fireEvent(new ModelChangeEvent(Action.RELOAD, this)); 057 } 058 059 /** 060 * @see org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId#setReferenceKey(java.lang.String) 061 */ 062 @Override 063 public String getReferenceId() { 064 return referenceId; 065 } 066 067 @Override 068 public String getReferenceTypeKey() { 069 return referenceTypeKey; 070 } 071 072 @Override 073 public void setReferenceTypeKey(String referenceTypeKey) { 074 this.referenceTypeKey = referenceTypeKey; 075 handlers.fireEvent(new ModelChangeEvent(Action.RELOAD, this)); 076 } 077 078 @Override 079 public String getReferenceType() { 080 return referenceType; 081 } 082 083 @Override 084 public void setReferenceType(String referenceType) { 085 this.referenceType = referenceType; 086 handlers.fireEvent(new ModelChangeEvent(Action.RELOAD, this)); 087 } 088 089 @Override 090 public String getReferenceState() { 091 return referenceState; 092 } 093 094 @Override 095 public void setReferenceState(String referenceState) { 096 this.referenceState = referenceState; 097 handlers.fireEvent(new ModelChangeEvent(Action.RELOAD, this)); 098 } 099 100 public Map<String, String> getReferenceAttributes(){ 101 if(referenceAttributes!=null){ 102 return referenceAttributes; 103 } 104 else{ 105 return new HashMap<String,String>(); 106 } 107 } 108 public void setReferenceAttributes(Map<String, String> referenceAttributes){ 109 this.referenceAttributes = referenceAttributes; 110 handlers.fireEvent(new ModelChangeEvent(Action.RELOAD, this)); 111 } 112 }