Coverage Report - org.kuali.student.lum.common.client.lo.LOBuilder
 
Classes in this File Line Coverage Branch Coverage Complexity
LOBuilder
0%
0/33
N/A
1.32
LOBuilder$LearningObjectiveList
0%
0/66
0%
0/16
1.32
LOBuilder$LearningObjectiveList$1
0%
0/3
N/A
1.32
LOBuilder$LearningObjectiveList$2
0%
0/5
N/A
1.32
LOBuilder$LearningObjectiveList$3
0%
0/4
N/A
1.32
 
 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.lum.common.client.lo;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.ui.client.application.Application;
 22  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 23  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 24  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 25  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
 26  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
 27  
 import org.kuali.student.common.ui.client.widgets.search.KSPicker;
 28  
 import org.kuali.student.core.assembly.data.Metadata;
 29  
 import org.kuali.student.lum.common.client.lu.LUUIConstants;
 30  
 
 31  
 import com.google.gwt.event.dom.client.ChangeEvent;
 32  
 import com.google.gwt.event.dom.client.ChangeHandler;
 33  
 import com.google.gwt.event.dom.client.ClickEvent;
 34  
 import com.google.gwt.event.dom.client.ClickHandler;
 35  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 36  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 37  
 import com.google.gwt.event.shared.HandlerRegistration;
 38  
 import com.google.gwt.user.client.ui.Composite;
 39  
 import com.google.gwt.user.client.ui.HasValue;
 40  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 41  
 import com.google.gwt.user.client.ui.VerticalPanel;
 42  
 
 43  
 /**
 44  
  * This class manages the users interactions when building/updating Learning
 45  
  * Objectives within the context of managing CLUs. It allows the user to type in
 46  
  * LO text directly or execute a search and select one or more of the returned
 47  
  * LOs.
 48  
  * 
 49  
  * Users can then re-organize LOs on the screen including altering the sequence
 50  
  * and creating sub LOs
 51  
  * 
 52  
  * @author Kuali Student Team
 53  
  * 
 54  
  */
 55  0
 public class LOBuilder extends Composite implements        HasValue<List<OutlineNode<LOPicker>>> {
 56  
 
 57  
         private static String type;
 58  
         private static String state;
 59  
         private static String repoKey;
 60  
         private static String messageGroup;
 61  
 
 62  0
         VerticalPanel main = new VerticalPanel();
 63  0
         HorizontalPanel searchMainPanel = new HorizontalPanel();
 64  
         KSPicker searchWindow;
 65  0
         VerticalPanel loPanel = new VerticalPanel();
 66  
 
 67  
         LearningObjectiveList loList;
 68  
         KSLabel instructions;
 69  
 
 70  0
         protected LOBuilder() {
 71  0
         }
 72  
 
 73  
         public LOBuilder(String luType, String luState, String luGroup,        String loRepoKey, final Metadata metadata) {
 74  0
                 super();
 75  0
                 initWidget(main);
 76  
 
 77  0
                 type = luType;
 78  0
                 state = luState;
 79  0
                 repoKey = loRepoKey;
 80  0
                 messageGroup = luGroup;
 81  
 
 82  
                 // searchLink = new KSLabel(getLabel(LUConstants.LO_SEARCH_LINK_KEY));
 83  
                 // picker needs to handle labels like this
 84  
                 /*
 85  
                  * TODO - KSLUM-527: temporally comment out link to LO Search for M9.
 86  
                  * Need to be fixed later.
 87  
                  */
 88  
                 /*
 89  
                  * if(metadata.getInitialLookup() != null){ searchWindow = new
 90  
                  * KSPicker(metadata.getInitialLookup(),
 91  
                  * metadata.getAdditionalLookups());
 92  
                  * searchWindow.addValuesChangeHandler(new
 93  
                  * ValueChangeHandler<List<String>>(){ public void
 94  
                  * onValueChange(ValueChangeEvent<List<String>> event) { List<String>
 95  
                  * selection = (List<String>)event.getValue();
 96  
                  * loList.addSelectedLOs(selection); } });
 97  
                  * searchMainPanel.add(searchWindow); }
 98  
                  */
 99  
 
 100  
                 // adding search icon - should this be part of search link? coordinate
 101  
                 // with UX
 102  
                 // searchImage.addClickHandler(searchClickHandler);
 103  
                 // Image searchImage = Theme.INSTANCE.getCommonImages().getSearchIcon();
 104  
                 // searchLinkPanel.add(searchImage);
 105  0
                 instructions = new KSLabel(getLabel(LUUIConstants.LO_INSTRUCTIONS_KEY));
 106  
 
 107  0
                 loList = new LearningObjectiveList();
 108  0
                 loPanel.add(loList);
 109  
 
 110  
                 // searchImage.addStyleName("KS-LOBuilder-Search-Image");
 111  0
                 searchMainPanel.addStyleName("KS-LOBuilder-Search-Panel");
 112  0
                 loPanel.addStyleName("KS-LOBuilder-LO-Panel");
 113  0
                 instructions.addStyleName("KS-LOBuilder-Instructions");
 114  
 
 115  0
                 main.add(searchMainPanel);
 116  0
                 main.add(instructions);
 117  0
                 main.add(loPanel);
 118  0
         }
 119  
 
 120  
         /**
 121  
          * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object,
 122  
          *      boolean)
 123  
          */
 124  
         @Override
 125  
         public void setValue(List<OutlineNode<LOPicker>> value, boolean fireEvents) {
 126  0
                 setValue(value);
 127  0
         }
 128  
 
 129  
         /**
 130  
          * @see com.google.gwt.user.client.ui.HasValue#setValue(java.lang.Object)
 131  
          */
 132  
         @Override
 133  
         public void setValue(List<OutlineNode<LOPicker>> data) {
 134  0
                 loList.setValue(data);
 135  0
         }
 136  
 
 137  
         /**
 138  
          * @see com.google.gwt.user.client.ui.HasValue#getValue()
 139  
          */
 140  
         @Override
 141  
         public List<OutlineNode<LOPicker>> getValue() {
 142  0
                 return loList.getValue();
 143  
         }
 144  
 
 145  
         /**
 146  
          * @see com.google.gwt.event.logical.shared.HasValueChangeHandlers#addValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler)
 147  
          */
 148  
         @Override
 149  
         public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<OutlineNode<LOPicker>>> handler) {
 150  0
                 return loList.addValueChangeHandler(handler);
 151  
         }
 152  
 
 153  
         private static String getLabel(String labelKey) {
 154  0
                 return Application.getApplicationContext().getUILabel(messageGroup,
 155  
                                 type, state, labelKey);
 156  
         }
 157  
 
 158  
         /**
 159  
          * @return the type
 160  
          */
 161  
         public static String getType() {
 162  0
                 return type;
 163  
         }
 164  
 
 165  
         /**
 166  
          * @return the state
 167  
          */
 168  
         public static String getState() {
 169  0
                 return state;
 170  
         }
 171  
 
 172  
         public static String getRepoKey() {
 173  0
                 return repoKey;
 174  
         }
 175  
 
 176  
         /**
 177  
          * @return the messageGroup
 178  
          */
 179  
         public static String getMessageGroup() {
 180  0
                 return messageGroup;
 181  
         }
 182  
 
 183  0
         public static class LearningObjectiveList extends Composite implements HasValue<List<OutlineNode<LOPicker>>> {
 184  0
                 OutlineNodeModel<LOPicker> outlineModel = new OutlineNodeModel<LOPicker>();
 185  0
                 OutlineManager outlineComposite = new OutlineManager();
 186  0
                 VerticalPanel mainPanel = new VerticalPanel();
 187  
                 
 188  0
                 SelectionChangeHandler loPickerChangeHandler = new SelectionChangeHandler(){
 189  
                         public void onSelectionChange(SelectionChangeEvent event) {
 190  0
                                 fireChangeEvent();
 191  0
                         }                        
 192  
                 };
 193  
                 
 194  0
                 public LearningObjectiveList() {
 195  0
                         mainPanel.add(outlineComposite);
 196  0
                         KSButton addnew = new KSButton("Add item",ButtonStyle.SECONDARY, new ClickHandler() {
 197  
                                 public void onClick(ClickEvent event) {
 198  0
                                         setValue(getValue());
 199  0
                                         appendLO("");
 200  0
                                         reDraw();
 201  0
                                 }
 202  
                         });
 203  
                         
 204  0
                         addnew.addStyleName("KS-LOBuilder-New");
 205  0
                         mainPanel.add(addnew);
 206  0
                         super.initWidget(mainPanel);
 207  
 
 208  0
                         outlineComposite.setValue(outlineModel);
 209  0
                         outlineModel.addChangeHandler(new ChangeHandler() {
 210  
                                 public void onChange(ChangeEvent event) {
 211  0
                                         outlineComposite.render();
 212  0
                                         fireChangeEvent();
 213  0
                                 }
 214  
                         });
 215  
 
 216  0
                         initEmptyLoList();
 217  0
                 }
 218  
 
 219  
                 protected void initEmptyLoList(){
 220  0
                         List<String> list = new ArrayList<String>();
 221  0
                         list.add("");
 222  0
                         list.add("");
 223  0
                         list.add("");
 224  0
                         list.add("");
 225  0
                         list.add("");
 226  0
                         addSelectedLOs(list);                        
 227  0
                 }
 228  
                 
 229  
                 protected void fireChangeEvent(){
 230  0
                         ValueChangeEvent.fire(this, outlineModel.getOutlineNodes());
 231  0
                 }
 232  
                 
 233  
                 public List<OutlineNode<LOPicker>> getValue() {
 234  0
                         return outlineModel.getOutlineNodes();
 235  
                 }
 236  
 
 237  
                 public void setValue(List<OutlineNode<LOPicker>> value) {
 238  0
                         outlineModel.clearNodes();
 239  0
                         outlineModel.getOutlineNodes().addAll(value);
 240  
 
 241  0
                         if (value == null || value.isEmpty()){
 242  0
                                 initEmptyLoList();
 243  
                         } else {
 244  
                                 //Add selection change handler to LOPickers if not set
 245  0
                                 for (OutlineNode<LOPicker> node:value){
 246  0
                                         LOPicker picker = node.getUserObject();
 247  0
                                         if (!picker.hasChangeHandler()){
 248  0
                                                 picker.addSelectionChangeHandler(loPickerChangeHandler);
 249  
                                         }
 250  0
                                 }
 251  
                                 
 252  0
                                 reDraw();
 253  
                         }
 254  0
                 }
 255  
 
 256  
                 private void appendLO(String loValue) {
 257  0
                         OutlineNode<LOPicker> aNode = new OutlineNode<LOPicker>();
 258  0
                         LOPicker newPicker = new LOPicker(messageGroup, type, state,
 259  
                                         repoKey);
 260  
 
 261  0
                         newPicker.addSelectionChangeHandler(loPickerChangeHandler);
 262  0
                         newPicker.setLOText(loValue);
 263  0
                         aNode.setUserObject(newPicker);
 264  0
                         aNode.setModel(outlineModel);
 265  
 
 266  0
                         outlineModel.addOutlineNode(aNode);
 267  0
                 }
 268  
 
 269  
                 // add one or more description by going through existing LO box and
 270  
                 // populating the empty ones
 271  
                 // if not enough empty LO boxes then add new ones
 272  
                 public void addSelectedLOs(List<String> loDescription) {
 273  
 
 274  0
                         List<OutlineNode<LOPicker>> existingLOs = outlineModel
 275  
                                         .getOutlineNodes();
 276  
 
 277  0
                         int ix = existingLOs.size();
 278  0
                         for (String strValue : loDescription) {
 279  
 
 280  0
                                 boolean foundEmptyBox = false;
 281  0
                                 while (ix > 0) {
 282  0
                                         ix--;
 283  0
                                         if (existingLOs.get(ix).getUserObject().getLOText().trim()
 284  
                                                         .length() == 0) {
 285  0
                                                 existingLOs.get(ix).getUserObject().setLOText(strValue);
 286  0
                                                 foundEmptyBox = true;
 287  0
                                                 break;
 288  
                                         }
 289  
                                 }
 290  
 
 291  
                                 // we didn't find empty LO box so add a new one
 292  0
                                 if (foundEmptyBox == false) {
 293  0
                                         appendLO(strValue);
 294  
                                 }
 295  0
                         }
 296  0
                         reDraw();
 297  0
                 }
 298  
 
 299  
                 private void reDraw() {
 300  0
                         outlineComposite.render();
 301  0
                 }
 302  
 
 303  
                 public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<OutlineNode<LOPicker>>> handler) {
 304  0
                         return addHandler(handler, ValueChangeEvent.getType());
 305  
                 }
 306  
                 
 307  
                 public SelectionChangeHandler getChangeHandlerForLOPicker(){
 308  0
                         return loPickerChangeHandler;
 309  
                 }
 310  
 
 311  
                 @Override
 312  
                 public void setValue(List<OutlineNode<LOPicker>> value,
 313  
                                 boolean fireEvents) {
 314  0
                         setValue(value);
 315  0
                 }
 316  
         }
 317  
 }