-
Notifications
You must be signed in to change notification settings - Fork 188
/
MessagePanel.java
111 lines (85 loc) · 3 KB
/
MessagePanel.java
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
/*
* Copyright (c) 2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.api.component.result;
import java.io.Serializable;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;
import com.evolveum.midpoint.gui.api.component.BasePanel;
public class MessagePanel extends BasePanel<String> {
private static final String ID_MESSAGE = "message";
public enum MessagePanelType {INFO, WARN, SUCCESS, ERROR}
private MessagePanelType type;
public MessagePanel(String id, MessagePanelType type, IModel<String> model) {
super(id, model);
this.type = type;
}
@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
}
public void initLayout() {
WebMarkupContainer detailsBox = new WebMarkupContainer("detailsBox");
detailsBox.setOutputMarkupId(true);
detailsBox.add(AttributeModifier.append("class", createHeaderCss()));
add(detailsBox);
initHeader(detailsBox);
}
private IModel<String> createHeaderCss() {
return (IModel<String>) () -> {
switch (type) {
case INFO:
return " box-info";
case SUCCESS:
return " box-success";
case ERROR:
return " box-danger";
case WARN: // TODO:
default:
return " box-warning";
}
};
}
private void initHeader(WebMarkupContainer box) {
WebMarkupContainer iconType = new WebMarkupContainer("iconType");
iconType.setOutputMarkupId(true);
iconType.add(new AttributeAppender("class", (IModel) () -> {
switch (type) {
case INFO:
return " fa-info";
case SUCCESS:
return " fa-check";
case ERROR:
return " fa-ban";
case WARN:
default:
return " fa-warning";
}
}));
box.add(iconType);
Label message = new Label(ID_MESSAGE, getModel());
box.add(message);
AjaxLink<Void> close = new AjaxLink<Void>("close") {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
close(target);
}
};
box.add(close);
}
public void close(AjaxRequestTarget target){
this.setVisible(false);
target.add(this);
}
}