View Javadoc

1   package org.kuali.student.lum.program.client.variation.edit;
2   
3   import org.kuali.student.r1.common.assembly.data.Metadata;
4   import org.kuali.student.r1.common.assembly.data.QueryPath;
5   import org.kuali.student.common.ui.client.configurable.mvc.Configurer;
6   import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
7   import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
8   import org.kuali.student.common.ui.client.configurable.mvc.sections.HorizontalSection;
9   import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
10  import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
11  import org.kuali.student.common.ui.client.mvc.DataModel;
12  import org.kuali.student.common.ui.client.widgets.KSTextBox;
13  import org.kuali.student.common.ui.client.widgets.search.KSPicker;
14  import org.kuali.student.common.ui.client.widgets.search.SearchPanel;
15  import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
16  import org.kuali.student.lum.program.client.ProgramConstants;
17  import org.kuali.student.lum.program.client.ProgramMsgConstants;
18  import org.kuali.student.lum.program.client.ProgramSections;
19  
20  import com.google.gwt.core.client.GWT;
21  import com.google.gwt.user.client.ui.Widget;
22  
23  /**
24   * @author Igor
25   */
26  public class VariationInformationEditConfiguration extends AbstractSectionConfiguration {
27  
28      public VariationInformationEditConfiguration(Configurer configurer) {
29          this.setConfigurer(configurer);
30          rootSection = new VerticalSectionView(ProgramSections.PROGRAM_DETAILS_EDIT, getLabel(
31                  ProgramMsgConstants.PROGRAM_MENU_SECTIONS_PROGRAMINFORMATION), ProgramConstants.PROGRAM_MODEL_ID);
32      }
33  
34      @Override
35      protected void buildLayout() {
36          HorizontalSection horizontalSection = new HorizontalSection();
37          horizontalSection.addSection(createLeftSection());
38          horizontalSection.addSection(createRightSection());
39          rootSection.addSection(horizontalSection);
40      }
41  
42      private VerticalSection createLeftSection() {
43          VerticalSection section = new VerticalSection();
44          section.addSection(createKeyProgramInformationSection());
45          section.addSection(createProgramTitleSection());
46          section.addSection(createDatesSection());
47          section.addSection(createOtherInformationSection());
48          return section;
49      }
50  
51      private VerticalSection createRightSection() {
52          VerticalSection section = new VerticalSection();
53          section.addStyleName("readOnlySection");
54          section.addSection(createReadOnlySection());
55          return section;
56      }
57  
58      private VerticalSection createKeyProgramInformationSection() {
59          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_IDENTIFYINGDETAILS)));
60          configurer.addField(section, ProgramConstants.CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CODE));
61          configurer.addField(section, ProgramConstants.PROGRAM_CLASSIFICATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CLASSIFICATION));
62          configurer.addField(section, ProgramConstants.DEGREE_TYPE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_DEGREETYPE));
63          return section;
64      }
65  
66      private VerticalSection createProgramTitleSection() {
67          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_PROGRAMTITLE)));
68          configurer.addField(section, ProgramConstants.LONG_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEFULL));
69          configurer.addField(section, ProgramConstants.SHORT_TITLE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLESHORT));
70          configurer.addField(section, ProgramConstants.TRANSCRIPT, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLETRANSCRIPT));
71          configurer.addField(section, ProgramConstants.DIPLOMA, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_TITLEDIPLOMA)).setWidgetBinding(new DiplomaBinding());
72          return section;
73      }
74  
75      private VerticalSection createDatesSection() {
76          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_DATES)));
77          configurer.addField(section, ProgramConstants.START_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_STARTTERM));
78          configurer.addField(section, ProgramConstants.END_INSTITUTIONAL_ADMIT_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ADMITTERM));
79          configurer.addField(section, ProgramConstants.END_PROGRAM_ENTRY_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENTRYTERM));
80          configurer.addField(section, ProgramConstants.END_PROGRAM_ENROLL_TERM, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_ENROLLTERM));
81          return section;
82      }
83  
84      private VerticalSection createOtherInformationSection() {
85          VerticalSection section = new VerticalSection(SectionTitle.generateH3Title(getLabel(ProgramMsgConstants.PROGRAMINFORMATION_OTHERINFORMATION)));
86          configurer.addField(section, ProgramConstants.LOCATION, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LOCATION));
87          Widget cip2000Picker = configureSearch(ProgramConstants.CIP_2000);
88          configurer.addField(section, ProgramConstants.CIP_2000, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2000), cip2000Picker);
89          Widget cip2010Picker = configureSearch(ProgramConstants.CIP_2010);
90          configurer.addField(section, ProgramConstants.CIP_2010, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CIP2010), cip2010Picker);
91          configurer.addField(section, ProgramConstants.HEGIS_CODE, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_HEGIS));
92          return section;
93      }
94  
95      private VerticalSection createReadOnlySection() {
96          VerticalSection section = new VerticalSection();
97          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_INSTITUTION_ID, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_INSTITUTION));
98          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_TYPE_NAME, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_CREDENTIALPROGRAM));
99          configurer.addReadOnlyField(section, ProgramConstants.CREDENTIAL_PROGRAM_LEVEL, generateMessageInfo(ProgramMsgConstants.PROGRAMINFORMATION_LEVEL));
100         return section;
101     }
102 
103 	private Widget configureSearch(String fieldKey) {	    
104 		Widget searchWidget;
105 		QueryPath path = QueryPath.concat(null, fieldKey);
106 		Metadata meta = configurer.getModelDefinition().getMetadata(path);
107 	        
108         searchWidget = GWT.create(KSPicker.class);
109         ((KSPicker) searchWidget).init(meta.getInitialLookup(), meta.getAdditionalLookups());
110 		SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
111         if (panel != null) {
112             panel.setMutipleSelect(false);
113         }
114         
115 		return searchWidget;
116 	}
117 	
118     public class DiplomaBinding extends ModelWidgetBindingSupport<KSTextBox> {
119 		private boolean isEmpty(String value){
120 			return value == null || (value != null && "".equals(value));
121 		}
122 
123 		@Override
124 		public void setModelValue(KSTextBox widget, DataModel model, String path) {
125 			String 	diplomaTitle = 	widget.getText();
126 			if(diplomaTitle != null)
127 				model.set(QueryPath.concat(null, "/" + ProgramConstants.DIPLOMA), diplomaTitle);
128 		}
129 
130 		@Override
131 		public void setWidgetValue(KSTextBox widget, DataModel model, String path) {
132 			String diplomaTitle = model.get("/" + ProgramConstants.DIPLOMA);
133 			if(isEmpty(diplomaTitle)){
134 				String programTitle = model.get("/" + ProgramConstants.LONG_TITLE);
135 				if (!isEmpty(programTitle))
136 					widget.setText(programTitle);
137 			}
138 			else
139 				widget.setText(diplomaTitle);
140 		}
141 	}
142 }