Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * Copyright 2010 Daniel Kurka
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.googlecode.mgwt.ui.client.dialog;

import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.MGWTStyle;
import com.googlecode.mgwt.ui.client.theme.base.DialogCss;

/**
 * A simple confirm dialog with ok and cancel buttons
 * 
 * @author Daniel Kurka
 */
public class ConfirmDialog implements HasText, HasTitleText, Dialog {
  /**
   * The callback used when buttons are taped
   * 
   * @author Daniel Kurka
   * 
   */
  public interface ConfirmCallback {
    /**
     * Called if ok button is taped
     */
    public void onOk();

    /**
     * called if cancel button is taped
     */
    public void onCancel();
  }

  private PopinDialog popinDialog;
  private DialogPanel dialogPanel1;
  private Label textLabel;
  private ConfirmCallback callback;

  /**
   * Construct a Confirmdialg
   * 
   * @param title - the title of the dialog
   * @param text - the text of the dialog
   * @param callback - the callback used when a button of the dialog is taped
   */
  public ConfirmDialog(String title, String text, ConfirmCallback callback) {
    this(MGWTStyle.getTheme().getMGWTClientBundle().getDialogCss(), title, text, callback);
  }

  /**
   * Construct a Confirmdialg
   * 
   * @param css . css to use
   * @param title - the title of the dialog
   * @param text - the text of the dialog
   * @param callback - the callback used when a button of the dialog is taped
   */
  public ConfirmDialog(DialogCss css, String title, String text, ConfirmCallback callback) {
    this(css, title, text, callback, "Ok", "Cancel");
  }

  /**
   * Construct a Confirmdialg
   * 
   * @param css . css to use
   * @param title - the title of the dialog
   * @param text - the text of the dialog
   * @param callback - the callback used when a button of the dialog is taped
   */
  public ConfirmDialog(DialogCss css, String title, String text, ConfirmCallback callback,
      String okButtonText, String cancelButtonText) {
    this.callback = callback;
    popinDialog = new PopinDialog(css);
    dialogPanel1 = new DialogPanel();
    dialogPanel1.showCancelButton(true);
    dialogPanel1.showOkButton(true);

    textLabel = new Label();
    dialogPanel1.getContent().add(textLabel);
    popinDialog.add(dialogPanel1);

    dialogPanel1.getOkButton().addTapHandler(new TapHandler() {

      @Override
      public void onTap(TapEvent event) {
        popinDialog.hide();
        if (ConfirmDialog.this.callback != null)
          ConfirmDialog.this.callback.onOk();
      }
    });

    dialogPanel1.getCancelButton().addTapHandler(new TapHandler() {

      @Override
      public void onTap(TapEvent event) {
        popinDialog.hide();
        if (ConfirmDialog.this.callback != null)
          ConfirmDialog.this.callback.onCancel();
      }
    });

    setText(text);
    setTitleText(title);
    dialogPanel1.setCancelButtonText(cancelButtonText);
    dialogPanel1.setOkButtonText(okButtonText);

  }

  /*
   * (non-Javadoc)
   * 
   * @see com.googlecode.mgwt.ui.client.dialog.HasTitleText#setTitleText(java.lang.String)
   */
  /** {@inheritDoc} */
  @Override
  public void setTitleText(String title) {
    dialogPanel1.getDialogTitle().setHTML(title);

  }

  /*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.user.client.ui.HasText#setText(java.lang.String)
   */
  /** {@inheritDoc} */
  @Override
  public void setText(String text) {
    textLabel.setText(text);

  }

  /*
   * (non-Javadoc)
   * 
   * @see com.googlecode.mgwt.ui.client.dialog.HasTitleText#getTitleText()
   */
  /** {@inheritDoc} */
  @Override
  public String getTitleText() {
    return dialogPanel1.getDialogTitle().getHTML();
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.google.gwt.user.client.ui.HasText#getText()
   */
  /** {@inheritDoc} */
  @Override
  public String getText() {
    return textLabel.getText();
  }

  /*
   * (non-Javadoc)
   * 
   * @see com.googlecode.mgwt.ui.client.dialog.Dialog#show()
   */
  /**
   * <p>
   * show
   * </p>
   */
  public void show() {
    popinDialog.center();
  }

}

Commits for litesoft/trunk/mobileGWT/zOriginal/mgwt/src_main_java_com_googlecode_mgwt_ui_client_dialog/ConfirmDialog.java

Diff revisions: vs.
Revision Author Commited Message
751 GeorgeS picture GeorgeS Sat 07 Jul, 2012 18:21:49 +0000