Coverage Report - org.kuali.student.lum.lu.ui.tools.client.widgets.WarningDialog
 
Classes in this File Line Coverage Branch Coverage Complexity
WarningDialog
0%
0/38
N/A
1.571
WarningDialog$1
0%
0/5
0%
0/4
1.571
WarningDialog$2
0%
0/5
0%
0/4
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.lum.lu.ui.tools.client.widgets;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.ui.client.mvc.Callback;
 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.KSLightBox;
 25  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 26  
 
 27  
 import com.google.gwt.event.dom.client.ClickEvent;
 28  
 import com.google.gwt.event.dom.client.ClickHandler;
 29  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 30  
 import com.google.gwt.user.client.ui.Panel;
 31  
 import com.google.gwt.user.client.ui.SimplePanel;
 32  
 
 33  0
 public class WarningDialog {
 34  
     
 35  0
     private KSLightBox dialog = new KSLightBox();
 36  0
     private KSLabel titleLabel = null;
 37  0
     private KSLabel messageLabel = null;
 38  0
     private KSLabel questionLabel = null;
 39  0
     private VerticalFlowPanel layout = new VerticalFlowPanel();
 40  0
     private List<Callback<Boolean>> confirmationCallbacks = new ArrayList<Callback<Boolean>>();
 41  
     private KSButton affirmativeButton;
 42  
     private KSButton negativeButton;
 43  
 
 44  
     public WarningDialog(String title, String message, String question,
 45  0
             String affirmativeChoice, String negativeChoice) {
 46  0
         titleLabel = new KSLabel(title);
 47  0
         messageLabel = new KSLabel(message);
 48  0
         questionLabel = new KSLabel(question);
 49  0
         affirmativeButton = new KSButton(affirmativeChoice);
 50  0
         negativeButton = new KSButton(negativeChoice);
 51  
         
 52  0
         layout.add(titleLabel);
 53  0
         layout.add(createSpacerPanel("0px","20px"));
 54  0
         layout.add(messageLabel);
 55  0
         layout.add(createSpacerPanel("0px","50px"));
 56  0
         layout.add(questionLabel);
 57  
         
 58  0
         HorizontalPanel buttonsPanel = new HorizontalPanel();
 59  0
         buttonsPanel.add(affirmativeButton);
 60  0
         buttonsPanel.add(createSpacerPanel("10px", "0px"));
 61  0
         buttonsPanel.add(negativeButton);
 62  0
         layout.add(createSpacerPanel("0px","5px"));
 63  0
         layout.add(buttonsPanel);
 64  
         
 65  0
         affirmativeButton.addClickHandler(new ClickHandler() {
 66  
             @Override
 67  
             public void onClick(ClickEvent event) {
 68  0
                 if (confirmationCallbacks != null) {
 69  0
                     for (Callback<Boolean> confirmationCallback : confirmationCallbacks) {
 70  0
                         confirmationCallback.exec(Boolean.TRUE);
 71  
                     }
 72  
                 }
 73  0
             }
 74  
         });
 75  0
         negativeButton.addClickHandler(new ClickHandler() {
 76  
             @Override
 77  
             public void onClick(ClickEvent event) {
 78  0
                 if (confirmationCallbacks != null) {
 79  0
                     for (Callback<Boolean> confirmationCallback : confirmationCallbacks) {
 80  0
                         confirmationCallback.exec(Boolean.FALSE);
 81  
                     }
 82  
                 }
 83  0
             }
 84  
         });
 85  0
         dialog.setWidget(layout);
 86  0
     }
 87  
     
 88  
     private Panel createSpacerPanel(String width, String height) {
 89  0
         Panel spacerPanel = new SimplePanel();
 90  0
         spacerPanel.setWidth(width);
 91  0
         spacerPanel.setHeight(height);
 92  0
         return spacerPanel;
 93  
     }
 94  
     
 95  
     public void show() {
 96  0
         dialog.show();
 97  0
     }
 98  
     
 99  
     public void hide() {
 100  0
         dialog.hide();
 101  0
     }
 102  
     
 103  
     public void addConfirmationCallback(Callback<Boolean> confirmationCallback) {
 104  0
         confirmationCallbacks.add(confirmationCallback);
 105  0
     }
 106  
     
 107  
 }