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 com.vaadin.ui.Button;
37 import com.vaadin.ui.Button.ClickEvent;
38 import com.vaadin.ui.Button.ClickListener;
39 import com.vaadin.ui.Component;
40 import com.vaadin.ui.CssLayout;
41 import com.vaadin.v7.ui.Label;
42
43
44
45
46
47
48 @Deprecated
49 public class ConfirmationDialog extends LightDialog {
50
51 public static final String CONFIRM_ACTION_NAME = "confirm";
52
53 private String message;
54
55 private Button confirmButton;
56
57 private Button cancelButton;
58
59 public ConfirmationDialog(final String message, String confirmLabel, String cancelLabel, boolean cancelIsDefault) {
60 super();
61 setMessage(message);
62 init(confirmLabel, cancelLabel, cancelIsDefault);
63 }
64
65 public ConfirmationDialog(final Component contents, String confirmLabel, String cancelLabel, boolean cancelIsDefault) {
66 super();
67 message = "";
68 setContent(contents);
69 init(confirmLabel, cancelLabel, cancelIsDefault);
70 }
71
72 public void init(String confirmLabel, String cancelLabel, boolean cancelIsDefault) {
73 CssLayout footer = new CssLayout();
74 footer.addStyleName("v-align-right");
75
76 confirmButton = new Button(confirmLabel, new ClickListener() {
77 @Override
78 public void buttonClick(ClickEvent event) {
79 confirm();
80 }
81 });
82 confirmButton.setDisableOnClick(true);
83
84 cancelButton = new Button(cancelLabel, new ClickListener() {
85 @Override
86 public void buttonClick(ClickEvent event) {
87 cancel();
88 }
89 });
90 cancelButton.setDisableOnClick(true);
91
92 footer.addComponent(cancelButton);
93 footer.addComponent(confirmButton);
94
95 cancelButton.addStyleName("btn-dialog");
96 cancelButton.addStyleName("cancel");
97 confirmButton.addStyleName("btn-dialog");
98 confirmButton.addStyleName("commit");
99
100 footer.setWidth(100, Unit.PERCENTAGE);
101 setFooterToolbar(footer);
102
103
104 if (cancelIsDefault) {
105 cancelButton.focus();
106 } else {
107 confirmButton.focus();
108 }
109 }
110
111 public void confirm(){
112 fireEvent(new ConfirmationEvent(ConfirmationDialog.this, true));
113 }
114
115 public void cancel(){
116 fireEvent(new ConfirmationEvent(ConfirmationDialog.this, false));
117 }
118
119 public void setMessage(String message) {
120 this.message = message;
121 if (getContent() != null && getContent() instanceof Label) {
122 ((Label) getContent()).setValue(message);
123 }
124 }
125
126 public String getMessage() {
127 return message;
128 }
129
130 @Override
131 public void setContent(Component content) {
132 super.setContent(content);
133 }
134
135 @Override
136 protected Component createDefaultContent() {
137 return new Label();
138 }
139
140 public void addConfirmationHandler(ConfirmationEvent.Handler handler) {
141 addListener("confirmation_event", ConfirmationEvent.class, handler, ConfirmationEvent.ON_CONFIRMATION);
142 }
143
144 public void removeConfirmationHandler(ConfirmationEvent.Handler handler) {
145 removeListener("confirmation_event", ConfirmationEvent.class, handler);
146 }
147
148
149
150
151 public static class ConfirmationEvent extends Component.Event {
152
153
154
155
156 public interface Handler {
157 void onConfirmation(ConfirmationEvent event);
158 }
159
160 public static final java.lang.reflect.Method ON_CONFIRMATION;
161
162 static {
163 try {
164 ON_CONFIRMATION = ConfirmationEvent.Handler.class.getDeclaredMethod("onConfirmation", new Class[]{ConfirmationEvent.class});
165 } catch (final java.lang.NoSuchMethodException e) {
166 throw new java.lang.RuntimeException(e);
167 }
168 }
169
170 private final boolean isConfirmed;
171
172 public ConfirmationEvent(Component source, boolean isConfirmed) {
173 super(source);
174 this.isConfirmed = isConfirmed;
175 }
176
177 public boolean isConfirmed() {
178 return isConfirmed;
179 }
180 }
181 }