-
Notifications
You must be signed in to change notification settings - Fork 45
/
Button.java
159 lines (125 loc) · 4.46 KB
/
Button.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
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
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.components.forms;
import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.forms.validation.Diagnostic;
import org.eclipse.sirius.components.representations.IStatus;
/**
* The button widget.
*
* @author arichard
*/
@Immutable
public final class Button extends AbstractWidget {
private String label;
private String buttonLabel;
private String imageURL;
private Supplier<IStatus> pushButtonHandler;
private ButtonStyle style;
private Button() {
// Prevent instantiation
}
@Override
public String getLabel() {
return this.label;
}
public String getButtonLabel() {
return this.buttonLabel;
}
public ButtonStyle getStyle() {
return this.style;
}
public String getImageURL() {
return this.imageURL;
}
public Supplier<IStatus> getPushButtonHandler() {
return this.pushButtonHandler;
}
public static Builder newButton(String id) {
return new Builder(id);
}
@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}, buttonLabel: {3}, imageURL: {4}'}'";
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.getId(), this.label, this.buttonLabel, this.imageURL);
}
/**
* The builder used to create the button.
*
* @author arichard
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String id;
private String label;
private String iconURL;
private String buttonLabel;
private String imageURL;
private Supplier<IStatus> pushButtonHandler;
private ButtonStyle style;
private List<Diagnostic> diagnostics;
private Supplier<String> helpTextProvider;
private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
public Builder iconURL(String iconURL) {
this.iconURL = Objects.requireNonNull(iconURL);
return this;
}
public Builder label(String label) {
this.label = Objects.requireNonNull(label);
return this;
}
public Builder buttonLabel(String buttonLabel) {
this.buttonLabel = Objects.requireNonNull(buttonLabel);
return this;
}
public Builder imageURL(String imageURL) {
this.imageURL = Objects.requireNonNull(imageURL);
return this;
}
public Builder pushButtonHandler(Supplier<IStatus> pushButtonHandler) {
this.pushButtonHandler = Objects.requireNonNull(pushButtonHandler);
return this;
}
public Builder style(ButtonStyle style) {
this.style = Objects.requireNonNull(style);
return this;
}
public Builder diagnostics(List<Diagnostic> diagnostics) {
this.diagnostics = Objects.requireNonNull(diagnostics);
return this;
}
public Builder helpTextProvider(Supplier<String> helpTextProvider) {
this.helpTextProvider = Objects.requireNonNull(helpTextProvider);
return this;
}
public Button build() {
Button button = new Button();
button.id = Objects.requireNonNull(this.id);
button.label = Objects.requireNonNull(this.label);
button.buttonLabel = this.buttonLabel;
button.iconURL = this.iconURL;
button.imageURL = this.imageURL;
button.pushButtonHandler = Objects.requireNonNull(this.pushButtonHandler);
button.style = this.style; // Optional on purpose
button.diagnostics = Objects.requireNonNull(this.diagnostics);
button.helpTextProvider = this.helpTextProvider;
return button;
}
}
}