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.views.VerticalSectionView;
9   import org.kuali.student.common.ui.client.mvc.Controller;
10  import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
11  import org.kuali.student.common.ui.client.widgets.menus.KSListPanel;
12  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldBlock;
13  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableFieldRow;
14  import org.kuali.student.common.ui.client.widgets.table.summary.SummaryTableSection;
15  import org.kuali.student.lum.common.client.configuration.AbstractSectionConfiguration;
16  import org.kuali.student.lum.common.client.lo.TreeStringBinding;
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.core.client.GWT;
25  import com.google.gwt.user.client.ui.Widget;
26  
27  /**
28   * @author Igor
29   */
30  public class LearningObjectivesViewConfiguration extends AbstractSectionConfiguration {
31  
32  	private Controller controller = null;
33  
34      public static LearningObjectivesViewConfiguration create(Configurer configurer) {
35          return new LearningObjectivesViewConfiguration(configurer);
36      }
37  
38      public static LearningObjectivesViewConfiguration createSpecial(Configurer configurer, Controller controller) {
39          return new LearningObjectivesViewConfiguration(configurer, controller);
40      }
41  
42      private LearningObjectivesViewConfiguration(Configurer configurer) {
43          this.setConfigurer(configurer);
44          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_LEARNINGOBJECTIVES);
45          rootSection = new VerticalSectionView(ProgramSections.LEARNING_OBJECTIVES_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID);
46      }
47  
48      private LearningObjectivesViewConfiguration(Configurer configurer, Controller controller) {
49          this.setConfigurer(configurer);
50          String title = getLabel(ProgramMsgConstants.PROGRAM_MENU_SECTIONS_LEARNINGOBJECTIVES);
51          rootSection = new VerticalSectionView(ProgramSections.LEARNING_OBJECTIVES_VIEW, title, ProgramConstants.PROGRAM_MODEL_ID, new MajorEditableHeader(title, ProgramSections.LEARNING_OBJECTIVES_EDIT));
52         	this.controller = controller;        
53      }
54  
55      protected void buildLayout() {
56      	if (controller instanceof MajorProposalController || controller instanceof MajorEditController) 
57         		rootSection.addSection(createLearningObjectivesSectionEdit());       		
58      	else	
59      		configurer.addReadOnlyField(rootSection, ProgramConstants.LEARNING_OBJECTIVES, new MessageKeyInfo(""), new KSListPanel()).setWidgetBinding(new TreeStringBinding());       	
60      }
61      
62      // Side-by-side comparison (when controller is not null)  
63      private SummaryTableSection createLearningObjectivesSectionEdit() { 
64          SummaryTableSection section = GWT.create(SummaryTableSection.class);
65          section.init((Controller) controller);
66        	section.setEditable(false);
67        	section.addSummaryTableFieldBlock(createLearningObjectivesSectionEditBlock());
68  
69          return section;
70      }
71  
72      public SummaryTableFieldBlock createLearningObjectivesSectionEditBlock() {
73    		SummaryTableFieldBlock block = new SummaryTableFieldBlock();
74  
75          block.addSummaryTableFieldRow(getFieldRow(ProgramConstants.LEARNING_OBJECTIVES, new MessageKeyInfo(""), new KSListPanel(),
76          		new KSListPanel(), null, new TreeStringBinding(), false));        
77  
78    		return block;
79    	}
80  
81    	protected SummaryTableFieldRow getFieldRow(String fieldKey, MessageKeyInfo messageKey) {
82    		return getFieldRow(fieldKey, messageKey, null, null, null, null, false);
83    	}
84       
85    	protected SummaryTableFieldRow getFieldRow(String fieldKey,
86    			MessageKeyInfo messageKey, Widget widget, Widget widget2,
87    			String parentPath, ModelWidgetBinding<?> binding, boolean optional) 
88    	{
89    		QueryPath path = QueryPath.concat(parentPath, fieldKey);
90    		Metadata meta = configurer.getModelDefinition().getMetadata(path);
91  
92    		FieldDescriptorReadOnly fd = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
93    		if (widget != null) {
94    			fd.setFieldWidget(widget);
95    		}
96    		if (binding != null) {
97    			fd.setWidgetBinding(binding);
98    		}
99    		fd.setOptional(optional);
100 
101   		FieldDescriptorReadOnly fd2 = new FieldDescriptorReadOnly(path.toString(), messageKey, meta);
102   		if (widget2 != null) {
103   			fd2.setFieldWidget(widget2);
104   		}
105   		if (binding != null) {
106   			fd2.setWidgetBinding(binding);
107   		}
108   		fd2.setOptional(optional);
109 
110   		SummaryTableFieldRow fieldRow = new SummaryTableFieldRow(fd, fd2);
111 
112   		return fieldRow;
113   	} 
114 }