Coverage Report - org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite
 
Classes in this File Line Coverage Branch Coverage Complexity
MultiplicityComposite
0%
0/54
0%
0/16
1.571
MultiplicityComposite$1
0%
0/6
N/A
1.571
MultiplicityComposite$StyleType
0%
0/1
N/A
1.571
 
 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.common.ui.client.configurable.mvc.multiplicity;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 import java.util.Set;
 21  
 
 22  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 23  
 import org.kuali.student.common.ui.client.mvc.Callback;
 24  
 
 25  
 import com.google.gwt.user.client.ui.Composite;
 26  
 import com.google.gwt.user.client.ui.FlowPanel;
 27  
 import com.google.gwt.user.client.ui.Widget;
 28  
 
 29  
 /**
 30  
  * A multiplicity composite allows a users to add/remove/display a list of 
 31  
  * item widgets. The item widget to be used must be provided by the createItem()
 32  
  * method, which can be a MultiplicitySection, another MultiplicityComposite, 
 33  
  * or any widget that supports the HasModelDTOValue interface.  
 34  
  * 
 35  
  * @author Kuali Student Team
 36  
  *
 37  
  */
 38  
 
 39  
 /**
 40  
  * @deprecated
 41  
  */
 42  
 public abstract class MultiplicityComposite extends Composite {
 43  
 
 44  0
     protected FlowPanel mainPanel = new FlowPanel();
 45  0
     protected FlowPanel itemsPanel = new FlowPanel();
 46  0
     protected boolean loaded = false;
 47  0
     protected int itemCount = 0;
 48  0
     protected int visualItemCount = 0;
 49  0
     protected int minEmptyItems = 0;
 50  0
     protected List<MultiplicityItem> items = new ArrayList<MultiplicityItem>();
 51  0
     protected List<MultiplicityItem> removed = new ArrayList<MultiplicityItem>();
 52  
     protected Set<Integer> itemKeys;
 53  0
     public static enum StyleType{TOP_LEVEL, SUB_LEVEL};
 54  
     protected StyleType style;
 55  0
     protected SectionTitle titleWidget = SectionTitle.generateEmptyTitle();
 56  
     
 57  0
     public MultiplicityComposite(StyleType style){
 58  0
             this.style = style;
 59  0
         initWidget(mainPanel);
 60  0
     }
 61  
         
 62  0
     protected Callback<MultiplicityItem> removeCallback = new Callback<MultiplicityItem>(){
 63  
 
 64  
         public void exec(MultiplicityItem itemToRemove) {
 65  
             //items.remove(itemToRemove);
 66  0
                 visualItemCount--;
 67  0
             itemToRemove.setDeleted(true);
 68  0
             removed.add(itemToRemove);
 69  0
             itemsPanel.remove(itemToRemove);
 70  0
         }
 71  
     };
 72  
         
 73  
     
 74  
     /**
 75  
      * This adds an item to the multiplicity composite by calling createItem.
 76  
      * 
 77  
      * @return
 78  
      */
 79  
         public MultiplicityItem addItem(){
 80  0
                 itemCount++;
 81  0
                 visualItemCount++;
 82  
             //itemCount = itemsPanel.getWidgetCount();
 83  0
             MultiplicityItem item = getItemDecorator(style);
 84  0
             Widget itemWidget = createItem();
 85  
             
 86  0
             if (item != null){
 87  0
                     item.setItemKey(new Integer(itemCount -1));
 88  0
                     item.setItemWidget(itemWidget);
 89  0
                     item.setRemoveCallback(removeCallback);
 90  0
             } else if (itemWidget instanceof MultiplicityItem){
 91  0
                     item = (MultiplicityItem)itemWidget;
 92  0
                     item.setItemKey(new Integer(itemCount -1));
 93  
             }
 94  0
             items.add(item);
 95  0
             item.redraw();
 96  0
             itemsPanel.add(item);
 97  
             
 98  0
             return item;
 99  
         }
 100  
         
 101  
         /**
 102  
          * This returns the index key for the model for the item currently being added by addItem
 103  
          * This is useful, if you need to refer to the index in the createItem method
 104  
          * @return
 105  
          */
 106  
         public int getAddItemKey(){
 107  0
                 return itemCount-1;
 108  
         }
 109  
         
 110  
         public void incrementItemKey(){
 111  0
                 itemCount++;
 112  0
         }
 113  
        
 114  
     public void onLoad() {
 115  0
         if (!loaded) {            
 116  
             //mainPanel.addStyleName("KS-Multiplicity-Composite");
 117  
                 //mainPanel.add(titleWidget);
 118  0
             mainPanel.add(itemsPanel);
 119  
            
 120  0
             Widget addWidget = generateAddWidget();
 121  0
             if (addWidget != null){
 122  0
                 mainPanel.add(addWidget);
 123  
             }
 124  
             
 125  0
             loaded = true;
 126  
         }
 127  
         
 128  0
         if (!loaded || itemCount == 0){
 129  0
             for (int i=0; i < minEmptyItems; i++){
 130  0
                     addItem();
 131  
             }                
 132  
         }
 133  0
     }
 134  
 
 135  
     public List<MultiplicityItem> getItems() {
 136  0
         return items;
 137  
     }
 138  
 
 139  
     public List<MultiplicityItem> getRemovedItems() {
 140  0
         return removed;
 141  
     }
 142  
 
 143  
     public void clear(){
 144  0
         itemsPanel.clear();
 145  0
         items.clear();
 146  0
         removed.clear();
 147  0
         itemCount = 0;
 148  0
     }
 149  
            
 150  
     public void redraw(){
 151  0
         for (MultiplicityItem item:items){
 152  0
             item.redraw();
 153  
         }
 154  0
     }
 155  
     
 156  
     /**
 157  
      * This method will set the number of minimum empty rows to display on initial display of widget.   
 158  
      */
 159  
     public void setMinEmptyItems(int minCount){
 160  0
             this.minEmptyItems = minCount;
 161  0
     }
 162  
 
 163  
     /**
 164  
      * Method used to get the item decorator for each multiplicity item 
 165  
      */
 166  
     public abstract MultiplicityItem getItemDecorator(StyleType style);
 167  
 
 168  
     
 169  
     /**
 170  
      * Method used to create a instance of the multiplicity item
 171  
      */
 172  
     public abstract Widget createItem();
 173  
 
 174  
     /**
 175  
      * Method used to get the add button to add additional multiplicity item
 176  
      * 
 177  
      * @return
 178  
      */
 179  
     public abstract Widget generateAddWidget();
 180  
 
 181  
 }