View Javadoc

1   package org.kuali.student.lum.program.client.major.view;
2   
3   import org.kuali.student.common.assembly.data.Metadata;
4   import org.kuali.student.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.FieldDescriptorReadOnly;
7   import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
8   import org.kuali.student.common.ui.client.configurable.mvc.sections.CollapsableSection;
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.Controller;
12  import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
13  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock;
14  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldRow;
15  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
16  import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
17  import org.kuali.student.lum.program.client.ProgramConstants;
18  import org.kuali.student.lum.program.client.ProgramMsgConstants;
19  import org.kuali.student.lum.program.client.ProgramSections;
20  import org.kuali.student.lum.program.client.major.MajorEditableHeader;
21  import org.kuali.student.lum.program.client.major.edit.MajorEditController;
22  import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
23  
24  import com.google.gwt.user.client.ui.Widget;
25  
26  /**
27   * @author Igor
28   */
29  public class ManagingBodiesViewConfiguration extends AbstractSectionConfiguration {
30  
31  	private Controller controller = null;
32  
33      public static ManagingBodiesViewConfiguration create(Configurer configurer) {
34          return new ManagingBodiesViewConfiguration(configurer);
35      }
36  
37      public static ManagingBodiesViewConfiguration createSpecial(Configurer configurer, Controller controller) {
38          return new ManagingBodiesViewConfiguration(configurer, controller);
39      }
40  
41      private ManagingBodiesViewConfiguration(Configurer configurer) {
42          this.setConfigurer(configurer);
43          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_MANAGINGBODIES);
44          this.rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_VIEW, title, 
45                  ProgramConstants.PROGRAM_MODEL_ID);
46          
47      }
48  
49      private ManagingBodiesViewConfiguration(Configurer configurer, Controller controller) {
50          this.setConfigurer(configurer);
51          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_MANAGINGBODIES);
52          this.rootSection = new VerticalSectionView(ProgramSections.MANAGE_BODIES_VIEW, title, 
53                  ProgramConstants.PROGRAM_MODEL_ID, new MajorEditableHeader(title, ProgramSections.MANAGE_BODIES_EDIT));
54      	this.controller = controller;
55      	
56      }
57  
58      @Override
59      protected void buildLayout() {
60      	if (controller instanceof MajorProposalController || controller instanceof MajorEditController) 
61      	{
62      		SummaryTableSection section = createMainSectionEdit(); 
63      		CollapsableSection collapsableSection = createAdditionalSectionEdit();
64              rootSection.addSection(section);
65              rootSection.addSection(collapsableSection);
66      	} else
67      	{
68      		VerticalSection section = createMainSection();
69      		CollapsableSection collapsableSection = createAdditionalSection();
70              rootSection.addSection(section);
71              rootSection.addSection(collapsableSection);
72      	}
73      }
74  
75      private VerticalSection createMainSection() {
76          VerticalSection section = new VerticalSection();
77          configurer.addReadOnlyField(section, ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTDIVISION));
78          configurer.addReadOnlyField(section, ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTUNIT));
79          configurer.addReadOnlyField(section, ProgramConstants.STUDENT_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTDIVISION));
80          configurer.addReadOnlyField(section, ProgramConstants.STUDENT_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTUNIT));
81          return section;
82      }
83  
84      private CollapsableSection createAdditionalSection() {
85          CollapsableSection section = new CollapsableSection(getLabel(ProgramMsgConstants.MANAGINGBODIES_SEEALL));
86          configurer.addReadOnlyField(section, ProgramConstants.DEPLOYMENT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTDIVISION));
87          configurer.addReadOnlyField(section, ProgramConstants.DEPLOYMENT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTUNIT));
88          configurer.addReadOnlyField(section, ProgramConstants.FINANCIAL_RESOURCES_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESDIVISION));
89          configurer.addReadOnlyField(section, ProgramConstants.FINANCIAL_RESOURCES_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESUNIT));
90          configurer.addReadOnlyField(section, ProgramConstants.FINANCIAL_CONTROL_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLDIVISION));
91          configurer.addReadOnlyField(section, ProgramConstants.FINANCIAL_CONTROL_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLUNIT));
92          return section;
93      }
94      
95      
96      // Side-by-side comparison (when controller is not null)  
97      private SummaryTableSection createMainSectionEdit() { 
98        	SummaryTableSection section = new SummaryTableSection((Controller) controller);     		
99        	section.setEditable(false);
100       	section.addSummaryTableFieldBlock(createMainSectionEditBlock());
101 
102         return section;
103     }
104 
105   	public SummaryTableFieldBlock createMainSectionEditBlock() {
106   		SummaryTableFieldBlock block = new SummaryTableFieldBlock();
107   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.CURRICULUM_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTDIVISION)));
108   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.CURRICULUM_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_CURRICULUMOVERSIGHTUNIT)));
109   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.STUDENT_OVERSIGHT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTDIVISION)));
110   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.STUDENT_OVERSIGHT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_STUDENTOVERSIGHTUNIT)));
111 
112   		return block;
113   	}
114 
115     private CollapsableSection createAdditionalSectionEdit() { 
116       	SummaryTableSection section = new SummaryTableSection((Controller) controller);     		
117       	section.setEditable(false);
118       	section.addSummaryTableFieldBlock(createAdditionalSectionEditBlock());
119       	
120       	CollapsableSection collapsableSection = new CollapsableSection(getLabel(ProgramMsgConstants.MANAGINGBODIES_SEEALL));
121       	collapsableSection.addSection(section);
122       	
123         return collapsableSection;
124     }
125 
126   	public SummaryTableFieldBlock createAdditionalSectionEditBlock() {
127   		SummaryTableFieldBlock block = new SummaryTableFieldBlock();
128   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.DEPLOYMENT_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTDIVISION)));
129   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.DEPLOYMENT_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_DEPLOYMENTUNIT)));
130   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.FINANCIAL_RESOURCES_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESDIVISION)));
131   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.FINANCIAL_RESOURCES_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALRESOURCESUNIT)));
132   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.FINANCIAL_CONTROL_DIVISION, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLDIVISION)));
133   		block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.FINANCIAL_CONTROL_UNIT, generateMessageInfo(ProgramMsgConstants.MANAGINGBODIES_FINANCIALCONTROLUNIT)));
134 
135   		return block;
136   	}
137 
138   	protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
139   		return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
140   	}
141      
142   	protected SummaryTableFieldRow getFieldRow(String fieldKey,
143   			MessageKeyInfo messageKey, Widget widget, Widget widget2,
144   			String parentPath, ModelWidgetBinding<?> binding, boolean optional) 
145   	{
146   		QueryPath path = QueryPath.concat(parentPath, fieldKey);
147   		Metadata meta = configurer.getModelDefinition().getMetadata(path);
148 
149   		FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
150   		if (widget != null) {
151   			fd.setFieldWidget(widget);
152   		}
153   		if (binding != null) {
154   			fd.setWidgetBinding(binding);
155   		}
156   		fd.setOptional(optional);
157 
158   		FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
159   		if (widget2 != null) {
160   			fd2.setFieldWidget(widget2);
161   		}
162   		if (binding != null) {
163   			fd2.setWidgetBinding(binding);
164   		}
165   		fd2.setOptional(optional);
166 
167   		SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
168 
169   		return fieldRow;
170   	}    
171 }