1
|
package eu.dnetlib.client.widgets;
|
2
|
|
3
|
import com.github.gwtbootstrap.client.ui.*;
|
4
|
import com.github.gwtbootstrap.client.ui.constants.AlertType;
|
5
|
import com.github.gwtbootstrap.client.ui.constants.AlternateSize;
|
6
|
import com.google.gwt.user.client.Window;
|
7
|
import com.google.gwt.user.client.ui.FlowPanel;
|
8
|
import com.google.gwt.user.client.ui.IsWidget;
|
9
|
import com.google.gwt.user.client.ui.Widget;
|
10
|
import eu.dnetlib.goldoa.domain.Affiliation;
|
11
|
import eu.dnetlib.goldoa.domain.Author;
|
12
|
import eu.dnetlib.goldoa.domain.User;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.List;
|
16
|
|
17
|
/**
|
18
|
* Created by stefania on 3/9/15.
|
19
|
*/
|
20
|
public class AuthorInfoWidget implements IsWidget {
|
21
|
|
22
|
private FlowPanel authorInfoPanel = new FlowPanel();
|
23
|
|
24
|
private Alert errorLabel = new Alert();
|
25
|
|
26
|
private TextBox firstNameTextBox = new TextBox();
|
27
|
private TextBox lastNameTextBox = new TextBox();
|
28
|
private TextBox initialsTextBox = new TextBox();
|
29
|
private TextBox emailTextBox = new TextBox();
|
30
|
|
31
|
private AffiliationInfoWidget affiliationInfoWidget = new AffiliationInfoWidget();
|
32
|
|
33
|
private DeleteAuthorListener deleteAuthorListener;
|
34
|
|
35
|
public AuthorInfoWidget() {
|
36
|
|
37
|
authorInfoPanel.addStyleName("authorInfo");
|
38
|
authorInfoPanel.add(errorLabel);
|
39
|
|
40
|
errorLabel.addStyleName("alertLabel");
|
41
|
errorLabel.setType(AlertType.ERROR);
|
42
|
errorLabel.setHeading("Error! ");
|
43
|
errorLabel.setVisible(false);
|
44
|
errorLabel.setClose(false);
|
45
|
|
46
|
firstNameTextBox.setAlternateSize(AlternateSize.MEDIUM);
|
47
|
firstNameTextBox.setPlaceholder(" First name (*)");
|
48
|
firstNameTextBox.addStyleName("inlineBlock");
|
49
|
authorInfoPanel.add(firstNameTextBox);
|
50
|
|
51
|
initialsTextBox.setAlternateSize(AlternateSize.MINI);
|
52
|
initialsTextBox.setPlaceholder(" Initials");
|
53
|
initialsTextBox.addStyleName("inlineBlock");
|
54
|
authorInfoPanel.add(initialsTextBox);
|
55
|
|
56
|
lastNameTextBox.setAlternateSize(AlternateSize.MEDIUM);
|
57
|
lastNameTextBox.setPlaceholder(" Last name (*)");
|
58
|
lastNameTextBox.addStyleName("inlineBlock");
|
59
|
authorInfoPanel.add(lastNameTextBox);
|
60
|
|
61
|
emailTextBox.setAlternateSize(AlternateSize.XXLARGE);
|
62
|
emailTextBox.setPlaceholder(" E-mail Address");
|
63
|
authorInfoPanel.add(emailTextBox);
|
64
|
|
65
|
AffiliationInfoWidget.DeleteAffiliationListener deleteAffiliationListener = new AffiliationInfoWidget.DeleteAffiliationListener() {
|
66
|
@Override
|
67
|
public void deleteAffiliation() {
|
68
|
if(deleteAuthorListener!=null)
|
69
|
deleteAuthorListener.removeAuthor();
|
70
|
}
|
71
|
};
|
72
|
affiliationInfoWidget.setDeleteAffiliationListener(deleteAffiliationListener);
|
73
|
authorInfoPanel.add(affiliationInfoWidget.asWidget());
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public Widget asWidget() {
|
78
|
return authorInfoPanel;
|
79
|
}
|
80
|
|
81
|
public interface DeleteAuthorListener {
|
82
|
public void removeAuthor();
|
83
|
}
|
84
|
|
85
|
public void setDeleteAuthorListener(DeleteAuthorListener deleteAuthorListener) {
|
86
|
this.deleteAuthorListener = deleteAuthorListener;
|
87
|
}
|
88
|
|
89
|
public Author getAuthor() {
|
90
|
|
91
|
if(isComplete()) {
|
92
|
Author author = new Author();
|
93
|
author.setFirstname(firstNameTextBox.getValue().trim());
|
94
|
author.setInitials(initialsTextBox.getValue().trim());
|
95
|
author.setLastname(lastNameTextBox.getValue().trim());
|
96
|
author.setEmail(emailTextBox.getValue().trim());
|
97
|
|
98
|
if(affiliationInfoWidget.getAffiliation()!=null) {
|
99
|
author.setOrganization(affiliationInfoWidget.getAffiliation().getOrganization());
|
100
|
if (affiliationInfoWidget.getAffiliation().getDepartment() != null && !affiliationInfoWidget.getAffiliation().getDepartment().equals(""))
|
101
|
author.setDepartment(affiliationInfoWidget.getAffiliation().getDepartment());
|
102
|
}
|
103
|
return author;
|
104
|
}
|
105
|
|
106
|
return null;
|
107
|
}
|
108
|
|
109
|
private boolean isComplete() {
|
110
|
|
111
|
if(!firstNameTextBox.getValue().trim().equals("") && !lastNameTextBox.getValue().trim().equals(""))
|
112
|
return true;
|
113
|
|
114
|
return false;
|
115
|
}
|
116
|
|
117
|
public void loadAuthor(Author author) {
|
118
|
|
119
|
if(author!=null) {
|
120
|
if(author.getFirstname()!=null)
|
121
|
firstNameTextBox.setValue(author.getFirstname());
|
122
|
if(author.getLastname()!=null)
|
123
|
lastNameTextBox.setValue(author.getLastname());
|
124
|
if(author.getInitials()!=null)
|
125
|
initialsTextBox.setValue(author.getInitials());
|
126
|
if(author.getEmail()!=null)
|
127
|
emailTextBox.setValue(author.getEmail());
|
128
|
}
|
129
|
|
130
|
if(author != null && author.getOrganization()!=null) {
|
131
|
Affiliation affiliation = new Affiliation();
|
132
|
affiliation.setOrganization(author.getOrganization());
|
133
|
affiliation.setDepartment(author.getDepartment());
|
134
|
affiliationInfoWidget.loadAffiliation(affiliation);
|
135
|
}
|
136
|
}
|
137
|
|
138
|
public boolean hasEmailCompleted() {
|
139
|
|
140
|
if(!emailTextBox.getValue().trim().equals(""))
|
141
|
return true;
|
142
|
|
143
|
return false;
|
144
|
}
|
145
|
}
|