Coverage Report - org.kuali.student.lum.common.client.lo.OutlineManager
 
Classes in this File Line Coverage Branch Coverage Complexity
OutlineManager
0%
0/51
0%
0/18
1.706
OutlineManager$NodePanel
0%
0/42
0%
0/5
1.706
 
 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.HashMap;
 20  
 import java.util.Map;
 21  
 
 22  
 import org.kuali.student.common.assembly.data.QueryPath;
 23  
 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
 24  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
 25  
 import org.kuali.student.common.ui.client.theme.Theme;
 26  
 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
 27  
 
 28  
 import com.google.gwt.event.dom.client.MouseMoveHandler;
 29  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 30  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 31  
 import com.google.gwt.event.shared.HandlerRegistration;
 32  
 import com.google.gwt.user.client.DOM;
 33  
 import com.google.gwt.user.client.Event;
 34  
 import com.google.gwt.user.client.ui.HasValue;
 35  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 36  
 import com.google.gwt.user.client.ui.Image;
 37  
 import com.google.gwt.user.client.ui.Label;
 38  
 import com.google.gwt.user.client.ui.VerticalPanel;
 39  
 import com.google.gwt.user.client.ui.Widget;
 40  
 
 41  
 
 42  0
 public class OutlineManager extends VerticalSection implements HasValue<OutlineNodeModel> {
 43  
     OutlineNodeModel<?> outlineModel;
 44  
     String startOfPath;
 45  
     String endOfPath;
 46  
     String middleOfPath;
 47  
 
 48  0
     public OutlineManager(String pathStart, String pathMiddle, String pathEnd) {
 49  0
         startOfPath = pathStart;
 50  0
         middleOfPath = pathMiddle;
 51  0
         endOfPath = pathEnd;
 52  0
         }
 53  
 
 54  
         public void render() {
 55  0
         Map<Integer, Integer> levelIndexes = new HashMap<Integer, Integer>();
 56  0
         int currIndent = 0;
 57  
 
 58  0
         levelIndexes.put(0, -1); // first node increments the 0'th indent's index
 59  0
         OutlineNode[] outlineNodes = outlineModel.toOutlineNodes();
 60  0
         for (final OutlineNode aNode : outlineNodes) {
 61  0
                         NodePanel nodePanel = new NodePanel();
 62  0
                         nodePanel.setStyleName("KS-LONodePanel");
 63  0
                         nodePanel.setOutlineNode(aNode);
 64  0
             if (aNode.getIndentLevel() > currIndent) {
 65  0
                 currIndent = aNode.getIndentLevel();
 66  0
                 levelIndexes.put(currIndent, 0);
 67  0
             } else if (aNode.getIndentLevel() < currIndent) {
 68  0
                 currIndent = aNode.getIndentLevel();
 69  0
                 levelIndexes.put(currIndent, levelIndexes.get(currIndent) + 1);
 70  
             } else {
 71  0
                 levelIndexes.put(currIndent, levelIndexes.get(currIndent) + 1);
 72  
             }
 73  
 
 74  0
             addField(getFieldKey(currIndent, levelIndexes), null, nodePanel, null);
 75  
 
 76  0
                         showAllToolbar();
 77  
                 }
 78  0
         }
 79  
 
 80  
     private String getFieldKey(int currIndent, Map<Integer, Integer> levelIndexes) {
 81  0
         StringBuilder keyBuilder = new StringBuilder(startOfPath);
 82  
 
 83  0
         keyBuilder.append("/").append(levelIndexes.get(0)).append("/");
 84  0
         for (int idx = 1; idx <= currIndent; idx++) {
 85  0
             keyBuilder.append(middleOfPath).append("/").append(levelIndexes.get(idx)).append("/");
 86  
         }
 87  0
         keyBuilder.append(endOfPath);
 88  
 
 89  0
         return keyBuilder.toString();
 90  
     }
 91  
 
 92  
     private FieldDescriptor addField(String fieldKey, MessageKeyInfo messageKey, Widget widget, String parentPath) {
 93  0
         QueryPath path = QueryPath.concat(parentPath, fieldKey);
 94  
 
 95  0
         FieldDescriptor fd = new FieldDescriptor(path.toString(), messageKey, null);
 96  0
         if (widget != null) {
 97  0
             fd.setFieldWidget(widget);
 98  0
             fd.setHasHadFocus(true);
 99  
         }
 100  0
         this.addField(fd);
 101  0
         return fd;
 102  
     }
 103  
 
 104  
         public void closeAllToolbar(){
 105  0
         for (FieldDescriptor fd : this.getFields()) {
 106  0
             if (fd.getFieldWidget() instanceof NodePanel) {
 107  0
                 ((NodePanel) fd.getFieldWidget()).hideToolbar();
 108  
             }
 109  
         }
 110  0
         }
 111  
         
 112  
         public void showAllToolbar(){
 113  0
         for (FieldDescriptor fd : this.getFields()) {
 114  0
             if (fd.getFieldWidget() instanceof NodePanel) {
 115  0
                 ((NodePanel) fd.getFieldWidget()).showToolbar();
 116  
             }
 117  
         }
 118  0
         }
 119  
         
 120  
         class NodePanel extends  VerticalPanel{
 121  0
                 OutlineManagerToolbar toolbar = new OutlineManagerToolbar();
 122  0
                 HorizontalPanel emptySpacePanel = new HorizontalPanel();
 123  0
                 ArrayList<MouseMoveHandler> mouseMoveHandlerList = new ArrayList<MouseMoveHandler>();
 124  0
                 HorizontalPanel horitonalPanel = new HorizontalPanel();
 125  
         OutlineNode currentNode;
 126  0
                 NodePanel() {
 127  0
                         toolbar.setModel(outlineModel);
 128  0
                         horitonalPanel.setStyleName("KS-LOHNodePanel");
 129  0
                         super.sinkEvents(Event.ONMOUSEMOVE);
 130  0
                         super.sinkEvents(Event.ONMOUSEOUT);
 131  0
                         emptySpacePanel.setStyleName("KS-LOOutlineManagerToolbar");
 132  0
                         Image ieHack = Theme.INSTANCE.getCommonImages().getSpacer();
 133  0
                         emptySpacePanel.add(ieHack);
 134  0
                         super.insert(emptySpacePanel,0);
 135  0
                 }
 136  
 
 137  
         public void setOutlineNode(OutlineNode aNode) {
 138  0
                         currentNode = aNode;
 139  0
                         for (int i = 0; i < aNode.getIndentLevel(); i++) {
 140  0
                                 Label label = new Label();
 141  0
                                 label.setStyleName("KS-LONodeIndent");
 142  0
                                 horitonalPanel.add(label);
 143  
 
 144  
                                 // space for toolbar
 145  0
                                 label = new Label();
 146  0
                                 label.setStyleName("KS-LONodeIndentToolbar");
 147  0
                                 toolbar.insert(label, 0);
 148  
                         }
 149  0
                         Widget userWidget = (Widget) aNode.getUserObject();
 150  0
                         userWidget.setStyleName("KS-LOaNode");
 151  0
                         horitonalPanel.add(userWidget);
 152  
 
 153  0
                         add(horitonalPanel);
 154  0
                 }
 155  
 
 156  
                 public void addMouseMoveHandler(MouseMoveHandler handler) {
 157  0
                         mouseMoveHandlerList.add(handler);
 158  0
                 }
 159  
 
 160  
                 public void setToolbar(OutlineManagerToolbar t) {
 161  0
                         toolbar = t;
 162  0
                 }
 163  
                 public void showToolbar(){
 164  0
                         super.remove(emptySpacePanel);
 165  0
                         super.insert(toolbar, 0);
 166  0
                 }
 167  
                 public void hideToolbar(){
 168  0
                         super.remove(toolbar);
 169  0
                         super.insert(emptySpacePanel,0);
 170  0
                 }
 171  
                 @Override
 172  
         public void onBrowserEvent(Event event) {
 173  0
                         switch (DOM.eventGetType(event)) {
 174  
                         case Event.ONMOUSEMOVE: {
 175  0
                     outlineModel.setCurrentNode(currentNode);
 176  0
                                 break;
 177  
                         }
 178  
                         case Event.ONMOUSEOUT:
 179  
                                 break;
 180  
                         }
 181  0
                         super.onBrowserEvent(event);
 182  0
                 }
 183  
         }
 184  
         
 185  
         @Override
 186  
     public OutlineNodeModel getValue() {
 187  0
                 return outlineModel;
 188  
         }
 189  
 
 190  
         @Override
 191  
     public void setValue(OutlineNodeModel value) {
 192  0
                 outlineModel = value;                
 193  0
         }
 194  
 
 195  
         @Override
 196  
     public void setValue(OutlineNodeModel value, boolean fireEvents) {
 197  0
                 setValue(value);
 198  0
         }
 199  
 
 200  
         @Override
 201  
     public HandlerRegistration addValueChangeHandler(ValueChangeHandler<OutlineNodeModel> handler) {
 202  0
                 return addHandler(handler, ValueChangeEvent.getType());
 203  
         }
 204  
 }