View Javadoc

1   package org.kuali.student.lum.program.client.major.view;
2   
3   import com.google.gwt.core.client.GWT;
4   import com.google.gwt.user.client.ui.FlexTable;
5   import com.google.gwt.user.client.ui.Widget;
6   
7   import org.kuali.student.r1.common.assembly.data.Metadata;
8   import org.kuali.student.r1.common.assembly.data.QueryPath;
9   import org.kuali.student.common.ui.client.configurable.mvc.Configurer;
10  import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptorReadOnly;
11  import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
12  import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
13  import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
14  import org.kuali.student.common.ui.client.mvc.Controller;
15  import org.kuali.student.common.ui.client.widgets.KSCheckBox;
16  import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
17  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock;
18  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldRow;
19  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
20  import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
21  import org.kuali.student.lum.common.client.widgets.AppLocations;
22  import org.kuali.student.lum.program.client.ProgramConstants;
23  import org.kuali.student.lum.program.client.ProgramMsgConstants;
24  import org.kuali.student.lum.program.client.ProgramSections;
25  import org.kuali.student.lum.program.client.major.MajorEditableHeader;
26  import org.kuali.student.lum.program.client.major.edit.MajorEditController;
27  import org.kuali.student.lum.program.client.major.proposal.MajorProposalController;
28  import org.kuali.student.lum.program.client.variation.VariationsBinding;
29  
30  /**
31   * @author Igor
32   */
33  public class SpecializationsViewConfiguration extends AbstractSectionConfiguration {
34  
35  	private Controller controller = null;
36  
37      public static SpecializationsViewConfiguration create(Configurer configurer) {
38          return new SpecializationsViewConfiguration(configurer);
39      }
40  
41      public static SpecializationsViewConfiguration createSpecial(Configurer configurer, Controller controller) {
42          return new SpecializationsViewConfiguration(configurer, controller);
43      }
44  
45      private SpecializationsViewConfiguration(Configurer configurer) {
46          this.setConfigurer(configurer);
47          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_SPECIALIZATIONS);
48          rootSection = new VerticalSectionView(ProgramSections.SPECIALIZATIONS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID);
49      }
50  
51      private SpecializationsViewConfiguration(Configurer configurer, Controller controller) {
52          this.setConfigurer(configurer);
53          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_SPECIALIZATIONS);
54          rootSection = new VerticalSectionView(ProgramSections.SPECIALIZATIONS_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID, 
55                  new MajorEditableHeader(title, ProgramSections.SPECIALIZATIONS_EDIT));
56      	this.controller = controller;
57      }
58  
59      @Override
60      protected void buildLayout() {
61      	if (controller instanceof MajorProposalController || controller instanceof MajorEditController) 
62      		rootSection.addSection(createSpecializationsSectionEdit());
63      	else
64      	{
65      		VerticalSection section = new VerticalSection();
66      		KSCheckBox isVariationRequiredCheckBox = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
67      		isVariationRequiredCheckBox.setEnabled(false);
68      		configurer.addReadOnlyField(section, ProgramConstants.IS_VARIATION_REQUIRED, null, isVariationRequiredCheckBox);
69      		configurer.addReadOnlyField(section, ProgramConstants.VARIATIONS, new MessageKeyInfo(""), new FlexTable()).setWidgetBinding(new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false));
70      		rootSection.addSection(section);
71      	}
72      }
73      
74      // Side-by-side comparison (when controller is not null)  
75      private SummaryTableSection createSpecializationsSectionEdit() { 
76          SummaryTableSection section = GWT.create(SummaryTableSection.class);
77          section.init((Controller) controller);
78        	section.setEditable(false);
79        	section.addSummaryTableFieldBlock(createSpecializationsSectionEditBlock());
80  
81          return section;
82      }
83  
84    	public SummaryTableFieldBlock createSpecializationsSectionEditBlock() {
85    		SummaryTableFieldBlock block = new SummaryTableFieldBlock();
86   
87  		KSCheckBox isVariationRequiredCheckBox = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
88  		isVariationRequiredCheckBox.setEnabled(false);
89  		KSCheckBox isVariationRequiredCheckBox2 = new KSCheckBox(getLabel(ProgramMsgConstants.PROGRAMSPECIALIZATION_INSTRUCTIONS));
90  		isVariationRequiredCheckBox2.setEnabled(false);
91  
92          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.IS_VARIATION_REQUIRED, null, isVariationRequiredCheckBox, isVariationRequiredCheckBox2, null, null, false));        
93          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.VARIATIONS, new MessageKeyInfo(""), new FlexTable(),
94          		new FlexTable(), null, new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false), false));        
95  
96    		return block;
97    	}
98  
99    	protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
100   		return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
101   	}
102      
103   	protected SummaryTableFieldRow getFieldRow(String fieldKey,
104   			MessageKeyInfo messageKey, Widget widget, Widget widget2,
105   			String parentPath, ModelWidgetBinding<?> binding, boolean optional) 
106   	{
107   		QueryPath path = QueryPath.concat(parentPath, fieldKey);
108   		Metadata meta = configurer.getModelDefinition().getMetadata(path);
109 
110   		FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
111   		if (widget != null) {
112   			fd.setFieldWidget(widget);
113   		}
114   		if (binding != null) {
115   			fd.setWidgetBinding(binding);
116   		}
117   		fd.setOptional(optional);
118 
119   		FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
120   		if (widget2 != null) {
121   			fd2.setFieldWidget(widget2);
122   		}
123   		if (binding != null) {
124   		    // Pass in a variable to distinguish that this is the right hand column of side-by-side
125   		    // so we can disable links in that column.  We created a new constructor to pass this
126   		    // variable
127   		    if (binding instanceof VariationsBinding){
128   		      binding = new VariationsBinding(AppLocations.Locations.VIEW_VARIATION.getLocation(), false, true); 
129   		    }
130   			fd2.setWidgetBinding(binding);
131   		}
132   		fd2.setOptional(optional);
133 
134   		SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
135 
136   		return fieldRow;
137   	} 
138 }