Coverage Report - org.kuali.student.core.organization.ui.client.mvc.view.CommonConfigurer
 
Classes in this File Line Coverage Branch Coverage Complexity
CommonConfigurer
0%
0/67
0%
0/20
2.391
CommonConfigurer$CommonMultiplicityList
0%
0/76
0%
0/40
2.391
CommonConfigurer$CommonMultiplicityList$1
0%
0/3
N/A
2.391
CommonConfigurer$SectionsEnum
0%
0/2
N/A
2.391
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.core.organization.ui.client.mvc.view;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import org.kuali.student.common.ui.client.application.Application;
 21  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.layouts.ConfigurableLayout;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityItem;
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.UpdatableMultiplicityComposite;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.GroupSection;
 27  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.RemovableItemWithHeader;
 28  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.Section;
 29  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
 30  
 import org.kuali.student.common.ui.client.configurable.mvc.views.SectionView;
 31  
 import org.kuali.student.common.ui.client.configurable.mvc.views.VerticalSectionView;
 32  
 import org.kuali.student.common.ui.client.mvc.DataModelDefinition;
 33  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 34  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 35  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 36  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 37  
 import org.kuali.student.core.assembly.data.Metadata;
 38  
 import org.kuali.student.core.assembly.data.QueryPath;
 39  
 import org.kuali.student.core.organization.ui.client.mvc.model.FieldInfo;
 40  
 import org.kuali.student.core.organization.ui.client.mvc.model.MultipleFieldInfoImpl;
 41  
 import org.kuali.student.core.organization.ui.client.mvc.model.SectionConfigInfo;
 42  
 import org.kuali.student.core.organization.ui.client.mvc.model.SectionViewInfo;
 43  
 
 44  
 import com.google.gwt.core.client.GWT;
 45  
 import com.google.gwt.event.dom.client.ClickEvent;
 46  
 import com.google.gwt.event.dom.client.ClickHandler;
 47  
 import com.google.gwt.user.client.DOM;
 48  
 import com.google.gwt.user.client.ui.Widget;
 49  
 
 50  0
 public class CommonConfigurer {
 51  
 
 52  
 
 53  
     private DataModelDefinition modelDefinition;
 54  
     private SectionConfigInfo sectionConfigInfo;
 55  0
     private static String groupName = "org";
 56  0
     private boolean WITH_DIVIDER = true;
 57  
     public static final String ORG_PROPOSAL_MODEL = "orgProposalModel";
 58  
     public static final String ORG_SEARCH = "searchOrgs";
 59  
     public PositionTable positionTable;
 60  
     public OrgPersonRelationTypePicker personRelationPicker;
 61  
     private String orgId;
 62  
     public static final String ORG_INFO_PATH                  = "orgInfo";
 63  
     public static final String POSITION_PATH                  = "OrgPositionRestrictionInfo";
 64  
     public static final String PERSON_PATH                  = "orgPersonRelationInfo";
 65  
     public static final String ORGORG_PATH                  = "orgOrgRelationInfo";
 66  
 
 67  0
     public enum SectionsEnum {
 68  0
         ORG_INFO, ORG_RELATIONS, POSITIONS, PERSON_RELATIONS,BROWSE_TREE,BROWSE_LIST,BROWSE_CHART,BROWSE_NAME,SEARCH
 69  
     }
 70  
 
 71  
     public void setModelDefinition(DataModelDefinition modelDefinition){
 72  0
         this.modelDefinition = modelDefinition;
 73  0
     }
 74  
 
 75  
     public void setSectionConfigInfo(SectionConfigInfo sectionConfigInfo){
 76  0
         this.sectionConfigInfo=sectionConfigInfo;
 77  0
     }
 78  
 
 79  
     public void setOrgId(String orgId){
 80  0
         this.orgId=orgId;
 81  
 
 82  0
     }
 83  
 
 84  
     public String getOrgId(){
 85  0
         return orgId;
 86  
     }
 87  
 
 88  
     /**
 89  
      * The method will create all the sections as defined in the screen config XML
 90  
      * @param layout
 91  
      */
 92  
     public void configureOrgProposal(ConfigurableLayout layout){
 93  
         List<SectionViewInfo> sectionViewInfoList;
 94  0
         sectionViewInfoList = sectionConfigInfo.getSectionViewInfoList();
 95  0
         for(SectionViewInfo sectionViewInfo:sectionViewInfoList){
 96  0
           layout.addSection(new String[] {sectionViewInfo.getTab(),sectionViewInfo.getMenu()}, generateSection(sectionViewInfo));
 97  
 //          layout.addStartSection(generateSection(sectionViewInfo));
 98  
         }
 99  
 
 100  
 //        layout.addSection(new String[] {"Create", "Create"}, generateOrgCreateSection());
 101  0
     }
 102  
 
 103  
     /**
 104  
      * The method will parse through the section parent tag and read all the field declarations.
 105  
      * @param sectionViewInfo
 106  
      * @return
 107  
      */
 108  
     private SectionView generateSection(SectionViewInfo sectionViewInfo){
 109  
         try {
 110  0
         VerticalSectionView section = initSectionView(SectionsEnum.valueOf(sectionViewInfo.getSectionEnum()), sectionViewInfo.getSectionName());
 111  
 //        VerticalSectionView section = initSectionView(SectionsEnum.ORG_INFO, sectionViewInfo.getSectionName());
 112  
 //        VerticalSection orgInfo = initSection(getH3Title(sectionViewInfo.getSectionName()), WITH_DIVIDER);   
 113  0
         VerticalSection orgInfo = new VerticalSection();
 114  
         //orgInfo.setSectionTitle(getH3Title(""));
 115  0
         groupName="org";
 116  0
         List<FieldInfo> fieldList = sectionViewInfo.getfields();
 117  0
         if (fieldList != null) {
 118  0
                 for (FieldInfo field : fieldList) {
 119  
                     // Parse through all the field declarations and add specific behaviors for non text fields.
 120  0
                     if (field instanceof MultipleFieldInfoImpl) {
 121  0
                         List<FieldInfo> fieldMultiList = ((MultipleFieldInfoImpl) field).getFields();
 122  
 
 123  
                         // Add multiplicity widget
 124  0
                         addField(orgInfo, field.getKey(), generateMessageInfo(field.getLabel()), new CommonMultiplicityList("Add", " ", fieldMultiList, field.getKey()));
 125  
 
 126  0
                     } else {
 127  
                         // Initialize the Widget picker with specific widgets like pickers, drop-downs, etc
 128  0
                         Widget widget = null;
 129  0
                         if (field.getWidget() != null) {
 130  0
                             if (field.getWidget().equals("OrgLocateTree")) {
 131  0
                                 widget = new OrgTree(section);
 132  
                             }
 133  0
                             if (field.getWidget().equals("PositionTable")) {
 134  0
                                 positionTable = new PositionTable();
 135  0
                                 DOM.setElementAttribute(positionTable.getElement(), "id", "orgPositionsTable");
 136  0
                                 widget = positionTable;
 137  
                             }
 138  
 
 139  
                         }
 140  0
                         addField(orgInfo, field.getKey(), generateMessageInfo(field.getLabel()), widget);
 141  0
                     }
 142  
                 }
 143  
             }
 144  
 //        for(MultipleField multipleField: fieldList){
 145  
 //
 146  
 //        }
 147  0
         orgInfo.addStyleName("KS-CORE-Section-Divider");
 148  
         // courseNumber.addSection(crossListed);
 149  0
         section.addSection(orgInfo);
 150  
         //section.addSection(orgInfo);
 151  0
         return section;
 152  
         }
 153  0
         catch(Exception e){
 154  0
             GWT.log("Error in config", e);
 155  
         }
 156  0
         return null;
 157  
     }
 158  
     
 159  
     protected static MessageKeyInfo generateMessageInfo(String labelKey) {
 160  0
         return new MessageKeyInfo(groupName, "org", "draft", labelKey);
 161  
     }
 162  
     
 163  
     private static VerticalSection initSection(SectionTitle title, boolean withDivider) {
 164  0
         VerticalSection section = new VerticalSection();
 165  0
         if (title !=  null) {
 166  0
           section.getLayout().setLayoutTitle(title);
 167  
         }
 168  0
         section.addStyleName("KS-CORE-Section");
 169  0
         if (withDivider)
 170  0
             section.addStyleName("KS-CORE-Section-Divider");
 171  0
         return section;
 172  
     }
 173  
 
 174  
     private static VerticalSectionView initSectionView (Enum<?> viewEnum, String labelKey) {
 175  0
         VerticalSectionView section = new VerticalSectionView(viewEnum, labelKey, ORG_PROPOSAL_MODEL);
 176  0
         section.addStyleName("KS-CORE-Section");
 177  0
         section.getLayout().setLayoutTitle(getH1Title(labelKey));
 178  0
         return section;
 179  
     }
 180  
     private static SectionTitle getH1Title(String labelKey) {
 181  0
         return SectionTitle.generateH1Title(getLabel(labelKey));
 182  
     }
 183  
     private static SectionTitle getH3Title(String labelKey) {
 184  0
         return SectionTitle.generateH3Title(getLabel(labelKey));
 185  
     }
 186  
     public static String getLabel(String labelKey) {
 187  0
         return Application.getApplicationContext().getUILabel(groupName, "org", "draft", labelKey);
 188  
     }
 189  
     
 190  
     
 191  
     // TODO - when DOL is pushed farther down into LOBuilder,
 192  
     // revert these 5 methods to returning void again.
 193  
     protected FieldDescriptor addField(Section section, String fieldKey) {
 194  0
             return addField(section, fieldKey, null, null, null);
 195  
     }    
 196  
     protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey) {
 197  0
             return addField(section, fieldKey, messageKey, null, null);
 198  
     }
 199  
     protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget) {
 200  0
             return addField(section, fieldKey, messageKey, widget, null);
 201  
     }
 202  
     protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, String parentPath) {
 203  0
         return addField(section, fieldKey, messageKey, null, parentPath);
 204  
     }
 205  
     protected FieldDescriptor addField(Section section, String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) {
 206  0
         QueryPath path = QueryPath.concat(parentPath, fieldKey);
 207  0
             Metadata meta = modelDefinition.getMetadata(path);
 208  
 
 209  0
             FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, meta);
 210  0
             if (widget != null) {
 211  0
                     fd.setFieldWidget(widget);
 212  
             }
 213  0
             section.addField(fd);
 214  0
             return fd;
 215  
     }
 216  
 
 217  
     /**
 218  
      *
 219  
      * This class will define the common implementation for adding a multiplicity widget.
 220  
      * It initializes a list of fieldInfo that is read from the screen config xml.
 221  
      * The parent query path is also passed.
 222  
      * @author Kuali Student Team
 223  
      *
 224  
      */
 225  0
     public class CommonMultiplicityList extends UpdatableMultiplicityComposite {
 226  
         private  List<FieldInfo> fieldList;
 227  
         private String parentPath;
 228  
 
 229  
         public CommonMultiplicityList(String addItemLabel, String itemLabel,List<FieldInfo> fieldList,String parentPath)
 230  0
         {
 231  0
                 super(StyleType.TOP_LEVEL);
 232  0
             setAddItemLabel(getLabel(addItemLabel));
 233  0
             setItemLabel(getLabel(itemLabel));
 234  0
             this.fieldList=fieldList;
 235  0
             this.parentPath=parentPath;
 236  0
         }
 237  
 
 238  
         @Override
 239  
         public MultiplicityItem getItemDecorator(StyleType style) {
 240  0
             RemovableItemWithHeader item = new RemovableItemWithHeader(style);
 241  0
             item.setItemLabel(itemLabel);
 242  
 
 243  0
             if(parentPath.equals(POSITION_PATH)){
 244  0
                 QueryPath qPath = QueryPath.concat(null, POSITION_PATH);
 245  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 246  0
                 if(!meta.isCanEdit()){
 247  0
                     item.isReadOnly(true);
 248  
                 }
 249  
                 else{
 250  0
                     item.isReadOnly(false);
 251  
                 }
 252  
             }
 253  0
             if(parentPath.equals(ORGORG_PATH)){
 254  0
                 QueryPath qPath = QueryPath.concat(null, ORGORG_PATH);
 255  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 256  0
                 if(!meta.isCanEdit()){
 257  0
                     item.isReadOnly(true);
 258  
                 }
 259  
                 else{
 260  0
                     item.isReadOnly(false);
 261  
                 }
 262  
             }
 263  0
             if(parentPath.equals(PERSON_PATH)){
 264  0
                 QueryPath qPath = QueryPath.concat(null, PERSON_PATH);
 265  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 266  0
                 if(!meta.isCanEdit()){
 267  0
                     item.isReadOnly(true);
 268  
                 }
 269  
                 else{
 270  0
                     item.isReadOnly(false);
 271  
                 }
 272  
             }
 273  0
             return item;
 274  
         }
 275  
 
 276  
         public Widget generateAddWidget() {
 277  
             //Label addWidget =  new Label(addItemLabel);
 278  
             //addWidget.addStyleName("KS-Multiplicity-Link-Label");
 279  
             KSButton addWidget;
 280  0
             if(style == StyleType.TOP_LEVEL){
 281  0
                 addWidget = new KSButton(addItemLabel, ButtonStyle.FORM_LARGE);
 282  
             }
 283  
             else{
 284  0
                 addWidget = new KSButton(addItemLabel, ButtonStyle.FORM_SMALL);
 285  
             }
 286  0
             addWidget.addClickHandler(new ClickHandler(){
 287  
                 public void onClick(ClickEvent event) {
 288  0
                     addItem();
 289  0
                 }
 290  
             });
 291  
 
 292  0
             if(parentPath.equals(POSITION_PATH)){
 293  0
                 QueryPath qPath = QueryPath.concat(null, POSITION_PATH);
 294  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 295  0
                 if(!meta.isCanEdit()){
 296  0
                     addWidget.setEnabled(false);
 297  
                 }
 298  
                 else{
 299  0
                     addWidget.setEnabled(true);
 300  
                 }
 301  
             }
 302  0
             if(parentPath.equals(ORGORG_PATH)){
 303  0
                 QueryPath qPath = QueryPath.concat(null, ORGORG_PATH);
 304  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 305  0
                 if(!meta.isCanEdit()){
 306  0
                     addWidget.setEnabled(false);
 307  
                 }
 308  
                 else{
 309  0
                     addWidget.setEnabled(true);
 310  
                 }
 311  
             }
 312  0
             if(parentPath.equals(PERSON_PATH)){
 313  0
                 QueryPath qPath = QueryPath.concat(null, PERSON_PATH);
 314  0
                 Metadata meta = modelDefinition.getMetadata(qPath);
 315  0
                 if(!meta.isCanEdit()){
 316  0
                     addWidget.setEnabled(false);
 317  
                 }
 318  
                 else{
 319  0
                     addWidget.setEnabled(true);
 320  
                 }
 321  
             }
 322  0
             return addWidget;
 323  
         }
 324  
 
 325  
         private boolean readPermission(String path){
 326  0
             QueryPath qPath = QueryPath.concat(null, path);
 327  0
             Metadata meta = modelDefinition.getMetadata(qPath);
 328  0
             return meta.isCanEdit();
 329  
         }
 330  
         @Override
 331  
         public Widget createItem() {
 332  0
             String path = QueryPath.concat(parentPath, String.valueOf(itemCount-1)).toString();
 333  0
             GroupSection ns = new GroupSection();
 334  
             //ns.setCurrentFieldLabelType(FieldLabelType.LABEL_TOP);
 335  0
             for (FieldInfo field : fieldList) {
 336  
 
 337  
 //                if(path.equals("orgPersonRelationInfo" + "/" + String.valueOf(itemCount-1).toString())){
 338  
 //                    if(field.getKey().equals("type")){
 339  
 //                        QueryPath metaPath = QueryPath.concat(null, "orgPersonRelationInfo" + "/" + "*" + "/" + "type");
 340  
 //                        Metadata meta = modelDefinition.getOldMetadata(metaPath);
 341  
 //                        LookupMetadata lookup = meta.getInitialLookup();
 342  
 //                        LookupParamMetadata parammeta = lookup.getParams().get(0);
 343  
 //                        parammeta.setDefaultValueString(orgId);
 344  
 //                    }
 345  
 //                }
 346  0
                 Widget widget = null;
 347  
                 //Define specific widgets as they are defined in the xml config.
 348  0
                 if (field.getWidget() != null) {
 349  0
                     QueryPath qPath = QueryPath.concat(path, field.getKey());
 350  0
                     Metadata meta = modelDefinition.getMetadata(qPath);
 351  0
                     if (field.getWidget().equals("OrgRelationTypePicker")) {
 352  
 
 353  0
                         if(meta.isCanEdit()){
 354  0
                             widget = new OrgRelationTypePicker();
 355  
 
 356  
                         }
 357  
                         else{
 358  
 //                            final OrgRelationTypePicker picker = new OrgRelationTypePicker();
 359  
 //                            picker.onLoad();
 360  
 //                            ListItems list = picker.getListItems();
 361  
 //                            if(list==null){
 362  
 //                                picker.addWidgetReadyCallback(new Callback<Widget>() {
 363  
 //                                    @Override
 364  
 //                                    public void exec(Widget widget) {
 365  
 //                                        final ListItems searchResults = picker.getListItems();
 366  
 //                                        String value =searchResults.getItemText("REV_kuali.org.CurriculumChild");
 367  
 //
 368  
 //                                    }
 369  
 //                                });
 370  
 //
 371  
 //                            }
 372  0
                             widget = new KSLabel();
 373  
                         }
 374  
 
 375  
                     }
 376  
 
 377  0
                     if (field.getWidget().equals("OrgPositionTypePicker")) {
 378  
 
 379  0
                         widget = new OrgPositionTypePicker();
 380  
                     }
 381  0
                     if (field.getWidget().equals("OrgPersonRelationTypePicker")) {
 382  0
                         if(meta.isCanEdit()){
 383  0
                         personRelationPicker = new OrgPersonRelationTypePicker();
 384  0
                         personRelationPicker.setOrgId(orgId);
 385  0
                         widget = personRelationPicker;
 386  
                         }
 387  
                         else{
 388  0
                             widget = new KSLabel();
 389  
                         }
 390  
 
 391  
                     }
 392  
 
 393  
 
 394  
                 }
 395  0
                 addField(ns, field.getKey(), generateMessageInfo(field.getLabel()),widget,path);    
 396  0
             }
 397  0
             return ns;
 398  
         }
 399  
     }
 400  
 
 401  
 
 402  
 }