| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 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 |  |  } |