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.FlowPanel;
|
6
|
import com.google.gwt.user.client.ui.IsWidget;
|
7
|
import com.google.gwt.user.client.ui.Widget;
|
8
|
import eu.dnetlib.repo.manager.client.widgets.TextBox;
|
9
|
import org.gwtbootstrap3.client.ui.Alert;
|
10
|
import org.gwtbootstrap3.client.ui.Form;
|
11
|
import org.gwtbootstrap3.client.ui.ListBox;
|
12
|
import org.gwtbootstrap3.client.ui.RadioButton;
|
13
|
import org.gwtbootstrap3.client.ui.constants.AlertType;
|
14
|
import org.gwtbootstrap3.client.ui.constants.ButtonType;
|
15
|
|
16
|
import java.util.List;
|
17
|
|
18
|
/**
|
19
|
* Created by stefania on 2/10/16.
|
20
|
*/
|
21
|
public class SelectRepositoryOrJournalWidget implements IsWidget {
|
22
|
|
23
|
private FlowPanel selectRepositoryOrJournalWidgetPanel = new FlowPanel();
|
24
|
|
25
|
private Alert errorLabel = new Alert();
|
26
|
|
27
|
private Form baseURLForm = new Form();
|
28
|
|
29
|
private RadioButton chooseExistingBaseURLRadio = new RadioButton("baseURLRadio", "Choose existing base URL", false);
|
30
|
private ListBox existingBaseURLsListBox = new ListBox();
|
31
|
private RadioButton addManuallyRadio = new RadioButton("baseURLRadio", "or enter one manually", false);
|
32
|
private TextBox baseURLTextBox = new TextBox();
|
33
|
|
34
|
public SelectRepositoryOrJournalWidget(List<String> repositoryURLs) {
|
35
|
|
36
|
errorLabel.setType(AlertType.DANGER);
|
37
|
errorLabel.setDismissable(false);
|
38
|
errorLabel.setVisible(false);
|
39
|
|
40
|
selectRepositoryOrJournalWidgetPanel.add(errorLabel);
|
41
|
selectRepositoryOrJournalWidgetPanel.add(baseURLForm);
|
42
|
|
43
|
chooseExistingBaseURLRadio.setValue(true);
|
44
|
chooseExistingBaseURLRadio.setType(ButtonType.LINK);
|
45
|
chooseExistingBaseURLRadio.addStyleName("validationSetRadio");
|
46
|
chooseExistingBaseURLRadio.addChangeHandler(new ChangeHandler() {
|
47
|
@Override
|
48
|
public void onChange(ChangeEvent event) {
|
49
|
if(chooseExistingBaseURLRadio.getValue()) {
|
50
|
existingBaseURLsListBox.setEnabled(true);
|
51
|
baseURLTextBox.setEnabled(false);
|
52
|
}
|
53
|
}
|
54
|
});
|
55
|
baseURLForm.add(chooseExistingBaseURLRadio);
|
56
|
|
57
|
existingBaseURLsListBox.addItem("-- none selected --", "noneSelected");
|
58
|
for(String repositoryURL : repositoryURLs)
|
59
|
existingBaseURLsListBox.addItem(repositoryURL, repositoryURL);
|
60
|
baseURLForm.add(existingBaseURLsListBox);
|
61
|
|
62
|
addManuallyRadio.setType(ButtonType.LINK);
|
63
|
addManuallyRadio.addStyleName("validationSetRadio");
|
64
|
addManuallyRadio.addChangeHandler(new ChangeHandler() {
|
65
|
@Override
|
66
|
public void onChange(ChangeEvent event) {
|
67
|
if(addManuallyRadio.getValue()) {
|
68
|
baseURLTextBox.setEnabled(true);
|
69
|
existingBaseURLsListBox.setEnabled(false);
|
70
|
}
|
71
|
}
|
72
|
});
|
73
|
baseURLForm.add(addManuallyRadio);
|
74
|
|
75
|
baseURLTextBox.setEnabled(false);
|
76
|
baseURLForm.add(baseURLTextBox);
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
public Widget asWidget() {
|
81
|
return selectRepositoryOrJournalWidgetPanel;
|
82
|
}
|
83
|
|
84
|
public String getSelectedBaseURL() {
|
85
|
|
86
|
errorLabel.setVisible(false);
|
87
|
|
88
|
if(chooseExistingBaseURLRadio.getValue()) {
|
89
|
if(!existingBaseURLsListBox.getSelectedValue().equals("noneSelected"))
|
90
|
return existingBaseURLsListBox.getSelectedValue();
|
91
|
else {
|
92
|
errorLabel.setText("You need to select a base URL");
|
93
|
errorLabel.setVisible(true);
|
94
|
}
|
95
|
} else {
|
96
|
if(baseURLTextBox.getValue()!=null && !baseURLTextBox.getValue().trim().isEmpty())
|
97
|
return baseURLTextBox.getValue().trim();
|
98
|
else {
|
99
|
errorLabel.setText("You need to enter a base URL");
|
100
|
errorLabel.setVisible(true);
|
101
|
}
|
102
|
}
|
103
|
|
104
|
return null;
|
105
|
}
|
106
|
}
|