Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.sections.MultiplicitySection
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiplicitySection
0%
0/55
0%
0/21
2.444
MultiplicitySection$1
0%
0/1
N/A
2.444
 
 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  
  * User: hjohnson
 15  
  * Date: 2-Jun-2010
 16  
  * Time: 3:26:53 PM
 17  
  *
 18  
  */
 19  
 
 20  
 package org.kuali.student.common.ui.client.configurable.mvc.sections;
 21  
 
 22  
 import java.util.List;
 23  
 import java.util.Map;
 24  
 
 25  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityGroupBinding;
 27  
 import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityTableBinding;
 28  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration;
 29  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroup;
 30  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityTable;
 31  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeCondition;
 32  
 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeConditionFieldConfig;
 33  
 import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
 34  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.TableFieldLayout;
 35  
 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout;
 36  
 
 37  
 import com.google.gwt.user.client.ui.Widget;
 38  
 
 39  
 /**
 40  
  *
 41  
  * This class creates a section containing a multiplicity widget based on the supplied configuration
 42  
  *
 43  
  * Sample code to use this class :-
 44  
  * 
 45  
  *
 46  
  * {@code
 47  
     private void addVersionCodeFields(Section section) {
 48  
         QueryPath parentPath = QueryPath.concat(COURSE, QueryPath.getPathSeparator(), VERSIONS);
 49  
 
 50  
         MultiplicityConfiguration config = new MultiplicityConfiguration(MultiplicityConfiguration.MultiplicityType.GROUP,
 51  
                 MultiplicityConfiguration.StyleType.TOP_LEVEL_GROUP, getMetaData(parentPath.toString()));
 52  
         config.setAddItemLabel(getLabel(LUConstants.ADD_VERSION_CODE_LABEL_KEY));
 53  
         config.setItemLabel(getLabel(LUConstants.VERSION_CODE_LABEL_KEY));
 54  
         config.setUpdateable(true);
 55  
 
 56  
         FieldDescriptor parentFd = buildFieldDescriptor(COURSE + QueryPath.getPathSeparator() + VERSIONS, getLabel(LUConstants.VERSION_CODES_LABEL_KEY), null);
 57  
         config.setParentFd(parentFd);
 58  
 
 59  
         FieldDescriptor versionCode = buildFieldDescriptor(CreditCourseVersionsConstants.VERSION_CODE, LUConstants.VERSION_CODE_LABEL_KEY, parentPath.toString());
 60  
         FieldDescriptor versionTitle = buildFieldDescriptor(CreditCourseVersionsConstants.VERSION_TITLE, LUConstants.TITLE_LABEL_KEY, parentPath.toString());
 61  
         config.addField(versionCode);
 62  
         config.addField(versionTitle);
 63  
 
 64  
         MultiplicitySection ms = new MultiplicitySection(config);
 65  
         section.addSection(ms);
 66  
         }
 67  
  * }
 68  
  * 
 69  
  * TODO:
 70  
  *   - Create factory methods for each 'flavour' of multiplicity
 71  
  *   - Styling options for table, e.g. no grid lines
 72  
  *   - For read-only multiplicities, set contained widgets to be read only too
 73  
  *   
 74  
  */
 75  
     public class MultiplicitySection extends BaseSection {
 76  
 
 77  
     private MultiplicityConfiguration config;
 78  
     private Widget widget;
 79  
     private Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition;
 80  
     private List<String> deletionParentKeys;
 81  0
     public MultiplicitySection(MultiplicityConfiguration config) {
 82  0
         this.config = config;
 83  0
         initialize();
 84  0
     }
 85  
 
 86  
     public MultiplicitySection( 
 87  
             MultiplicityConfiguration config,
 88  
             Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition,
 89  0
             List<String> deletionParentKeys) {
 90  0
         this.config = config;
 91  0
         this.swappableFieldsDefinition = swappableFieldsDefinition;
 92  0
         this.deletionParentKeys = deletionParentKeys;
 93  0
         initialize();
 94  0
     }
 95  
     
 96  
 
 97  
     private void initialize() {
 98  0
         buildLayout();
 99  0
         this.add(layout);
 100  0
     }
 101  
 
 102  
     /**
 103  
      * Builds a suitable layout and adds the required multiplicity widget
 104  
      *
 105  
      * Builds a MultiplicityGroup for a grid layout or a MultiplicityTable
 106  
      * for a FlexTable layout . Sets the appropriate binding for the selected
 107  
      * widget
 108  
      *
 109  
      */
 110  
     private void buildLayout() {
 111  
 
 112  0
         if (config.getParentFd() == null) {
 113  0
             KSErrorDialog.show (new Throwable ("Multiplicity Parent FD cannot be null"));
 114  0
             return;
 115  
         }
 116  0
          switch (config.getLayoutType()) {
 117  
             case GROUP:
 118  0
                 layout = new VerticalFieldLayout(config.getTitle());
 119  0
                 if (config.getCustomMultiplicityGroup() == null) {
 120  0
                     widget = new MultiplicityGroup(config, swappableFieldsDefinition, deletionParentKeys);
 121  
                 } else {
 122  0
                     widget = config.getCustomMultiplicityGroup();
 123  
                 }
 124  0
                 config.getParentFd().setFieldWidget(widget);
 125  0
                 config.getParentFd().setWidgetBinding(new MultiplicityGroupBinding());
 126  0
                 this.addField(config.getParentFd());
 127  
 
 128  0
                 break;
 129  
             case TABLE:
 130  0
                 if (config.getFields().size() > 1) {
 131  0
                     KSErrorDialog.show (new Throwable ("MultiplicityTable can have only one row defined"));
 132  0
                     return;
 133  
                 }
 134  0
                 if (config.getTitle() == null) {
 135  0
                     layout = new TableFieldLayout();
 136  
                 }
 137  
                 else {
 138  0
                     layout = new TableFieldLayout(config.getTitle(), false);
 139  
                 }
 140  0
                 widget = new MultiplicityTable(config);
 141  0
                 config.getParentFd().setFieldWidget(widget);
 142  0
                 config.getParentFd().setWidgetBinding(new MultiplicityTableBinding());
 143  0
                 this.addField(config.getParentFd());
 144  
 
 145  0
                 break;
 146  
             default:
 147  0
                 layout = null;
 148  
             }
 149  0
         }
 150  
 
 151  
     public void setParentPath(String parentPath) {
 152  0
             if (widget instanceof MultiplicityGroup) {
 153  0
                     ((MultiplicityGroup)widget).setParentPath(parentPath);
 154  
             }
 155  
             else {
 156  0
             ((MultiplicityTable)widget).setParentPath(parentPath);
 157  
             }
 158  
             
 159  0
     }
 160  
 
 161  
     @Override
 162  
     public void resetFieldInteractionFlags() {
 163  0
             super.resetFieldInteractionFlags();
 164  0
                 if (widget instanceof MultiplicityGroup){
 165  0
                         ((MultiplicityGroup)widget).resetDirtyFlags();
 166  
                 }                
 167  0
     }
 168  
 
 169  
     @Override
 170  
         public void resetDirtyFlags() {
 171  0
                 super.resetDirtyFlags();
 172  0
                 if (widget instanceof MultiplicityGroup){
 173  0
                         ((MultiplicityGroup)widget).resetDirtyFlags();
 174  
                 }                
 175  0
         }
 176  
 
 177  
         @Override
 178  
         public boolean isDirty() {
 179  0
                 boolean isDirty = super.isDirty();
 180  0
                 if (!isDirty && widget instanceof MultiplicityGroup){
 181  0
                         isDirty = ((MultiplicityGroup)widget).isDirty();
 182  
                 }
 183  
                 
 184  0
                 return isDirty;
 185  
         }
 186  
         
 187  
         public MultiplicityConfiguration getConfig(){
 188  0
                 return config;
 189  
         }
 190  
 }