1
|
package eu.dnetlib.repo.manager.client.validator.test;
|
2
|
|
3
|
import com.google.gwt.event.dom.client.ChangeEvent;
|
4
|
import com.google.gwt.event.dom.client.ChangeHandler;
|
5
|
import com.google.gwt.user.client.ui.*;
|
6
|
import eu.dnetlib.repo.manager.client.widgets.TextBox;
|
7
|
import eu.dnetlib.repo.manager.shared.Triple;
|
8
|
import org.gwtbootstrap3.client.ui.Alert;
|
9
|
import org.gwtbootstrap3.client.ui.Form;
|
10
|
import org.gwtbootstrap3.client.ui.ListBox;
|
11
|
import org.gwtbootstrap3.client.ui.RadioButton;
|
12
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
13
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
14
|
|
15
|
import java.util.List;
|
16
|
|
17
|
/**
|
18
|
* Created by stefania on 2/18/16.
|
19
|
*/
|
20
|
public class SelectParametersWidget implements IsWidget {
|
21
|
|
22
|
private FlowPanel selectParametersWidgetPanel = new FlowPanel();
|
23
|
|
24
|
private Alert errorLabel = new Alert();
|
25
|
|
26
|
private FlowPanel recordsPanel = new FlowPanel();
|
27
|
private HTML recordsLabel = new HTML();
|
28
|
private Form recordsForm = new Form();
|
29
|
private RadioButton allRecordsRadio = new RadioButton("records", "All", false);
|
30
|
private RadioButton customRecordsRadio = new RadioButton("records", "Custom", false);
|
31
|
private TextBox customRecordsTextBox = new TextBox();
|
32
|
|
33
|
private FlowPanel setsPanel = new FlowPanel();
|
34
|
private HTML setsLabel = new HTML();
|
35
|
private Form setsForm = new Form();
|
36
|
private ListBox setsListBox = new ListBox();
|
37
|
|
38
|
private FlowPanel xPathPanel = new FlowPanel();
|
39
|
private HTML xPathLabel = new HTML();
|
40
|
private Form xPathForm = new Form();
|
41
|
private RadioButton noXPathRadio = new RadioButton("xPath", "No", false);
|
42
|
private RadioButton yesXPathRadio = new RadioButton("xPath", "Yes", false);
|
43
|
private TextBox xPathTextBox = new TextBox();
|
44
|
private HTML xPathComment = new HTML();
|
45
|
|
46
|
public SelectParametersWidget() {
|
47
|
|
48
|
errorLabel.setType(AlertType.DANGER);
|
49
|
errorLabel.setDismissable(false);
|
50
|
errorLabel.setVisible(false);
|
51
|
|
52
|
selectParametersWidgetPanel.add(errorLabel);
|
53
|
selectParametersWidgetPanel.add(recordsPanel);
|
54
|
selectParametersWidgetPanel.add(setsPanel);
|
55
|
selectParametersWidgetPanel.add(xPathPanel);
|
56
|
|
57
|
selectParametersWidgetPanel.addStyleName("uk-margin-top");
|
58
|
|
59
|
// RECORDS
|
60
|
recordsLabel.setHTML("<label>Number of records to validate</label>");
|
61
|
|
62
|
recordsPanel.addStyleName("marginBottom20");
|
63
|
recordsPanel.add(recordsLabel);
|
64
|
recordsPanel.add(recordsForm);
|
65
|
|
66
|
recordsForm.addStyleName("uk-margin uk-grid");
|
67
|
|
68
|
allRecordsRadio.setType(ButtonType.LINK);
|
69
|
allRecordsRadio.setValue(true);
|
70
|
allRecordsRadio.addChangeHandler(new ChangeHandler() {
|
71
|
@Override
|
72
|
public void onChange(ChangeEvent event) {
|
73
|
if(allRecordsRadio.getValue())
|
74
|
customRecordsTextBox.setEnabled(false);
|
75
|
}
|
76
|
});
|
77
|
FlowPanel allRecordsRadioWrapper = new FlowPanel();
|
78
|
allRecordsRadioWrapper.addStyleName("uk-width-1-4@s");
|
79
|
allRecordsRadioWrapper.add(allRecordsRadio);
|
80
|
recordsForm.add(allRecordsRadioWrapper);
|
81
|
|
82
|
customRecordsRadio.setType(ButtonType.LINK);
|
83
|
customRecordsRadio.addChangeHandler(new ChangeHandler() {
|
84
|
@Override
|
85
|
public void onChange(ChangeEvent event) {
|
86
|
if(customRecordsRadio.getValue())
|
87
|
customRecordsTextBox.setEnabled(true);
|
88
|
}
|
89
|
});
|
90
|
FlowPanel customRecordsRadioWrapper = new FlowPanel();
|
91
|
customRecordsRadioWrapper.addStyleName("uk-width-1-4@s");
|
92
|
customRecordsRadioWrapper.add(customRecordsRadio);
|
93
|
recordsForm.add(customRecordsRadioWrapper);
|
94
|
|
95
|
customRecordsTextBox.setValue("10");
|
96
|
customRecordsTextBox.setEnabled(false);
|
97
|
FlowPanel customRecordsTextBoxWrapper = new FlowPanel();
|
98
|
customRecordsTextBoxWrapper.addStyleName("uk-width-1-2@s");
|
99
|
customRecordsTextBoxWrapper.add(customRecordsTextBox);
|
100
|
recordsForm.add(customRecordsTextBoxWrapper);
|
101
|
|
102
|
// VALIDATION SET
|
103
|
setsLabel.setHTML("<label>Validation Set</label>");
|
104
|
|
105
|
setsPanel.addStyleName("marginBottom20");
|
106
|
setsPanel.add(setsLabel);
|
107
|
setsPanel.add(setsForm);
|
108
|
|
109
|
setsListBox.addItem("All Sets", "all");
|
110
|
setsForm.add(setsListBox);
|
111
|
|
112
|
// XPATH
|
113
|
xPathLabel.setHTML("<label>Would you like to group your results by a specific field?</label>");
|
114
|
|
115
|
xPathPanel.addStyleName("xPathPanel marginBottom20");
|
116
|
xPathPanel.add(xPathLabel);
|
117
|
xPathPanel.add(xPathForm);
|
118
|
xPathPanel.add(xPathComment);
|
119
|
|
120
|
xPathForm.addStyleName("uk-grid");
|
121
|
|
122
|
noXPathRadio.setType(ButtonType.LINK);
|
123
|
noXPathRadio.setValue(true);
|
124
|
noXPathRadio.addChangeHandler(new ChangeHandler() {
|
125
|
@Override
|
126
|
public void onChange(ChangeEvent event) {
|
127
|
if(noXPathRadio.getValue())
|
128
|
xPathTextBox.setEnabled(false);
|
129
|
}
|
130
|
});
|
131
|
FlowPanel noXPathRadioWrapper = new FlowPanel();
|
132
|
noXPathRadioWrapper.addStyleName("uk-width-1-4@s");
|
133
|
noXPathRadioWrapper.add(noXPathRadio);
|
134
|
xPathForm.add(noXPathRadioWrapper);
|
135
|
|
136
|
yesXPathRadio.setType(ButtonType.LINK);
|
137
|
yesXPathRadio.addChangeHandler(new ChangeHandler() {
|
138
|
@Override
|
139
|
public void onChange(ChangeEvent event) {
|
140
|
if(yesXPathRadio.getValue())
|
141
|
xPathTextBox.setEnabled(true);
|
142
|
}
|
143
|
});
|
144
|
FlowPanel yesXPathRadioWrapper = new FlowPanel();
|
145
|
yesXPathRadioWrapper.addStyleName("uk-width-1-4@s");
|
146
|
yesXPathRadioWrapper.add(yesXPathRadio);
|
147
|
xPathForm.add(yesXPathRadioWrapper);
|
148
|
|
149
|
xPathTextBox.setPlaceholder("-XPATH-");
|
150
|
xPathTextBox.setEnabled(false);
|
151
|
FlowPanel xPathTextBoxWrapper = new FlowPanel();
|
152
|
xPathTextBoxWrapper.addStyleName("uk-width-1-2@s");
|
153
|
xPathTextBoxWrapper.add(xPathTextBox);
|
154
|
xPathForm.add(xPathTextBoxWrapper);
|
155
|
|
156
|
xPathComment.setHTML("<strong>XPath Examples:</strong> 1. //header/setSpec 2. //record/metadata//*[name()='dc:language'] ");
|
157
|
xPathComment.addStyleName("comment fontItalic marginTop10");
|
158
|
}
|
159
|
|
160
|
@Override
|
161
|
public Widget asWidget() {
|
162
|
return selectParametersWidgetPanel;
|
163
|
}
|
164
|
|
165
|
public void loadSets(List<String> sets) {
|
166
|
for(String set : sets)
|
167
|
setsListBox.addItem(set, set);
|
168
|
}
|
169
|
|
170
|
public Triple<Integer, String, String> getParameters() {
|
171
|
|
172
|
errorLabel.setVisible(false);
|
173
|
|
174
|
Triple<Integer, String, String> parameters = new Triple<Integer, String, String>();
|
175
|
|
176
|
if(allRecordsRadio.getValue())
|
177
|
parameters.setFirst(-1);
|
178
|
else {
|
179
|
if(isPositiveInteger(customRecordsTextBox.getValue().trim()))
|
180
|
parameters.setFirst(Integer.parseInt(customRecordsTextBox.getValue().trim()));
|
181
|
else {
|
182
|
errorLabel.setText("Number of records must be a positive integer");
|
183
|
errorLabel.setVisible(true);
|
184
|
parameters.setFirst(null);
|
185
|
}
|
186
|
}
|
187
|
|
188
|
if(setsListBox.getSelectedValue().equals("all"))
|
189
|
parameters.setSecond("none");
|
190
|
else
|
191
|
parameters.setSecond(setsListBox.getSelectedValue());
|
192
|
|
193
|
if(noXPathRadio.getValue())
|
194
|
parameters.setThird(null);
|
195
|
else {
|
196
|
if(xPathTextBox.getValue()==null || xPathTextBox.getValue().trim().isEmpty())
|
197
|
parameters.setThird(null);
|
198
|
else
|
199
|
parameters.setThird(xPathTextBox.getValue().trim());
|
200
|
}
|
201
|
|
202
|
return parameters;
|
203
|
}
|
204
|
|
205
|
private boolean isPositiveInteger(String value) {
|
206
|
|
207
|
if(value.length()!=0) {
|
208
|
|
209
|
try {
|
210
|
|
211
|
int intValue = Integer.parseInt(value);
|
212
|
return intValue>0;
|
213
|
|
214
|
} catch (NumberFormatException nfe) {
|
215
|
return false;
|
216
|
}
|
217
|
}
|
218
|
|
219
|
return false;
|
220
|
}
|
221
|
}
|