001    package org.kuali.student.lum.program.client;
002    
003    import com.google.gwt.event.shared.EventHandler;
004    import com.google.gwt.event.shared.GwtEvent;
005    
006    import org.kuali.student.common.ui.client.application.Application;
007    import org.kuali.student.r1.common.assembly.data.Data;
008    import org.kuali.student.r2.common.dto.ValidationResultInfo;
009    
010    import java.util.ArrayList;
011    import java.util.HashMap;
012    import java.util.List;
013    
014    /**
015     * @author Igor
016     */
017    public class ProgramRegistry {
018    
019        private static Data data;
020    
021        private static int row;
022    
023        private static Enum<?> section;
024    
025        private static HashMap<GwtEvent.Type, EventHandler> specializationHandlers = new HashMap<GwtEvent.Type, EventHandler>();
026    
027        private static boolean createNew = false;
028    
029        public static Data getData() {
030            return data;
031        }
032    
033        public static void setData(Data data) {
034            ProgramRegistry.data = data;
035        }
036    
037        public static int getRow() {
038            return row;
039        }
040    
041        public static void setRow(int row) {
042            ProgramRegistry.row = row;
043        }
044    
045        public static Enum<?> getSection() {
046            return section;
047        }
048    
049        public static void setSection(Enum<?> section) {
050            ProgramRegistry.section = section;
051        }
052    
053        public static void addHandler(GwtEvent.Type<?> type, EventHandler handler) {
054            specializationHandlers.put(type, handler);
055        }
056    
057        public static HashMap<GwtEvent.Type, EventHandler> getSpecializationHandlers() {
058            return specializationHandlers;
059        }
060    
061        public static boolean isCreateNew() {
062            return createNew;
063        }
064    
065        public static void setCreateNew(boolean createNew) {
066            ProgramRegistry.createNew = createNew;
067        }
068        
069        /**
070         * @return  The validation warnings for the current variation found in the validation warnings stored in
071         * the ApplicationContext.
072         *  
073         */
074        public static List<ValidationResultInfo> getVariationWarnings(){
075            String variationPath = ProgramConstants.VARIATIONS+"/"+org.kuali.student.lum.program.client.ProgramRegistry.getRow()+"/";
076            List<ValidationResultInfo> validationWarnings = Application.getApplicationContext().getValidationWarnings();
077            List<ValidationResultInfo> variationWarnings = new ArrayList<ValidationResultInfo>();
078            for (ValidationResultInfo vr:validationWarnings){
079                    if (vr.getElement().contains(variationPath)){
080                            ValidationResultInfo newVr = new ValidationResultInfo(vr.getElement().substring(variationPath.length()));
081                            newVr.setWarning(vr.getMessage());
082                            variationWarnings.add(newVr);
083                    }
084            }
085            
086            return variationWarnings;
087        }
088    }