View Javadoc

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  public class WarningDialog {
34      
35      private KSLightBox dialog = new KSLightBox();
36      private KSLabel titleLabel = null;
37      private KSLabel messageLabel = null;
38      private KSLabel questionLabel = null;
39      private VerticalFlowPanel layout = new VerticalFlowPanel();
40      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              String affirmativeChoice, String negativeChoice) {
46          titleLabel = new KSLabel(title);
47          messageLabel = new KSLabel(message);
48          questionLabel = new KSLabel(question);
49          affirmativeButton = new KSButton(affirmativeChoice);
50          negativeButton = new KSButton(negativeChoice);
51          
52          layout.add(titleLabel);
53          layout.add(createSpacerPanel("0px","20px"));
54          layout.add(messageLabel);
55          layout.add(createSpacerPanel("0px","50px"));
56          layout.add(questionLabel);
57          
58          HorizontalPanel buttonsPanel = new HorizontalPanel();
59          buttonsPanel.add(affirmativeButton);
60          buttonsPanel.add(createSpacerPanel("10px", "0px"));
61          buttonsPanel.add(negativeButton);
62          layout.add(createSpacerPanel("0px","5px"));
63          layout.add(buttonsPanel);
64          
65          affirmativeButton.addClickHandler(new ClickHandler() {
66              @Override
67              public void onClick(ClickEvent event) {
68                  if (confirmationCallbacks != null) {
69                      for (Callback<Boolean> confirmationCallback : confirmationCallbacks) {
70                          confirmationCallback.exec(Boolean.TRUE);
71                      }
72                  }
73              }
74          });
75          negativeButton.addClickHandler(new ClickHandler() {
76              @Override
77              public void onClick(ClickEvent event) {
78                  if (confirmationCallbacks != null) {
79                      for (Callback<Boolean> confirmationCallback : confirmationCallbacks) {
80                          confirmationCallback.exec(Boolean.FALSE);
81                      }
82                  }
83              }
84          });
85          dialog.setWidget(layout);
86      }
87      
88      private Panel createSpacerPanel(String width, String height) {
89          Panel spacerPanel = new SimplePanel();
90          spacerPanel.setWidth(width);
91          spacerPanel.setHeight(height);
92          return spacerPanel;
93      }
94      
95      public void show() {
96          dialog.show();
97      }
98      
99      public void hide() {
100         dialog.hide();
101     }
102     
103     public void addConfirmationCallback(Callback<Boolean> confirmationCallback) {
104         confirmationCallbacks.add(confirmationCallback);
105     }
106     
107 }