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