Coverage Report - org.kuali.student.core.statement.ui.client.widgets.table.NodeWidget
 
Classes in this File Line Coverage Branch Coverage Complexity
NodeWidget
0%
0/38
0%
0/12
1.75
NodeWidget$1
0%
0/5
0%
0/2
1.75
 
 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.core.statement.ui.client.widgets.table;
 17  
 
 18  
 import org.kuali.student.core.statement.ui.client.widgets.rules.Token;
 19  
 
 20  
 import com.google.gwt.core.client.GWT;
 21  
 import com.google.gwt.dom.client.EventTarget;
 22  
 import com.google.gwt.dom.client.NativeEvent;
 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.Element;
 28  
 import com.google.gwt.user.client.Event;
 29  
 import com.google.gwt.user.client.Event.NativePreviewEvent;
 30  
 import com.google.gwt.user.client.Event.NativePreviewHandler;
 31  
 import com.google.gwt.user.client.ui.CheckBox;
 32  
 import com.google.gwt.user.client.ui.HTML;
 33  
 import com.google.gwt.user.client.ui.HasVerticalAlignment;
 34  
 import com.google.gwt.user.client.ui.SimplePanel;
 35  
 import com.google.gwt.user.client.ui.VerticalPanel;
 36  
 
 37  
 public class NodeWidget extends SimplePanel implements NativePreviewHandler {
 38  
     private Node node;
 39  0
     HTML html = new HTML();
 40  0
     CheckBox checkBox = new CheckBox();
 41  
     HandlerRegistration handlerRegistration;
 42  0
     VerticalPanel verticalPanel = new VerticalPanel();
 43  0
     public NodeWidget(Node<Token> n) {
 44  0
         Event.addNativePreviewHandler(this);
 45  
         
 46  0
         node = n;
 47  0
         super.setWidth("100%");
 48  0
         super.setHeight("100%");
 49  0
         setNode(n);
 50  
 
 51  
 //        checkBox.addBlurHandler(new BlurHandler() {
 52  
   //          @Override
 53  
     //        public void onBlur(BlurEvent event) {
 54  
       //          DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffffff");
 55  
         //    }
 56  
 //        });
 57  
   //      checkBox.addFocusHandler(new FocusHandler() {
 58  
     //        @Override
 59  
       //      public void onFocus(FocusEvent event) {
 60  
         //        DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffeeff");
 61  
           //  }
 62  
 //        });
 63  
        
 64  
   //      super.addBlurHandler(new BlurHandler() {
 65  
     //        @Override
 66  
       //      public void onBlur(BlurEvent event) {
 67  
         //        DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffffff");
 68  
           //  }
 69  
 //        });
 70  
   //      super.addFocusHandler(new FocusHandler() {
 71  
     //        @Override
 72  
       //      public void onFocus(FocusEvent event) {
 73  
         //        DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffeeff");
 74  
           //  }
 75  
 //        });
 76  
 //        super.addClickHandler(new ClickHandler() {
 77  
   //          @Override
 78  
     //        public void onClick(ClickEvent event) {
 79  
       
 80  
 //                boolean before = checkBox.getValue();
 81  
   //              checkBox.setValue(!before);
 82  
     //            ValueChangeEvent.fireIfNotEqual(checkBox, before,checkBox.getValue());
 83  
       //          checkBox.setFocus(true);
 84  
         //        setFocus(true);
 85  
          //   }
 86  
        // });
 87  0
         checkBox.addValueChangeHandler(new ValueChangeHandler(){
 88  
             @Override
 89  
             public void onValueChange(ValueChangeEvent event) {
 90  0
                 if(checkBox.getValue() == true){
 91  0
                     DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffeeff");
 92  
                 }else{
 93  0
                     DOM.setStyleAttribute(NodeWidget.this.getElement(), "background", "#ffffff");
 94  
                 }
 95  0
             }
 96  
             
 97  
         });
 98  0
     }
 99  
     @Override
 100  
     public void onPreviewNativeEvent(NativePreviewEvent pevent) {
 101  0
         NativeEvent event = pevent.getNativeEvent();
 102  0
         EventTarget target = event.getEventTarget();
 103  
      //   System.out.println(this.getElement().is(Element.as(target)));
 104  0
         if(checkBox.getElement().isOrHasChild(Element.as(target))){
 105  0
             return;
 106  0
         }else if(this.getElement().is(Element.as(target)) && 
 107  
                 Event.as(event).getTypeInt() == Event.ONMOUSEDOWN ){
 108  0
                     GWT.log("doing", null);
 109  0
                   boolean before = checkBox.getValue();
 110  0
                                   checkBox.setValue(!before);
 111  0
                                   ValueChangeEvent.fireIfNotEqual(checkBox, before,checkBox.getValue());
 112  
                                   //checkBox.setFocus(true);
 113  
                           //        setFocus(true);
 114  
                     
 115  
         }
 116  
 
 117  0
     }
 118  
     public Node getNode() {
 119  0
         return node;
 120  
     }
 121  
 
 122  
     public void installCheckBox() {
 123  0
         verticalPanel.clear();
 124  0
         verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
 125  0
         verticalPanel.setWidth("100%");
 126  0
         verticalPanel.setHeight("100%");
 127  0
         verticalPanel.add(checkBox);
 128  0
         super.setWidget(verticalPanel);
 129  
         //contentPanel.setWidget(checkBox);
 130  0
     }
 131  
 
 132  
     public boolean isSelected() {
 133  0
         return checkBox.getValue() == true;
 134  
     }
 135  
 
 136  
     public void addSelectionHandler(ValueChangeHandler<Boolean> ch) {
 137  0
         if (handlerRegistration != null) {
 138  0
             handlerRegistration.removeHandler();
 139  
         }
 140  0
         handlerRegistration = checkBox.addValueChangeHandler(ch);
 141  0
     }
 142  
 
 143  
     public void setNode(Node n) {
 144  0
         node = n;
 145  0
         html.setHTML(node.getUserObject().toString());
 146  0
         checkBox.setHTML(node.getUserObject().toString());
 147  0
     }
 148  
 }