1
|
package eu.dnetlib.repo.manager.client.validator.test;
|
2
|
|
3
|
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
4
|
import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
5
|
import com.google.gwt.user.client.ui.FlowPanel;
|
6
|
import com.google.gwt.user.client.ui.IsWidget;
|
7
|
import com.google.gwt.user.client.ui.Widget;
|
8
|
import eu.dnetlib.domain.functionality.validator.Rule;
|
9
|
import org.gwtbootstrap3.client.ui.CheckBox;
|
10
|
|
11
|
import java.util.*;
|
12
|
|
13
|
/**
|
14
|
* Created by stefania on 2/12/16.
|
15
|
*/
|
16
|
public class SelectRulesWidget implements IsWidget {
|
17
|
|
18
|
private FlowPanel selectRulesPanel = new FlowPanel();
|
19
|
private FlowPanel selectRulesInnerPanel = new FlowPanel();
|
20
|
|
21
|
private CheckBox selectAllCheckBox;
|
22
|
final private List<CheckBox> rulesCheckBoxes = new ArrayList<CheckBox>();
|
23
|
|
24
|
private Map<CheckBox, Rule> checkBoxRuleMap = new HashMap<CheckBox, Rule>();
|
25
|
|
26
|
public SelectRulesWidget(List<Rule> rules, String name) {
|
27
|
|
28
|
selectRulesPanel.addStyleName("uk-width-expand@m uk-width-1-2@s uk-grid-item-match uk-first-column");
|
29
|
selectRulesPanel.add(selectRulesInnerPanel);
|
30
|
|
31
|
selectRulesInnerPanel.addStyleName("margin10");
|
32
|
|
33
|
selectAllCheckBox = new CheckBox("Select / Deselect All " + name);
|
34
|
selectAllCheckBox.setValue(true);
|
35
|
selectAllCheckBox.addStyleName("selectAll");
|
36
|
selectAllCheckBox.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
|
37
|
@Override
|
38
|
public void onValueChange(ValueChangeEvent<Boolean> event) {
|
39
|
|
40
|
for(CheckBox checkBox : rulesCheckBoxes)
|
41
|
checkBox.setValue(selectAllCheckBox.getValue());
|
42
|
}
|
43
|
});
|
44
|
selectRulesInnerPanel.add(selectAllCheckBox);
|
45
|
|
46
|
for(Rule rule : rules) {
|
47
|
CheckBox ruleCheckBox = new CheckBox(rule.getName());
|
48
|
ruleCheckBox.setValue(true);
|
49
|
ruleCheckBox.setTitle(rule.getDescription());
|
50
|
rulesCheckBoxes.add(ruleCheckBox);
|
51
|
checkBoxRuleMap.put(ruleCheckBox, rule);
|
52
|
selectRulesInnerPanel.add(ruleCheckBox);
|
53
|
}
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public Widget asWidget() {
|
58
|
return selectRulesPanel;
|
59
|
}
|
60
|
|
61
|
public Set<Integer> getSelectedRules() {
|
62
|
|
63
|
Set<Integer> selectedRules = new HashSet<Integer>();
|
64
|
|
65
|
for(CheckBox checkBox : rulesCheckBoxes) {
|
66
|
if (checkBox.getValue())
|
67
|
selectedRules.add(checkBoxRuleMap.get(checkBox).getId());
|
68
|
}
|
69
|
|
70
|
return selectedRules;
|
71
|
}
|
72
|
}
|