1
|
package eu.dnetlib.client.fundingrequest.newrequest.publicationstep;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.Alert;
|
4
|
import com.github.gwtbootstrap.client.ui.Form;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
6
|
import com.github.gwtbootstrap.client.ui.constants.FormType;
|
7
|
import com.google.gwt.core.client.GWT;
|
8
|
import com.google.gwt.user.client.ui.FlowPanel;
|
9
|
import com.google.gwt.user.client.ui.IsWidget;
|
10
|
import com.google.gwt.user.client.ui.Widget;
|
11
|
import eu.dnetlib.client.GoldOAConstants;
|
12
|
import eu.dnetlib.client.widgets.AutoCompleteWidget;
|
13
|
import eu.dnetlib.client.widgets.FormFieldSet;
|
14
|
import eu.dnetlib.goldoa.domain.Publisher;
|
15
|
import eu.dnetlib.goldoa.domain.Vocabulary;
|
16
|
|
17
|
/**
|
18
|
* Created by stefania on 3/11/15.
|
19
|
*/
|
20
|
public class PublisherInfoStep implements IsWidget {
|
21
|
|
22
|
private FlowPanel publisherInfoStepPanel = new FlowPanel();
|
23
|
|
24
|
private Alert errorLabel = new Alert();
|
25
|
|
26
|
private Form publisherAutoCompleteForm = new Form();
|
27
|
private AutoCompleteWidget publisherAutoComplete = new AutoCompleteWidget("publisher", "Search or insert publisher's name...");
|
28
|
|
29
|
private Vocabulary publisher = null;
|
30
|
|
31
|
private GoldOAConstants goldOAConstants = GWT.create(GoldOAConstants.class);
|
32
|
|
33
|
public PublisherInfoStep() {
|
34
|
|
35
|
errorLabel.addStyleName("alertLabel");
|
36
|
errorLabel.setType(AlertType.ERROR);
|
37
|
errorLabel.setVisible(false);
|
38
|
errorLabel.setClose(false);
|
39
|
|
40
|
publisherAutoCompleteForm.setType(FormType.HORIZONTAL);
|
41
|
publisherAutoCompleteForm.addStyleName("publisherAutoCompleteForm");
|
42
|
|
43
|
publisherInfoStepPanel.add(errorLabel);
|
44
|
publisherInfoStepPanel.add(publisherAutoCompleteForm);
|
45
|
|
46
|
AutoCompleteWidget.AutoCompleteListener publisherAutoCompleteListener = new AutoCompleteWidget.AutoCompleteListener() {
|
47
|
@Override
|
48
|
public void valueSelected(Vocabulary vocabulary) {
|
49
|
publisher = vocabulary;
|
50
|
}
|
51
|
};
|
52
|
publisherAutoComplete.setAutoCompleteListener(publisherAutoCompleteListener);
|
53
|
|
54
|
publisherAutoCompleteForm.add(new FormFieldSet("Publisher name (*)", publisherAutoComplete.asWidget()));
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
public Widget asWidget() {
|
59
|
return publisherInfoStepPanel;
|
60
|
}
|
61
|
|
62
|
public Publisher getPublisher() {
|
63
|
|
64
|
errorLabel.setVisible(false);
|
65
|
|
66
|
if(!publisherAutoComplete.getValue().equals("")) {
|
67
|
|
68
|
Publisher publisher = new Publisher();
|
69
|
if(this.publisher!=null && this.publisher.getName().equals(publisherAutoComplete.getValue())) {
|
70
|
publisher.setId(this.publisher.getId());
|
71
|
} else {
|
72
|
publisher.setName(publisherAutoComplete.getValue());
|
73
|
}
|
74
|
return publisher;
|
75
|
} else {
|
76
|
errorLabel.setText(goldOAConstants.publisherNotSelectedError());
|
77
|
errorLabel.setVisible(true);
|
78
|
}
|
79
|
|
80
|
return null;
|
81
|
}
|
82
|
|
83
|
public void clear() {
|
84
|
|
85
|
errorLabel.setVisible(false);
|
86
|
|
87
|
publisher = null;
|
88
|
publisherAutoComplete.setValue("");
|
89
|
}
|
90
|
|
91
|
public void loadPublisherInfo(Publisher publisher) {
|
92
|
|
93
|
this.publisher = null;
|
94
|
publisherAutoComplete.setValue(publisher.getName());
|
95
|
}
|
96
|
}
|