|
@@ -1,16 +1,14 @@ |
1 |
1 |
|
/* |
2 |
2 |
|
* Copyright 2010 Daniel Kurka |
3 |
3 |
|
* |
4 |
|
- |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not |
5 |
|
- |
* use this file except in compliance with the License. You may obtain a copy of |
6 |
|
- |
* the License at |
|
4 |
+ |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
|
5 |
+ |
* in compliance with the License. You may obtain a copy of the License at |
7 |
6 |
|
* |
8 |
7 |
|
* http://www.apache.org/licenses/LICENSE-2.0 |
9 |
8 |
|
* |
10 |
|
- |
* Unless required by applicable law or agreed to in writing, software |
11 |
|
- |
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
12 |
|
- |
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
13 |
|
- |
* License for the specific language governing permissions and limitations under |
|
9 |
+ |
* Unless required by applicable law or agreed to in writing, software distributed under the License |
|
10 |
+ |
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
|
11 |
+ |
* or implied. See the License for the specific language governing permissions and limitations under |
14 |
12 |
|
* the License. |
15 |
13 |
|
*/ |
16 |
14 |
|
package com.googlecode.mgwt.ui.client.dialog; |
|
@@ -31,175 +29,156 @@ |
31 |
29 |
|
* @author Daniel Kurka |
32 |
30 |
|
*/ |
33 |
31 |
|
public class DialogPanel extends Composite { |
34 |
|
- |
public static final String BUTTON_TEXT_OK = "Ok"; |
35 |
|
- |
public static final String BUTTON_TEXT_CANCEL = "Cancel"; |
|
32 |
+ |
private static class CancelButton extends ButtonBase { |
36 |
33 |
|
|
37 |
|
- |
private static class CancelButton extends ButtonBase { |
|
34 |
+ |
public CancelButton(DialogCss css, String text) { |
|
35 |
+ |
super(css); |
|
36 |
+ |
setText(text); |
|
37 |
+ |
addStyleName(css.cancelbutton()); |
38 |
38 |
|
|
39 |
|
- |
public CancelButton(DialogCss css, String text) { |
40 |
|
- |
super(css); |
41 |
|
- |
setText(text); |
42 |
|
- |
addStyleName(css.cancelbutton()); |
43 |
|
- |
|
44 |
|
- |
} |
45 |
|
- |
|
46 |
|
- |
} |
47 |
|
- |
|
48 |
|
- |
private static class OkButton extends ButtonBase { |
49 |
|
- |
|
50 |
|
- |
public OkButton(DialogCss css, String text) { |
51 |
|
- |
|
52 |
|
- |
super(css); |
53 |
|
- |
setText(text); |
54 |
|
- |
addStyleName(css.okbutton()); |
55 |
|
- |
|
56 |
|
- |
} |
57 |
|
- |
|
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
private FlowPanel main; |
61 |
|
- |
private FlowPanel container; |
62 |
|
- |
private HTML title; |
63 |
|
- |
private FlowPanel content; |
64 |
|
- |
private FlowPanel buttonContainer; |
65 |
|
- |
private OkButton okButton; |
66 |
|
- |
private CancelButton cancelButton; |
67 |
|
- |
private final DialogCss css; |
68 |
|
- |
|
69 |
|
- |
/** |
70 |
|
- |
* Construct the panel |
71 |
|
- |
*/ |
72 |
|
- |
public DialogPanel() { |
73 |
|
- |
this(MGWTStyle.getTheme().getMGWTClientBundle().getDialogCss()); |
74 |
|
- |
} |
75 |
|
- |
|
76 |
|
- |
/** |
77 |
|
- |
* Construct panel with a special css |
78 |
|
- |
* |
79 |
|
- |
* @param css the css to use |
80 |
|
- |
*/ |
81 |
|
- |
public DialogPanel(DialogCss css) { |
82 |
|
- |
this(css, null, null); |
83 |
39 |
|
} |
84 |
40 |
|
|
85 |
|
- |
/** |
86 |
|
- |
* Construct panel with a special text for buttons |
87 |
|
- |
* |
88 |
|
- |
* @param buttonTextOK text for OK button (if not null) |
89 |
|
- |
* @param buttonTextCancel text for Cancel button (if not null) |
90 |
|
- |
*/ |
91 |
|
- |
public DialogPanel(String buttonTextOK, String buttonTextCancel) { |
92 |
|
- |
this(MGWTStyle.getTheme().getMGWTClientBundle().getDialogCss(), buttonTextOK, buttonTextCancel); |
|
41 |
+ |
} |
|
42 |
+ |
|
|
43 |
+ |
private static class OkButton extends ButtonBase { |
|
44 |
+ |
|
|
45 |
+ |
public OkButton(DialogCss css, String text) { |
|
46 |
+ |
|
|
47 |
+ |
super(css); |
|
48 |
+ |
setText(text); |
|
49 |
+ |
addStyleName(css.okbutton()); |
|
50 |
+ |
|
93 |
51 |
|
} |
94 |
52 |
|
|
95 |
|
- |
/** |
96 |
|
- |
* Construct panel with a special css and text for buttons |
97 |
|
- |
* |
98 |
|
- |
* @param css the css to use |
99 |
|
- |
* @param buttonTextOK text for OK button (if not null) |
100 |
|
- |
* @param buttonTextCancel text for Cancel button (if not null) |
101 |
|
- |
*/ |
102 |
|
- |
public DialogPanel(DialogCss css, String buttonTextOK, String buttonTextCancel) { |
103 |
|
- |
this.css = css; |
104 |
|
- |
this.css.ensureInjected(); |
105 |
|
- |
main = new FlowPanel(); |
106 |
|
- |
initWidget(main); |
107 |
|
- |
|
108 |
|
- |
main.addStyleName(css.getDialogPanel()); |
109 |
|
- |
|
110 |
|
- |
container = new FlowPanel(); |
111 |
|
- |
container.addStyleName(css.container()); |
112 |
|
- |
|
113 |
|
- |
main.add(container); |
114 |
|
- |
|
115 |
|
- |
title = new HTML(); |
116 |
|
- |
title.addStyleName(css.title()); |
117 |
|
- |
container.add(title); |
118 |
|
- |
|
119 |
|
- |
content = new FlowPanel(); |
120 |
|
- |
content.addStyleName(css.content()); |
121 |
|
- |
container.add(content); |
122 |
|
- |
|
123 |
|
- |
buttonContainer = new FlowPanel(); |
124 |
|
- |
buttonContainer.addStyleName(css.footer()); |
125 |
|
- |
container.add(buttonContainer); |
126 |
|
- |
|
127 |
|
- |
okButton = new OkButton(css, deNull(buttonTextOK, BUTTON_TEXT_OK) ); |
128 |
|
- |
|
129 |
|
- |
buttonContainer.add(okButton); |
130 |
|
- |
|
131 |
|
- |
cancelButton = new CancelButton(css, deNull(buttonTextCancel, BUTTON_TEXT_CANCEL)); |
132 |
|
- |
|
133 |
|
- |
buttonContainer.add(cancelButton); |
134 |
|
- |
|
135 |
|
- |
} |
136 |
|
- |
|
137 |
|
- |
/** |
138 |
|
- |
* get the container of the panel |
139 |
|
- |
* |
140 |
|
- |
* @return the container of the dialog panel |
141 |
|
- |
*/ |
142 |
|
- |
public HasWidgets getContent() { |
143 |
|
- |
return content; |
144 |
|
- |
} |
145 |
|
- |
|
146 |
|
- |
/** |
147 |
|
- |
* get {@link HasTapHandlers} for the cancel button |
148 |
|
- |
* |
149 |
|
- |
* @return the {@link HasTapHandlers} for cancel button |
150 |
|
- |
*/ |
151 |
|
- |
public HasTapHandlers getCancelButton() { |
152 |
|
- |
return cancelButton; |
153 |
|
- |
} |
154 |
|
- |
|
155 |
|
- |
/** |
156 |
|
- |
* get {@link HasTapHandlers} for the ok button |
157 |
|
- |
* |
158 |
|
- |
* @return the {@link HasTapHandlers} for ok button |
159 |
|
- |
*/ |
160 |
|
- |
public HasTapHandlers getOkButton() { |
161 |
|
- |
return okButton; |
162 |
|
- |
} |
163 |
|
- |
|
164 |
|
- |
/** |
165 |
|
- |
* show the cancel button |
166 |
|
- |
* |
167 |
|
- |
* @param show true to show, otherwise hidden |
168 |
|
- |
*/ |
169 |
|
- |
public void showCancelButton(boolean show) { |
170 |
|
- |
if (show) { |
171 |
|
- |
int widgetCount = buttonContainer.getWidgetCount(); |
172 |
|
- |
if (widgetCount == 0) { |
173 |
|
- |
buttonContainer.add(cancelButton); |
174 |
|
- |
} |
175 |
|
- |
} else { |
176 |
|
- |
buttonContainer.remove(cancelButton); |
177 |
|
- |
} |
178 |
|
- |
} |
179 |
|
- |
|
180 |
|
- |
/** |
181 |
|
- |
* show the ok button |
182 |
|
- |
* |
183 |
|
- |
* @param show true to show, otherwise hidden |
184 |
|
- |
*/ |
185 |
|
- |
public void showOkButton(boolean show) { |
186 |
|
- |
if (show) { |
187 |
|
- |
buttonContainer.insert(okButton, 0); |
188 |
|
- |
} else { |
189 |
|
- |
buttonContainer.remove(okButton); |
190 |
|
- |
} |
191 |
|
- |
} |
192 |
|
- |
|
193 |
|
- |
/** |
194 |
|
- |
* Get the title of the dialog |
195 |
|
- |
* |
196 |
|
- |
* @return the title of the dialog |
197 |
|
- |
*/ |
198 |
|
- |
public HasHTML getDialogTitle() { |
199 |
|
- |
return title; |
200 |
|
- |
} |
|
53 |
+ |
} |
201 |
54 |
|
|
202 |
|
- |
private String deNull(String orig, String defaultIfNull) { |
203 |
|
- |
return (orig != null) ? orig : defaultIfNull; |
|
55 |
+ |
private FlowPanel main; |
|
56 |
+ |
private FlowPanel container; |
|
57 |
+ |
private HTML title; |
|
58 |
+ |
private FlowPanel content; |
|
59 |
+ |
private FlowPanel buttonContainer; |
|
60 |
+ |
private OkButton okButton; |
|
61 |
+ |
private CancelButton cancelButton; |
|
62 |
+ |
private final DialogCss css; |
|
63 |
+ |
|
|
64 |
+ |
/** |
|
65 |
+ |
* Construct the panel |
|
66 |
+ |
*/ |
|
67 |
+ |
public DialogPanel() { |
|
68 |
+ |
this(MGWTStyle.getTheme().getMGWTClientBundle().getDialogCss()); |
|
69 |
+ |
} |
|
70 |
+ |
|
|
71 |
+ |
/** |
|
72 |
+ |
* Construct panel with a special css |
|
73 |
+ |
* |
|
74 |
+ |
* @param css the css to use |
|
75 |
+ |
*/ |
|
76 |
+ |
public DialogPanel(DialogCss css) { |
|
77 |
+ |
this.css = css; |
|
78 |
+ |
this.css.ensureInjected(); |
|
79 |
+ |
main = new FlowPanel(); |
|
80 |
+ |
initWidget(main); |
|
81 |
+ |
|
|
82 |
+ |
main.addStyleName(css.getDialogPanel()); |
|
83 |
+ |
|
|
84 |
+ |
container = new FlowPanel(); |
|
85 |
+ |
container.addStyleName(css.container()); |
|
86 |
+ |
|
|
87 |
+ |
main.add(container); |
|
88 |
+ |
|
|
89 |
+ |
title = new HTML(); |
|
90 |
+ |
title.addStyleName(css.title()); |
|
91 |
+ |
container.add(title); |
|
92 |
+ |
|
|
93 |
+ |
content = new FlowPanel(); |
|
94 |
+ |
content.addStyleName(css.content()); |
|
95 |
+ |
container.add(content); |
|
96 |
+ |
|
|
97 |
+ |
buttonContainer = new FlowPanel(); |
|
98 |
+ |
buttonContainer.addStyleName(css.footer()); |
|
99 |
+ |
container.add(buttonContainer); |
|
100 |
+ |
|
|
101 |
+ |
okButton = new OkButton(css, "Ok"); |
|
102 |
+ |
|
|
103 |
+ |
buttonContainer.add(okButton); |
|
104 |
+ |
|
|
105 |
+ |
cancelButton = new CancelButton(css, "Cancel"); |
|
106 |
+ |
|
|
107 |
+ |
buttonContainer.add(cancelButton); |
|
108 |
+ |
|
|
109 |
+ |
} |
|
110 |
+ |
|
|
111 |
+ |
/** |
|
112 |
+ |
* get the container of the panel |
|
113 |
+ |
* |
|
114 |
+ |
* @return the container of the dialog panel |
|
115 |
+ |
*/ |
|
116 |
+ |
public HasWidgets getContent() { |
|
117 |
+ |
return content; |
|
118 |
+ |
} |
|
119 |
+ |
|
|
120 |
+ |
/** |
|
121 |
+ |
* get {@link HasTapHandlers} for the cancel button |
|
122 |
+ |
* |
|
123 |
+ |
* @return the {@link HasTapHandlers} for cancel button |
|
124 |
+ |
*/ |
|
125 |
+ |
public HasTapHandlers getCancelButton() { |
|
126 |
+ |
return cancelButton; |
|
127 |
+ |
} |
|
128 |
+ |
|
|
129 |
+ |
/** |
|
130 |
+ |
* get {@link HasTapHandlers} for the ok button |
|
131 |
+ |
* |
|
132 |
+ |
* @return the {@link HasTapHandlers} for ok button |
|
133 |
+ |
*/ |
|
134 |
+ |
public HasTapHandlers getOkButton() { |
|
135 |
+ |
return okButton; |
|
136 |
+ |
} |
|
137 |
+ |
|
|
138 |
+ |
public void setOkButtonText(String text) { |
|
139 |
+ |
this.okButton.setText(text); |
|
140 |
+ |
} |
|
141 |
+ |
|
|
142 |
+ |
public void setCancelButtonText(String text) { |
|
143 |
+ |
this.cancelButton.setText(text); |
|
144 |
+ |
} |
|
145 |
+ |
|
|
146 |
+ |
/** |
|
147 |
+ |
* show the cancel button |
|
148 |
+ |
* |
|
149 |
+ |
* @param show true to show, otherwise hidden |
|
150 |
+ |
*/ |
|
151 |
+ |
public void showCancelButton(boolean show) { |
|
152 |
+ |
if (show) { |
|
153 |
+ |
int widgetCount = buttonContainer.getWidgetCount(); |
|
154 |
+ |
if (widgetCount == 0) { |
|
155 |
+ |
buttonContainer.add(cancelButton); |
|
156 |
+ |
} |
|
157 |
+ |
} else { |
|
158 |
+ |
buttonContainer.remove(cancelButton); |
204 |
159 |
|
} |
|
160 |
+ |
} |
|
161 |
+ |
|
|
162 |
+ |
/** |
|
163 |
+ |
* show the ok button |
|
164 |
+ |
* |
|
165 |
+ |
* @param show true to show, otherwise hidden |
|
166 |
+ |
*/ |
|
167 |
+ |
public void showOkButton(boolean show) { |
|
168 |
+ |
if (show) { |
|
169 |
+ |
buttonContainer.insert(okButton, 0); |
|
170 |
+ |
} else { |
|
171 |
+ |
buttonContainer.remove(okButton); |
|
172 |
+ |
} |
|
173 |
+ |
} |
|
174 |
+ |
|
|
175 |
+ |
/** |
|
176 |
+ |
* Get the title of the dialog |
|
177 |
+ |
* |
|
178 |
+ |
* @return the title of the dialog |
|
179 |
+ |
*/ |
|
180 |
+ |
public HasHTML getDialogTitle() { |
|
181 |
+ |
return title; |
|
182 |
+ |
} |
|
183 |
+ |
|
205 |
184 |
|
} |