View Javadoc

1   package org.kuali.student.lum.program.client.major.view;
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.FieldDescriptorReadOnly;
7   import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
8   import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
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.proposal.MajorProposalController;
22  
23  import com.google.gwt.core.client.GWT;
24  import com.google.gwt.user.client.ui.Widget;
25  
26  /**
27   * @author Igor
28   */
29  public class ProposalChangeImpactViewConfiguration extends AbstractSectionConfiguration {
30      
31      private Controller controller;
32  
33      public static ProposalChangeImpactViewConfiguration create(Configurer configurer) { 
34          return new ProposalChangeImpactViewConfiguration(configurer);
35      }
36  
37      public static ProposalChangeImpactViewConfiguration createSpecial(Configurer configurer, Controller controller) { 
38          return new ProposalChangeImpactViewConfiguration(configurer, controller);
39      }
40  
41      private ProposalChangeImpactViewConfiguration(Configurer configurer) {
42          this.setConfigurer(configurer);
43          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_PROPOSALCHANGEIMPACT);
44          rootSection = new VerticalSectionView(ProgramSections.PROGRAM_PROPOSAL_CHANGE_IMPACT_VIEW, 
45                  title, ProgramConstants.PROGRAM_MODEL_ID);
46      }
47  
48      private ProposalChangeImpactViewConfiguration(Configurer configurer, Controller controller) {
49          this.setConfigurer(configurer);
50          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_PROPOSALCHANGEIMPACT);
51          rootSection = new VerticalSectionView(ProgramSections.PROGRAM_PROPOSAL_CHANGE_IMPACT_VIEW, 
52                  title, ProgramConstants.PROGRAM_MODEL_ID, new MajorEditableHeader(title, 
53                          ProgramSections.PROGRAM_PROPOSAL_CHANGE_IMPACT_EDIT));
54          this.controller = controller;
55      }
56  
57      @Override
58      protected void buildLayout() {
59          if (controller instanceof MajorProposalController) {
60          	rootSection.addSection(createEditableSection());
61          } else {
62          	rootSection.addSection(createReadOnlySection());
63          }
64      }  
65      
66      private Section createEditableSection() {
67          SummaryTableSection section = GWT.create(SummaryTableSection.class);
68          section.init((Controller) controller);
69          section.setEditable(false);
70          section.addSummaryTableFieldBlock(createSummaryTableFieldBlock());
71          return section;
72      }
73      
74      public SummaryTableFieldBlock createSummaryTableFieldBlock() {
75          SummaryTableFieldBlock block = new SummaryTableFieldBlock();
76          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.PROPOSAL_RELATED_COURSE_CHANGES_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLURELATEDCOURSECHANGESTYPE)));
77          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.PROPOSAL_IMPACTED_UNITS_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUIMPACTEDUNITSTYPE)));
78          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.PROPOSAL_IMPACTED_ARTICULATION_TRANSFER_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUIMPACTEDARTICULATIONTRANSFERPROGRAMSTYPE)));
79          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.PROPOSAL_STUDENT_TRANSITION_PLANS_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUSTUDENTTRANSITIONPLANSTYPE)));
80          return block;
81      }
82      
83      protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
84          return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
85      }
86       
87      protected SummaryTableFieldRow getFieldRow(String fieldKey,
88              MessageKeyInfo messageKey, Widget widget, Widget widget2,
89              String parentPath, ModelWidgetBinding<?> binding, boolean optional) 
90      {
91          QueryPath path = QueryPath.concat(parentPath, fieldKey);
92          Metadata meta = configurer.getModelDefinition().getMetadata(path);
93  
94          FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
95          if (widget != null) {
96              fd.setFieldWidget(widget);
97          }
98          if (binding != null) {
99              fd.setWidgetBinding(binding);
100         }
101         fd.setOptional(optional);
102 
103         FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
104         if (widget2 != null) {
105             fd2.setFieldWidget(widget2);
106         }
107         if (binding != null) {
108             fd2.setWidgetBinding(binding);
109         }
110         fd2.setOptional(optional);
111 
112         SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
113 
114         return fieldRow;
115     }
116     
117     private VerticalSection createReadOnlySection() {
118         VerticalSection section = new VerticalSection(); 
119         configurer.addReadOnlyField(section, ProgramConstants.PROPOSAL_RELATED_COURSE_CHANGES_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLURELATEDCOURSECHANGESTYPE));        
120         configurer.addReadOnlyField(section, ProgramConstants.PROPOSAL_IMPACTED_UNITS_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUIMPACTEDUNITSTYPE));        
121         configurer.addReadOnlyField(section, ProgramConstants.PROPOSAL_IMPACTED_ARTICULATION_TRANSFER_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUIMPACTEDARTICULATIONTRANSFERPROGRAMSTYPE));
122         configurer.addReadOnlyField(section, ProgramConstants.PROPOSAL_STUDENT_TRANSITION_PLANS_PATH, generateMessageInfo(ProgramMsgConstants.PROPOSALINFORMATION_CLUSTUDENTTRANSITIONPLANSTYPE));
123         return section;
124     }
125 
126 }