Coverage Report - org.kuali.student.lum.common.client.lo.OutlineManager
 
Classes in this File Line Coverage Branch Coverage Complexity
OutlineManager
0%
0/31
0%
0/10
1.533
OutlineManager$NodePanel
0%
0/42
0%
0/5
1.533
 
 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  
 
 20  
 import org.kuali.student.common.ui.client.theme.Theme;
 21  
 
 22  
 import com.google.gwt.event.dom.client.MouseMoveHandler;
 23  
 import com.google.gwt.event.logical.shared.ValueChangeEvent;
 24  
 import com.google.gwt.event.logical.shared.ValueChangeHandler;
 25  
 import com.google.gwt.event.shared.HandlerRegistration;
 26  
 import com.google.gwt.user.client.DOM;
 27  
 import com.google.gwt.user.client.Event;
 28  
 import com.google.gwt.user.client.ui.Composite;
 29  
 import com.google.gwt.user.client.ui.HasValue;
 30  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 31  
 import com.google.gwt.user.client.ui.Image;
 32  
 import com.google.gwt.user.client.ui.Label;
 33  
 import com.google.gwt.user.client.ui.VerticalPanel;
 34  
 import com.google.gwt.user.client.ui.Widget;
 35  
 
 36  
 
 37  0
 public class OutlineManager extends Composite implements HasValue<OutlineNodeModel>{
 38  
         OutlineNodeModel outlineModel;
 39  
 
 40  0
         VerticalPanel mainPanel = new VerticalPanel();
 41  
 
 42  0
         public OutlineManager() {
 43  0
                 super.initWidget(mainPanel);
 44  0
                 mainPanel.setStyleName("KS-LOMainPanel");
 45  0
         }
 46  
 
 47  
         public void render() {
 48  0
                 mainPanel.clear();
 49  0
                 OutlineNode[] outlineNodes = outlineModel.toOutlineNodes();
 50  0
                 for (final OutlineNode aNode : outlineNodes) {
 51  0
                         NodePanel nodePanel = new NodePanel();
 52  0
                         nodePanel.setStyleName("KS-LONodePanel");
 53  0
                         nodePanel.setOutlineNode(aNode);
 54  
 
 55  0
                         mainPanel.add(nodePanel);
 56  0
                         showAllToolbar();
 57  
                 }
 58  0
         }
 59  
         
 60  
         public void closeAllToolbar(){
 61  0
                 for(int i=0;i< mainPanel.getWidgetCount();i++){
 62  0
                         if(mainPanel.getWidget(i) instanceof NodePanel){
 63  0
                                 NodePanel p = (NodePanel)mainPanel.getWidget(i);
 64  0
                                 p.hideToolbar();
 65  
                         }
 66  
                 }
 67  0
         }
 68  
         
 69  
         public void showAllToolbar(){
 70  0
                 for(int i=0;i< mainPanel.getWidgetCount();i++){
 71  0
                         if(mainPanel.getWidget(i) instanceof NodePanel){
 72  0
                                 NodePanel p = (NodePanel)mainPanel.getWidget(i);
 73  0
                                 p.showToolbar();
 74  
                         }
 75  
                 }
 76  0
         }
 77  
         
 78  
         class NodePanel extends  VerticalPanel{
 79  0
                 OutlineManagerToolbar toolbar = new OutlineManagerToolbar();
 80  0
                 HorizontalPanel emptySpacePanel = new HorizontalPanel();
 81  0
                 ArrayList<MouseMoveHandler> mouseMoveHandlerList = new ArrayList<MouseMoveHandler>();
 82  0
                 HorizontalPanel horitonalPanel = new HorizontalPanel();
 83  
                 OutlineNode currentNode;
 84  0
                 NodePanel() {
 85  0
                         toolbar.setModel(outlineModel);
 86  0
                         horitonalPanel.setStyleName("KS-LOHNodePanel");
 87  0
                         super.sinkEvents(Event.ONMOUSEMOVE);
 88  0
                         super.sinkEvents(Event.ONMOUSEOUT);
 89  0
                         emptySpacePanel.setStyleName("KS-LOOutlineManagerToolbar");
 90  0
                         Image ieHack = Theme.INSTANCE.getCommonImages().getSpacer();
 91  0
                         emptySpacePanel.add(ieHack);
 92  0
                         super.insert(emptySpacePanel,0);
 93  0
                 }
 94  
 
 95  
                 public void setOutlineNode(OutlineNode aNode) {
 96  0
                         currentNode = aNode;
 97  0
                         for (int i = 0; i < aNode.getIndentLevel(); i++) {
 98  0
                                 Label label = new Label();
 99  0
                                 label.setStyleName("KS-LONodeIndent");
 100  0
                                 horitonalPanel.add(label);
 101  
 
 102  
                                 // space for toolbar
 103  0
                                 label = new Label();
 104  0
                                 label.setStyleName("KS-LONodeIndentToolbar");
 105  0
                                 toolbar.insert(label, 0);
 106  
                         }
 107  0
                         Widget userWidget = (Widget) aNode.getUserObject();
 108  0
                         userWidget.setStyleName("KS-LOaNode");
 109  0
                         horitonalPanel.add(userWidget);
 110  
 
 111  0
                         add(horitonalPanel);
 112  0
                 }
 113  
 
 114  
                 public void addMouseMoveHandler(MouseMoveHandler handler) {
 115  0
                         mouseMoveHandlerList.add(handler);
 116  0
                 }
 117  
 
 118  
                 public void setToolbar(OutlineManagerToolbar t) {
 119  0
                         toolbar = t;
 120  0
                 }
 121  
                 public void showToolbar(){
 122  0
                         super.remove(emptySpacePanel);
 123  0
                         super.insert(toolbar, 0);
 124  0
                 }
 125  
                 public void hideToolbar(){
 126  0
                         super.remove(toolbar);
 127  0
                         super.insert(emptySpacePanel,0);
 128  0
                 }
 129  
                 public void onBrowserEvent(Event event) {
 130  0
                         switch (DOM.eventGetType(event)) {
 131  
                         case Event.ONMOUSEMOVE: {
 132  
 //                                closeAllToolbar();
 133  
 
 134  
 
 135  0
                                 outlineModel.setCurrentNode(currentNode);
 136  
 
 137  
 //                                showToolbar();
 138  
 //                                toolbar.updateButtonStates();
 139  0
                                 break;
 140  
                         }
 141  
                         case Event.ONMOUSEOUT:
 142  
                                 break;
 143  
                         }
 144  0
                         super.onBrowserEvent(event);
 145  0
                 }
 146  
         }
 147  
         
 148  
         @Override
 149  
         public OutlineNodeModel getValue() {
 150  0
                 return outlineModel;
 151  
         }
 152  
 
 153  
         @Override
 154  
         public void setValue(OutlineNodeModel value) {
 155  0
                 outlineModel = value;                
 156  0
         }
 157  
 
 158  
         @Override
 159  
         public void setValue(OutlineNodeModel value, boolean fireEvents) {
 160  0
                 setValue(value);
 161  0
         }
 162  
 
 163  
         @Override
 164  
         public HandlerRegistration addValueChangeHandler(ValueChangeHandler<OutlineNodeModel> handler) {
 165  0
                 return addHandler(handler, ValueChangeEvent.getType());
 166  
         }
 167  
 }