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 eu.dnetlib.repo.manager.shared.Vocabulary;
|
10
|
import org.gwtbootstrap3.client.ui.CheckBox;
|
11
|
|
12
|
import java.util.*;
|
13
|
|
14
|
/**
|
15
|
* Created by stefania on 3/8/16.
|
16
|
*/
|
17
|
public class MultiSelectWidget implements IsWidget {
|
18
|
|
19
|
private FlowPanel multiSelectPanel = new FlowPanel();
|
20
|
private FlowPanel multiSelectInnerPanel = new FlowPanel();
|
21
|
|
22
|
private CheckBox selectAllCheckBox;
|
23
|
final private List<CheckBox> checkBoxes = new ArrayList<CheckBox>();
|
24
|
|
25
|
private Map<CheckBox, Vocabulary> checkBoxRule = new HashMap<CheckBox, Vocabulary>();
|
26
|
|
27
|
public MultiSelectWidget(List<Vocabulary> vocabularyList, String name) {
|
28
|
|
29
|
multiSelectPanel.add(multiSelectInnerPanel);
|
30
|
|
31
|
multiSelectInnerPanel.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 : checkBoxes)
|
41
|
checkBox.setValue(selectAllCheckBox.getValue());
|
42
|
}
|
43
|
});
|
44
|
multiSelectInnerPanel.add(selectAllCheckBox);
|
45
|
|
46
|
for(Vocabulary vocabulary : vocabularyList) {
|
47
|
CheckBox checkBox = new CheckBox(vocabulary.getName());
|
48
|
checkBox.setValue(true);
|
49
|
checkBoxes.add(checkBox);
|
50
|
checkBoxRule.put(checkBox, vocabulary);
|
51
|
multiSelectInnerPanel.add(checkBox);
|
52
|
}
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public Widget asWidget() {
|
57
|
return multiSelectPanel;
|
58
|
}
|
59
|
|
60
|
public List<String> getSelections() {
|
61
|
|
62
|
List<String> selections = new ArrayList<String>();
|
63
|
|
64
|
for(CheckBox checkBox : checkBoxes) {
|
65
|
if (checkBox.getValue())
|
66
|
selections.add(checkBoxRule.get(checkBox).getId());
|
67
|
}
|
68
|
|
69
|
return selections;
|
70
|
}
|
71
|
|
72
|
public void addStyleName(String styleName) {
|
73
|
multiSelectPanel.addStyleName(styleName);
|
74
|
}
|
75
|
}
|