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 package info.magnolia.ui.vaadin.dialog;
35
36 import info.magnolia.ui.vaadin.gwt.client.dialog.connector.BaseDialogState;
37 import info.magnolia.ui.vaadin.gwt.client.dialog.rpc.DialogServerRpc;
38
39 import java.util.ArrayList;
40 import java.util.Collections;
41 import java.util.Iterator;
42 import java.util.List;
43
44 import com.vaadin.ui.AbstractComponent;
45 import com.vaadin.ui.AbstractSingleComponentContainer;
46 import com.vaadin.ui.Component;
47 import com.vaadin.ui.HasComponents;
48 import com.vaadin.v7.ui.HorizontalLayout;
49 import com.vaadin.v7.ui.VerticalLayout;
50
51
52
53
54
55
56
57
58 @Deprecated
59 public class BaseDialog extends AbstractComponent implements HasComponents {
60
61 public static final String CANCEL_ACTION_NAME = "cancel";
62
63 public static final String COMMIT_ACTION_NAME = "commit";
64
65 public BaseDialog() {
66 super();
67 setContent(createDefaultContent());
68 registerRpc(new DialogServerRpc() {
69
70 @Override
71 public void closeSelf() {
72 BaseDialog.this.closeSelf();
73 }
74
75 @Override
76 public void setWide(boolean isWide) {
77 BaseDialog.this.setWide(isWide);
78 }
79
80 @Override
81 public void setDescriptionVisibility(boolean isVisible) {
82 BaseDialog.this.setDescriptionVisibility(isVisible);
83 }
84 });
85 }
86
87 @Override
88 protected BaseDialogState getState() {
89 return (BaseDialogState) super.getState();
90 }
91
92 public void closeSelf() {
93 fireEvent(new DialogCloseEvent(this, this));
94 }
95
96 public void setWide(boolean isWide) {
97 fireEvent(new WideEvent(this, isWide));
98 }
99
100 public void setDescriptionVisibility(boolean isVisible) {
101 fireEvent(new DescriptionVisibilityEvent(this, isVisible));
102 }
103
104 public void setDialogDescription(String description) {
105 getState().componentDescription = description;
106 }
107
108
109
110 @Override
111 public Iterator<Component> iterator() {
112 List<Component> components = new ArrayList<Component>() {
113 @Override
114 public boolean add(Component c) {
115 if (c != null) {
116 return super.add(c);
117 }
118 return false;
119 };
120 };
121
122 Collections.addAll(components, (Component) getState().content, (Component) getState().headerToolbar, (Component) getState().footerToolbar);
123 return components.iterator();
124 }
125
126 public void setContent(Component newContent) {
127 final Component actualContent = newContent == null ? createDefaultContent() : newContent;
128 if (getState().content != null) {
129 ((Component)getState().content).setParent(null);
130 }
131 getState().content = actualContent;
132 adoptComponent((Component) getState().content);
133 }
134
135 public void setHeaderToolbar(Component newHeader) {
136 final Component actualHeader = newHeader == null ? createDefaultHeader() : newHeader;
137 if (getState().headerToolbar != null) {
138 ((Component)getState().headerToolbar).setParent(null);
139 }
140 getState().headerToolbar = actualHeader;
141 adoptComponent((Component) getState().headerToolbar);
142 }
143
144 public void setFooterToolbar(Component newFooter) {
145 final Component actualFooter = newFooter == null ? createDefaultFooter() : newFooter;
146 if (getState().footerToolbar != null) {
147 ((Component)getState().footerToolbar).setParent(null);
148 }
149 getState().footerToolbar = actualFooter;
150 adoptComponent((Component) getState().footerToolbar);
151 }
152
153
154
155
156
157
158
159
160
161
162 protected void adoptComponent(Component newContent) {
163 if (newContent != null) {
164
165 if (newContent.getParent() != null) {
166 if (newContent.getParent() == this) {
167 newContent.setParent(null);
168 } else {
169
170 AbstractSingleComponentContainer
171 .removeFromParent(newContent);
172 }
173 }
174 newContent.setParent(this);
175 }
176 markAsDirty();
177
178 }
179
180 public Component getContent() {
181 return (Component) getState().content;
182 }
183
184 @Override
185 public void setCaption(String caption) {
186 super.setCaption(caption);
187 getContent().setCaption(caption);
188 }
189
190 protected Component createDefaultContent() {
191 return new VerticalLayout();
192 }
193
194 protected Component createDefaultHeader() {
195 return new HorizontalLayout();
196 }
197
198 protected Component createDefaultFooter() {
199 return new HorizontalLayout();
200 }
201
202 public void showCloseButton() {
203 getState().hasCloseButton = true;
204 }
205
206 public void setModalityLevel(String modalityLevel){
207 getState().modalityLevel = modalityLevel;
208 }
209
210 public void setWideOnClient(boolean isWide){
211 getState().isWide = isWide;
212 }
213
214 public void addDescriptionVisibilityHandler(DescriptionVisibilityEvent.Handler handler) {
215 addListener("descriptionVisibilityEvent", DescriptionVisibilityEvent.class, handler, DescriptionVisibilityEvent.ON_DESCRIPTION_VISIBILITY_CHANGED);
216 }
217
218 public void removeDescriptionVisibilityHandler(DescriptionVisibilityEvent.Handler handler) {
219 removeListener("descriptionVisibilityEvent", DescriptionVisibilityEvent.class, handler);
220 }
221
222 public void addWideHandler(WideEvent.Handler handler) {
223 addListener("wideEvent", WideEvent.class, handler, WideEvent.ON_WIDE_CHANGED);
224 }
225
226 public void removeWideHandler(DialogCloseEvent.Handler handler) {
227 removeListener("wideEvent", WideEvent.class, handler);
228 }
229
230 public void addDialogCloseHandler(DialogCloseEvent.Handler handler) {
231 addListener("dialogCloseEvent", DialogCloseEvent.class, handler, DialogCloseEvent.ON_DIALOG_CLOSE);
232 }
233
234 public void removeDialogCloseHandler(DialogCloseEvent.Handler handler) {
235 removeListener("dialogCloseEvent", DialogCloseEvent.class, handler);
236 }
237
238
239
240
241
242 public static class DialogCloseEvent extends com.vaadin.ui.Component.Event {
243
244
245
246
247 public interface Handler {
248 void onClose(DialogCloseEvent event);
249 }
250
251 public static final java.lang.reflect.Method ON_DIALOG_CLOSE;
252
253 public BaseDialog dialog;
254
255 static {
256 try {
257 ON_DIALOG_CLOSE = DialogCloseEvent.Handler.class.getDeclaredMethod("onClose", new Class[] { DialogCloseEvent.class });
258 } catch (final java.lang.NoSuchMethodException e) {
259 throw new java.lang.RuntimeException(e);
260 }
261 }
262
263 public DialogCloseEvent(Component source, BaseDialog dialog) {
264 super(source);
265 this.dialog = dialog;
266 }
267
268 public BaseDialog getDialog() {
269 return dialog;
270 }
271 }
272
273
274
275
276 public static class WideEvent extends com.vaadin.ui.Component.Event {
277
278
279
280 public interface Handler {
281 void onWideChanged(WideEvent event);
282 }
283
284 public static final java.lang.reflect.Method ON_WIDE_CHANGED;
285
286 private boolean isWide;
287
288 static {
289 try {
290 ON_WIDE_CHANGED = WideEvent.Handler.class.getDeclaredMethod("onWideChanged", new Class[] { WideEvent.class });
291 } catch (final java.lang.NoSuchMethodException e) {
292 throw new java.lang.RuntimeException(e);
293 }
294 }
295
296 public WideEvent(Component source, boolean isWide) {
297 super(source);
298 this.isWide = isWide;
299 }
300
301 public boolean isWide() {
302 return isWide;
303 }
304 }
305
306
307
308
309 public static class DescriptionVisibilityEvent extends com.vaadin.ui.Component.Event {
310
311
312
313 public interface Handler {
314 void onDescriptionVisibilityChanged(DescriptionVisibilityEvent event);
315 }
316
317 public static final java.lang.reflect.Method ON_DESCRIPTION_VISIBILITY_CHANGED;
318
319 private boolean isVisible;
320
321 static {
322 try {
323 ON_DESCRIPTION_VISIBILITY_CHANGED = DescriptionVisibilityEvent.Handler.class.getDeclaredMethod("onDescriptionVisibilityChanged", new Class[] { DescriptionVisibilityEvent.class });
324 } catch (final java.lang.NoSuchMethodException e) {
325 throw new java.lang.RuntimeException(e);
326 }
327 }
328
329 public DescriptionVisibilityEvent(Component source, boolean isVisible) {
330 super(source);
331 this.isVisible = isVisible;
332 }
333
334 public boolean isVisible() {
335 return isVisible;
336 }
337 }
338
339 }